dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0445-fs-jfs-Catch-infinite-recursion.patch

468bd4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
468bd4
From: Daniel Axtens <dja@axtens.net>
468bd4
Date: Mon, 18 Jan 2021 15:47:24 +1100
468bd4
Subject: [PATCH] fs/jfs: Catch infinite recursion
468bd4
468bd4
It's possible with a fuzzed filesystem for JFS to keep getblk()-ing
468bd4
the same data over and over again, leading to stack exhaustion.
468bd4
468bd4
Check if we'd be calling the function with exactly the same data as
468bd4
was passed in, and if so abort.
468bd4
468bd4
I'm not sure what the performance impact of this is and am open to
468bd4
better ideas.
468bd4
468bd4
Signed-off-by: Daniel Axtens <dja@axtens.net>
468bd4
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
468bd4
---
468bd4
 grub-core/fs/jfs.c | 11 ++++++++++-
468bd4
 1 file changed, 10 insertions(+), 1 deletion(-)
468bd4
468bd4
diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c
468bd4
index 6e81f37da6c..20d966abfc0 100644
468bd4
--- a/grub-core/fs/jfs.c
468bd4
+++ b/grub-core/fs/jfs.c
468bd4
@@ -304,7 +304,16 @@ getblk (struct grub_jfs_treehead *treehead,
468bd4
 			   << (grub_le_to_cpu16 (data->sblock.log2_blksz)
468bd4
 			       - GRUB_DISK_SECTOR_BITS), 0,
468bd4
 			   sizeof (*tree), (char *) tree))
468bd4
-	ret = getblk (&tree->treehead, &tree->extents[0], 254, data, blk);
468bd4
+	{
468bd4
+	  if (grub_memcmp (&tree->treehead, treehead, sizeof (struct grub_jfs_treehead)) ||
468bd4
+	      grub_memcmp (&tree->extents, extents, 254 * sizeof (struct grub_jfs_tree_extent)))
468bd4
+	    ret = getblk (&tree->treehead, &tree->extents[0], 254, data, blk);
468bd4
+	  else
468bd4
+	    {
468bd4
+	      grub_error (GRUB_ERR_BAD_FS, "jfs: infinite recursion detected");
468bd4
+	      ret = -1;
468bd4
+	    }
468bd4
+	}
468bd4
       grub_free (tree);
468bd4
       return ret;
468bd4
     }