* [PATCH v4 1/2] f2fs: Rename f2fs_unlink exit label
2025-11-05 11:09 [PATCH v4 0/2] f2fs: Add sanity checks before unlinking and loading inodes Nikola Z. Ivanov
@ 2025-11-05 11:09 ` Nikola Z. Ivanov
2025-11-05 11:14 ` Chao Yu
2025-11-05 11:09 ` [PATCH v4 2/2] f2fs: Add sanity checks before unlinking and loading inodes Nikola Z. Ivanov
2025-11-11 22:50 ` [f2fs-dev] [PATCH v4 0/2] " patchwork-bot+f2fs
2 siblings, 1 reply; 6+ messages in thread
From: Nikola Z. Ivanov @ 2025-11-05 11:09 UTC (permalink / raw)
To: jaegeuk, chao, linux-f2fs-devel
Cc: linux-kernel, skhan, david.hunter.linux, linux-kernel-mentees,
khalid, stable, Nikola Z. Ivanov
Rename "fail" label to "out" as it's used as a default
exit path out of f2fs_unlink as well as error path.
Signed-off-by: Nikola Z. Ivanov <zlatistiv@gmail.com>
---
fs/f2fs/namei.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index b882771e4699..40cf80fd9d9a 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -552,21 +552,21 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
if (unlikely(f2fs_cp_error(sbi))) {
err = -EIO;
- goto fail;
+ goto out;
}
err = f2fs_dquot_initialize(dir);
if (err)
- goto fail;
+ goto out;
err = f2fs_dquot_initialize(inode);
if (err)
- goto fail;
+ goto out;
de = f2fs_find_entry(dir, &dentry->d_name, &folio);
if (!de) {
if (IS_ERR(folio))
err = PTR_ERR(folio);
- goto fail;
+ goto out;
}
if (unlikely(inode->i_nlink == 0)) {
@@ -575,7 +575,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
err = -EFSCORRUPTED;
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
f2fs_folio_put(folio, false);
- goto fail;
+ goto out;
}
f2fs_balance_fs(sbi, true);
@@ -585,7 +585,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
if (err) {
f2fs_unlock_op(sbi);
f2fs_folio_put(folio, false);
- goto fail;
+ goto out;
}
f2fs_delete_entry(de, folio, dir, inode);
f2fs_unlock_op(sbi);
@@ -601,7 +601,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
if (IS_DIRSYNC(dir))
f2fs_sync_fs(sbi->sb, 1);
-fail:
+out:
trace_f2fs_unlink_exit(inode, err);
return err;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v4 1/2] f2fs: Rename f2fs_unlink exit label
2025-11-05 11:09 ` [PATCH v4 1/2] f2fs: Rename f2fs_unlink exit label Nikola Z. Ivanov
@ 2025-11-05 11:14 ` Chao Yu
0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2025-11-05 11:14 UTC (permalink / raw)
To: Nikola Z. Ivanov, jaegeuk, linux-f2fs-devel
Cc: chao, linux-kernel, skhan, david.hunter.linux,
linux-kernel-mentees, khalid, stable
On 11/5/25 19:09, Nikola Z. Ivanov wrote:
> Rename "fail" label to "out" as it's used as a default
> exit path out of f2fs_unlink as well as error path.
>
> Signed-off-by: Nikola Z. Ivanov <zlatistiv@gmail.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 2/2] f2fs: Add sanity checks before unlinking and loading inodes
2025-11-05 11:09 [PATCH v4 0/2] f2fs: Add sanity checks before unlinking and loading inodes Nikola Z. Ivanov
2025-11-05 11:09 ` [PATCH v4 1/2] f2fs: Rename f2fs_unlink exit label Nikola Z. Ivanov
@ 2025-11-05 11:09 ` Nikola Z. Ivanov
2025-11-05 11:14 ` Chao Yu
2025-11-11 22:50 ` [f2fs-dev] [PATCH v4 0/2] " patchwork-bot+f2fs
2 siblings, 1 reply; 6+ messages in thread
From: Nikola Z. Ivanov @ 2025-11-05 11:09 UTC (permalink / raw)
To: jaegeuk, chao, linux-f2fs-devel
Cc: linux-kernel, skhan, david.hunter.linux, linux-kernel-mentees,
khalid, stable, Nikola Z. Ivanov, syzbot+c07d47c7bc68f47b9083
Add check for inode->i_nlink == 1 for directories during unlink,
as their value is decremented twice, which can trigger a warning in
drop_nlink. In such case mark the filesystem as corrupted and return
from the function call with the relevant failure return value.
Additionally add the check for i_nlink == 1 in
sanity_check_inode in order to detect on-disk corruption early.
Reported-by: syzbot+c07d47c7bc68f47b9083@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c07d47c7bc68f47b9083
Tested-by: syzbot+c07d47c7bc68f47b9083@syzkaller.appspotmail.com
Signed-off-by: Nikola Z. Ivanov <zlatistiv@gmail.com>
---
fs/f2fs/inode.c | 6 ++++++
fs/f2fs/namei.c | 17 ++++++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 8c4eafe9ffac..e2405b79b3cc 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -294,6 +294,12 @@ static bool sanity_check_inode(struct inode *inode, struct folio *node_folio)
return false;
}
+ if (S_ISDIR(inode->i_mode) && unlikely(inode->i_nlink == 1)) {
+ f2fs_warn(sbi, "%s: directory inode (ino=%lx) has a single i_nlink",
+ __func__, inode->i_ino);
+ return false;
+ }
+
if (f2fs_has_extra_attr(inode)) {
if (!f2fs_sb_has_extra_attr(sbi)) {
f2fs_warn(sbi, "%s: inode (ino=%lx) is with extra_attr, but extra_attr feature is off",
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 40cf80fd9d9a..849cfdc57b30 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -570,12 +570,13 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
}
if (unlikely(inode->i_nlink == 0)) {
- f2fs_warn(F2FS_I_SB(inode), "%s: inode (ino=%lx) has zero i_nlink",
+ f2fs_warn(sbi, "%s: inode (ino=%lx) has zero i_nlink",
__func__, inode->i_ino);
- err = -EFSCORRUPTED;
- set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
- f2fs_folio_put(folio, false);
- goto out;
+ goto corrupted;
+ } else if (S_ISDIR(inode->i_mode) && unlikely(inode->i_nlink == 1)) {
+ f2fs_warn(sbi, "%s: directory inode (ino=%lx) has a single i_nlink",
+ __func__, inode->i_ino);
+ goto corrupted;
}
f2fs_balance_fs(sbi, true);
@@ -601,6 +602,12 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
if (IS_DIRSYNC(dir))
f2fs_sync_fs(sbi->sb, 1);
+
+ goto out;
+corrupted:
+ err = -EFSCORRUPTED;
+ set_sbi_flag(sbi, SBI_NEED_FSCK);
+ f2fs_folio_put(folio, false);
out:
trace_f2fs_unlink_exit(inode, err);
return err;
--
2.51.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v4 2/2] f2fs: Add sanity checks before unlinking and loading inodes
2025-11-05 11:09 ` [PATCH v4 2/2] f2fs: Add sanity checks before unlinking and loading inodes Nikola Z. Ivanov
@ 2025-11-05 11:14 ` Chao Yu
0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2025-11-05 11:14 UTC (permalink / raw)
To: Nikola Z. Ivanov, jaegeuk, linux-f2fs-devel
Cc: chao, linux-kernel, skhan, david.hunter.linux,
linux-kernel-mentees, khalid, stable, syzbot+c07d47c7bc68f47b9083
On 11/5/25 19:09, Nikola Z. Ivanov wrote:
> Add check for inode->i_nlink == 1 for directories during unlink,
> as their value is decremented twice, which can trigger a warning in
> drop_nlink. In such case mark the filesystem as corrupted and return
> from the function call with the relevant failure return value.
>
> Additionally add the check for i_nlink == 1 in
> sanity_check_inode in order to detect on-disk corruption early.
>
> Reported-by: syzbot+c07d47c7bc68f47b9083@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=c07d47c7bc68f47b9083
> Tested-by: syzbot+c07d47c7bc68f47b9083@syzkaller.appspotmail.com
> Signed-off-by: Nikola Z. Ivanov <zlatistiv@gmail.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [f2fs-dev] [PATCH v4 0/2] f2fs: Add sanity checks before unlinking and loading inodes
2025-11-05 11:09 [PATCH v4 0/2] f2fs: Add sanity checks before unlinking and loading inodes Nikola Z. Ivanov
2025-11-05 11:09 ` [PATCH v4 1/2] f2fs: Rename f2fs_unlink exit label Nikola Z. Ivanov
2025-11-05 11:09 ` [PATCH v4 2/2] f2fs: Add sanity checks before unlinking and loading inodes Nikola Z. Ivanov
@ 2025-11-11 22:50 ` patchwork-bot+f2fs
2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+f2fs @ 2025-11-11 22:50 UTC (permalink / raw)
To: Nikola Z. Ivanov
Cc: jaegeuk, chao, linux-f2fs-devel, david.hunter.linux, linux-kernel,
khalid, skhan, linux-kernel-mentees, stable
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Wed, 5 Nov 2025 13:09:41 +0200 you wrote:
> This series is provoked by syzbot warnings caused by corrupted directory
> inode with i_nlink == 1 that passes the initial sanity check which will
> only mark the filesystem as corrupted in case i_nlink == 0.
>
> Tests:
> - fio/fsmark parallel create/unlink on VM with f2fs root filesystem.
> - syzbot
>
> [...]
Here is the summary with links:
- [f2fs-dev,v4,1/2] f2fs: Rename f2fs_unlink exit label
https://git.kernel.org/jaegeuk/f2fs/c/7b4827ce2d2a
- [f2fs-dev,v4,2/2] f2fs: Add sanity checks before unlinking and loading inodes
https://git.kernel.org/jaegeuk/f2fs/c/d43f8de77d6c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread