linux/fs/f2fs
Yi Chen 594b6d0428 f2fs: fix to avoid NULL pointer dereference
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
pc : f2fs_put_page+0x1c/0x26c
lr : __revoke_inmem_pages+0x544/0x75c
f2fs_put_page+0x1c/0x26c
__revoke_inmem_pages+0x544/0x75c
__f2fs_commit_inmem_pages+0x364/0x3c0
f2fs_commit_inmem_pages+0xc8/0x1a0
f2fs_ioc_commit_atomic_write+0xa4/0x15c
f2fs_ioctl+0x5b0/0x1574
file_ioctl+0x154/0x320
do_vfs_ioctl+0x164/0x740
__arm64_sys_ioctl+0x78/0xa4
el0_svc_common+0xbc/0x1d0
el0_svc_handler+0x74/0x98
el0_svc+0x8/0xc

In f2fs_put_page, we access page->mapping is NULL.
The root cause is:
In some cases, the page refcount and ATOMIC_WRITTEN_PAGE
flag miss set for page-priavte flag has been set.
We add f2fs_bug_on like this:

f2fs_register_inmem_page()
{
	...
	f2fs_set_page_private(page, ATOMIC_WRITTEN_PAGE);

	f2fs_bug_on(F2FS_I_SB(inode), !IS_ATOMIC_WRITTEN_PAGE(page));
	...
}

The bug on stack follow link this:
PC is at f2fs_register_inmem_page+0x238/0x2b4
LR is at f2fs_register_inmem_page+0x2a8/0x2b4
f2fs_register_inmem_page+0x238/0x2b4
f2fs_set_data_page_dirty+0x104/0x164
set_page_dirty+0x78/0xc8
f2fs_write_end+0x1b4/0x444
generic_perform_write+0x144/0x1cc
__generic_file_write_iter+0xc4/0x174
f2fs_file_write_iter+0x2c0/0x350
__vfs_write+0x104/0x134
vfs_write+0xe8/0x19c
SyS_pwrite64+0x78/0xb8

To fix this issue, let's add page refcount add page-priavte flag.
The page-private flag is not cleared and needs further analysis.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Ge Qiu <qiuge@huawei.com>
Signed-off-by: Dehe Gu <gudehe@huawei.com>
Signed-off-by: Yi Chen <chenyi77@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2021-04-13 10:46:34 -07:00
..
acl.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
acl.h fs: make helpers idmap mount aware 2021-01-24 14:27:20 +01:00
checkpoint.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
compress.c f2fs: add sysfs nodes to get runtime compression stat 2021-03-25 18:20:50 -07:00
data.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
debug.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
dir.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
extent_cache.c f2fs: support 64-bits key in f2fs rb-tree node entry 2020-09-10 14:03:30 -07:00
f2fs.h f2fs: introduce gc_merge mount option 2021-03-30 18:48:56 -07:00
file.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
gc.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
gc.h f2fs: introduce gc_merge mount option 2021-03-30 18:48:56 -07:00
hash.c f2fs: Handle casefolding with Encryption 2020-12-02 22:00:21 -08:00
inline.c f2fs: fix a redundant call to f2fs_balance_fs if an error occurs 2021-03-12 13:16:44 -08:00
inode.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
Kconfig f2fs: compress: Allow modular (de)compression algorithms 2021-03-12 13:16:42 -08:00
Makefile f2fs: deprecate f2fs_trace_io 2021-01-27 15:20:07 -08:00
namei.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
node.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
node.h f2fs: allow to change discard policy based on cached discard cmds 2021-03-26 10:27:44 -07:00
recovery.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
segment.c f2fs: fix to avoid NULL pointer dereference 2021-04-13 10:46:34 -07:00
segment.h f2fs: fix to avoid touching checkpointed data in get_victim() 2021-03-26 10:27:01 -07:00
shrinker.c f2fs: avoid race condition for shrinker count 2020-12-03 00:59:26 -08:00
super.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
sysfs.c f2fs: add sysfs nodes to get runtime compression stat 2021-03-25 18:20:50 -07:00
verity.c f2fs: fix error handling in f2fs_end_enable_verity() 2021-03-12 13:16:44 -08:00
xattr.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
xattr.h f2fs: code cleanup by removing ifdef macro surrounding 2020-05-26 18:56:10 -07:00