Skip to content

Commit 4ee186f

Browse files
ikichajmberg-intel
authored andcommitted
wifi: mac80211_hwsim: fix race condition in pending packet
A pending packet uses a cookie as an unique key, but it can be duplicated because it didn't use atomic operators. And also, a pending packet can be null in hwsim_tx_info_frame_received_nl due to race condition with mac80211_hwsim_stop. For this, * Use an atomic type and operator for a cookie * Add a lock around the loop for pending packets Signed-off-by: Jeongik Cha <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent 37babce commit 4ee186f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/net/wireless/mac80211_hwsim.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ struct mac80211_hwsim_data {
687687
bool ps_poll_pending;
688688
struct dentry *debugfs;
689689

690-
uintptr_t pending_cookie;
690+
atomic64_t pending_cookie;
691691
struct sk_buff_head pending; /* packets pending */
692692
/*
693693
* Only radios in the same group can communicate together (the
@@ -1358,7 +1358,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
13581358
int i;
13591359
struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES];
13601360
struct hwsim_tx_rate_flag tx_attempts_flags[IEEE80211_TX_MAX_RATES];
1361-
uintptr_t cookie;
1361+
u64 cookie;
13621362

13631363
if (data->ps != PS_DISABLED)
13641364
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
@@ -1427,8 +1427,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
14271427
goto nla_put_failure;
14281428

14291429
/* We create a cookie to identify this skb */
1430-
data->pending_cookie++;
1431-
cookie = data->pending_cookie;
1430+
cookie = (u64)atomic64_inc_return(&data->pending_cookie);
14321431
info->rate_driver_data[0] = (void *)cookie;
14331432
if (nla_put_u64_64bit(skb, HWSIM_ATTR_COOKIE, cookie, HWSIM_ATTR_PAD))
14341433
goto nla_put_failure;
@@ -4178,6 +4177,7 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
41784177
const u8 *src;
41794178
unsigned int hwsim_flags;
41804179
int i;
4180+
unsigned long flags;
41814181
bool found = false;
41824182

41834183
if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] ||
@@ -4205,18 +4205,20 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
42054205
}
42064206

42074207
/* look for the skb matching the cookie passed back from user */
4208+
spin_lock_irqsave(&data2->pending.lock, flags);
42084209
skb_queue_walk_safe(&data2->pending, skb, tmp) {
42094210
u64 skb_cookie;
42104211

42114212
txi = IEEE80211_SKB_CB(skb);
4212-
skb_cookie = (u64)(uintptr_t)txi->rate_driver_data[0];
4213+
skb_cookie = (u64)txi->rate_driver_data[0];
42134214

42144215
if (skb_cookie == ret_skb_cookie) {
4215-
skb_unlink(skb, &data2->pending);
4216+
__skb_unlink(skb, &data2->pending);
42164217
found = true;
42174218
break;
42184219
}
42194220
}
4221+
spin_unlock_irqrestore(&data2->pending.lock, flags);
42204222

42214223
/* not found */
42224224
if (!found)

0 commit comments

Comments
 (0)