Skip to content

Commit

Permalink
net: really orphan skbs tied to closing sk
Browse files Browse the repository at this point in the history
[ Upstream commit 098116e ]

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: 9adc89a ("net: let skb_orphan_partial wake-up waiters.")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Paolo Abeni authored and gregkh committed Jun 3, 2021
1 parent 90ee484 commit 718f5f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion include/net/sock.h
Expand Up @@ -2225,13 +2225,15 @@ static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
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)) {
skb_orphan(skb);
skb->destructor = sock_efree;
skb->sk = sk;
return true;
}
return false;
}

void sk_reset_timer(struct sock *sk, struct timer_list *timer,
Expand Down
8 changes: 4 additions & 4 deletions net/core/sock.c
Expand Up @@ -2132,10 +2132,10 @@ void skb_orphan_partial(struct sk_buff *skb)
if (skb_is_tcp_pure_ack(skb))
return;

if (can_skb_orphan_partial(skb))
skb_set_owner_sk_safe(skb, skb->sk);
else
skb_orphan(skb);
if (can_skb_orphan_partial(skb) && skb_set_owner_sk_safe(skb, skb->sk))
return;

skb_orphan(skb);
}
EXPORT_SYMBOL(skb_orphan_partial);

Expand Down

0 comments on commit 718f5f7

Please sign in to comment.