linux/fs/hfs
ZhangPeng bfc9d8f27f hfs: fix OOB Read in __hfs_brec_find
[ Upstream commit 8d824e69d9 ]

Syzbot reported a OOB read bug:

==================================================================
BUG: KASAN: slab-out-of-bounds in hfs_strcmp+0x117/0x190
fs/hfs/string.c:84
Read of size 1 at addr ffff88807eb62c4e by task kworker/u4:1/11
CPU: 1 PID: 11 Comm: kworker/u4:1 Not tainted
6.1.0-rc6-syzkaller-00308-g644e9524388a #0
Workqueue: writeback wb_workfn (flush-7:0)
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106
 print_address_description+0x74/0x340 mm/kasan/report.c:284
 print_report+0x107/0x1f0 mm/kasan/report.c:395
 kasan_report+0xcd/0x100 mm/kasan/report.c:495
 hfs_strcmp+0x117/0x190 fs/hfs/string.c:84
 __hfs_brec_find+0x213/0x5c0 fs/hfs/bfind.c:75
 hfs_brec_find+0x276/0x520 fs/hfs/bfind.c:138
 hfs_write_inode+0x34c/0xb40 fs/hfs/inode.c:462
 write_inode fs/fs-writeback.c:1440 [inline]

If the input inode of hfs_write_inode() is incorrect:
struct inode
  struct hfs_inode_info
    struct hfs_cat_key
      struct hfs_name
        u8 len # len is greater than HFS_NAMELEN(31) which is the
maximum length of an HFS filename

OOB read occurred:
hfs_write_inode()
  hfs_brec_find()
    __hfs_brec_find()
      hfs_cat_keycmp()
        hfs_strcmp() # OOB read occurred due to len is too large

Fix this by adding a Check on len in hfs_write_inode() before calling
hfs_brec_find().

Link: https://lkml.kernel.org/r/20221130065959.2168236-1-zhangpeng362@huawei.com
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
Reported-by: <syzbot+e836ff7133ac02be825f@syzkaller.appspotmail.com>
Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Nanyong Sun <sunnanyong@huawei.com>
Cc: Viacheslav Dubeyko <slava@dubeyko.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-12-31 13:32:58 +01:00
..
attr.c acl: handle idmapped mounts 2021-01-24 14:27:17 +01:00
bfind.c hfs: add lock nesting notation to hfs_find_init 2021-07-15 10:13:49 -07:00
bitmap.c hfs/hfsplus: convert dprint to hfs_dbg 2013-04-30 17:04:05 -07:00
bnode.c hfs: replace kmap() with kmap_local_page() in bnode.c 2022-09-11 21:55:08 -07:00
brec.c hfs: fix BUG on bnode parent update 2018-10-31 08:54:13 -07:00
btree.c hfs: replace kmap() with kmap_local_page() in btree.c 2022-09-11 21:55:09 -07:00
btree.h hfs: add lock nesting notation to hfs_find_init 2021-07-15 10:13:49 -07:00
catalog.c hfs: prevent btree data loss on ENOSPC 2018-10-31 08:54:13 -07:00
dir.c fs: make helpers idmap mount aware 2021-01-24 14:27:20 +01:00
extent.c hfs: Call hfs_write_begin() and generic_write_end() directly 2022-05-08 14:45:56 -04:00
hfs_fs.h hfs: Call hfs_write_begin() and generic_write_end() directly 2022-05-08 14:45:56 -04:00
hfs.h
inode.c hfs: fix OOB Read in __hfs_brec_find 2022-12-31 13:32:58 +01:00
Kconfig docs: filesystems: fix renamed references 2020-04-20 15:45:22 -06:00
Makefile treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
mdb.c block: remove genhd.h 2022-02-02 07:49:59 -07:00
part_tbl.c
string.c get rid of 'parent' argument of ->d_compare() 2016-07-31 16:37:25 -04:00
super.c fs: allocate inode by using alloc_inode_sb() 2022-03-22 15:57:03 -07:00
sysdep.c VFS: normal filesystems (and lustre): d_inode() annotations 2015-04-15 15:06:57 -04:00
trans.c hfs: Fix OOB Write in hfs_asc2mac 2022-12-31 13:32:00 +01:00