android_kernel_oneplus_msm8998/fs/f2fs
Chao Yu 9e4ed17b94 f2fs: fix to do sanity check on valid block count of segment
[ Upstream commit e95bcdb2fefa129f37bd9035af1d234ca92ee4ef ]

As Jungyeon reported in bugzilla:

https://bugzilla.kernel.org/show_bug.cgi?id=203233

- Overview
When mounting the attached crafted image and running program, following errors are reported.
Additionally, it hangs on sync after running program.

The image is intentionally fuzzed from a normal f2fs image for testing.
Compile options for F2FS are as follows.
CONFIG_F2FS_FS=y
CONFIG_F2FS_STAT_FS=y
CONFIG_F2FS_FS_XATTR=y
CONFIG_F2FS_FS_POSIX_ACL=y
CONFIG_F2FS_CHECK_FS=y

- Reproduces
cc poc_13.c
mkdir test
mount -t f2fs tmp.img test
cp a.out test
cd test
sudo ./a.out
sync

- Kernel messages
 F2FS-fs (sdb): Bitmap was wrongly set, blk:4608
 kernel BUG at fs/f2fs/segment.c:2102!
 RIP: 0010:update_sit_entry+0x394/0x410
 Call Trace:
  f2fs_allocate_data_block+0x16f/0x660
  do_write_page+0x62/0x170
  f2fs_do_write_node_page+0x33/0xa0
  __write_node_page+0x270/0x4e0
  f2fs_sync_node_pages+0x5df/0x670
  f2fs_write_checkpoint+0x372/0x1400
  f2fs_sync_fs+0xa3/0x130
  f2fs_do_sync_file+0x1a6/0x810
  do_fsync+0x33/0x60
  __x64_sys_fsync+0xb/0x10
  do_syscall_64+0x43/0xf0
  entry_SYSCALL_64_after_hwframe+0x44/0xa9

sit.vblocks and sum valid block count in sit.valid_map may be
inconsistent, segment w/ zero vblocks will be treated as free
segment, while allocating in free segment, we may allocate a
free block, if its bitmap is valid previously, it can cause
kernel crash due to bitmap verification failure.

Anyway, to avoid further serious metadata inconsistence and
corruption, it is necessary and worth to detect SIT
inconsistence. So let's enable check_block_count() to verify
vblocks and valid_map all the time rather than do it only
CONFIG_F2FS_CHECK_FS is enabled.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-06-22 08:18:19 +02:00
..
acl.c f2fs: fix wrong return value of f2fs_acl_create 2019-02-20 10:13:06 +01:00
acl.h
checkpoint.c f2fs: fix invalid memory access 2019-01-26 09:42:48 +01:00
crypto.c f2fs crypto: replace some BUG_ON()'s with error checks 2017-10-27 10:23:18 +02:00
crypto_fname.c f2fs crypto: replace some BUG_ON()'s with error checks 2017-10-27 10:23:18 +02:00
crypto_key.c fscrypt: fix dereference of NULL user_key_payload 2017-10-27 10:23:18 +02:00
crypto_policy.c
data.c f2fs: fix to do sanity check with block address in main area v2 2019-01-26 09:42:48 +01:00
debug.c
dir.c f2fs: fix to convert inline directory correctly 2019-01-26 09:42:45 +01:00
extent_cache.c f2fs: fix a bug caused by NULL extent tree 2018-03-03 10:19:41 +01:00
f2fs.h f2fs: fix to do sanity check with block address in main area 2019-01-26 09:42:48 +01:00
f2fs_crypto.h
file.c f2fs: move dir data flush to write checkpoint process 2019-02-20 10:13:06 +01:00
gc.c f2fs: relax node version check for victim data in gc 2018-03-22 09:23:22 +01:00
gc.h
hash.c
inline.c f2fs: fix to do sanity check with reserved blkaddr of inline inode 2019-01-26 09:42:48 +01:00
inode.c f2fs: fix to do sanity check with block address in main area v2 2019-01-26 09:42:48 +01:00
Kconfig
Makefile
namei.c do d_instantiate/unlock_new_inode combinations safely 2018-05-30 07:48:52 +02:00
node.c f2fs: read page index before freeing 2019-02-06 19:43:05 +01:00
node.h f2fs: use crc and cp version to determine roll-forward recovery 2019-01-26 09:42:46 +01:00
recovery.c f2fs: fix to avoid panic in do_recover_data() 2019-06-22 08:18:19 +02:00
segment.c f2fs: introduce and spread verify_blkaddr 2019-01-26 09:42:48 +01:00
segment.h f2fs: fix to do sanity check on valid block count of segment 2019-06-22 08:18:19 +02:00
shrinker.c
super.c f2fs: fix to do sanity check with current segment number 2019-04-27 09:33:58 +02:00
trace.c f2fs: do not use mutex lock in atomic context 2019-04-27 09:33:49 +02:00
trace.h
xattr.c
xattr.h