Commit 098116e7 authored by Paolo Abeni's avatar Paolo Abeni Committed by David S. Miller

net: really orphan skbs tied to closing sk

If the owing socket is shutting down - e.g. the sock reference
count already dropped to 0 and only sk_wmem_alloc is keeping
the sock alive, skb_orphan_partial() becomes a no-op.

When forwarding packets over veth with GRO enabled, the above
causes refcount errors.

This change addresses the issue with a plain skb_orphan() call
in the critical scenario.

Fixes: 9adc89af ("net: let skb_orphan_partial wake-up waiters.")
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 440c3247
...@@ -2231,13 +2231,15 @@ static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk) ...@@ -2231,13 +2231,15 @@ static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
sk_mem_charge(sk, skb->truesize); sk_mem_charge(sk, skb->truesize);
} }
static inline void skb_set_owner_sk_safe(struct sk_buff *skb, struct sock *sk) static inline __must_check bool skb_set_owner_sk_safe(struct sk_buff *skb, struct sock *sk)
{ {
if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) { if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) {
skb_orphan(skb); skb_orphan(skb);
skb->destructor = sock_efree; skb->destructor = sock_efree;
skb->sk = sk; skb->sk = sk;
return true;
} }
return false;
} }
void sk_reset_timer(struct sock *sk, struct timer_list *timer, void sk_reset_timer(struct sock *sk, struct timer_list *timer,
......
...@@ -2132,10 +2132,10 @@ void skb_orphan_partial(struct sk_buff *skb) ...@@ -2132,10 +2132,10 @@ void skb_orphan_partial(struct sk_buff *skb)
if (skb_is_tcp_pure_ack(skb)) if (skb_is_tcp_pure_ack(skb))
return; return;
if (can_skb_orphan_partial(skb)) if (can_skb_orphan_partial(skb) && skb_set_owner_sk_safe(skb, skb->sk))
skb_set_owner_sk_safe(skb, skb->sk); return;
else
skb_orphan(skb); skb_orphan(skb);
} }
EXPORT_SYMBOL(skb_orphan_partial); EXPORT_SYMBOL(skb_orphan_partial);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment