Re: [PATCH v2] kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node

From: Greg Kroah-Hartman
Date: Mon Nov 24 2025 - 11:15:46 EST


On Mon, Nov 24, 2025 at 09:02:26AM -0700, Will Rosenberg 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: f72dae20891d7bcc43e9263ab206960b6ae5209f ("Merge tag 'selinux-pr-20190507' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux")

Did the error really happen on a merge? That feels very wrong.

Also, please read the docs, it says how big to make that sha1 value :)

> Co-developed-by: Oliver Rosenberg <olrose55@xxxxxxxxx>
> Signed-off-by: Oliver Rosenberg <olrose55@xxxxxxxxx>
> Signed-off-by: Will Rosenberg <whrosenb@xxxxxxx>
> ---
> fs/kernfs/dir.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)

What changed from v2?

Again, please read the kernel docs on how to submit a patch.

thanks,

greg k-h