1From 20ab8cb44bc140a1dedda82a3fccdd45e9bc6929 Mon Sep 17 00:00:00 2001 2From: Daniel Axtens <dja@axtens.net> 3Date: Mon, 18 Jan 2021 16:49:09 +1100 4Subject: [PATCH] fs/nilfs2: Reject too-large keys 5 6NILFS2 has up to 7 keys, per the data structure. Do not permit array 7indices in excess of that. 8 9This catches some OOB reads. I don't know how controllable the invalidly 10read data is or if that could be used later in the program. 11 12Signed-off-by: Daniel Axtens <dja@axtens.net> 13Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> 14Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com> 15--- 16 grub-core/fs/nilfs2.c | 7 ++++++- 17 1 file changed, 6 insertions(+), 1 deletion(-) 18 19diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c 20index 7ed148d..fee2242 100644 21--- a/grub-core/fs/nilfs2.c 22+++ b/grub-core/fs/nilfs2.c 23@@ -569,6 +569,11 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data, 24 static inline grub_uint64_t 25 grub_nilfs2_direct_lookup (struct grub_nilfs2_inode *inode, grub_uint64_t key) 26 { 27+ if (1 + key > 6) 28+ { 29+ grub_error (GRUB_ERR_BAD_FS, "key is too large"); 30+ return 0xffffffffffffffff; 31+ } 32 return grub_le_to_cpu64 (inode->i_bmap[1 + key]); 33 } 34 35@@ -584,7 +589,7 @@ grub_nilfs2_bmap_lookup (struct grub_nilfs2_data *data, 36 { 37 grub_uint64_t ptr; 38 ptr = grub_nilfs2_direct_lookup (inode, key); 39- if (need_translate) 40+ if (ptr != ((grub_uint64_t) 0xffffffffffffffff) && need_translate) 41 ptr = grub_nilfs2_dat_translate (data, ptr); 42 return ptr; 43 } 44-- 452.14.2 46 47