Skip to content

Commit 884ee6d

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: get rid of online repaire on corrupted directory
syzbot reports a f2fs bug as below: kernel BUG at fs/f2fs/inode.c:896! RIP: 0010:f2fs_evict_inode+0x1598/0x15c0 fs/f2fs/inode.c:896 Call Trace: evict+0x532/0x950 fs/inode.c:704 dispose_list fs/inode.c:747 [inline] evict_inodes+0x5f9/0x690 fs/inode.c:797 generic_shutdown_super+0x9d/0x2d0 fs/super.c:627 kill_block_super+0x44/0x90 fs/super.c:1696 kill_f2fs_super+0x344/0x690 fs/f2fs/super.c:4898 deactivate_locked_super+0xc4/0x130 fs/super.c:473 cleanup_mnt+0x41f/0x4b0 fs/namespace.c:1373 task_work_run+0x24f/0x310 kernel/task_work.c:228 ptrace_notify+0x2d2/0x380 kernel/signal.c:2402 ptrace_report_syscall include/linux/ptrace.h:415 [inline] ptrace_report_syscall_exit include/linux/ptrace.h:477 [inline] syscall_exit_work+0xc6/0x190 kernel/entry/common.c:173 syscall_exit_to_user_mode_prepare kernel/entry/common.c:200 [inline] __syscall_exit_to_user_mode_work kernel/entry/common.c:205 [inline] syscall_exit_to_user_mode+0x279/0x370 kernel/entry/common.c:218 do_syscall_64+0x100/0x230 arch/x86/entry/common.c:89 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0010:f2fs_evict_inode+0x1598/0x15c0 fs/f2fs/inode.c:896 Online repaire on corrupted directory in f2fs_lookup() can generate dirty data/meta while racing w/ readonly remount, it may leave dirty inode after filesystem becomes readonly, however, checkpoint() will skips flushing dirty inode in a state of readonly mode, result in above panic. Let's get rid of online repaire in f2fs_lookup(), and leave the work to fsck.f2fs. Fixes: 510022a ("f2fs: add F2FS_INLINE_DOTS to recover missing dot dentries") Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected] Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent fccaa81 commit 884ee6d

File tree

3 files changed

+1
-80
lines changed

3 files changed

+1
-80
lines changed

fs/f2fs/f2fs.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ enum {
790790
FI_NEED_IPU, /* used for ipu per file */
791791
FI_ATOMIC_FILE, /* indicate atomic file */
792792
FI_DATA_EXIST, /* indicate data exists */
793-
FI_INLINE_DOTS, /* indicate inline dot dentries */
794793
FI_SKIP_WRITES, /* should skip data page writeback */
795794
FI_OPU_WRITE, /* used for opu per file */
796795
FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */
@@ -3065,7 +3064,6 @@ static inline void __mark_inode_dirty_flag(struct inode *inode,
30653064
return;
30663065
fallthrough;
30673066
case FI_DATA_EXIST:
3068-
case FI_INLINE_DOTS:
30693067
case FI_PIN_FILE:
30703068
case FI_COMPRESS_RELEASED:
30713069
f2fs_mark_inode_dirty_sync(inode, true);
@@ -3189,8 +3187,6 @@ static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri)
31893187
set_bit(FI_INLINE_DENTRY, fi->flags);
31903188
if (ri->i_inline & F2FS_DATA_EXIST)
31913189
set_bit(FI_DATA_EXIST, fi->flags);
3192-
if (ri->i_inline & F2FS_INLINE_DOTS)
3193-
set_bit(FI_INLINE_DOTS, fi->flags);
31943190
if (ri->i_inline & F2FS_EXTRA_ATTR)
31953191
set_bit(FI_EXTRA_ATTR, fi->flags);
31963192
if (ri->i_inline & F2FS_PIN_FILE)
@@ -3211,8 +3207,6 @@ static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
32113207
ri->i_inline |= F2FS_INLINE_DENTRY;
32123208
if (is_inode_flag_set(inode, FI_DATA_EXIST))
32133209
ri->i_inline |= F2FS_DATA_EXIST;
3214-
if (is_inode_flag_set(inode, FI_INLINE_DOTS))
3215-
ri->i_inline |= F2FS_INLINE_DOTS;
32163210
if (is_inode_flag_set(inode, FI_EXTRA_ATTR))
32173211
ri->i_inline |= F2FS_EXTRA_ATTR;
32183212
if (is_inode_flag_set(inode, FI_PIN_FILE))
@@ -3293,11 +3287,6 @@ static inline int f2fs_exist_data(struct inode *inode)
32933287
return is_inode_flag_set(inode, FI_DATA_EXIST);
32943288
}
32953289

3296-
static inline int f2fs_has_inline_dots(struct inode *inode)
3297-
{
3298-
return is_inode_flag_set(inode, FI_INLINE_DOTS);
3299-
}
3300-
33013290
static inline int f2fs_is_mmap_file(struct inode *inode)
33023291
{
33033292
return is_inode_flag_set(inode, FI_MMAP_FILE);

fs/f2fs/namei.c

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -457,62 +457,6 @@ struct dentry *f2fs_get_parent(struct dentry *child)
457457
return d_obtain_alias(f2fs_iget(child->d_sb, ino));
458458
}
459459

460-
static int __recover_dot_dentries(struct inode *dir, nid_t pino)
461-
{
462-
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
463-
struct qstr dot = QSTR_INIT(".", 1);
464-
struct f2fs_dir_entry *de;
465-
struct page *page;
466-
int err = 0;
467-
468-
if (f2fs_readonly(sbi->sb)) {
469-
f2fs_info(sbi, "skip recovering inline_dots inode (ino:%lu, pino:%u) in readonly mountpoint",
470-
dir->i_ino, pino);
471-
return 0;
472-
}
473-
474-
if (!S_ISDIR(dir->i_mode)) {
475-
f2fs_err(sbi, "inconsistent inode status, skip recovering inline_dots inode (ino:%lu, i_mode:%u, pino:%u)",
476-
dir->i_ino, dir->i_mode, pino);
477-
set_sbi_flag(sbi, SBI_NEED_FSCK);
478-
return -ENOTDIR;
479-
}
480-
481-
err = f2fs_dquot_initialize(dir);
482-
if (err)
483-
return err;
484-
485-
f2fs_balance_fs(sbi, true);
486-
487-
f2fs_lock_op(sbi);
488-
489-
de = f2fs_find_entry(dir, &dot, &page);
490-
if (de) {
491-
f2fs_put_page(page, 0);
492-
} else if (IS_ERR(page)) {
493-
err = PTR_ERR(page);
494-
goto out;
495-
} else {
496-
err = f2fs_do_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR);
497-
if (err)
498-
goto out;
499-
}
500-
501-
de = f2fs_find_entry(dir, &dotdot_name, &page);
502-
if (de)
503-
f2fs_put_page(page, 0);
504-
else if (IS_ERR(page))
505-
err = PTR_ERR(page);
506-
else
507-
err = f2fs_do_add_link(dir, &dotdot_name, NULL, pino, S_IFDIR);
508-
out:
509-
if (!err)
510-
clear_inode_flag(dir, FI_INLINE_DOTS);
511-
512-
f2fs_unlock_op(sbi);
513-
return err;
514-
}
515-
516460
static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
517461
unsigned int flags)
518462
{
@@ -522,7 +466,6 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
522466
struct dentry *new;
523467
nid_t ino = -1;
524468
int err = 0;
525-
unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
526469
struct f2fs_filename fname;
527470

528471
trace_f2fs_lookup_start(dir, dentry, flags);
@@ -558,17 +501,6 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
558501
goto out;
559502
}
560503

561-
if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) {
562-
err = __recover_dot_dentries(dir, root_ino);
563-
if (err)
564-
goto out_iput;
565-
}
566-
567-
if (f2fs_has_inline_dots(inode)) {
568-
err = __recover_dot_dentries(inode, dir->i_ino);
569-
if (err)
570-
goto out_iput;
571-
}
572504
if (IS_ENCRYPTED(dir) &&
573505
(S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
574506
!fscrypt_has_permitted_context(dir, inode)) {

include/linux/f2fs_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ struct node_footer {
278278
#define F2FS_INLINE_DATA 0x02 /* file inline data flag */
279279
#define F2FS_INLINE_DENTRY 0x04 /* file inline dentry flag */
280280
#define F2FS_DATA_EXIST 0x08 /* file inline data exist flag */
281-
#define F2FS_INLINE_DOTS 0x10 /* file having implicit dot dentries */
281+
#define F2FS_INLINE_DOTS 0x10 /* file having implicit dot dentries (obsolete) */
282282
#define F2FS_EXTRA_ATTR 0x20 /* file having extra attribute */
283283
#define F2FS_PIN_FILE 0x40 /* file should not be gced */
284284
#define F2FS_COMPRESS_RELEASED 0x80 /* file released compressed blocks */

0 commit comments

Comments
 (0)