Skip to content

Commit cc9b364

Browse files
Zhang Changzhongklassert
authored andcommitted
xfrm6: fix inet6_dev refcount underflow problem
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: 510c321 ("xfrm: reuse uncached_list to track xdsts") Signed-off-by: Zhang Changzhong <[email protected]> Reviewed-by: Xin Long <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 3e4bc23 commit cc9b364

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/ipv6/xfrm6_policy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ static void xfrm6_dst_destroy(struct dst_entry *dst)
117117
{
118118
struct xfrm_dst *xdst = (struct xfrm_dst *)dst;
119119

120-
if (likely(xdst->u.rt6.rt6i_idev))
121-
in6_dev_put(xdst->u.rt6.rt6i_idev);
122120
dst_destroy_metrics_generic(dst);
123121
rt6_uncached_list_del(&xdst->u.rt6);
122+
if (likely(xdst->u.rt6.rt6i_idev))
123+
in6_dev_put(xdst->u.rt6.rt6i_idev);
124124
xfrm_dst_destroy(xdst);
125125
}
126126

0 commit comments

Comments
 (0)