linux-stable/fs/f2fs
Chao Yu 0d2d6857db f2fs: fix to set/clear I_LINKABLE under i_lock
[ Upstream commit 46085f37fc ]

fsstress + fault injection test case reports a warning message as
below:

WARNING: CPU: 13 PID: 6226 at fs/inode.c:361 inc_nlink+0x32/0x40
Call Trace:
 f2fs_init_inode_metadata+0x25c/0x4a0 [f2fs]
 f2fs_add_inline_entry+0x153/0x3b0 [f2fs]
 f2fs_add_dentry+0x75/0x80 [f2fs]
 f2fs_do_add_link+0x108/0x160 [f2fs]
 f2fs_rename2+0x6ab/0x14f0 [f2fs]
 vfs_rename+0x70c/0x940
 do_renameat2+0x4d8/0x4f0
 __x64_sys_renameat2+0x4b/0x60
 do_syscall_64+0x33/0x80
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Following race case can cause this:
Thread A				Kworker
- f2fs_rename
 - f2fs_create_whiteout
  - __f2fs_tmpfile
   - f2fs_i_links_write
    - f2fs_mark_inode_dirty_sync
     - mark_inode_dirty_sync
					- writeback_single_inode
					 - __writeback_single_inode
					  - spin_lock(&inode->i_lock)
   - inode->i_state |= I_LINKABLE
					  - inode->i_state &= ~dirty
					  - spin_unlock(&inode->i_lock)
 - f2fs_add_link
  - f2fs_do_add_link
   - f2fs_add_dentry
    - f2fs_add_inline_entry
     - f2fs_init_inode_metadata
      - f2fs_i_links_write
       - inc_nlink
        - WARN_ON(!(inode->i_state & I_LINKABLE))

Fix to add i_lock to avoid i_state update race condition.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-03-07 12:34:12 +01:00
..
acl.c
acl.h
checkpoint.c f2fs: avoid race condition for shrinker count 2021-01-06 14:56:54 +01:00
compress.c f2fs: compress: fix potential deadlock 2021-03-04 11:37:44 +01:00
data.c f2fs: fix a wrong condition in __submit_bio 2021-03-04 11:37:46 +01:00
debug.c f2fs: avoid race condition for shrinker count 2021-01-06 14:56:54 +01:00
dir.c
extent_cache.c
f2fs.h f2fs: compress: fix potential deadlock 2021-03-04 11:37:44 +01:00
file.c f2fs: enforce the immutable flag on open files 2021-03-04 11:38:43 +01:00
gc.c
gc.h
hash.c
inline.c f2fs: fix to avoid inconsistent quota data 2021-03-04 11:37:46 +01:00
inode.c
Kconfig
Makefile
namei.c f2fs: fix to set/clear I_LINKABLE under i_lock 2021-03-07 12:34:12 +01:00
node.c f2fs: avoid race condition for shrinker count 2021-01-06 14:56:54 +01:00
node.h f2fs: avoid race condition for shrinker count 2021-01-06 14:56:54 +01:00
recovery.c
segment.c f2fs: init dirty_secmap incorrectly 2020-12-26 16:02:42 +01:00
segment.h f2fs: handle unallocated section and zone on pinned/atgc 2021-03-07 12:34:12 +01:00
shrinker.c f2fs: avoid race condition for shrinker count 2021-01-06 14:56:54 +01:00
super.c f2fs: flush data when enabling checkpoint back 2021-03-04 11:38:43 +01:00
sysfs.c
trace.c
trace.h
verity.c
xattr.c
xattr.h