Skip to content

Commit 605b6b2

Browse files
edumazetgregkh
authored andcommitted
netem: fix skb_orphan_partial()
commit f6ba8d33cfbb46df569972e64dbb5bb7e929bfd9 upstream. I should have known that lowering skb->truesize was dangerous :/ In case packets are not leaving the host via a standard Ethernet device, but looped back to local sockets, bad things can happen, as reported by Michael Madsen ( https://bugzilla.kernel.org/show_bug.cgi?id=195713 ) So instead of tweaking skb->truesize, lets change skb->destructor and keep a reference on the owner socket via its sk_refcnt. Fixes: f2f872f ("netem: Introduce skb_orphan_partial() helper") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Michael Madsen <mkm@nabto.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 338f665 commit 605b6b2

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

net/core/sock.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,17 +1690,17 @@ EXPORT_SYMBOL(skb_set_owner_w);
16901690

16911691
void skb_orphan_partial(struct sk_buff *skb)
16921692
{
1693-
/* TCP stack sets skb->ooo_okay based on sk_wmem_alloc,
1694-
* so we do not completely orphan skb, but transfert all
1695-
* accounted bytes but one, to avoid unexpected reorders.
1696-
*/
16971693
if (skb->destructor == sock_wfree
16981694
#ifdef CONFIG_INET
16991695
|| skb->destructor == tcp_wfree
17001696
#endif
17011697
) {
1702-
atomic_sub(skb->truesize - 1, &skb->sk->sk_wmem_alloc);
1703-
skb->truesize = 1;
1698+
struct sock *sk = skb->sk;
1699+
1700+
if (atomic_inc_not_zero(&sk->sk_refcnt)) {
1701+
atomic_sub(skb->truesize, &sk->sk_wmem_alloc);
1702+
skb->destructor = sock_efree;
1703+
}
17041704
} else {
17051705
skb_orphan(skb);
17061706
}

0 commit comments

Comments
 (0)