acrn-kernel/fs
Ryusuke Konishi 7532ff6edb nilfs2: fix use-after-free of nilfs_root in dirtying inodes via iput
commit f8654743a0 upstream.

During unmount process of nilfs2, nothing holds nilfs_root structure after
nilfs2 detaches its writer in nilfs_detach_log_writer().  Previously,
nilfs_evict_inode() could cause use-after-free read for nilfs_root if
inodes are left in "garbage_list" and released by nilfs_dispose_list at
the end of nilfs_detach_log_writer(), and this bug was fixed by commit
9b5a04ac3a ("nilfs2: fix use-after-free bug of nilfs_root in
nilfs_evict_inode()").

However, it turned out that there is another possibility of UAF in the
call path where mark_inode_dirty_sync() is called from iput():

nilfs_detach_log_writer()
  nilfs_dispose_list()
    iput()
      mark_inode_dirty_sync()
        __mark_inode_dirty()
          nilfs_dirty_inode()
            __nilfs_mark_inode_dirty()
              nilfs_load_inode_block() --> causes UAF of nilfs_root struct

This can happen after commit 0ae45f63d4 ("vfs: add support for a
lazytime mount option"), which changed iput() to call
mark_inode_dirty_sync() on its final reference if i_state has I_DIRTY_TIME
flag and i_nlink is non-zero.

This issue appears after commit 28a65b49eb ("nilfs2: do not write dirty
data after degenerating to read-only") when using the syzbot reproducer,
but the issue has potentially existed before.

Fix this issue by adding a "purging flag" to the nilfs structure, setting
that flag while disposing the "garbage_list" and checking it in
__nilfs_mark_inode_dirty().

Unlike commit 9b5a04ac3a ("nilfs2: fix use-after-free bug of nilfs_root
in nilfs_evict_inode()"), this patch does not rely on ns_writer to
determine whether to skip operations, so as not to break recovery on
mount.  The nilfs_salvage_orphan_logs routine dirties the buffer of
salvaged data before attaching the log writer, so changing
__nilfs_mark_inode_dirty() to skip the operation when ns_writer is NULL
will cause recovery write to fail.  The purpose of using the cleanup-only
flag is to allow for narrowing of such conditions.

Link: https://lkml.kernel.org/r/20230728191318.33047-1-konishi.ryusuke@gmail.com
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reported-by: syzbot+74db8b3087f293d3a13a@syzkaller.appspotmail.com
Closes: https://lkml.kernel.org/r/000000000000b4e906060113fd63@google.com
Fixes: 0ae45f63d4 ("vfs: add support for a lazytime mount option")
Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org> # 4.0+
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-08-16 18:27:22 +02:00
..
9p
adfs
affs
afs afs: Fix accidental truncation when storing data 2023-07-19 16:22:06 +02:00
autofs
befs
bfs
btrfs btrfs: remove BUG_ON()'s in add_new_free_space() 2023-08-11 12:08:24 +02:00
cachefiles
ceph ceph: defer stopping mdsc delayed_work 2023-08-11 12:08:19 +02:00
coda coda: Avoid partial allocation of sig_inputArgs 2023-03-10 09:33:52 +01:00
configfs
cramfs fs/cramfs/inode.c: initialize file_ra_state 2023-03-10 09:34:09 +01:00
crypto blk-crypto: add a blk_crypto_config_supported_natively helper 2023-05-11 23:03:00 +09:00
debugfs
devpts
dlm fs: dlm: fix mismatch of plock results from userspace 2023-07-23 13:49:38 +02:00
ecryptfs
efivarfs
efs
erofs erofs: fix wrong primary bvec selection on deduplicated extents 2023-08-11 12:08:11 +02:00
exfat exfat: check if filename entries exceeds max filename length 2023-08-11 12:08:26 +02:00
exportfs
ext2 ext2: Drop fragment support 2023-08-11 12:08:24 +02:00
ext4 ext4: correct inline offset when handling xattrs in inode body 2023-07-27 08:50:31 +02:00
f2fs f2fs: don't reset unchangable mount option in f2fs_remount() 2023-08-11 12:08:26 +02:00
fat
freevxfs
fscache
fuse fuse: ioctl: translate ENOSYS in outarg 2023-07-27 08:50:25 +02:00
gfs2 gfs2: Fix duplicate should_fault_in_pages() call 2023-07-19 16:21:54 +02:00
hfs hfs: fix missing hfs_bnode_get() in __hfs_bnode_create 2023-03-10 09:34:07 +01:00
hfsplus fs: hfsplus: remove WARN_ON() from hfsplus_cat_{read,write}_inode() 2023-05-24 17:32:34 +01:00
hostfs
hpfs
hugetlbfs
iomap
isofs
jbd2 jbd2: Fix wrongly judgement for buffer head removing while doing checkpoint 2023-08-03 10:23:47 +02:00
jffs2 jffs2: reduce stack usage in jffs2_build_xattr_subsystem() 2023-07-19 16:22:11 +02:00
jfs FS: JFS: Check for read-only mounted filesystem in txBegin 2023-07-27 08:50:33 +02:00
kernfs kernfs: fix missing kernfs_idr_lock to remove an ID from the IDR 2023-07-19 16:21:53 +02:00
lockd lockd: drop inappropriate svc_get() from locked_get() 2023-07-19 16:20:56 +02:00
minix
netfs
nfs NFSv4.1: freeze the session table upon receiving NFS4ERR_BADSESSION 2023-07-19 16:21:43 +02:00
nfs_common
nfsd nfsd: Remove incorrect check in nfsd4_validate_stateid 2023-08-03 10:24:13 +02:00
nilfs2 nilfs2: fix use-after-free of nilfs_root in dirtying inodes via iput 2023-08-16 18:27:22 +02:00
nls
notify fanotify: disallow mount/sb marks on kernel internal pseudo fs 2023-07-19 16:22:05 +02:00
ntfs
ntfs3 fs/ntfs3: Use __GFP_NOWARN allocation at ntfs_load_attr_list() 2023-08-11 12:08:23 +02:00
ocfs2 ocfs2: Fix use of slab data with sendpage 2023-07-19 16:21:13 +02:00
omfs
openpromfs
orangefs
overlayfs ovl: fix null pointer dereference in ovl_permission() 2023-08-03 10:23:47 +02:00
proc proc/vmcore: fix signedness bug in read_from_oldmem() 2023-08-03 10:24:14 +02:00
pstore pstore/ram: Add check for kstrdup 2023-07-19 16:21:03 +02:00
qnx4
qnx6
quota quota: fix warning in dqgrab() 2023-07-27 08:50:32 +02:00
ramfs shmem: use ramfs_kill_sb() for kill_sb method of ramfs-based tmpfs 2023-07-19 16:22:11 +02:00
reiserfs reiserfs: Add security prefix to xattr name in reiserfs_security_write() 2023-05-11 23:03:02 +09:00
romfs
smb ksmbd: fix wrong next length validation of ea buffer in smb2_set_ea() 2023-08-16 18:27:20 +02:00
squashfs
sysfs
sysv fs/sysv: Null check to prevent null-ptr-deref bug 2023-08-11 12:08:23 +02:00
tracefs
ubifs ubifs: Fix memory leak in do_rename 2023-05-11 23:03:05 +09:00
udf udf: Fix uninitialized array access for some pathnames 2023-07-27 08:50:32 +02:00
ufs
unicode
vboxsf
verity fsverity: don't drop pagecache at end of FS_IOC_ENABLE_VERITY 2023-04-06 12:10:34 +02:00
xfs xfs: fix xfs_inodegc_stop racing with mod_delayed_work 2023-07-19 16:22:15 +02:00
zonefs zonefs: Always invalidate last cached page on append write 2023-04-06 12:10:52 +02:00
Kconfig smb: move client and server files to common directory fs/smb 2023-06-28 11:12:40 +02:00
Kconfig.binfmt
Makefile smb: move client and server files to common directory fs/smb 2023-06-28 11:12:40 +02:00
aio.c
anon_inodes.c
attr.c
bad_inode.c
binfmt_elf.c mm: always expand the stack with the mmap write lock held 2023-07-01 13:16:25 +02:00
binfmt_elf_fdpic.c
binfmt_elf_test.c
binfmt_flat.c
binfmt_misc.c
binfmt_script.c
buffer.c
char_dev.c
compat_binfmt_elf.c
coredump.c
d_path.c
dax.c
dcache.c
direct-io.c
drop_caches.c
eventfd.c
eventpoll.c epoll: ep_autoremove_wake_function should use list_del_init_careful 2023-06-21 16:00:54 +02:00
exec.c mm: always expand the stack with the mmap write lock held 2023-07-01 13:16:25 +02:00
fcntl.c
fhandle.c
file.c file: reinstate f_pos locking optimization for regular files 2023-08-11 12:08:23 +02:00
file_table.c
filesystems.c
fs-writeback.c writeback: fix call of incorrect macro 2023-05-17 11:53:33 +02:00
fs_context.c fs: avoid empty option when generating legacy mount string 2023-07-19 16:22:11 +02:00
fs_parser.c
fs_pin.c
fs_struct.c
fs_types.c
fsopen.c
init.c
inode.c fs: Establish locking order for unrelated directories 2023-07-19 16:22:12 +02:00
internal.h fs: Establish locking order for unrelated directories 2023-07-19 16:22:12 +02:00
ioctl.c
kernel_read_file.c
libfs.c
locks.c filelocks: use mount idmapping for setlease permission check 2023-03-17 08:50:32 +01:00
mbcache.c
mount.h
mpage.c
namei.c fs: no need to check source 2023-07-19 16:22:15 +02:00
namespace.c fs: drop peer group ids under namespace lock 2023-04-13 16:55:33 +02:00
no-block.c
nsfs.c
open.c open: make RESOLVE_CACHED correctly test for O_TMPFILE 2023-08-11 12:08:22 +02:00
pipe.c
pnode.c
pnode.h
posix_acl.c
proc_namespace.c
read_write.c
readdir.c
remap_range.c
select.c
seq_file.c
signalfd.c
splice.c
stack.c
stat.c
statfs.c statfs: enforce statfs[64] structure initialization 2023-05-24 17:32:51 +01:00
super.c fs: Protect reconfiguration of sb read-write from racing writes 2023-08-11 12:08:24 +02:00
sync.c
sysctls.c
timerfd.c
userfaultfd.c Revert "userfaultfd: don't fail on unrecognized features" 2023-04-26 14:28:37 +02:00
utimes.c
xattr.c