anolis-cloud-kernel/fs
Chao Yu 218a9ce97b f2fs: fix to avoid NULL pointer dereference f2fs_write_end_io()
ANBZ: #20922

commit d8189834d4 upstream.

butt3rflyh4ck reports a bug as below:

When a thread always calls F2FS_IOC_RESIZE_FS to resize fs, if resize fs is
failed, f2fs kernel thread would invoke callback function to update f2fs io
info, it would call  f2fs_write_end_io and may trigger null-ptr-deref in
NODE_MAPPING.

general protection fault, probably for non-canonical address
KASAN: null-ptr-deref in range [0x0000000000000030-0x0000000000000037]
RIP: 0010:NODE_MAPPING fs/f2fs/f2fs.h:1972 [inline]
RIP: 0010:f2fs_write_end_io+0x727/0x1050 fs/f2fs/data.c:370
 <TASK>
 bio_endio+0x5af/0x6c0 block/bio.c:1608
 req_bio_endio block/blk-mq.c:761 [inline]
 blk_update_request+0x5cc/0x1690 block/blk-mq.c:906
 blk_mq_end_request+0x59/0x4c0 block/blk-mq.c:1023
 lo_complete_rq+0x1c6/0x280 drivers/block/loop.c:370
 blk_complete_reqs+0xad/0xe0 block/blk-mq.c:1101
 __do_softirq+0x1d4/0x8ef kernel/softirq.c:571
 run_ksoftirqd kernel/softirq.c:939 [inline]
 run_ksoftirqd+0x31/0x60 kernel/softirq.c:931
 smpboot_thread_fn+0x659/0x9e0 kernel/smpboot.c:164
 kthread+0x33e/0x440 kernel/kthread.c:379
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

The root cause is below race case can cause leaving dirty metadata
in f2fs after filesystem is remount as ro:

Thread A				Thread B
- f2fs_ioc_resize_fs
 - f2fs_readonly   --- return false
 - f2fs_resize_fs
					- f2fs_remount
					 - write_checkpoint
					 - set f2fs as ro
  - free_segment_range
   - update meta_inode's data

Then, if f2fs_put_super()  fails to write_checkpoint due to readonly
status, and meta_inode's dirty data will be writebacked after node_inode
is put, finally, f2fs_write_end_io will access NULL pointer on
sbi->node_inode.

Thread A				IRQ context
- f2fs_put_super
 - write_checkpoint fails
 - iput(node_inode)
 - node_inode = NULL
 - iput(meta_inode)
  - write_inode_now
   - f2fs_write_meta_page
					- f2fs_write_end_io
					 - NODE_MAPPING(sbi)
					 : access NULL pointer on node_inode

Fixes: b4b10061ef ("f2fs: refactor resize_fs to avoid meta updates in progress")
Reported-by: butt3rflyh4ck <butterflyhuangxx@gmail.com>
Closes: https://lore.kernel.org/r/1684480657-2375-1-git-send-email-yangtiezhu@loongson.cn
Tested-by: butt3rflyh4ck <butterflyhuangxx@gmail.com>
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Stefan Ghinea <stefan.ghinea@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Fixes: CVE-2023-2898
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/5565
2025-08-01 11:21:00 +08:00
..
9p vfs: add rcu argument to ->get_acl() callback 2022-10-24 02:54:58 +00:00
adfs
affs
afs afs: Fix dynamic root getattr 2022-06-29 08:59:49 +02:00
autofs file: Replace ksys_close with close_fd 2024-08-30 01:14:57 +00:00
befs
bfs
btrfs btrfs: do not ASSERT() if the newly created subvolume already got read 2025-04-30 00:54:36 +00:00
cachefiles file: Rename __close_fd to close_fd and remove the files parameter 2024-08-30 01:14:57 +00:00
ceph ceph: fix incorrect kmalloc size of pagevec mempool 2025-01-15 07:40:18 +00:00
cifs smb: client: Add check for next_buffer in receive_encrypted_standard() 2025-03-17 10:23:58 +08:00
coda
configfs configfs: fix possible memory leak in configfs_create_dir() 2023-03-05 11:43:45 +00:00
cramfs
crypto fscrypt: fix keyring memory leak on mount failure 2024-08-12 08:20:08 +00:00
debugfs debugfs: add debugfs_lookup_and_remove() 2024-08-06 12:34:21 +00:00
devpts fsnotify: fix fsnotify hooks in pseudo filesystems 2022-02-01 17:25:39 +01:00
dlm dlm: fix pending remove if msg allocation fails 2022-07-29 17:19:24 +02:00
ecryptfs ecryptfs: Reject casefold directory inodes 2024-07-12 05:49:57 +00:00
efivarfs efivarfs: force RO when remounting if SetVariable is not supported 2025-01-11 11:35:49 +00:00
efs
erofs erofs: impersonate the opener's credentials when accessing backing file 2025-07-22 13:34:00 +08:00
exfat exfat: check if filename entries exceeds max filename length 2025-08-01 10:07:23 +08:00
exportfs
ext2 fs: introduce a wrapper uuid_to_fsid() 2024-05-29 11:58:45 +00:00
ext4 ext4: fix FS_IOC_GETFSMAP handling 2025-01-07 06:07:52 +00:00
f2fs f2fs: fix to avoid NULL pointer dereference f2fs_write_end_io() 2025-08-01 11:21:00 +08:00
fat fat: fix uninitialized field in nostale filehandles 2024-04-24 03:24:24 +00:00
freevxfs
fscache anolis: fscache: export fscache_object_wq 2022-11-25 03:08:14 +00:00
fuse fuse: fix dax truncate/punch_hole fault path 2025-04-22 01:26:36 +00:00
gfs2 gfs2: Always check inode size of inline inodes 2025-04-08 03:08:55 +00:00
hfs
hfsplus fs: hfsplus: fix UAF issue in hfsplus_put_super 2023-06-21 23:25:50 +00:00
hostfs
hpfs
hugetlbfs mm: hugetlb pages should not be reserved by shmat() if SHM_NORESERVE 2024-08-01 00:39:22 +00:00
iomap block: ignore RWF_HIPRI hint for sync dio 2024-12-09 06:40:29 +00:00
isofs isofs: handle CDs with bad root inode but good Joliet root directory 2024-08-06 02:20:52 +00:00
jbd2 anolis: sched: fix proc entry leak of proxy_exec 2025-04-21 14:05:00 +08:00
jffs2 vfs: add rcu argument to ->get_acl() callback 2022-10-24 02:54:58 +00:00
jfs vfs: add rcu argument to ->get_acl() callback 2022-10-24 02:54:58 +00:00
kernfs anolis: Revert "kernfs: switch kernfs to use an rwsem" 2025-02-10 09:52:06 +00:00
lockd fs: lockd: avoid possible wrong NULL parameter 2024-08-01 01:20:02 +00:00
minix minix: fix bug when opening a file with O_DIRECT 2022-04-13 21:01:01 +02:00
nfs NFSv4: Prevent NULL-pointer dereference in nfs42_complete_copies() 2024-12-27 09:54:07 +00:00
nfs_common
nfsd NFSD: Prevent NULL dereference in nfsd4_process_cb_update() 2025-04-08 02:40:43 +00:00
nilfs2 nilfs2: fix use-after-free of timer for log writer thread 2024-10-10 17:18:21 +08:00
nls
notify file: Rename fcheck lookup_fd_rcu 2024-08-30 01:14:57 +00:00
ntfs ntfs: check overflow when iterating ATTR_RECORDs 2024-08-05 01:08:42 +00:00
ocfs2 attr: use consistent sgid stripping checks 2023-05-26 07:12:17 +00:00
omfs
openpromfs
orangefs orangefs: fix a oob in orangefs_debug_write 2025-05-26 02:02:17 +00:00
overlayfs ovl: fix UAF in ovl_dentry_update_reval by moving dput() in ovl_link_up 2025-04-08 03:07:44 +00:00
proc anolis: timens: fix start boottime calculate bug when rich container and timens enabled 2025-07-16 07:35:40 +00:00
pstore pstore: inode: Only d_invalidate() is needed 2024-12-24 08:01:24 +00:00
qnx4
qnx6
quota quota: flush quota_release_work upon quota writeback 2025-01-12 01:06:31 +08:00
ramfs shmem: use ramfs_kill_sb() for kill_sb method of ramfs-based tmpfs 2024-07-12 05:49:57 +00:00
reiserfs fs: reiserfs: remove useless new_opts in reiserfs_remount 2023-02-28 07:26:24 +00:00
resctrl x86/resctrl: Move mbm_cfg_mask to struct rdt_resource 2025-06-11 08:33:21 +00:00
romfs
squashfs squashfs: harden sanity check in squashfs_read_xattr_id_table 2025-04-08 02:33:18 +00:00
sysfs fs: sysfs: Fix reference leak in sysfs_break_active_protection() 2024-08-01 01:39:28 +00:00
sysv
tracefs tracefs: Only clobber mode/uid/gid on remount if asked 2024-08-06 02:20:52 +00:00
ubifs ubifs: Rectify space amount budget for mkdir/tmpfile operations 2022-04-13 21:00:53 +02:00
udf udf: Fix preallocation discarding at indirect extent boundary 2024-12-23 03:33:52 +00:00
ufs
unicode
vboxsf
verity fsverity: don't drop pagecache at end of FS_IOC_ENABLE_VERITY 2024-08-12 08:20:08 +00:00
xfs xfs: Fix deadlock on xfs_inodegc_worker 2025-06-11 06:38:59 +00:00
zonefs block: switch polling to be bio based 2024-11-26 01:40:15 +00:00
Kconfig mm: hugetlb_vmemmap: cleanup CONFIG_HUGETLB_PAGE_FREE_VMEMMAP* 2023-04-21 14:44:21 +08:00
Kconfig.binfmt
Makefile io_uring: import 5.15-stable io_uring 2023-09-25 12:04:35 +00:00
aio.c fs/aio: Check IOCB_AIO_RW before the struct aio_kiocb conversion 2024-08-01 01:39:28 +00:00
anon_inodes.c
attr.c attr: block mode changes of symlinks 2024-08-01 01:20:02 +00:00
bad_inode.c vfs: add rcu argument to ->get_acl() callback 2022-10-24 02:54:58 +00:00
binfmt_aout.c
binfmt_elf.c anolis: mm: enhance sbrk/brk to support THP alignment 2025-03-02 12:24:47 +00:00
binfmt_elf_fdpic.c binfmt: Fix error return code in load_elf_fdpic_binary() 2024-08-06 02:52:58 +00:00
binfmt_em86.c
binfmt_flat.c binfmt_flat: Fix integer overflow bug on 32 bit systems 2025-03-03 12:18:53 +00:00
binfmt_misc.c binfmt_misc: fix shift-out-of-bounds in check_special_flags 2024-07-31 09:31:21 +00:00
binfmt_script.c
block_dev.c block: ignore RWF_HIPRI hint for sync dio 2024-12-09 06:40:29 +00:00
buffer.c mm: fs: initialize fsdata passed to write_begin/write_end interface 2024-08-06 02:52:58 +00:00
char_dev.c chardev: fix error handling in cdev_device_add() 2024-07-26 06:26:44 +00:00
compat_binfmt_elf.c
coredump.c exec: Simplify unshare_files 2024-08-30 01:14:57 +00:00
d_path.c anolis: virtfuse: improve mntpoint printing 2023-12-26 05:39:48 +00:00
dax.c fsdax: Fix infinite loop in dax_iomap_rw() 2024-12-23 08:59:37 +00:00
dcache.c anolis: mm: kidled: Add spinlock protection when cleaning *KIDLED_YOUNG flag 2024-08-29 05:58:33 +00:00
dcookies.c
direct-io.c direct-io: remove blk_poll support 2024-11-26 01:40:15 +00:00
drop_caches.c
eventfd.c eventfd: prevent underflow for eventfd semaphores 2024-08-01 01:20:02 +00:00
eventpoll.c epoll: ep_autoremove_wake_function should use list_del_init_careful 2024-07-31 09:04:37 +00:00
exec.c exec: Fix ToCToU between perm check and set-uid/gid usage 2024-09-27 06:09:13 +00:00
fcntl.c fcntl: fix potential deadlocks for &fown_struct.lock 2024-07-31 09:18:30 +00:00
fhandle.c do_sys_name_to_handle(): use kzalloc() to fix kernel-infoleak 2024-08-01 01:39:28 +00:00
file.c fs/file.c: add fast path in find_next_fd() 2024-12-26 05:49:42 +00:00
file_table.c SUNRPC: Ensure we flush any closed sockets before xs_xprt_free() 2022-05-18 10:23:48 +02:00
filesystems.c
fs-writeback.c writeback: fix call of incorrect macro 2024-07-31 09:41:17 +00:00
fs_context.c fs: avoid empty option when generating legacy mount string 2024-07-31 11:11:16 +00:00
fs_parser.c
fs_pin.c
fs_struct.c
fs_types.c
fsopen.c
init.c
inode.c vfs: fix race between evice_inodes() and find_inode()&iput() 2024-12-23 02:00:53 +00:00
internal.h fs: Establish locking order for unrelated directories 2024-07-31 11:11:16 +00:00
ioctl.c anolis: Revert "ck: io_uring: support ioctl" 2022-11-29 16:46:54 +08:00
kernel_read_file.c
libfs.c libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value 2024-07-12 05:49:57 +00:00
locks.c filelock: Fix fcntl/close race recovery compat path 2024-08-30 11:17:22 +08:00
mbcache.c ext4: fix deadlock due to mbcache entry corruption 2024-07-16 01:21:13 +00:00
mount.h anolis: kabi: Reserve some fields 2023-02-24 07:45:32 +00:00
mpage.c
namei.c fuse: don't truncate cached, mutated symlink 2025-04-22 01:26:36 +00:00
namespace.c move_mount: allow to add a mount into an existing group 2024-12-20 01:38:00 +00:00
no-block.c
nsfs.c
open.c ftruncate: pass a signed offset 2024-12-23 07:39:24 +00:00
pipe.c pipe: wakeup wr_wait after setting max_usage 2024-08-01 01:20:02 +00:00
pnode.c pnode: terminate at peers of source 2024-07-31 09:31:21 +00:00
pnode.h
posix_acl.c ovl: enable RCU'd ->get_acl() 2023-06-29 01:23:21 +00:00
proc_namespace.c
read_write.c vfs: fix copy_file_range() averts filesystem freeze protection 2024-08-01 01:39:28 +00:00
readdir.c
remap_range.c anolis: mm: support fast reflink 2024-03-01 01:09:03 +00:00
select.c fs/select: rework stack allocation hack for clang 2024-08-01 01:39:28 +00:00
seq_file.c seq_file: Add a seq_bprintf function 2023-12-19 06:09:56 +00:00
signalfd.c io_uring: import 5.15-stable io_uring 2023-09-25 12:04:35 +00:00
splice.c
stack.c
stat.c stat: fix inconsistency between struct stat and struct compat_stat 2022-04-27 13:53:54 +02:00
statfs.c statfs: enforce statfs[64] structure initialization 2024-07-31 09:41:17 +00:00
super.c fscrypt: fix keyring memory leak on mount failure 2024-08-12 08:20:08 +00:00
sync.c riscv: compat: syscall: Add compat_sys_call_table implementation 2023-02-23 10:29:07 +08:00
timerfd.c
userfaultfd.c userfaultfd: open userfaultfds with O_RDONLY 2024-07-31 09:18:30 +00:00
utimes.c
xattr.c fs: don't audit the capability check in simple_xattr_list() 2024-07-31 09:31:21 +00:00