Blame SOURCES/0446-fs-nilfs2-Reject-too-large-keys.patch

468bd4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
468bd4
From: Daniel Axtens <dja@axtens.net>
468bd4
Date: Mon, 18 Jan 2021 16:49:09 +1100
468bd4
Subject: [PATCH] fs/nilfs2: Reject too-large keys
468bd4
468bd4
NILFS2 has up to 7 keys, per the data structure. Do not permit array
468bd4
indices in excess of that.
468bd4
468bd4
This catches some OOB reads. I don't know how controllable the invalidly
468bd4
read data is or if that could be used later in the program.
468bd4
468bd4
Signed-off-by: Daniel Axtens <dja@axtens.net>
468bd4
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
468bd4
---
468bd4
 grub-core/fs/nilfs2.c | 7 ++++++-
468bd4
 1 file changed, 6 insertions(+), 1 deletion(-)
468bd4
468bd4
diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c
f6e916
index 598a2a55b..61e8af9ff 100644
468bd4
--- a/grub-core/fs/nilfs2.c
468bd4
+++ b/grub-core/fs/nilfs2.c
468bd4
@@ -569,6 +569,11 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data,
468bd4
 static inline grub_uint64_t
468bd4
 grub_nilfs2_direct_lookup (struct grub_nilfs2_inode *inode, grub_uint64_t key)
468bd4
 {
468bd4
+  if (1 + key > 6)
468bd4
+    {
468bd4
+      grub_error (GRUB_ERR_BAD_FS, "key is too large");
468bd4
+      return 0xffffffffffffffff;
468bd4
+    }
468bd4
   return grub_le_to_cpu64 (inode->i_bmap[1 + key]);
468bd4
 }
468bd4
 
468bd4
@@ -584,7 +589,7 @@ grub_nilfs2_bmap_lookup (struct grub_nilfs2_data *data,
468bd4
     {
468bd4
       grub_uint64_t ptr;
468bd4
       ptr = grub_nilfs2_direct_lookup (inode, key);
468bd4
-      if (need_translate)
468bd4
+      if (ptr != ((grub_uint64_t) 0xffffffffffffffff) && need_translate)
468bd4
 	ptr = grub_nilfs2_dat_translate (data, ptr);
468bd4
       return ptr;
468bd4
     }