* [PATCH] kernfs: fix NULL pointer dereference in __kernfs_new_node()
[not found] <AOoAIQD0J-9V1NW0JM55A4po.1.1769761572059.Hmail.3019244382@tju.edu.cn>
@ 2026-02-01 17:05 ` Tejun Heo
2026-02-01 17:41 ` Will Rosenberg
0 siblings, 1 reply; 2+ messages in thread
From: Tejun Heo @ 2026-02-01 17:05 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Will Rosenberg, Oliver Rosenberg, 杜义恒,
linux-kernel, stable
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1368 bytes --]
Commit 382b1e8f30f7 ("kernfs: fix memory leak of kernfs_iattrs in
__kernfs_new_node") introduced an err_out4 error path which frees iattr
when security_kernfs_init_security() fails. However, iattr is only
allocated by __kernfs_setattr() when the node has non-default uid/gid.
If the node uses default ownership, iattr remains NULL, and
security_kernfs_init_security() failure would cause a NULL pointer
dereference when err_out4 tries to access kn->iattr->xattrs.
Add a NULL check before freeing iattr.
Fixes: 382b1e8f30f7 ("kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node")
Cc: stable@vger.kernel.org
Reported-by: 杜义恒 <duyiheng@tju.edu.cn>
Signed-off-by: Tejun Heo <tj@kernel.org>
---
fs/kernfs/dir.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 5c0efd6b239f..29baeeb97871 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -681,8 +681,10 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
return kn;
err_out4:
- simple_xattrs_free(&kn->iattr->xattrs, NULL);
- kmem_cache_free(kernfs_iattrs_cache, kn->iattr);
+ if (kn->iattr) {
+ simple_xattrs_free(&kn->iattr->xattrs, NULL);
+ kmem_cache_free(kernfs_iattrs_cache, kn->iattr);
+ }
err_out3:
spin_lock(&root->kernfs_idr_lock);
idr_remove(&root->ino_idr, (u32)kernfs_ino(kn));
--
2.47.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] kernfs: fix NULL pointer dereference in __kernfs_new_node()
2026-02-01 17:05 ` [PATCH] kernfs: fix NULL pointer dereference in __kernfs_new_node() Tejun Heo
@ 2026-02-01 17:41 ` Will Rosenberg
0 siblings, 0 replies; 2+ messages in thread
From: Will Rosenberg @ 2026-02-01 17:41 UTC (permalink / raw)
To: Tejun Heo
Cc: Greg Kroah-Hartman, Oliver Rosenberg, 杜义恒,
linux-kernel, stable
On Sun, Feb 01, 2026 at 07:05:50AM -1000, Tejun Heo wrote:
> Commit 382b1e8f30f7 ("kernfs: fix memory leak of kernfs_iattrs in
> __kernfs_new_node") introduced an err_out4 error path which frees iattr
> when security_kernfs_init_security() fails. However, iattr is only
> allocated by __kernfs_setattr() when the node has non-default uid/gid.
> If the node uses default ownership, iattr remains NULL, and
> security_kernfs_init_security() failure would cause a NULL pointer
> dereference when err_out4 tries to access kn->iattr->xattrs.
>
> Add a NULL check before freeing iattr.
>
> Fixes: 382b1e8f30f7 ("kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node")
Thank you for reporting the bug.
This bug has been fixed by Commit 2b742094582d ("fs/kernfs: null-ptr deref in simple_xattrs_free()").
Commit 382b1e8f30f7 ("kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node")
was also caught from entering any stable releases, so the bug should be
fixed on all active branches.
Please correct me if this bug has not been fully addressed.
--
Will Rosenberg
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-01 17:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <AOoAIQD0J-9V1NW0JM55A4po.1.1769761572059.Hmail.3019244382@tju.edu.cn>
2026-02-01 17:05 ` [PATCH] kernfs: fix NULL pointer dereference in __kernfs_new_node() Tejun Heo
2026-02-01 17:41 ` Will Rosenberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox