|
| 1 | +fs: fix UAF/GPF bug in nilfs_mdt_destroy |
| 2 | + |
| 3 | +jira LE-4704 |
| 4 | +cve CVE-2022-50367 |
| 5 | +Rebuild_History Non-Buildable kernel-4.18.0-553.83.1.el8_10 |
| 6 | +commit-author Dongliang Mu <mudongliangabcd@gmail.com> |
| 7 | +commit 2e488f13755ffbb60f307e991b27024716a33b29 |
| 8 | +Empty-Commit: Cherry-Pick Conflicts during history rebuild. |
| 9 | +Will be included in final tarball splat. Ref for failed cherry-pick at: |
| 10 | +ciq/ciq_backports/kernel-4.18.0-553.83.1.el8_10/2e488f13.failed |
| 11 | + |
| 12 | +In alloc_inode, inode_init_always() could return -ENOMEM if |
| 13 | +security_inode_alloc() fails, which causes inode->i_private |
| 14 | +uninitialized. Then nilfs_is_metadata_file_inode() returns |
| 15 | +true and nilfs_free_inode() wrongly calls nilfs_mdt_destroy(), |
| 16 | +which frees the uninitialized inode->i_private |
| 17 | +and leads to crashes(e.g., UAF/GPF). |
| 18 | + |
| 19 | +Fix this by moving security_inode_alloc just prior to |
| 20 | +this_cpu_inc(nr_inodes) |
| 21 | + |
| 22 | +Link: https://lkml.kernel.org/r/CAFcO6XOcf1Jj2SeGt=jJV59wmhESeSKpfR0omdFRq+J9nD1vfQ@mail.gmail.com |
| 23 | + Reported-by: butt3rflyh4ck <butterflyhuangxx@gmail.com> |
| 24 | + Reported-by: Hao Sun <sunhao.th@gmail.com> |
| 25 | + Reported-by: Jiacheng Xu <stitch@zju.edu.cn> |
| 26 | + Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org> |
| 27 | + Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com> |
| 28 | + Cc: Al Viro <viro@zeniv.linux.org.uk> |
| 29 | + Cc: stable@vger.kernel.org |
| 30 | + Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> |
| 31 | +(cherry picked from commit 2e488f13755ffbb60f307e991b27024716a33b29) |
| 32 | + Signed-off-by: Jonathan Maple <jmaple@ciq.com> |
| 33 | + |
| 34 | +# Conflicts: |
| 35 | +# fs/inode.c |
| 36 | +diff --cc fs/inode.c |
| 37 | +index 024853e8ceb1,5559a2983341..000000000000 |
| 38 | +--- a/fs/inode.c |
| 39 | ++++ b/fs/inode.c |
| 40 | +@@@ -166,10 -192,6 +166,13 @@@ int inode_init_always(struct super_bloc |
| 41 | + inode->i_wb_frn_history = 0; |
| 42 | + #endif |
| 43 | + |
| 44 | +++<<<<<<< HEAD |
| 45 | + + inode->rh_reserved2 = 0; |
| 46 | + + |
| 47 | + + if (security_inode_alloc(inode)) |
| 48 | + + goto out; |
| 49 | +++======= |
| 50 | +++>>>>>>> 2e488f13755f (fs: fix UAF/GPF bug in nilfs_mdt_destroy) |
| 51 | + spin_lock_init(&inode->i_lock); |
| 52 | + lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key); |
| 53 | + |
| 54 | +* Unmerged path fs/inode.c |
0 commit comments