Skip to content

Commit f803982

Browse files
author
Jaegeuk Kim
committed
f2fs: split initial and dynamic conditions for extent_cache
Let's allocate the extent_cache tree without dynamic conditions to avoid a missing condition causing a panic as below. # create a file w/ a compressed flag # disable the compression # panic while updating extent_cache F2FS-fs (dm-64): Swapfile: last extent is not aligned to section F2FS-fs (dm-64): Swapfile (3) is not align to section: 1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(2097152 * N) Adding 124996k swap on ./swap-file. Priority:0 extents:2 across:17179494468k ================================================================== BUG: KASAN: null-ptr-deref in instrument_atomic_read_write out/common/include/linux/instrumented.h:101 [inline] BUG: KASAN: null-ptr-deref in atomic_try_cmpxchg_acquire out/common/include/asm-generic/atomic-instrumented.h:705 [inline] BUG: KASAN: null-ptr-deref in queued_write_lock out/common/include/asm-generic/qrwlock.h:92 [inline] BUG: KASAN: null-ptr-deref in __raw_write_lock out/common/include/linux/rwlock_api_smp.h:211 [inline] BUG: KASAN: null-ptr-deref in _raw_write_lock+0x5a/0x110 out/common/kernel/locking/spinlock.c:295 Write of size 4 at addr 0000000000000030 by task syz-executor154/3327 CPU: 0 PID: 3327 Comm: syz-executor154 Tainted: G O 5.10.185 #1 Hardware name: emulation qemu-x86/qemu-x86, BIOS 2023.01-21885-gb3cc1cd24d 01/01/2023 Call Trace: __dump_stack out/common/lib/dump_stack.c:77 [inline] dump_stack_lvl+0x17e/0x1c4 out/common/lib/dump_stack.c:118 __kasan_report+0x16c/0x260 out/common/mm/kasan/report.c:415 kasan_report+0x51/0x70 out/common/mm/kasan/report.c:428 kasan_check_range+0x2f3/0x340 out/common/mm/kasan/generic.c:186 __kasan_check_write+0x14/0x20 out/common/mm/kasan/shadow.c:37 instrument_atomic_read_write out/common/include/linux/instrumented.h:101 [inline] atomic_try_cmpxchg_acquire out/common/include/asm-generic/atomic-instrumented.h:705 [inline] queued_write_lock out/common/include/asm-generic/qrwlock.h:92 [inline] __raw_write_lock out/common/include/linux/rwlock_api_smp.h:211 [inline] _raw_write_lock+0x5a/0x110 out/common/kernel/locking/spinlock.c:295 __drop_extent_tree+0xdf/0x2f0 out/common/fs/f2fs/extent_cache.c:1155 f2fs_drop_extent_tree+0x17/0x30 out/common/fs/f2fs/extent_cache.c:1172 f2fs_insert_range out/common/fs/f2fs/file.c:1600 [inline] f2fs_fallocate+0x19fd/0x1f40 out/common/fs/f2fs/file.c:1764 vfs_fallocate+0x514/0x9b0 out/common/fs/open.c:310 ksys_fallocate out/common/fs/open.c:333 [inline] __do_sys_fallocate out/common/fs/open.c:341 [inline] __se_sys_fallocate out/common/fs/open.c:339 [inline] __x64_sys_fallocate+0xb8/0x100 out/common/fs/open.c:339 do_syscall_64+0x35/0x50 out/common/arch/x86/entry/common.c:46 Cc: [email protected] Fixes: 72840cc ("f2fs: allocate the extent_cache by default") Reported-and-tested-by: [email protected] Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 7e1b150 commit f803982

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

fs/f2fs/extent_cache.c

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,40 +74,14 @@ static void __set_extent_info(struct extent_info *ei,
7474
}
7575
}
7676

77-
static bool __may_read_extent_tree(struct inode *inode)
78-
{
79-
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
80-
81-
if (!test_opt(sbi, READ_EXTENT_CACHE))
82-
return false;
83-
if (is_inode_flag_set(inode, FI_NO_EXTENT))
84-
return false;
85-
if (is_inode_flag_set(inode, FI_COMPRESSED_FILE) &&
86-
!f2fs_sb_has_readonly(sbi))
87-
return false;
88-
return S_ISREG(inode->i_mode);
89-
}
90-
91-
static bool __may_age_extent_tree(struct inode *inode)
92-
{
93-
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
94-
95-
if (!test_opt(sbi, AGE_EXTENT_CACHE))
96-
return false;
97-
if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
98-
return false;
99-
if (file_is_cold(inode))
100-
return false;
101-
102-
return S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode);
103-
}
104-
10577
static bool __init_may_extent_tree(struct inode *inode, enum extent_type type)
10678
{
10779
if (type == EX_READ)
108-
return __may_read_extent_tree(inode);
109-
else if (type == EX_BLOCK_AGE)
110-
return __may_age_extent_tree(inode);
80+
return test_opt(F2FS_I_SB(inode), READ_EXTENT_CACHE) &&
81+
S_ISREG(inode->i_mode);
82+
if (type == EX_BLOCK_AGE)
83+
return test_opt(F2FS_I_SB(inode), AGE_EXTENT_CACHE) &&
84+
(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode));
11185
return false;
11286
}
11387

@@ -120,7 +94,22 @@ static bool __may_extent_tree(struct inode *inode, enum extent_type type)
12094
if (list_empty(&F2FS_I_SB(inode)->s_list))
12195
return false;
12296

123-
return __init_may_extent_tree(inode, type);
97+
if (!__init_may_extent_tree(inode, type))
98+
return false;
99+
100+
if (type == EX_READ) {
101+
if (is_inode_flag_set(inode, FI_NO_EXTENT))
102+
return false;
103+
if (is_inode_flag_set(inode, FI_COMPRESSED_FILE) &&
104+
!f2fs_sb_has_readonly(F2FS_I_SB(inode)))
105+
return false;
106+
} else if (type == EX_BLOCK_AGE) {
107+
if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
108+
return false;
109+
if (file_is_cold(inode))
110+
return false;
111+
}
112+
return true;
124113
}
125114

126115
static void __try_update_largest_extent(struct extent_tree *et,

0 commit comments

Comments
 (0)