linux-stable/fs
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
..
9p
adfs
affs
afs afs: Fix server->active leak in afs_put_server 2022-11-30 10:02:37 -08:00
autofs
befs
bfs
btrfs btrfs: do not panic if we can't allocate a prealloc extent state 2022-12-31 13:32:58 +01:00
cachefiles
ceph
cifs cifs: don't leak -ENOMEM in smb2_open_file() 2022-12-31 13:32:56 +01:00
coda
configfs configfs: fix possible memory leak in configfs_create_dir() 2022-12-31 13:32:22 +01:00
cramfs
crypto
debugfs debugfs: fix error when writing negative value to atomic_t debugfs file 2022-12-31 13:31:58 +01:00
devpts
dlm
ecryptfs
efivarfs
efs
erofs erofs: validate the extent length for uncompressed pclusters 2022-12-31 13:31:59 +01:00
exfat
exportfs
ext2
ext4
f2fs f2fs: fix iostat parameter for discard 2022-12-31 13:32:38 +01:00
fat
freevxfs
fscache fscache: Fix oops due to race with cookie_lru and use_cookie 2022-12-07 11:49:18 -08:00
fuse fuse: lock inode unconditionally in fuse_fallocate() 2022-11-23 09:10:42 +01:00
gfs2 gfs2: Partially revert gfs2_inode_lookup change 2022-12-31 13:32:45 +01:00
hfs hfs: fix OOB Read in __hfs_brec_find 2022-12-31 13:32:58 +01:00
hfsplus
hostfs
hpfs
hugetlbfs
iomap
isofs
jbd2
jffs2
jfs fs: jfs: fix shift-out-of-bounds in dbDiscardAG 2022-12-31 13:32:57 +01:00
kernfs
ksmbd ksmbd: Fix resource leak in ksmbd_session_rpc_open() 2022-12-31 13:32:42 +01:00
lockd lockd: set other missing fields when unlocking files 2022-12-31 13:32:00 +01:00
minix
netfs
nfs NFSv4.x: Fail client initialisation if state manager thread can't run 2022-12-31 13:32:23 +01:00
nfs_common
nfsd nfsd: under NFSv4.1, fix double svc_xprt_put on rpc_create failure 2022-12-31 13:32:53 +01:00
nilfs2 nilfs2: fix shift-out-of-bounds due to too large exponent of block size 2022-12-31 13:32:58 +01:00
nls
notify
ntfs
ntfs3 fs/ntfs3: Fix slab-out-of-bounds read in ntfs_trim_fs 2022-12-31 13:32:49 +01:00
ocfs2 ocfs2: fix memory leak in ocfs2_mount_volume() 2022-12-31 13:31:58 +01:00
omfs
openpromfs
orangefs orangefs: Fix sysfs not cleanup when dev init failed 2022-12-31 13:32:37 +01:00
overlayfs ovl: remove privs in ovl_fallocate() 2022-12-31 13:31:54 +01:00
proc proc/meminfo: fix spacing in SecPageTables 2022-11-22 18:50:44 -08:00
pstore pstore: Avoid kcore oops by vmap()ing with VM_IOREMAP 2022-12-31 13:31:54 +01:00
qnx4
qnx6
quota
ramfs
reiserfs
romfs
smbfs_common
squashfs
sysfs
sysv fs: sysv: Fix sysv_nblocks() returns wrong value 2022-12-31 13:32:00 +01:00
tracefs
ubifs
udf udf: Avoid double brelse() in udf_rename() 2022-12-31 13:32:57 +01:00
ufs
unicode
vboxsf
verity
xfs
zonefs zonefs: Fix active zone accounting 2022-11-25 17:01:22 +09:00
aio.c
anon_inodes.c
attr.c
bad_inode.c
binfmt_elf.c
binfmt_elf_fdpic.c
binfmt_elf_test.c
binfmt_flat.c
binfmt_misc.c binfmt_misc: fix shift-out-of-bounds in check_special_flags 2022-12-31 13:32:57 +01:00
binfmt_script.c
buffer.c
char_dev.c chardev: fix error handling in cdev_device_add() 2022-12-31 13:32:41 +01:00
compat_binfmt_elf.c
coredump.c
d_path.c
dax.c
dcache.c
direct-io.c
drop_caches.c
eventfd.c
eventpoll.c
exec.c
fcntl.c
fhandle.c
file.c
file_table.c
filesystems.c
fs-writeback.c fs: do not update freeing inode i_io_list 2022-11-22 17:00:00 -05:00
fs_context.c
fs_parser.c
fs_pin.c
fs_struct.c
fs_types.c
fsopen.c
init.c
inode.c
internal.h
ioctl.c
Kconfig
Kconfig.binfmt
kernel_read_file.c
libfs.c libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value 2022-12-31 13:31:58 +01:00
locks.c
Makefile
mbcache.c
mount.h
mpage.c
namei.c
namespace.c
no-block.c
nsfs.c
open.c
pipe.c
pnode.c
pnode.h
posix_acl.c
proc_namespace.c
read_write.c vfs: fix copy_file_range() averts filesystem freeze protection 2022-11-25 00:52:28 -05:00
readdir.c
remap_range.c
select.c
seq_file.c
signalfd.c
splice.c
stack.c
stat.c
statfs.c
super.c
sync.c
sysctls.c
timerfd.c
userfaultfd.c
utimes.c
xattr.c fs: don't audit the capability check in simple_xattr_list() 2022-12-31 13:31:55 +01:00