Skip to content

Commit 9e76833

Browse files
edumazetgregkh
authored andcommitted
net: fix socket refcounting in skb_complete_wifi_ack()
[ Upstream commit dd4f10722aeb10f4f582948839f066bebe44e5fb ] 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 2681a78 commit 9e76833

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
@@ -3735,7 +3735,7 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
37353735
{
37363736
struct sock *sk = skb->sk;
37373737
struct sock_exterr_skb *serr;
3738-
int err;
3738+
int err = 1;
37393739

37403740
skb->wifi_acked_valid = 1;
37413741
skb->wifi_acked = acked;
@@ -3745,14 +3745,15 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
37453745
serr->ee.ee_errno = ENOMSG;
37463746
serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;
37473747

3748-
/* take a reference to prevent skb_orphan() from freeing the socket */
3749-
sock_hold(sk);
3750-
3751-
err = sock_queue_err_skb(sk, skb);
3748+
/* Take a reference to prevent skb_orphan() from freeing the socket,
3749+
* but only if the socket refcount is not zero.
3750+
*/
3751+
if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) {
3752+
err = sock_queue_err_skb(sk, skb);
3753+
sock_put(sk);
3754+
}
37523755
if (err)
37533756
kfree_skb(skb);
3754-
3755-
sock_put(sk);
37563757
}
37573758
EXPORT_SYMBOL_GPL(skb_complete_wifi_ack);
37583759

0 commit comments

Comments
 (0)