Skip to content

Commit bf7fa55

Browse files
Alexander Duyckdavem330
authored andcommitted
mac80211: Resolve sk_refcnt/sk_wmem_alloc issue in wifi ack path
There is a possible issue with the use, or lack thereof of sk_refcnt and sk_wmem_alloc in the wifi ack status functionality. Specifically if a socket were to request acknowledgements, and the socket were to have sk_refcnt drop to 0 resulting in it waiting on sk_wmem_alloc to reach 0 it would be possible to have sock_queue_err_skb orphan the last buffer, resulting in __sk_free being called on the socket. After this the buffer is enqueued on sk_error_queue, however the queue has already been flushed resulting in at least a memory leak, if not a data corruption. Signed-off-by: Alexander Duyck <[email protected]> Acked-by: Johannes Berg <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cab41c4 commit bf7fa55

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

net/core/skbuff.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3628,9 +3628,14 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
36283628
serr->ee.ee_errno = ENOMSG;
36293629
serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;
36303630

3631+
/* take a reference to prevent skb_orphan() from freeing the socket */
3632+
sock_hold(sk);
3633+
36313634
err = sock_queue_err_skb(sk, skb);
36323635
if (err)
36333636
kfree_skb(skb);
3637+
3638+
sock_put(sk);
36343639
}
36353640
EXPORT_SYMBOL_GPL(skb_complete_wifi_ack);
36363641

net/mac80211/tx.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,30 +2072,23 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
20722072

20732073
if (unlikely(!multicast && skb->sk &&
20742074
skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)) {
2075-
struct sk_buff *orig_skb = skb;
2075+
struct sk_buff *ack_skb = skb_clone_sk(skb);
20762076

2077-
skb = skb_clone(skb, GFP_ATOMIC);
2078-
if (skb) {
2077+
if (ack_skb) {
20792078
unsigned long flags;
20802079
int id;
20812080

20822081
spin_lock_irqsave(&local->ack_status_lock, flags);
2083-
id = idr_alloc(&local->ack_status_frames, orig_skb,
2082+
id = idr_alloc(&local->ack_status_frames, ack_skb,
20842083
1, 0x10000, GFP_ATOMIC);
20852084
spin_unlock_irqrestore(&local->ack_status_lock, flags);
20862085

20872086
if (id >= 0) {
20882087
info_id = id;
20892088
info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2090-
} else if (skb_shared(skb)) {
2091-
kfree_skb(orig_skb);
20922089
} else {
2093-
kfree_skb(skb);
2094-
skb = orig_skb;
2090+
kfree_skb(ack_skb);
20952091
}
2096-
} else {
2097-
/* couldn't clone -- lose tx status ... */
2098-
skb = orig_skb;
20992092
}
21002093
}
21012094

0 commit comments

Comments
 (0)