Skip to content

Commit 31343d2

Browse files
tytsogregkh
authored andcommitted
ext4: check to make sure the rename(2)'s destination is not freed
commit b50282f upstream. If the destination of the rename(2) system call exists, the inode's link count (i_nlinks) must be non-zero. If it is, the inode can end up on the orphan list prematurely, leading to all sorts of hilarity, including a use-after-free. https://bugzilla.kernel.org/show_bug.cgi?id=200931 Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reported-by: Wen Xu <wen.xu@gatech.edu> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4334a6a commit 31343d2

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

fs/ext4/namei.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3514,6 +3514,12 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
35143514
int credits;
35153515
u8 old_file_type;
35163516

3517+
if (new.inode && new.inode->i_nlink == 0) {
3518+
EXT4_ERROR_INODE(new.inode,
3519+
"target of rename is already freed");
3520+
return -EFSCORRUPTED;
3521+
}
3522+
35173523
if ((ext4_test_inode_flag(new_dir, EXT4_INODE_PROJINHERIT)) &&
35183524
(!projid_eq(EXT4_I(new_dir)->i_projid,
35193525
EXT4_I(old_dentry->d_inode)->i_projid)))

0 commit comments

Comments
 (0)