Re: [PATCH 3/3] net-sysfs: Fix error path for kobject_init_and_add()

From: wanghai (M)
Date: Wed May 08 2019 - 11:00:37 EST

å 2019/5/1 0:11, Andy Shevchenko åé:
On Tue, Apr 30, 2019 at 10:28:17AM +1000, Tobin C. Harding wrote:
Currently error return from kobject_init_and_add() is not followed by a
call to kobject_put(). This means there is a memory leak.

Add call to kobject_put() in error path of kobject_init_and_add().
It's not obvious to me if this will help to fix what is stated in the
(reverted) commit 6b70fc94afd1 ("net-sysfs: Fix memory leak in

If so, perhaps we need to tell syzkaller guys about this.
Thanks for reminding. It seems that the bug has not been completely fixed.

in netdev_register_kobject():

1746ÂÂÂÂÂÂÂÂ error = device_add(dev);
1747ÂÂÂÂÂÂÂÂ if (error)
1748ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return error;
1750ÂÂÂÂÂÂÂÂ error = register_queue_kobjects(ndev);
1751ÂÂÂÂÂÂÂÂ if (error) {
1752ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ device_del(dev);
1753ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return error;

This only fixes a memory leak after a failure in register_queue_kobjects(). If device_add() fails, kobject_put() still cann't be called, and the memory leak still exists.