nlink overflow in jfs_rename
PATCH 1/1 nlink overflow in jfs_rename
If nlink is maximal for a directory (-1) and inside that directory you perform a rename for some child directory (not moving from the parent), then the nlink of the first directory is first incremented and later decremented. Normally this is fine, but when nlink = -1 this causes a wrap around to 0, and then drop_nlink issues a warning.
After applying the patch syzbot no longer issues any warnings. I also ran some basic fs tests to look for any regressions.
--- fs/jfs/namei.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/jfs/namei.c +4 -2
@@ -1228,7 +1228,7 @@ static int jfs_rename(struct mnt_idmap *idmap, struct inode *old_dir,jfs_err ("jfs_rename: dtInsert returned -EIO" ); goto out_tx; } -if (S_ISDIR (old_ip->i_mode)) +if (S_ISDIR (old_ip->i_mode) && old_dir != new_dir)inc_nlink (new_dir); }/*
@@ -1244,7 +1244,9 @@ static int jfs_rename(struct mnt_idmap *idmap, struct inode *old_dir, goto out_tx; }if (S_ISDIR (old_ip->i_mode)) { -drop_nlink (old_dir); +if (new_ip || old_dir != new_dir) +drop_nlink (old_dir); +if (old_dir != new_dir) {/* * Change inode number of parent for moved directory
Signature · 1 line
2.51.0
PATCH 1/1 nlink overflow in jfs_rename
Below syzbot bug has not been fixed yet. If anyone has time I would greatly appreciate a review of my patch, so it can be moved along. It has been sitting for a few weeks.
Thanks,
Jori.
Apologies for the resend, I messed up the email headers.
Quoted 15 lines
Op 28-10-2025 13:22 CET schreef Jori Koolstra <[email protected]>:
If nlink is maximal for a directory (-1) and inside that directory you perform a rename for some child directory (not moving from the parent), then the nlink of the first directory is first incremented and later decremented. Normally this is fine, but when nlink = -1 this causes a wrap around to 0, and then
drop_nlinkissues a warning.After applying the patch syzbot no longer issues any warnings. I also ran some basic fs tests to look for any regressions.
Signed-off-by Jori Koolstra <[email protected]>Reported-by [email protected]
PATCH 1/1 jfs: nlink overflow in jfs_rename
Below syzbot bug has not been fixed yet. If anyone has time I would greatly appreciate a review of my patch, so it can be moved along. It has been sitting for quite a few weeks.
Thanks,
Jori.
Quoted 15 lines
Op 28-10-2025 13:22 CET schreef Jori Koolstra <[email protected]>:
If nlink is maximal for a directory (-1) and inside that directory you perform a rename for some child directory (not moving from the parent), then the nlink of the first directory is first incremented and later decremented. Normally this is fine, but when nlink = -1 this causes a wrap around to 0, and then
drop_nlinkissues a warning.After applying the patch syzbot no longer issues any warnings. I also ran some basic fs tests to look for any regressions.
Signed-off-by Jori Koolstra <[email protected]>Reported-by [email protected]