summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2018-08-27 01:47:09 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-09-29 03:07:34 -0700
commit23f57cb1f1a3bddfccddc6f7026461b2a4d9bcc7 (patch)
tree171a3a10d58d906aea7ab1140640d8fe6879cb17
parent0ec459ec174031fad02a55e622cf2fc0d2e75a25 (diff)
ext4: check to make sure the rename(2)'s destination is not freed
commit b50282f3241acee880514212d88b6049fb5039c8 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>
-rw-r--r--fs/ext4/namei.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index a225a21d04ad..bc727c393a89 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -3527,6 +3527,12 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
int credits;
u8 old_file_type;
+ if (new.inode && new.inode->i_nlink == 0) {
+ EXT4_ERROR_INODE(new.inode,
+ "target of rename is already freed");
+ return -EFSCORRUPTED;
+ }
+
if ((ext4_test_inode_flag(new_dir, EXT4_INODE_PROJINHERIT)) &&
(!projid_eq(EXT4_I(new_dir)->i_projid,
EXT4_I(old_dentry->d_inode)->i_projid)))