]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.18.11/ext4-check-to-make-sure-the-rename-2-s-destination-is-not-freed.patch
Linux 4.9.169
[thirdparty/kernel/stable-queue.git] / releases / 4.18.11 / ext4-check-to-make-sure-the-rename-2-s-destination-is-not-freed.patch
CommitLineData
9d09275e
GKH
1From b50282f3241acee880514212d88b6049fb5039c8 Mon Sep 17 00:00:00 2001
2From: Theodore Ts'o <tytso@mit.edu>
3Date: Mon, 27 Aug 2018 01:47:09 -0400
4Subject: ext4: check to make sure the rename(2)'s destination is not freed
5
6From: Theodore Ts'o <tytso@mit.edu>
7
8commit b50282f3241acee880514212d88b6049fb5039c8 upstream.
9
10If the destination of the rename(2) system call exists, the inode's
11link count (i_nlinks) must be non-zero. If it is, the inode can end
12up on the orphan list prematurely, leading to all sorts of hilarity,
13including a use-after-free.
14
15https://bugzilla.kernel.org/show_bug.cgi?id=200931
16
17Signed-off-by: Theodore Ts'o <tytso@mit.edu>
18Reported-by: Wen Xu <wen.xu@gatech.edu>
19Cc: stable@vger.kernel.org
20Signed-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)))