Blame SOURCES/0438-fs-fshelp-Catch-impermissibly-large-block-sizes-in-r.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Daniel Axtens <dja@axtens.net>
9723a8
Date: Mon, 18 Jan 2021 11:46:39 +1100
9723a8
Subject: [PATCH] fs/fshelp: Catch impermissibly large block sizes in read
9723a8
 helper
9723a8
9723a8
A fuzzed HFS+ filesystem had log2blocksize = 22. This gave
9723a8
log2blocksize + GRUB_DISK_SECTOR_BITS = 31. 1 << 31 = 0x80000000,
9723a8
which is -1 as an int. This caused some wacky behavior later on in
9723a8
the function, leading to out-of-bounds writes on the destination buffer.
9723a8
9723a8
Catch log2blocksize + GRUB_DISK_SECTOR_BITS >= 31. We could be stricter,
9723a8
but this is the minimum that will prevent integer size weirdness.
9723a8
9723a8
Signed-off-by: Daniel Axtens <dja@axtens.net>
9723a8
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9723a8
---
9723a8
 grub-core/fs/fshelp.c | 12 ++++++++++++
9723a8
 1 file changed, 12 insertions(+)
9723a8
9723a8
diff --git a/grub-core/fs/fshelp.c b/grub-core/fs/fshelp.c
9723a8
index 4c902adf381..a2d0d297a52 100644
9723a8
--- a/grub-core/fs/fshelp.c
9723a8
+++ b/grub-core/fs/fshelp.c
9723a8
@@ -362,6 +362,18 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node,
9723a8
   grub_disk_addr_t i, blockcnt;
9723a8
   int blocksize = 1 << (log2blocksize + GRUB_DISK_SECTOR_BITS);
9723a8
 
9723a8
+  /*
9723a8
+   * Catch blatantly invalid log2blocksize. We could be a lot stricter, but
9723a8
+   * this is the most permissive we can be before we start to see integer
9723a8
+   * overflow/underflow issues.
9723a8
+   */
9723a8
+  if (log2blocksize + GRUB_DISK_SECTOR_BITS >= 31)
9723a8
+    {
9723a8
+      grub_error (GRUB_ERR_OUT_OF_RANGE,
9723a8
+		  N_("blocksize too large"));
9723a8
+      return -1;
9723a8
+    }
9723a8
+
9723a8
   if (pos > filesize)
9723a8
     {
9723a8
       grub_error (GRUB_ERR_OUT_OF_RANGE,