Commit e2fb24c
f2fs: don't reset unchangable mount option in f2fs_remount()
[ Upstream commit 458c15d ]
syzbot reports a bug as below:
general protection fault, probably for non-canonical address 0xdffffc0000000009: 0000 [#1] PREEMPT SMP KASAN
RIP: 0010:__lock_acquire+0x69/0x2000 kernel/locking/lockdep.c:4942
Call Trace:
lock_acquire+0x1e3/0x520 kernel/locking/lockdep.c:5691
__raw_write_lock include/linux/rwlock_api_smp.h:209 [inline]
_raw_write_lock+0x2e/0x40 kernel/locking/spinlock.c:300
__drop_extent_tree+0x3ac/0x660 fs/f2fs/extent_cache.c:1100
f2fs_drop_extent_tree+0x17/0x30 fs/f2fs/extent_cache.c:1116
f2fs_insert_range+0x2d5/0x3c0 fs/f2fs/file.c:1664
f2fs_fallocate+0x4e4/0x6d0 fs/f2fs/file.c:1838
vfs_fallocate+0x54b/0x6b0 fs/open.c:324
ksys_fallocate fs/open.c:347 [inline]
__do_sys_fallocate fs/open.c:355 [inline]
__se_sys_fallocate fs/open.c:353 [inline]
__x64_sys_fallocate+0xbd/0x100 fs/open.c:353
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
The root cause is race condition as below:
- since it tries to remount rw filesystem, so that do_remount won't
call sb_prepare_remount_readonly to block fallocate, there may be race
condition in between remount and fallocate.
- in f2fs_remount(), default_options() will reset mount option to default
one, and then update it based on result of parse_options(), so there is
a hole which race condition can happen.
Thread A Thread B
- f2fs_fill_super
- parse_options
- clear_opt(READ_EXTENT_CACHE)
- f2fs_remount
- default_options
- set_opt(READ_EXTENT_CACHE)
- f2fs_fallocate
- f2fs_insert_range
- f2fs_drop_extent_tree
- __drop_extent_tree
- __may_extent_tree
- test_opt(READ_EXTENT_CACHE) return true
- write_lock(&et->lock) access NULL pointer
- parse_options
- clear_opt(READ_EXTENT_CACHE)
Cc: <stable@vger.kernel.org>
Reported-by: syzbot+d015b6c2fbb5c383bf08@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/linux-f2fs-devel/20230522124203.3838360-1-chao@kernel.org
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 6ba0594 commit e2fb24c
1 file changed
+18
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2040 | 2040 | | |
2041 | 2041 | | |
2042 | 2042 | | |
2043 | | - | |
| 2043 | + | |
2044 | 2044 | | |
2045 | 2045 | | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
2046 | 2059 | | |
2047 | 2060 | | |
2048 | 2061 | | |
| |||
2065 | 2078 | | |
2066 | 2079 | | |
2067 | 2080 | | |
2068 | | - | |
2069 | 2081 | | |
2070 | | - | |
2071 | 2082 | | |
2072 | 2083 | | |
2073 | 2084 | | |
2074 | 2085 | | |
2075 | 2086 | | |
2076 | | - | |
2077 | | - | |
2078 | | - | |
| 2087 | + | |
2079 | 2088 | | |
2080 | | - | |
2081 | | - | |
| 2089 | + | |
2082 | 2090 | | |
2083 | | - | |
2084 | | - | |
2085 | 2091 | | |
2086 | 2092 | | |
2087 | 2093 | | |
| |||
2253 | 2259 | | |
2254 | 2260 | | |
2255 | 2261 | | |
2256 | | - | |
| 2262 | + | |
2257 | 2263 | | |
2258 | 2264 | | |
2259 | 2265 | | |
| |||
4150 | 4156 | | |
4151 | 4157 | | |
4152 | 4158 | | |
4153 | | - | |
| 4159 | + | |
4154 | 4160 | | |
4155 | 4161 | | |
4156 | 4162 | | |
| |||
0 commit comments