* [PATCH] net-sysfs: fix error handling in netdev_register_kobject()
@ 2025-03-13 7:55 Ma Ke
2025-03-13 9:01 ` Andy Shevchenko
2025-03-13 9:58 ` Greg KH
0 siblings, 2 replies; 4+ messages in thread
From: Ma Ke @ 2025-03-13 7:55 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, horms, jdamato, aleksander.lobakin,
make24, quic_zijuhu, andriy.shevchenko, wanghai26
Cc: netdev, linux-kernel, stable
Once device_add() failed, we should call put_device() to decrement
reference count for cleanup. Or it could cause memory leak.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 8ed633b9baf9 ("Revert "net-sysfs: Fix memory leak in netdev_register_kobject"")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
net/core/net-sysfs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 07cb99b114bd..f443eacc9237 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -2169,6 +2169,7 @@ int netdev_register_kobject(struct net_device *ndev)
error = device_add(dev);
if (error)
+ put_device(dev);
return error;
error = register_queue_kobjects(ndev);
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net-sysfs: fix error handling in netdev_register_kobject()
2025-03-13 7:55 [PATCH] net-sysfs: fix error handling in netdev_register_kobject() Ma Ke
@ 2025-03-13 9:01 ` Andy Shevchenko
2025-03-13 9:02 ` Andy Shevchenko
2025-03-13 9:58 ` Greg KH
1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2025-03-13 9:01 UTC (permalink / raw)
To: Ma Ke
Cc: davem, edumazet, kuba, pabeni, horms, jdamato, aleksander.lobakin,
quic_zijuhu, wanghai26, netdev, linux-kernel, stable
On Thu, Mar 13, 2025 at 03:55:28PM +0800, Ma Ke wrote:
> Once device_add() failed, we should call put_device() to decrement
> reference count for cleanup. Or it could cause memory leak.
>
> As comment of device_add() says, 'if device_add() succeeds, you should
> call device_del() when you want to get rid of it. If device_add() has
> not succeeded, use only put_device() to drop the reference count'.
Okay, have you read the history of this?
6b70fc94afd1 ("net-sysfs: Fix memory leak in netdev_register_kobject")
8ed633b9baf9 ("Revert "net-sysfs: Fix memory leak in netdev_register_kobject"")
https://syzkaller.appspot.com/x/log.txt?x=1737671b200000
TL;DR: next time provide a better changelog and clean syzkaller report.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net-sysfs: fix error handling in netdev_register_kobject()
2025-03-13 9:01 ` Andy Shevchenko
@ 2025-03-13 9:02 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-03-13 9:02 UTC (permalink / raw)
To: Ma Ke, Wang Hai
Cc: davem, edumazet, kuba, pabeni, horms, jdamato, aleksander.lobakin,
quic_zijuhu, wanghai26, netdev, linux-kernel, stable
+Cc: Wang Hai
On Thu, Mar 13, 2025 at 11:01:18AM +0200, Andy Shevchenko wrote:
> On Thu, Mar 13, 2025 at 03:55:28PM +0800, Ma Ke wrote:
> > Once device_add() failed, we should call put_device() to decrement
> > reference count for cleanup. Or it could cause memory leak.
> >
> > As comment of device_add() says, 'if device_add() succeeds, you should
> > call device_del() when you want to get rid of it. If device_add() has
> > not succeeded, use only put_device() to drop the reference count'.
>
> Okay, have you read the history of this?
> 6b70fc94afd1 ("net-sysfs: Fix memory leak in netdev_register_kobject")
> 8ed633b9baf9 ("Revert "net-sysfs: Fix memory leak in netdev_register_kobject"")
> https://syzkaller.appspot.com/x/log.txt?x=1737671b200000
>
> TL;DR: next time provide a better changelog and clean syzkaller report.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net-sysfs: fix error handling in netdev_register_kobject()
2025-03-13 7:55 [PATCH] net-sysfs: fix error handling in netdev_register_kobject() Ma Ke
2025-03-13 9:01 ` Andy Shevchenko
@ 2025-03-13 9:58 ` Greg KH
1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2025-03-13 9:58 UTC (permalink / raw)
To: Ma Ke
Cc: davem, edumazet, kuba, pabeni, horms, jdamato, aleksander.lobakin,
quic_zijuhu, andriy.shevchenko, wanghai26, netdev, linux-kernel,
stable
On Thu, Mar 13, 2025 at 03:55:28PM +0800, Ma Ke wrote:
> Once device_add() failed, we should call put_device() to decrement
> reference count for cleanup. Or it could cause memory leak.
>
> As comment of device_add() says, 'if device_add() succeeds, you should
> call device_del() when you want to get rid of it. If device_add() has
> not succeeded, use only put_device() to drop the reference count'.
>
> Found by code review.
>
> Cc: stable@vger.kernel.org
> Fixes: 8ed633b9baf9 ("Revert "net-sysfs: Fix memory leak in netdev_register_kobject"")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> net/core/net-sysfs.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
> index 07cb99b114bd..f443eacc9237 100644
> --- a/net/core/net-sysfs.c
> +++ b/net/core/net-sysfs.c
> @@ -2169,6 +2169,7 @@ int netdev_register_kobject(struct net_device *ndev)
>
> error = device_add(dev);
> if (error)
> + put_device(dev);
> return error;
You obviously did not test this :(
Please be more careful in the future.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-13 9:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-13 7:55 [PATCH] net-sysfs: fix error handling in netdev_register_kobject() Ma Ke
2025-03-13 9:01 ` Andy Shevchenko
2025-03-13 9:02 ` Andy Shevchenko
2025-03-13 9:58 ` Greg KH
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).