add patch set-ext4_dax_aops-for-dax-files
[ext4-patch-queue.git] / check-rename-destination-is-not-freed
blob8e0ca5f1e189ce1b32775d093679614c3eb74f35
1 ext4: check to make sure the rename(2)'s destination is not freed
3 If the destination of the rename(2) system call exists, the inode's
4 link count (i_nlinks) must be non-zero.  If it is, the inode can end
5 up on the orphan list prematurely, leading to all sorts of hilarity,
6 including a use-after-free.
8 https://bugzilla.kernel.org/show_bug.cgi?id=200931
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 Reported-by: Wen Xu <wen.xu@gatech.edu>
12 Cc: stable@vger.kernel.org
13 ---
14  fs/ext4/namei.c | 6 ++++++
15  1 file changed, 6 insertions(+)
17 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
18 index 116ff68c5bd4..377d516c475f 100644
19 --- a/fs/ext4/namei.c
20 +++ b/fs/ext4/namei.c
21 @@ -3478,6 +3478,12 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
22         int credits;
23         u8 old_file_type;
25 +       if (new.inode && new.inode->i_nlink == 0) {
26 +               EXT4_ERROR_INODE(new.inode,
27 +                                "target of rename is already freed");
28 +               return -EFSCORRUPTED;
29 +       }
31         if ((ext4_test_inode_flag(new_dir, EXT4_INODE_PROJINHERIT)) &&
32             (!projid_eq(EXT4_I(new_dir)->i_projid,
33                         EXT4_I(old_dentry->d_inode)->i_projid)))