Skip to content
This repository was archived by the owner on Jun 4, 2020. It is now read-only.

Commit 66aebd4

Browse files
edumazetgregkh
authored andcommitted
net: fix socket refcounting in skb_complete_wifi_ack()
commit dd4f10722aeb10f4f582948839f066bebe44e5fb upstream. TX skbs do not necessarily hold a reference on skb->sk->sk_refcnt By the time TX completion happens, sk_refcnt might be already 0. sock_hold()/sock_put() would then corrupt critical state, like sk_wmem_alloc. Fixes: bf7fa55 ("mac80211: Resolve sk_refcnt/sk_wmem_alloc issue in wifi ack path") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Alexander Duyck <alexander.h.duyck@intel.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Soheil Hassas Yeganeh <soheil@google.com> Cc: Willem de Bruijn <willemb@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1efd08f commit 66aebd4

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

net/core/skbuff.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,7 +3661,7 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
36613661
{
36623662
struct sock *sk = skb->sk;
36633663
struct sock_exterr_skb *serr;
3664-
int err;
3664+
int err = 1;
36653665

36663666
skb->wifi_acked_valid = 1;
36673667
skb->wifi_acked = acked;
@@ -3671,14 +3671,15 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
36713671
serr->ee.ee_errno = ENOMSG;
36723672
serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;
36733673

3674-
/* take a reference to prevent skb_orphan() from freeing the socket */
3675-
sock_hold(sk);
3676-
3677-
err = sock_queue_err_skb(sk, skb);
3674+
/* Take a reference to prevent skb_orphan() from freeing the socket,
3675+
* but only if the socket refcount is not zero.
3676+
*/
3677+
if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) {
3678+
err = sock_queue_err_skb(sk, skb);
3679+
sock_put(sk);
3680+
}
36783681
if (err)
36793682
kfree_skb(skb);
3680-
3681-
sock_put(sk);
36823683
}
36833684
EXPORT_SYMBOL_GPL(skb_complete_wifi_ack);
36843685

0 commit comments

Comments
 (0)