]>
Commit | Line | Data |
---|---|---|
9d09275e GKH |
1 | From b50282f3241acee880514212d88b6049fb5039c8 Mon Sep 17 00:00:00 2001 |
2 | From: Theodore Ts'o <tytso@mit.edu> | |
3 | Date: Mon, 27 Aug 2018 01:47:09 -0400 | |
4 | Subject: ext4: check to make sure the rename(2)'s destination is not freed | |
5 | ||
6 | From: Theodore Ts'o <tytso@mit.edu> | |
7 | ||
8 | commit b50282f3241acee880514212d88b6049fb5039c8 upstream. | |
9 | ||
10 | If the destination of the rename(2) system call exists, the inode's | |
11 | link count (i_nlinks) must be non-zero. If it is, the inode can end | |
12 | up on the orphan list prematurely, leading to all sorts of hilarity, | |
13 | including a use-after-free. | |
14 | ||
15 | https://bugzilla.kernel.org/show_bug.cgi?id=200931 | |
16 | ||
17 | Signed-off-by: Theodore Ts'o <tytso@mit.edu> | |
18 | Reported-by: Wen Xu <wen.xu@gatech.edu> | |
19 | Cc: stable@vger.kernel.org | |
20 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
21 | ||
22 | --- | |
23 | fs/ext4/namei.c | 6 ++++++ | |
24 | 1 file changed, 6 insertions(+) | |
25 | ||
26 | --- a/fs/ext4/namei.c | |
27 | +++ b/fs/ext4/namei.c | |
28 | @@ -3478,6 +3478,12 @@ static int ext4_rename(struct inode *old | |
29 | int credits; | |
30 | u8 old_file_type; | |
31 | ||
32 | + if (new.inode && new.inode->i_nlink == 0) { | |
33 | + EXT4_ERROR_INODE(new.inode, | |
34 | + "target of rename is already freed"); | |
35 | + return -EFSCORRUPTED; | |
36 | + } | |
37 | + | |
38 | if ((ext4_test_inode_flag(new_dir, EXT4_INODE_PROJINHERIT)) && | |
39 | (!projid_eq(EXT4_I(new_dir)->i_projid, | |
40 | EXT4_I(old_dentry->d_inode)->i_projid))) |