f2fs: fix potential corruption when moving a directory
commitd94772154e
upstream. F2FS has the same issue in ext4_rename causing crash revealed by xfstests/generic/707. See also commit0813299c58
("ext4: Fix possible corruption when moving a directory") CC: stable@vger.kernel.org Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
1424358cd6
commit
f201911009
|
@ -998,12 +998,20 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copied from ext4_rename: we need to protect against old.inode
|
||||||
|
* directory getting converted from inline directory format into
|
||||||
|
* a normal one.
|
||||||
|
*/
|
||||||
|
if (S_ISDIR(old_inode->i_mode))
|
||||||
|
inode_lock_nested(old_inode, I_MUTEX_NONDIR2);
|
||||||
|
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
|
old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
|
||||||
if (!old_entry) {
|
if (!old_entry) {
|
||||||
if (IS_ERR(old_page))
|
if (IS_ERR(old_page))
|
||||||
err = PTR_ERR(old_page);
|
err = PTR_ERR(old_page);
|
||||||
goto out;
|
goto out_unlock_old;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISDIR(old_inode->i_mode)) {
|
if (S_ISDIR(old_inode->i_mode)) {
|
||||||
|
@ -1111,6 +1119,9 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
|
||||||
|
|
||||||
f2fs_unlock_op(sbi);
|
f2fs_unlock_op(sbi);
|
||||||
|
|
||||||
|
if (S_ISDIR(old_inode->i_mode))
|
||||||
|
inode_unlock(old_inode);
|
||||||
|
|
||||||
if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
|
if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
|
||||||
f2fs_sync_fs(sbi->sb, 1);
|
f2fs_sync_fs(sbi->sb, 1);
|
||||||
|
|
||||||
|
@ -1125,6 +1136,9 @@ out_dir:
|
||||||
f2fs_put_page(old_dir_page, 0);
|
f2fs_put_page(old_dir_page, 0);
|
||||||
out_old:
|
out_old:
|
||||||
f2fs_put_page(old_page, 0);
|
f2fs_put_page(old_page, 0);
|
||||||
|
out_unlock_old:
|
||||||
|
if (S_ISDIR(old_inode->i_mode))
|
||||||
|
inode_unlock(old_inode);
|
||||||
out:
|
out:
|
||||||
iput(whiteout);
|
iput(whiteout);
|
||||||
return err;
|
return err;
|
||||||
|
|
Loading…
Reference in New Issue