netlink: put module reference if dump start fails
Subsystems (2)
PATCH 1/1 netlink: put module reference if dump start fails
Before, if cb->start() failed, the module reference would never be put, because cb->cb_running is intentionally false at this point. Users are generally annoyed by this because they can no longer unload modules that leak references. Also, it may be possible to tediously wrap a reference counter back to zero, especially since module.c still uses atomic_inc instead of refcount_inc.
This patch expands the error path to simply call module_put if cb->start() fails.
---
This probably should be queued up for stable.
net/netlink/af_netlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netlink/af_netlink.c +3 -1
@@ -2308,7 +2308,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,if (cb->start) { ret = cb->start (cb);if (ret) - goto error_unlock; + goto error_put; } nlk->cb_running = true;
@@ -2328,6 +2328,8 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,*/ return -EINTR ; +error_put: +module_put (control->module); error_unlock:sock_put (sk);mutex_unlock (nlk->cb_mutex);
Signature · 1 line
2.16.1
Quoted 7 lines · Jason A. Donenfeld
Before, if
cb->start()failed, the module reference would never be put, becausecb->cb_runningis intentionally false at this point. Users are generally annoyed by this because they can no longer unload modules that leak references. Also, it may be possible to tediously wrap a reference counter back to zero, especially sincemodule.cstill usesatomic_incinstead ofrefcount_inc.
Quoted 6 lines
This patch expands the error path to simply call
module_putifcb->start()fails.Signed-off-by Jason A. Donenfeld <[email protected]>---
This probably should be queued up for stable.
When was the bug added ? This would help a lot stable teams ...
Thanks.
Quoted 3 lines · Eric Dumazet
Quoted 1 line
This probably should be queued up for stable.
When was the bug added ? This would help a lot stable teams ...
This needs to be backported to 4.16-rc0+, 4.15+, 4.14+, 4.13.14+, and 4.9.63+.
Quoted 6 lines · Jason A. Donenfeld
Quoted 3 lines · Eric Dumazet
Quoted 1 line
This probably should be queued up for stable.
When was the bug added ? This would help a lot stable teams ...
This needs to be backported to 4.16-rc0+, 4.15+, 4.14+, 4.13.14+, and 4.9.63+.
I guess I should have asked you to provide an appropriate Fixes: tag, clearly identifying the commit that added the bug.
Thanks.
Hi,
Quoted 1 line · Jason A. Donenfeld
Fixes 41c87425a1ac ("netlink: do not set cb_running if dump's start() errs")
I think you Would better to resend it.
Bo,
David Miller
maintainerFrom: "Jason A. Donenfeld" <[email protected]>
Date: Wed, 21 Feb 2018 04:41:59 +0100
Quoted 7 lines
Before, if
cb->start()failed, the module reference would never be put, becausecb->cb_runningis intentionally false at this point. Users are generally annoyed by this because they can no longer unload modules that leak references. Also, it may be possible to tediously wrap a reference counter back to zero, especially sincemodule.cstill usesatomic_incinstead ofrefcount_inc.
Quoted 6 lines
This patch expands the error path to simply call
module_putifcb->start()fails.Signed-off-by Jason A. Donenfeld <[email protected]>---
This probably should be queued up for stable.
Applied and queued up for -stable.
Thanks!
Jason