linux/fs/f2fs
Yangtao Li d4bf15a7ce f2fs: reduce the scope of setting fsck tag when de->name_len is zero
I recently found a case where de->name_len is 0 in f2fs_fill_dentries()
easily reproduced, and finally set the fsck flag.

Thread A			Thread B
- f2fs_readdir
 - f2fs_read_inline_dir
  - ctx->pos = d.max
				- f2fs_add_dentry
				 - f2fs_add_inline_entry
				  - do_convert_inline_dir
				 - f2fs_add_regular_entry
- f2fs_readdir
 - f2fs_fill_dentries
  - set_sbi_flag(sbi, SBI_NEED_FSCK)

Process A opens the folder, and has been reading without closing it.
During this period, Process B created a file under the folder (occupying
multiple f2fs_dir_entry, exceeding the d.max of the inline dir). After
creation, process A uses the d.max of inline dir to read it again, and
it will read that de->name_len is 0.

And Chao pointed out that w/o inline conversion, the race condition still
can happen as below:

dir_entry1: A
dir_entry2: B
dir_entry3: C
free slot: _
ctx->pos: ^

Thread A is traversing directory,
ctx-pos moves to below position after readdir() by thread A:
AAAABBBB___
        ^

Then thread B delete dir_entry2, and create dir_entry3.

Thread A calls readdir() to lookup dirents starting from middle
of new dirent slots as below:
AAAACCCCCC_
        ^
In these scenarios, the file system is not damaged, and it's hard to
avoid it. But we can bypass tagging FSCK flag if:
a) bit_pos (:= ctx->pos % d->max) is non-zero and
b) before bit_pos moves to first valid dir_entry.

Fixes: ddf06b753a ("f2fs: fix to trigger fsck if dirent.name_len is zero")
Signed-off-by: Yangtao Li <frank.li@vivo.com>
[Chao: clean up description]
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2021-08-04 15:51:21 -07:00
..
acl.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
acl.h fs: make helpers idmap mount aware 2021-01-24 14:27:20 +01:00
checkpoint.c f2fs: fix to stop filesystem update once CP failed 2021-08-03 18:08:29 -07:00
compress.c f2fs: compress: add compress_inode to cache compressed blocks 2021-06-23 01:09:35 -07:00
data.c f2fs: turn back remapped address in compressed page endio 2021-08-02 11:24:25 -07:00
debug.c f2fs: show sbi status in debugfs/f2fs/status 2021-08-02 11:24:26 -07:00
dir.c f2fs: reduce the scope of setting fsck tag when de->name_len is zero 2021-08-04 15:51:21 -07:00
extent_cache.c f2fs: support 64-bits key in f2fs rb-tree node entry 2020-09-10 14:03:30 -07:00
f2fs.h f2fs: fix to stop filesystem update once CP failed 2021-08-03 18:08:29 -07:00
file.c f2fs: add sysfs node to control ra_pages for fadvise seq file 2021-08-03 11:16:22 -07:00
gc.c f2fs: Revert "f2fs: Fix indefinite loop in f2fs_gc() v1" 2021-07-19 11:54:48 -07:00
gc.h f2fs: introduce gc_merge mount option 2021-03-30 18:48:56 -07:00
hash.c f2fs: Handle casefolding with Encryption 2020-12-02 22:00:21 -08:00
inline.c f2fs: restructure f2fs page.private layout 2021-05-14 11:22:08 -07:00
inode.c f2fs: compress: add compress_inode to cache compressed blocks 2021-06-23 01:09:35 -07:00
Kconfig f2fs: compress: Allow modular (de)compression algorithms 2021-03-12 13:16:42 -08:00
Makefile f2fs: deprecate f2fs_trace_io 2021-01-27 15:20:07 -08:00
namei.c f2fs: compress: add nocompress extensions support 2021-07-01 18:34:31 -07:00
node.c f2fs: do not submit NEW_ADDR to read node block 2021-08-02 11:24:25 -07:00
node.h f2fs: swap: support migrating swapfile in aligned write mode 2021-06-23 01:09:35 -07:00
recovery.c f2fs: introduce f2fs_casefolded_name slab cache 2021-06-23 01:09:35 -07:00
segment.c f2fs: fix to stop filesystem update once CP failed 2021-08-03 18:08:29 -07:00
segment.h f2fs-for-5.13-rc1 2021-05-04 18:03:38 -07:00
shrinker.c f2fs: avoid race condition for shrinker count 2020-12-03 00:59:26 -08:00
super.c f2fs: add sysfs node to control ra_pages for fadvise seq file 2021-08-03 11:16:22 -07:00
sysfs.c f2fs: add sysfs node to control ra_pages for fadvise seq file 2021-08-03 11:16:22 -07:00
verity.c f2fs-for-5.13-rc1 2021-05-04 18:03:38 -07:00
xattr.c f2fs: clean up build warnings 2021-04-10 10:36:39 -07:00
xattr.h f2fs: code cleanup by removing ifdef macro surrounding 2020-05-26 18:56:10 -07:00