dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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