* [PATCH v3] fs/kernfs: null-ptr deref in simple_xattrs_free()
[not found] <2025121653-overfeed-giblet-5bde@gregkh>
@ 2025-12-16 16:43 ` Will Rosenberg
2025-12-17 5:19 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Will Rosenberg @ 2025-12-16 16:43 UTC (permalink / raw)
Cc: Paul Moore, Will Rosenberg, syzbot+6aaf7f48ae034ab0ea97, stable,
Greg Kroah-Hartman, Tejun Heo, Oliver Rosenberg, linux-kernel
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_xattr_free() at all. As
was previously discussed during the initial patch, simple_xattr_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: 382b1e8f30f7 ("kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node")
Cc: stable@vger.kernel.org
Signed-off-by: Will Rosenberg <whrosenb@asu.edu>
---
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));
base-commit: d358e5254674b70f34c847715ca509e46eb81e6f
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] fs/kernfs: null-ptr deref in simple_xattrs_free()
2025-12-16 16:43 ` [PATCH v3] fs/kernfs: null-ptr deref in simple_xattrs_free() Will Rosenberg
@ 2025-12-17 5:19 ` Greg Kroah-Hartman
2025-12-17 6:01 ` [PATCH v4] " Will Rosenberg
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2025-12-17 5:19 UTC (permalink / raw)
To: Will Rosenberg
Cc: Paul Moore, syzbot+6aaf7f48ae034ab0ea97, stable, Tejun Heo,
Oliver Rosenberg, linux-kernel
On Tue, Dec 16, 2025 at 09:43:35AM -0700, Will Rosenberg wrote:
> 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_xattr_free() at all. As
> was previously discussed during the initial patch, simple_xattr_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: 382b1e8f30f7 ("kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node")
> Cc: stable@vger.kernel.org
> Signed-off-by: Will Rosenberg <whrosenb@asu.edu>
> ---
> 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));
>
> base-commit: d358e5254674b70f34c847715ca509e46eb81e6f
> --
> 2.34.1
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- This looks like a new version of a previously submitted patch, but you
did not list below the --- line any changes from the previous version.
Please read the section entitled "The canonical patch format" in the
kernel file, Documentation/process/submitting-patches.rst for what
needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v4] fs/kernfs: null-ptr deref in simple_xattrs_free()
2025-12-17 5:19 ` Greg Kroah-Hartman
@ 2025-12-17 6:01 ` Will Rosenberg
0 siblings, 0 replies; 3+ messages in thread
From: Will Rosenberg @ 2025-12-17 6:01 UTC (permalink / raw)
To: gregkh
Cc: linux-kernel, olrose55, paul, stable, syzbot+6aaf7f48ae034ab0ea97,
tj, whrosenb
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: 382b1e8f30f7 ("kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node")
Cc: stable@vger.kernel.org
Signed-off-by: Will Rosenberg <whrosenb@asu.edu>
---
Notes:
v1 -> v2: fix patch formatting issues
v2 -> v3: add cc stable branch
v3 -> v4: re-add the notes section.
This bug was introduced as part of a patch I made, fixing a memory
leak in the error out case.
I apologize for the oversight. Further fuzzing revealed the bug,
and after checking, I found that syzbot detected the same issue.
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));
base-commit: d358e5254674b70f34c847715ca509e46eb81e6f
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-17 6:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <2025121653-overfeed-giblet-5bde@gregkh>
2025-12-16 16:43 ` [PATCH v3] fs/kernfs: null-ptr deref in simple_xattrs_free() Will Rosenberg
2025-12-17 5:19 ` Greg Kroah-Hartman
2025-12-17 6:01 ` [PATCH v4] " Will Rosenberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).