Blame SOURCES/0401-fs-hfsplus-Don-t-fetch-a-key-beyond-the-end-of-the-n.patch

b1bcb2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b1bcb2
From: Daniel Axtens <dja@axtens.net>
b1bcb2
Date: Fri, 22 Jan 2021 18:13:56 +1100
b1bcb2
Subject: [PATCH] fs/hfsplus: Don't fetch a key beyond the end of the node
b1bcb2
b1bcb2
Otherwise you get a wild pointer, leading to a bunch of invalid reads.
b1bcb2
Check it falls inside the given node.
b1bcb2
b1bcb2
Signed-off-by: Daniel Axtens <dja@axtens.net>
b1bcb2
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
b1bcb2
---
b1bcb2
 grub-core/fs/hfsplus.c | 4 ++++
b1bcb2
 1 file changed, 4 insertions(+)
b1bcb2
b1bcb2
diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c
b1bcb2
index 7ae66967b3a..d958c457e87 100644
b1bcb2
--- a/grub-core/fs/hfsplus.c
b1bcb2
+++ b/grub-core/fs/hfsplus.c
b1bcb2
@@ -629,6 +629,10 @@ grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree,
b1bcb2
 	      pointer = ((char *) currkey
b1bcb2
 			 + grub_be_to_cpu16 (currkey->keylen)
b1bcb2
 			 + 2);
b1bcb2
+
b1bcb2
+	      if ((char *) pointer > node + btree->nodesize - 2)
b1bcb2
+		return grub_error (GRUB_ERR_BAD_FS, "HFS+ key beyond end of node");
b1bcb2
+
b1bcb2
 	      currnode = grub_be_to_cpu32 (grub_get_unaligned32 (pointer));
b1bcb2
 	      match = 1;
b1bcb2
 	    }