WSL2-Linux-Kernel/fs/ubifs
Zhihao Cheng a801fcfeef ubifs: Set/Clear I_LINKABLE under i_lock for whiteout inode
xfstests-generic/476 reports a warning message as below:

WARNING: CPU: 2 PID: 30347 at fs/inode.c:361 inc_nlink+0x52/0x70
Call Trace:
  do_rename+0x502/0xd40 [ubifs]
  ubifs_rename+0x8b/0x180 [ubifs]
  vfs_rename+0x476/0x1080
  do_renameat2+0x67c/0x7b0
  __x64_sys_renameat2+0x6e/0x90
  do_syscall_64+0x66/0xe0
  entry_SYSCALL_64_after_hwframe+0x44/0xae

Following race case can cause this:
         rename_whiteout(Thread 1)             wb_workfn(Thread 2)
ubifs_rename
  do_rename
                                          __writeback_single_inode
					    spin_lock(&inode->i_lock)
    whiteout->i_state |= I_LINKABLE
                                            inode->i_state &= ~dirty;
---- How race happens on i_state:
    (tmp = whiteout->i_state | I_LINKABLE)
		                           (tmp = inode->i_state & ~dirty)
    (whiteout->i_state = tmp)
		                           (inode->i_state = tmp)
----
					    spin_unlock(&inode->i_lock)
    inc_nlink(whiteout)
    WARN_ON(!(inode->i_state & I_LINKABLE)) !!!

Fix to add i_lock to avoid i_state update race condition.

Fixes: 9e0a1fff8d ("ubifs: Implement RENAME_WHITEOUT")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-06-22 09:21:39 +02:00
..
Kconfig
Makefile
auth.c
budget.c
commit.c
compress.c
crypto.c
debug.c ubifs: fix snprintf() checking 2021-06-18 22:04:47 +02:00
debug.h
dir.c ubifs: Set/Clear I_LINKABLE under i_lock for whiteout inode 2021-06-22 09:21:39 +02:00
file.c ubifs: convert to fileattr 2021-04-12 15:04:30 +02:00
find.c
gc.c treewide: Change list_sort to use const pointers 2021-04-08 16:04:22 -07:00
io.c
ioctl.c ubifs: convert to fileattr 2021-04-12 15:04:30 +02:00
journal.c ubifs: Fix spelling mistakes 2021-06-22 09:21:39 +02:00
key.h
log.c
lprops.c
lpt.c
lpt_commit.c
master.c ubifs: Fix spelling mistakes 2021-06-22 09:21:39 +02:00
misc.c
misc.h
orphan.c
recovery.c
replay.c ubifs: Fix spelling mistakes 2021-06-22 09:21:39 +02:00
sb.c ubifs: Default to zstd compression 2021-04-15 22:00:26 +02:00
scan.c
shrinker.c
super.c ubifs: Fix spelling mistakes 2021-06-22 09:21:39 +02:00
tnc.c
tnc_commit.c ubifs: Fix spelling mistakes 2021-06-22 09:21:39 +02:00
tnc_misc.c
ubifs-media.h
ubifs.h ubifs: Fix spelling mistakes 2021-06-22 09:21:39 +02:00
xattr.c ubifs: Remove ui_mutex in ubifs_xattr_get and change_xattr 2021-06-18 22:04:47 +02:00