Blame SOURCES/0536-fs-f2fs-Do-not-copy-file-names-that-are-too-long.patch

0ccc47
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
0ccc47
From: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
0ccc47
Date: Wed, 6 Apr 2022 18:17:43 +0530
0ccc47
Subject: [PATCH] fs/f2fs: Do not copy file names that are too long
0ccc47
0ccc47
A corrupt f2fs file system might specify a name length which is greater
0ccc47
than the maximum name length supported by the GRUB f2fs driver.
0ccc47
0ccc47
We will allocate enough memory to store the overly long name, but there
0ccc47
are only F2FS_NAME_LEN bytes in the source, so we would read past the end
0ccc47
of the source.
0ccc47
0ccc47
While checking directory entries, do not copy a file name with an invalid
0ccc47
length.
0ccc47
0ccc47
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
0ccc47
Signed-off-by: Daniel Axtens <dja@axtens.net>
0ccc47
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
0ccc47
(cherry picked from commit 9a891f638509e031d322c94e3cbcf38d36f3993a)
0ccc47
(cherry picked from commit 13f9160ae0d2806baed459884999356817096cd7)
0ccc47
(cherry picked from commit a48ba4d48b3c66431e6bbeb386078efc6602110c)
0ccc47
---
0ccc47
 grub-core/fs/f2fs.c | 4 ++++
0ccc47
 1 file changed, 4 insertions(+)
0ccc47
0ccc47
diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c
0ccc47
index 33e565b180..07ea34196c 100644
0ccc47
--- a/grub-core/fs/f2fs.c
0ccc47
+++ b/grub-core/fs/f2fs.c
0ccc47
@@ -998,6 +998,10 @@ grub_f2fs_check_dentries (struct grub_f2fs_dir_iter_ctx *ctx)
0ccc47
 
0ccc47
       ftype = ctx->dentry[i].file_type;
0ccc47
       name_len = grub_le_to_cpu16 (ctx->dentry[i].name_len);
0ccc47
+
0ccc47
+      if (name_len >= F2FS_NAME_LEN)
0ccc47
+        return 0;
0ccc47
+
0ccc47
       filename = grub_malloc (name_len + 1);
0ccc47
       if (!filename)
0ccc47
         return 0;