add patch check-for-shutdown-and-ro-fs-in-ext4_write_inode
[ext4-patch-queue.git] / fix-possible-use-after-free-in-ext4_quota_enable
blob9c70c8730107564deb7227898738d986a8b55ce3
1 ext4: fix possible use after free in ext4_quota_enable
3 From: Pan Bian <bianpan2016@163.com>
5 The function frees qf_inode via iput but then pass qf_inode to
6 lockdep_set_quota_inode on the failure path. This may result in a
7 use-after-free bug. The patch frees df_inode only when it is never used.
9 Fixes: daf647d2dd5 ("ext4: add lockdep annotations for i_data_sem")
10 Cc: stable@kernel.org # 4.6
11 Reviewed-by: Jan Kara <jack@suse.cz>
12 Signed-off-by: Pan Bian <bianpan2016@163.com>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 ---
15  fs/ext4/super.c | 2 +-
16  1 file changed, 1 insertion(+), 1 deletion(-)
18 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
19 index 53ff6c2..35689eb 100644
20 --- a/fs/ext4/super.c
21 +++ b/fs/ext4/super.c
22 @@ -5690,9 +5690,9 @@ static int ext4_quota_enable(struct super_block *sb, int type, int format_id,
23         qf_inode->i_flags |= S_NOQUOTA;
24         lockdep_set_quota_inode(qf_inode, I_DATA_SEM_QUOTA);
25         err = dquot_enable(qf_inode, type, format_id, flags);
26 -       iput(qf_inode);
27         if (err)
28                 lockdep_set_quota_inode(qf_inode, I_DATA_SEM_NORMAL);
29 +       iput(qf_inode);
31         return err;
32  }
33 -- 
34 2.7.4