Re: [Linux Kernel Bug] memory leak in ubi_attach

From: gregkh@xxxxxxxxxxxxxxxxxxx
Date: Tue Oct 15 2024 - 02:55:09 EST


On Tue, Oct 15, 2024 at 03:41:24AM +0000, Ryder Wang wrote:
> By walking through all the related code, it looks to be a bug in slub.c rather than kobject or ubifs.
>
> sysfs_slab_add() calls kobject_init_and_add():
> - If kobject_init_and_add fails, sysfs_slab_add() will go to *out*. But unluckily, *out* code block will never release s->kobj, but it is expected to do so.
>
> Below is the function comment of kobject_init_and_add():
> * If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. *
> ==> It means sysfs_slab_add() shall release the related kobject.

Yup, that's a bug, please send a patch to fix this!

thanks,

greg k-h