[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221024112950.023006337@linuxfoundation.org>
Date: Mon, 24 Oct 2022 13:29:32 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: linux-kernel@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
stable@...r.kernel.org, butt3rflyh4ck <butterflyhuangxx@...il.com>,
Hao Sun <sunhao.th@...il.com>, Jiacheng Xu <stitch@....edu.cn>,
"Christian Brauner (Microsoft)" <brauner@...nel.org>,
Dongliang Mu <mudongliangabcd@...il.com>,
Al Viro <viro@...iv.linux.org.uk>
Subject: [PATCH 4.9 018/159] fs: fix UAF/GPF bug in nilfs_mdt_destroy
From: Dongliang Mu <mudongliangabcd@...il.com>
commit 2e488f13755ffbb60f307e991b27024716a33b29 upstream.
In alloc_inode, inode_init_always() could return -ENOMEM if
security_inode_alloc() fails, which causes inode->i_private
uninitialized. Then nilfs_is_metadata_file_inode() returns
true and nilfs_free_inode() wrongly calls nilfs_mdt_destroy(),
which frees the uninitialized inode->i_private
and leads to crashes(e.g., UAF/GPF).
Fix this by moving security_inode_alloc just prior to
this_cpu_inc(nr_inodes)
Link: https://lkml.kernel.org/r/CAFcO6XOcf1Jj2SeGt=jJV59wmhESeSKpfR0omdFRq+J9nD1vfQ@mail.gmail.com
Reported-by: butt3rflyh4ck <butterflyhuangxx@...il.com>
Reported-by: Hao Sun <sunhao.th@...il.com>
Reported-by: Jiacheng Xu <stitch@....edu.cn>
Reviewed-by: Christian Brauner (Microsoft) <brauner@...nel.org>
Signed-off-by: Dongliang Mu <mudongliangabcd@...il.com>
Cc: Al Viro <viro@...iv.linux.org.uk>
Cc: stable@...r.kernel.org
Signed-off-by: Al Viro <viro@...iv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
fs/inode.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -164,8 +164,6 @@ int inode_init_always(struct super_block
inode->i_wb_frn_history = 0;
#endif
- if (security_inode_alloc(inode))
- goto out;
spin_lock_init(&inode->i_lock);
lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
@@ -192,11 +190,12 @@ int inode_init_always(struct super_block
inode->i_fsnotify_mask = 0;
#endif
inode->i_flctx = NULL;
+
+ if (unlikely(security_inode_alloc(inode)))
+ return -ENOMEM;
this_cpu_inc(nr_inodes);
return 0;
-out:
- return -ENOMEM;
}
EXPORT_SYMBOL(inode_init_always);
Powered by blists - more mailing lists