Skip to content

Commit 8dca1e0

Browse files
committed
fs: fix UAF/GPF bug in nilfs_mdt_destroy
jira VULN-155283 cve CVE-2022-50367 commit-author Dongliang Mu <[email protected]> commit 2e488f1 upstream-diff | Adjusted context in inode_init_always to due rh specific variable rh_reserved2 being initialized to 0 added in commit: dbb05b7 ("Rebuild centos8 with kernel-4.18.0-80.el8") 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 <[email protected]> Reported-by: Hao Sun <[email protected]> Reported-by: Jiacheng Xu <[email protected]> Reviewed-by: Christian Brauner (Microsoft) <[email protected]> Signed-off-by: Dongliang Mu <[email protected]> Cc: Al Viro <[email protected]> Cc: [email protected] Signed-off-by: Al Viro <[email protected]> (cherry picked from commit 2e488f1) Signed-off-by: Roxana Nicolescu <[email protected]>
1 parent 8aed17c commit 8dca1e0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

fs/inode.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
168168

169169
inode->rh_reserved2 = 0;
170170

171-
if (security_inode_alloc(inode))
172-
goto out;
173171
spin_lock_init(&inode->i_lock);
174172
lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
175173

@@ -200,11 +198,12 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
200198
inode->i_fsnotify_mask = 0;
201199
#endif
202200
inode->i_flctx = NULL;
201+
202+
if (unlikely(security_inode_alloc(inode)))
203+
return -ENOMEM;
203204
this_cpu_inc(nr_inodes);
204205

205206
return 0;
206-
out:
207-
return -ENOMEM;
208207
}
209208
EXPORT_SYMBOL(inode_init_always);
210209

0 commit comments

Comments
 (0)