Skip to content

Commit d947721

Browse files
author
Jaegeuk Kim
committed
f2fs: fix potential corruption when moving a directory
F2FS has the same issue in ext4_rename causing crash revealed by xfstests/generic/707. See also commit 0813299 ("ext4: Fix possible corruption when moving a directory") CC: stable@vger.kernel.org Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent d09bd85 commit d947721

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

fs/f2fs/namei.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,12 +995,20 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
995995
goto out;
996996
}
997997

998+
/*
999+
* Copied from ext4_rename: we need to protect against old.inode
1000+
* directory getting converted from inline directory format into
1001+
* a normal one.
1002+
*/
1003+
if (S_ISDIR(old_inode->i_mode))
1004+
inode_lock_nested(old_inode, I_MUTEX_NONDIR2);
1005+
9981006
err = -ENOENT;
9991007
old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
10001008
if (!old_entry) {
10011009
if (IS_ERR(old_page))
10021010
err = PTR_ERR(old_page);
1003-
goto out;
1011+
goto out_unlock_old;
10041012
}
10051013

10061014
if (S_ISDIR(old_inode->i_mode)) {
@@ -1108,6 +1116,9 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
11081116

11091117
f2fs_unlock_op(sbi);
11101118

1119+
if (S_ISDIR(old_inode->i_mode))
1120+
inode_unlock(old_inode);
1121+
11111122
if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
11121123
f2fs_sync_fs(sbi->sb, 1);
11131124

@@ -1122,6 +1133,9 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
11221133
f2fs_put_page(old_dir_page, 0);
11231134
out_old:
11241135
f2fs_put_page(old_page, 0);
1136+
out_unlock_old:
1137+
if (S_ISDIR(old_inode->i_mode))
1138+
inode_unlock(old_inode);
11251139
out:
11261140
iput(whiteout);
11271141
return err;

0 commit comments

Comments
 (0)