Skip to content

Commit b4bbf38

Browse files
TropicaoSasha Levin
authored andcommitted
wifi: wilc1000: fix RCU usage in connect path
[ Upstream commit 205c503 ] With lockdep enabled, calls to the connect function from cfg802.11 layer lead to the following warning: ============================= WARNING: suspicious RCU usage 6.7.0-rc1-wt+ torvalds#333 Not tainted ----------------------------- drivers/net/wireless/microchip/wilc1000/hif.c:386 suspicious rcu_dereference_check() usage! [...] stack backtrace: CPU: 0 PID: 100 Comm: wpa_supplicant Not tainted 6.7.0-rc1-wt+ torvalds#333 Hardware name: Atmel SAMA5 unwind_backtrace from show_stack+0x18/0x1c show_stack from dump_stack_lvl+0x34/0x48 dump_stack_lvl from wilc_parse_join_bss_param+0x7dc/0x7f4 wilc_parse_join_bss_param from connect+0x2c4/0x648 connect from cfg80211_connect+0x30c/0xb74 cfg80211_connect from nl80211_connect+0x860/0xa94 nl80211_connect from genl_rcv_msg+0x3fc/0x59c genl_rcv_msg from netlink_rcv_skb+0xd0/0x1f8 netlink_rcv_skb from genl_rcv+0x2c/0x3c genl_rcv from netlink_unicast+0x3b0/0x550 netlink_unicast from netlink_sendmsg+0x368/0x688 netlink_sendmsg from ____sys_sendmsg+0x190/0x430 ____sys_sendmsg from ___sys_sendmsg+0x110/0x158 ___sys_sendmsg from sys_sendmsg+0xe8/0x150 sys_sendmsg from ret_fast_syscall+0x0/0x1c This warning is emitted because in the connect path, when trying to parse target BSS parameters, we dereference a RCU pointer whithout being in RCU critical section. Fix RCU dereference usage by moving it to a RCU read critical section. To avoid wrapping the whole wilc_parse_join_bss_param under the critical section, just use the critical section to copy ies data Fixes: c460495 ("staging: wilc1000: fix incorrent type in initializer") Signed-off-by: Alexis Lothoré <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://msgid.link/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent fd86efb commit b4bbf38

File tree

1 file changed

+24
-12
lines changed
  • drivers/net/wireless/microchip/wilc1000

1 file changed

+24
-12
lines changed

drivers/net/wireless/microchip/wilc1000/hif.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -359,38 +359,49 @@ static void handle_connect_timeout(struct work_struct *work)
359359
void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
360360
struct cfg80211_crypto_settings *crypto)
361361
{
362-
const struct cfg80211_bss_ies *ies = rcu_dereference(bss->ies);
363-
const u8 *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
362+
const u8 *ies_data, *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
364363
const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
365364
struct ieee80211_p2p_noa_attr noa_attr;
365+
const struct cfg80211_bss_ies *ies;
366366
struct wilc_join_bss_param *param;
367-
u8 rates_len = 0;
367+
u8 rates_len = 0, ies_len;
368368
int ret;
369369

370370
param = kzalloc(sizeof(*param), GFP_KERNEL);
371371
if (!param)
372372
return NULL;
373373

374+
rcu_read_lock();
375+
ies = rcu_dereference(bss->ies);
376+
ies_data = kmemdup(ies->data, ies->len, GFP_ATOMIC);
377+
if (!ies_data) {
378+
rcu_read_unlock();
379+
kfree(param);
380+
return NULL;
381+
}
382+
ies_len = ies->len;
383+
rcu_read_unlock();
384+
374385
param->beacon_period = cpu_to_le16(bss->beacon_interval);
375386
param->cap_info = cpu_to_le16(bss->capability);
376387
param->bss_type = WILC_FW_BSS_TYPE_INFRA;
377388
param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
378389
ether_addr_copy(param->bssid, bss->bssid);
379390

380-
ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
391+
ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies_data, ies_len);
381392
if (ssid_elm) {
382393
if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
383394
memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
384395
}
385396

386-
tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
397+
tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies_data, ies_len);
387398
if (tim_elm && tim_elm[1] >= 2)
388399
param->dtim_period = tim_elm[3];
389400

390401
memset(param->p_suites, 0xFF, 3);
391402
memset(param->akm_suites, 0xFF, 3);
392403

393-
rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies->data, ies->len);
404+
rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies_data, ies_len);
394405
if (rates_ie) {
395406
rates_len = rates_ie[1];
396407
if (rates_len > WILC_MAX_RATES_SUPPORTED)
@@ -401,7 +412,7 @@ void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
401412

402413
if (rates_len < WILC_MAX_RATES_SUPPORTED) {
403414
supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
404-
ies->data, ies->len);
415+
ies_data, ies_len);
405416
if (supp_rates_ie) {
406417
u8 ext_rates = supp_rates_ie[1];
407418

@@ -416,11 +427,11 @@ void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
416427
}
417428
}
418429

419-
ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
430+
ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies_data, ies_len);
420431
if (ht_ie)
421432
param->ht_capable = true;
422433

423-
ret = cfg80211_get_p2p_attr(ies->data, ies->len,
434+
ret = cfg80211_get_p2p_attr(ies_data, ies_len,
424435
IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
425436
(u8 *)&noa_attr, sizeof(noa_attr));
426437
if (ret > 0) {
@@ -444,7 +455,7 @@ void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
444455
}
445456
wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
446457
WLAN_OUI_TYPE_MICROSOFT_WMM,
447-
ies->data, ies->len);
458+
ies_data, ies_len);
448459
if (wmm_ie) {
449460
struct ieee80211_wmm_param_ie *ie;
450461

@@ -459,13 +470,13 @@ void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
459470

460471
wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
461472
WLAN_OUI_TYPE_MICROSOFT_WPA,
462-
ies->data, ies->len);
473+
ies_data, ies_len);
463474
if (wpa_ie) {
464475
param->mode_802_11i = 1;
465476
param->rsn_found = true;
466477
}
467478

468-
rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len);
479+
rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies_data, ies_len);
469480
if (rsn_ie) {
470481
int rsn_ie_len = sizeof(struct element) + rsn_ie[1];
471482
int offset = 8;
@@ -499,6 +510,7 @@ void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
499510
param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
500511
}
501512

513+
kfree(ies_data);
502514
return (void *)param;
503515
}
504516

0 commit comments

Comments
 (0)