diff options
author | Paolo Abeni <pabeni@redhat.com> | 2021-03-30 19:43:54 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-04-14 09:24:12 +0300 |
commit | b02bded94b91ca27888d9663e690e1c968d06c45 (patch) | |
tree | 4c9d5c2cb4cd90b70e270ea85360821809f3a429 /include/net | |
parent | fd8a95d56050696c99720ac8295f8066ab8d2537 (diff) | |
download | linux-b02bded94b91ca27888d9663e690e1c968d06c45.tar.xz |
net: let skb_orphan_partial wake-up waiters.
commit 9adc89af724f12a03b47099cd943ed54e877cd59 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: f6ba8d33cfbb ("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>
Diffstat (limited to 'include/net')
-rw-r--r-- | include/net/sock.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index e6a48ebb22aa..4137fa178790 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2150,6 +2150,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) +{ + if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) { + skb_orphan(skb); + skb->destructor = sock_efree; + skb->sk = sk; + } +} + void sk_reset_timer(struct sock *sk, struct timer_list *timer, unsigned long expires); |