* [PATCH net] xfrm6: fix inet6_dev refcount underflow problem
@ 2023-09-15 11:20 Zhang Changzhong
2023-09-15 18:51 ` Xin Long
2023-09-25 5:41 ` Steffen Klassert
0 siblings, 2 replies; 3+ messages in thread
From: Zhang Changzhong @ 2023-09-15 11:20 UTC (permalink / raw)
To: Steffen Klassert, Herbert Xu, David S. Miller, David Ahern,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Xin Long
Cc: Zhang Changzhong, netdev, linux-kernel
There are race conditions that may lead to inet6_dev refcount underflow
in xfrm6_dst_destroy() and rt6_uncached_list_flush_dev().
One of the refcount underflow bugs is shown below:
(cpu 1) | (cpu 2)
xfrm6_dst_destroy() |
... |
in6_dev_put() |
| rt6_uncached_list_flush_dev()
... | ...
| in6_dev_put()
rt6_uncached_list_del() | ...
... |
xfrm6_dst_destroy() calls rt6_uncached_list_del() after in6_dev_put(),
so rt6_uncached_list_flush_dev() has a chance to call in6_dev_put()
again for the same inet6_dev.
Fix it by moving in6_dev_put() after rt6_uncached_list_del() in
xfrm6_dst_destroy().
Fixes: 510c321b5571 ("xfrm: reuse uncached_list to track xdsts")
Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
---
net/ipv6/xfrm6_policy.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
index 41a680c..42fb6996 100644
--- a/net/ipv6/xfrm6_policy.c
+++ b/net/ipv6/xfrm6_policy.c
@@ -117,10 +117,10 @@ static void xfrm6_dst_destroy(struct dst_entry *dst)
{
struct xfrm_dst *xdst = (struct xfrm_dst *)dst;
- if (likely(xdst->u.rt6.rt6i_idev))
- in6_dev_put(xdst->u.rt6.rt6i_idev);
dst_destroy_metrics_generic(dst);
rt6_uncached_list_del(&xdst->u.rt6);
+ if (likely(xdst->u.rt6.rt6i_idev))
+ in6_dev_put(xdst->u.rt6.rt6i_idev);
xfrm_dst_destroy(xdst);
}
--
2.9.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] xfrm6: fix inet6_dev refcount underflow problem
2023-09-15 11:20 [PATCH net] xfrm6: fix inet6_dev refcount underflow problem Zhang Changzhong
@ 2023-09-15 18:51 ` Xin Long
2023-09-25 5:41 ` Steffen Klassert
1 sibling, 0 replies; 3+ messages in thread
From: Xin Long @ 2023-09-15 18:51 UTC (permalink / raw)
To: Zhang Changzhong
Cc: Steffen Klassert, Herbert Xu, David S. Miller, David Ahern,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
On Fri, Sep 15, 2023 at 6:54 AM Zhang Changzhong
<zhangchangzhong@huawei.com> wrote:
>
> There are race conditions that may lead to inet6_dev refcount underflow
> in xfrm6_dst_destroy() and rt6_uncached_list_flush_dev().
>
> One of the refcount underflow bugs is shown below:
> (cpu 1) | (cpu 2)
> xfrm6_dst_destroy() |
> ... |
> in6_dev_put() |
> | rt6_uncached_list_flush_dev()
> ... | ...
> | in6_dev_put()
> rt6_uncached_list_del() | ...
> ... |
>
> xfrm6_dst_destroy() calls rt6_uncached_list_del() after in6_dev_put(),
> so rt6_uncached_list_flush_dev() has a chance to call in6_dev_put()
> again for the same inet6_dev.
>
> Fix it by moving in6_dev_put() after rt6_uncached_list_del() in
> xfrm6_dst_destroy().
>
> Fixes: 510c321b5571 ("xfrm: reuse uncached_list to track xdsts")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
> ---
> net/ipv6/xfrm6_policy.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
> index 41a680c..42fb6996 100644
> --- a/net/ipv6/xfrm6_policy.c
> +++ b/net/ipv6/xfrm6_policy.c
> @@ -117,10 +117,10 @@ static void xfrm6_dst_destroy(struct dst_entry *dst)
> {
> struct xfrm_dst *xdst = (struct xfrm_dst *)dst;
>
> - if (likely(xdst->u.rt6.rt6i_idev))
> - in6_dev_put(xdst->u.rt6.rt6i_idev);
> dst_destroy_metrics_generic(dst);
> rt6_uncached_list_del(&xdst->u.rt6);
> + if (likely(xdst->u.rt6.rt6i_idev))
> + in6_dev_put(xdst->u.rt6.rt6i_idev);
> xfrm_dst_destroy(xdst);
> }
>
> --
> 2.9.5
>
Reviewed-by: Xin Long <lucien.xin@gmail.com>
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] xfrm6: fix inet6_dev refcount underflow problem
2023-09-15 11:20 [PATCH net] xfrm6: fix inet6_dev refcount underflow problem Zhang Changzhong
2023-09-15 18:51 ` Xin Long
@ 2023-09-25 5:41 ` Steffen Klassert
1 sibling, 0 replies; 3+ messages in thread
From: Steffen Klassert @ 2023-09-25 5:41 UTC (permalink / raw)
To: Zhang Changzhong
Cc: Herbert Xu, David S. Miller, David Ahern, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Xin Long, netdev, linux-kernel
On Fri, Sep 15, 2023 at 07:20:41PM +0800, Zhang Changzhong wrote:
> There are race conditions that may lead to inet6_dev refcount underflow
> in xfrm6_dst_destroy() and rt6_uncached_list_flush_dev().
>
> One of the refcount underflow bugs is shown below:
> (cpu 1) | (cpu 2)
> xfrm6_dst_destroy() |
> ... |
> in6_dev_put() |
> | rt6_uncached_list_flush_dev()
> ... | ...
> | in6_dev_put()
> rt6_uncached_list_del() | ...
> ... |
>
> xfrm6_dst_destroy() calls rt6_uncached_list_del() after in6_dev_put(),
> so rt6_uncached_list_flush_dev() has a chance to call in6_dev_put()
> again for the same inet6_dev.
>
> Fix it by moving in6_dev_put() after rt6_uncached_list_del() in
> xfrm6_dst_destroy().
>
> Fixes: 510c321b5571 ("xfrm: reuse uncached_list to track xdsts")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
Applied, thanks a lot!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-25 5:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-15 11:20 [PATCH net] xfrm6: fix inet6_dev refcount underflow problem Zhang Changzhong
2023-09-15 18:51 ` Xin Long
2023-09-25 5:41 ` Steffen Klassert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®