nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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