Skip to content

Commit 2b74209

Browse files
mowteamgregkh
authored andcommitted
fs/kernfs: null-ptr deref in simple_xattrs_free()
There exists a null pointer dereference in simple_xattrs_free() as part of the __kernfs_new_node() routine. Within __kernfs_new_node(), err_out4 calls simple_xattr_free(), but kn->iattr may be NULL if __kernfs_setattr() was never called. As a result, the first argument to simple_xattrs_free() may be NULL + 0x38, and no NULL check is done internally, causing an incorrect pointer dereference. Add a check to ensure kn->iattr is not NULL, meaning __kernfs_setattr() has been called and kn->iattr is allocated. Note that struct kernfs_node kn is allocated with kmem_cache_zalloc, so we can assume kn->iattr will be NULL if not allocated. An alternative fix could be to not call simple_xattrs_free() at all. As was previously discussed during the initial patch, simple_xattrs_free() is not strictly needed and is included to be consistent with kernfs_free_rcu(), which also helps the function maintain correctness if changes are made in __kernfs_new_node(). Reported-by: syzbot+6aaf7f48ae034ab0ea97@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=6aaf7f48ae034ab0ea97 Fixes: 382b1e8 ("kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node") Signed-off-by: Will Rosenberg <whrosenb@asu.edu> Link: https://patch.msgid.link/20251217060107.4171558-1-whrosenb@asu.edu Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 87e7f60 commit 2b74209

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

fs/kernfs/dir.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,10 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
681681
return kn;
682682

683683
err_out4:
684-
simple_xattrs_free(&kn->iattr->xattrs, NULL);
685-
kmem_cache_free(kernfs_iattrs_cache, kn->iattr);
684+
if (kn->iattr) {
685+
simple_xattrs_free(&kn->iattr->xattrs, NULL);
686+
kmem_cache_free(kernfs_iattrs_cache, kn->iattr);
687+
}
686688
err_out3:
687689
spin_lock(&root->kernfs_idr_lock);
688690
idr_remove(&root->ino_idr, (u32)kernfs_ino(kn));

0 commit comments

Comments
 (0)