Skip to content

Commit 84e8719

Browse files
kovalev0gregkh
authored andcommitted
hfs/hfsplus: fix slab-out-of-bounds in hfs_bnode_read_key
commit bb5e07c upstream. Syzbot reported an issue in hfs subsystem: BUG: KASAN: slab-out-of-bounds in memcpy_from_page include/linux/highmem.h:423 [inline] BUG: KASAN: slab-out-of-bounds in hfs_bnode_read fs/hfs/bnode.c:35 [inline] BUG: KASAN: slab-out-of-bounds in hfs_bnode_read_key+0x314/0x450 fs/hfs/bnode.c:70 Write of size 94 at addr ffff8880123cd100 by task syz-executor237/5102 Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:377 [inline] print_report+0x169/0x550 mm/kasan/report.c:488 kasan_report+0x143/0x180 mm/kasan/report.c:601 kasan_check_range+0x282/0x290 mm/kasan/generic.c:189 __asan_memcpy+0x40/0x70 mm/kasan/shadow.c:106 memcpy_from_page include/linux/highmem.h:423 [inline] hfs_bnode_read fs/hfs/bnode.c:35 [inline] hfs_bnode_read_key+0x314/0x450 fs/hfs/bnode.c:70 hfs_brec_insert+0x7f3/0xbd0 fs/hfs/brec.c:159 hfs_cat_create+0x41d/0xa50 fs/hfs/catalog.c:118 hfs_mkdir+0x6c/0xe0 fs/hfs/dir.c:232 vfs_mkdir+0x2f9/0x4f0 fs/namei.c:4257 do_mkdirat+0x264/0x3a0 fs/namei.c:4280 __do_sys_mkdir fs/namei.c:4300 [inline] __se_sys_mkdir fs/namei.c:4298 [inline] __x64_sys_mkdir+0x6c/0x80 fs/namei.c:4298 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fbdd6057a99 Add a check for key length in hfs_bnode_read_key to prevent out-of-bounds memory access. If the key length is invalid, the key buffer is cleared, improving stability and reliability. Fixes: 1da177e ("Linux-2.6.12-rc2") Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=5f3a973ed3dfb85a6683 Cc: [email protected] Signed-off-by: Vasiliy Kovalev <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Cengiz Can <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8132682 commit 84e8719

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

fs/hfs/bnode.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off)
6767
else
6868
key_len = tree->max_key_len + 1;
6969

70+
if (key_len > sizeof(hfs_btree_key) || key_len < 1) {
71+
memset(key, 0, sizeof(hfs_btree_key));
72+
pr_err("hfs: Invalid key length: %d\n", key_len);
73+
return;
74+
}
75+
7076
hfs_bnode_read(node, key, off, key_len);
7177
}
7278

fs/hfsplus/bnode.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off)
6767
else
6868
key_len = tree->max_key_len + 2;
6969

70+
if (key_len > sizeof(hfsplus_btree_key) || key_len < 1) {
71+
memset(key, 0, sizeof(hfsplus_btree_key));
72+
pr_err("hfsplus: Invalid key length: %d\n", key_len);
73+
return;
74+
}
75+
7076
hfs_bnode_read(node, key, off, key_len);
7177
}
7278

0 commit comments

Comments
 (0)