Skip to content

Commit b830650

Browse files
Paolo Abenigregkh
authored andcommitted
net: let skb_orphan_partial wake-up waiters.
commit 9adc89a upstream. Currently the mentioned helper can end-up freeing the socket wmem without waking-up any processes waiting for more write memory. If the partially orphaned skb is attached to an UDP (or raw) socket, the lack of wake-up can hang the user-space. Even for TCP sockets not calling the sk destructor could have bad effects on TSQ. Address the issue using skb_orphan to release the sk wmem before setting the new sock_efree destructor. Additionally bundle the whole ownership update in a new helper, so that later other potential users could avoid duplicate code. v1 -> v2: - use skb_orphan() instead of sort of open coding it (Eric) - provide an helper for the ownership change (Eric) Fixes: f6ba8d3 ("netem: fix skb_orphan_partial()") Suggested-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5d9216b commit b830650

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎include/net/sock.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,15 @@ static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
21972197
sk_mem_charge(sk, skb->truesize);
21982198
}
21992199

2200+
static inline void skb_set_owner_sk_safe(struct sk_buff *skb, struct sock *sk)
2201+
{
2202+
if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) {
2203+
skb_orphan(skb);
2204+
skb->destructor = sock_efree;
2205+
skb->sk = sk;
2206+
}
2207+
}
2208+
22002209
void sk_reset_timer(struct sock *sk, struct timer_list *timer,
22012210
unsigned long expires);
22022211

‎net/core/sock.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,16 +2099,10 @@ void skb_orphan_partial(struct sk_buff *skb)
20992099
if (skb_is_tcp_pure_ack(skb))
21002100
return;
21012101

2102-
if (can_skb_orphan_partial(skb)) {
2103-
struct sock *sk = skb->sk;
2104-
2105-
if (refcount_inc_not_zero(&sk->sk_refcnt)) {
2106-
WARN_ON(refcount_sub_and_test(skb->truesize, &sk->sk_wmem_alloc));
2107-
skb->destructor = sock_efree;
2108-
}
2109-
} else {
2102+
if (can_skb_orphan_partial(skb))
2103+
skb_set_owner_sk_safe(skb, skb->sk);
2104+
else
21102105
skb_orphan(skb);
2111-
}
21122106
}
21132107
EXPORT_SYMBOL(skb_orphan_partial);
21142108

0 commit comments

Comments
 (0)