lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHC9VhRwBmC+8iMk8rFbDdwCy+=_unNMybC=HQN=+v5v-nkE8g@mail.gmail.com>
Date: Mon, 24 Nov 2025 15:41:51 -0500
From: Paul Moore <paul@...l-moore.com>
To: Will Rosenberg <whrosenb@....edu>
Cc: Oliver Rosenberg <olrose55@...il.com>, Greg Kroah-Hartman <gregkh@...uxfoundation.org>, 
	Tejun Heo <tj@...nel.org>, Casey Schaufler <casey@...aufler-ca.com>, 
	Ondrej Mosnacek <omosnace@...hat.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node

On Mon, Nov 24, 2025 at 1:37 PM Will Rosenberg <whrosenb@....edu> wrote:
>
> There exists a memory leak of kernfs_iattrs contained as an element
> of kernfs_node allocated in __kernfs_new_node(). __kernfs_setattr()
> allocates kernfs_iattrs as a sub-object, and the LSM security check
> incorrectly errors out and does not free the kernfs_iattrs sub-object.
>
> Make an additional error out case that properly frees kernfs_iattrs if
> security_kernfs_init_security() fails.
>
> Fixes: e19dfdc83b60 ("kernfs: initialize security of newly created nodes")
> Co-developed-by: Oliver Rosenberg <olrose55@...il.com>
> Signed-off-by: Oliver Rosenberg <olrose55@...il.com>
> Signed-off-by: Will Rosenberg <whrosenb@....edu>
> ---
>
> Notes:
>     V1 -> V2: meant as a RESEND, but the commit message and notes were also made more succinct. Patch remained unchanged. v1 was not sent to LKML by mistake.
>     V2 -> V3: Update Fixes tag in commit message. Patch remains unchanged.
>
>  fs/kernfs/dir.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
> index a670ba3e565e..5a40bfee7055 100644
> --- a/fs/kernfs/dir.c
> +++ b/fs/kernfs/dir.c
> @@ -675,11 +675,13 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
>         if (parent) {
>                 ret = security_kernfs_init_security(parent, kn);
>                 if (ret)
> -                       goto err_out3;
> +                       goto err_out4;
>         }
>
>         return kn;
>
> + err_out4:
> +       kfree(kn->iattr);

Should this be kmem_cache_free(kernfs_iattrs_cache, kn->iattr)
instead?  I suspect it would also probably be a good idea to call
simple_xattrs_free() first.

I also noticed there is a reasonable amount of duplicated kernfs
cleanup code spread around fs/kernfs/dir.c, we could probably benefit
from some helper functions here, but that would be a follow-on patch;
keeping a small bugfix patch to ease stable tree backporting is a good
thing.

[HINT FOR THE FUTURE: for patches like this, look for a function that
normally does resource cleanup for the object and do what it does, in
this case kernfs_free_rcu() is a good example.]

>   err_out3:
>         spin_lock(&root->kernfs_idr_lock);
>         idr_remove(&root->ino_idr, (u32)kernfs_ino(kn));
>
> base-commit: dcb6fa37fd7bc9c3d2b066329b0d27dedf8becaa
> --
> 2.34.1

-- 
paul-moore.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ