linux-stable/fs/f2fs
Chao Yu 27a1306384 f2fs: fix to avoid out-of-bounds memory access
commit b862676e37 upstream.

butt3rflyh4ck <butterflyhuangxx@gmail.com> reported a bug found by
syzkaller fuzzer with custom modifications in 5.12.0-rc3+ [1]:

 dump_stack+0xfa/0x151 lib/dump_stack.c:120
 print_address_description.constprop.0.cold+0x82/0x32c mm/kasan/report.c:232
 __kasan_report mm/kasan/report.c:399 [inline]
 kasan_report.cold+0x7c/0xd8 mm/kasan/report.c:416
 f2fs_test_bit fs/f2fs/f2fs.h:2572 [inline]
 current_nat_addr fs/f2fs/node.h:213 [inline]
 get_next_nat_page fs/f2fs/node.c:123 [inline]
 __flush_nat_entry_set fs/f2fs/node.c:2888 [inline]
 f2fs_flush_nat_entries+0x258e/0x2960 fs/f2fs/node.c:2991
 f2fs_write_checkpoint+0x1372/0x6a70 fs/f2fs/checkpoint.c:1640
 f2fs_issue_checkpoint+0x149/0x410 fs/f2fs/checkpoint.c:1807
 f2fs_sync_fs+0x20f/0x420 fs/f2fs/super.c:1454
 __sync_filesystem fs/sync.c:39 [inline]
 sync_filesystem fs/sync.c:67 [inline]
 sync_filesystem+0x1b5/0x260 fs/sync.c:48
 generic_shutdown_super+0x70/0x370 fs/super.c:448
 kill_block_super+0x97/0xf0 fs/super.c:1394

The root cause is, if nat entry in checkpoint journal area is corrupted,
e.g. nid of journalled nat entry exceeds max nid value, during checkpoint,
once it tries to flush nat journal to NAT area, get_next_nat_page() may
access out-of-bounds memory on nat_bitmap due to it uses wrong nid value
as bitmap offset.

[1] https://lore.kernel.org/lkml/CAFcO6XOMWdr8pObek6eN6-fs58KG9doRFadgJj-FnF-1x43s2g@mail.gmail.com/T/#u

Reported-and-tested-by: butt3rflyh4ck <butterflyhuangxx@gmail.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-05-11 14:04:14 +02:00
..
acl.c f2fs: Replace spaces with tab 2019-05-08 21:23:11 -07:00
acl.h f2fs: add SPDX license identifiers 2018-09-12 13:07:10 -07:00
checkpoint.c f2fs: avoid race condition for shrinker count 2021-01-06 14:48:40 +01:00
data.c f2fs: fix a wrong condition in __submit_bio 2021-03-04 10:26:24 +01:00
debug.c f2fs: avoid race condition for shrinker count 2021-01-06 14:48:40 +01:00
dir.c f2fs: fix uninit-value in f2fs_lookup 2020-11-05 11:43:13 +01:00
extent_cache.c f2fs: introduce f2fs_<level> macros to wrap f2fs_printk() 2019-07-02 15:40:40 -07:00
f2fs.h f2fs: avoid race condition for shrinker count 2021-01-06 14:48:40 +01:00
file.c f2fs: fix out-of-repair __setattr_copy() 2021-03-04 10:26:50 +01:00
gc.c f2fs: stop GC when the victim becomes fully valid 2020-10-01 13:17:21 +02:00
gc.h f2fs: add SPDX license identifiers 2018-09-12 13:07:10 -07:00
hash.c f2fs: Support case-insensitive file name lookups 2019-08-23 07:57:13 -07:00
inline.c f2fs: fix to avoid inconsistent quota data 2021-03-04 10:26:24 +01:00
inode.c f2fs: fix to update time in lazytime mode 2020-01-04 19:16:31 +01:00
Kconfig f2fs: Add a small clarification to CONFIG_FS_F2FS_FS_SECURITY 2019-09-16 08:38:48 -07:00
Makefile f2fs: add fs-verity support 2019-08-12 19:33:51 -07:00
namei.c f2fs: fix to set/clear I_LINKABLE under i_lock 2021-03-07 12:20:46 +01:00
node.c f2fs: fix to avoid out-of-bounds memory access 2021-05-11 14:04:14 +02:00
node.h f2fs: avoid race condition for shrinker count 2021-01-06 14:48:40 +01:00
recovery.c f2fs: fix error path in do_recover_data() 2020-09-03 11:26:45 +02:00
segment.c f2fs: handle errors of f2fs_get_meta_page_nofail 2020-11-05 11:43:14 +01:00
segment.h f2fs: handle unallocated section and zone on pinned/atgc 2021-03-07 12:20:46 +01:00
shrinker.c f2fs: avoid race condition for shrinker count 2021-01-06 14:48:40 +01:00
super.c f2fs: fix shift-out-of-bounds in sanity_check_raw_super() 2021-01-06 14:48:38 +01:00
sysfs.c f2fs: wait for sysfs kobject removal before freeing f2fs_sb_info 2020-10-29 09:57:52 +01:00
trace.c f2fs: do not use mutex lock in atomic context 2019-03-05 19:58:06 -08:00
trace.h f2fs: add SPDX license identifiers 2018-09-12 13:07:10 -07:00
verity.c f2fs: add fs-verity support 2019-08-12 19:33:51 -07:00
xattr.c f2fs: fix to avoid memory leakage in f2fs_listxattr 2020-04-29 16:32:55 +02:00
xattr.h f2fs: add fs-verity support 2019-08-12 19:33:51 -07:00