Skip to content
/ linux Public

Commit a3d6608

Browse files
LATENTBOUNCESasha Levin
authored andcommitted
jfs: nlink overflow in jfs_rename
[ Upstream commit 9218dc2 ] 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. Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl> Reported-by: syzbot+9131ddfd7870623b719f@syzkaller.appspotmail.com Closes: https://syzbot.org/bug?extid=9131ddfd7870623b719f Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e789466 commit a3d6608

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/jfs/namei.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ static int jfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
12271227
jfs_err("jfs_rename: dtInsert returned -EIO");
12281228
goto out_tx;
12291229
}
1230-
if (S_ISDIR(old_ip->i_mode))
1230+
if (S_ISDIR(old_ip->i_mode) && old_dir != new_dir)
12311231
inc_nlink(new_dir);
12321232
}
12331233
/*
@@ -1243,7 +1243,9 @@ static int jfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
12431243
goto out_tx;
12441244
}
12451245
if (S_ISDIR(old_ip->i_mode)) {
1246-
drop_nlink(old_dir);
1246+
if (new_ip || old_dir != new_dir)
1247+
drop_nlink(old_dir);
1248+
12471249
if (old_dir != new_dir) {
12481250
/*
12491251
* Change inode number of parent for moved directory

0 commit comments

Comments
 (0)