提交 93bb64ea 编写于 作者: E Eric Dumazet 提交者: David S. Miller

net: skb_free_datagram_locked() fix

Commit 4b0b72f7 ( net: speedup udp receive path )
introduced a bug in skb_free_datagram_locked().

We should not skb_orphan() skb if we dont have the guarantee we are the
last skb user, this might happen with MSG_PEEK concurrent users.

To keep socket locked for the smallest period of time, we split
consume_skb() logic, inlined in skb_free_datagram_locked()
Reported-by: NStephen Hemminger <shemminger@vyatta.com>
Signed-off-by: NEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 f5460618
...@@ -229,13 +229,18 @@ EXPORT_SYMBOL(skb_free_datagram); ...@@ -229,13 +229,18 @@ EXPORT_SYMBOL(skb_free_datagram);
void skb_free_datagram_locked(struct sock *sk, struct sk_buff *skb) void skb_free_datagram_locked(struct sock *sk, struct sk_buff *skb)
{ {
if (likely(atomic_read(&skb->users) == 1))
smp_rmb();
else if (likely(!atomic_dec_and_test(&skb->users)))
return;
lock_sock_bh(sk); lock_sock_bh(sk);
skb_orphan(skb); skb_orphan(skb);
sk_mem_reclaim_partial(sk); sk_mem_reclaim_partial(sk);
unlock_sock_bh(sk); unlock_sock_bh(sk);
/* skb is now orphaned, might be freed outside of locked section */ /* skb is now orphaned, can be freed outside of locked section */
consume_skb(skb); __kfree_skb(skb);
} }
EXPORT_SYMBOL(skb_free_datagram_locked); EXPORT_SYMBOL(skb_free_datagram_locked);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册