Skip to content

Commit 05cbcc4

Browse files
jwrdegoedegregkh
authored andcommitted
staging: rtl8723bs: Fix key-store index handling
There are 2 issues with the key-store index handling 1. The non WEP key stores can store keys with indexes 0 - BIP_MAX_KEYID, this means that they should be an array with BIP_MAX_KEYID + 1 entries. But some of the arrays where just BIP_MAX_KEYID entries big. While one other array was hardcoded to a size of 6 entries, instead of using the BIP_MAX_KEYID define. 2. The rtw_cfg80211_set_encryption() and wpa_set_encryption() functions index check where checking that the passed in key-index would fit inside both the WEP key store (which only has 4 entries) as well as in the non WEP key stores. This breaks any attempts to set non WEP keys with index 4 or 5. Issue 2. specifically breaks wifi connection with some access points which advertise PMF support. Without this fix connecting to these access points fails with the following wpa_supplicant messages: nl80211: kernel reports: key addition failed wlan0: WPA: Failed to configure IGTK to the driver wlan0: RSN: Failed to configure IGTK wlan0: CTRL-EVENT-DISCONNECTED bssid=... reason=1 locally_generated=1 Fix 1. by using the right size for the key-stores. After this 2. can safely be fixed by checking the right max-index value depending on the used algorithm, fixing wifi not working with some PMF capable APs. Cc: [email protected] Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fe413a0 commit 05cbcc4

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

drivers/staging/rtl8723bs/include/rtw_security.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ struct security_priv {
107107

108108
u32 dot118021XGrpPrivacy; /* This specify the privacy algthm. used for Grp key */
109109
u32 dot118021XGrpKeyid; /* key id used for Grp Key (tx key index) */
110-
union Keytype dot118021XGrpKey[BIP_MAX_KEYID]; /* 802.1x Group Key, for inx0 and inx1 */
111-
union Keytype dot118021XGrptxmickey[BIP_MAX_KEYID];
112-
union Keytype dot118021XGrprxmickey[BIP_MAX_KEYID];
110+
union Keytype dot118021XGrpKey[BIP_MAX_KEYID + 1]; /* 802.1x Group Key, for inx0 and inx1 */
111+
union Keytype dot118021XGrptxmickey[BIP_MAX_KEYID + 1];
112+
union Keytype dot118021XGrprxmickey[BIP_MAX_KEYID + 1];
113113
union pn48 dot11Grptxpn; /* PN48 used for Grp Key xmit. */
114114
union pn48 dot11Grprxpn; /* PN48 used for Grp Key recv. */
115115
u32 dot11wBIPKeyid; /* key id used for BIP Key (tx key index) */
116-
union Keytype dot11wBIPKey[6]; /* BIP Key, for index4 and index5 */
116+
union Keytype dot11wBIPKey[BIP_MAX_KEYID + 1]; /* BIP Key, for index4 and index5 */
117117
union pn48 dot11wBIPtxpn; /* PN48 used for Grp Key xmit. */
118118
union pn48 dot11wBIPrxpn; /* PN48 used for Grp Key recv. */
119119

drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
711711
static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
712712
{
713713
int ret = 0;
714+
u8 max_idx;
714715
u32 wep_key_idx, wep_key_len;
715716
struct adapter *padapter = rtw_netdev_priv(dev);
716717
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -724,26 +725,29 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param
724725
goto exit;
725726
}
726727

727-
if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
728-
param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
729-
param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
730-
if (param->u.crypt.idx >= WEP_KEYS
731-
|| param->u.crypt.idx >= BIP_MAX_KEYID) {
732-
ret = -EINVAL;
733-
goto exit;
734-
}
735-
} else {
736-
{
728+
if (param->sta_addr[0] != 0xff || param->sta_addr[1] != 0xff ||
729+
param->sta_addr[2] != 0xff || param->sta_addr[3] != 0xff ||
730+
param->sta_addr[4] != 0xff || param->sta_addr[5] != 0xff) {
737731
ret = -EINVAL;
738732
goto exit;
739733
}
734+
735+
if (strcmp(param->u.crypt.alg, "WEP") == 0)
736+
max_idx = WEP_KEYS - 1;
737+
else
738+
max_idx = BIP_MAX_KEYID;
739+
740+
if (param->u.crypt.idx > max_idx) {
741+
netdev_err(dev, "Error crypt.idx %d > %d\n", param->u.crypt.idx, max_idx);
742+
ret = -EINVAL;
743+
goto exit;
740744
}
741745

742746
if (strcmp(param->u.crypt.alg, "WEP") == 0) {
743747
wep_key_idx = param->u.crypt.idx;
744748
wep_key_len = param->u.crypt.key_len;
745749

746-
if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
750+
if (wep_key_len <= 0) {
747751
ret = -EINVAL;
748752
goto exit;
749753
}

drivers/staging/rtl8723bs/os_dep/ioctl_linux.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static int wpa_set_auth_algs(struct net_device *dev, u32 value)
4646
static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
4747
{
4848
int ret = 0;
49+
u8 max_idx;
4950
u32 wep_key_idx, wep_key_len, wep_total_len;
5051
struct ndis_802_11_wep *pwep = NULL;
5152
struct adapter *padapter = rtw_netdev_priv(dev);
@@ -60,19 +61,22 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
6061
goto exit;
6162
}
6263

63-
if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
64-
param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
65-
param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
66-
if (param->u.crypt.idx >= WEP_KEYS ||
67-
param->u.crypt.idx >= BIP_MAX_KEYID) {
68-
ret = -EINVAL;
69-
goto exit;
70-
}
71-
} else {
72-
{
73-
ret = -EINVAL;
74-
goto exit;
75-
}
64+
if (param->sta_addr[0] != 0xff || param->sta_addr[1] != 0xff ||
65+
param->sta_addr[2] != 0xff || param->sta_addr[3] != 0xff ||
66+
param->sta_addr[4] != 0xff || param->sta_addr[5] != 0xff) {
67+
ret = -EINVAL;
68+
goto exit;
69+
}
70+
71+
if (strcmp(param->u.crypt.alg, "WEP") == 0)
72+
max_idx = WEP_KEYS - 1;
73+
else
74+
max_idx = BIP_MAX_KEYID;
75+
76+
if (param->u.crypt.idx > max_idx) {
77+
netdev_err(dev, "Error crypt.idx %d > %d\n", param->u.crypt.idx, max_idx);
78+
ret = -EINVAL;
79+
goto exit;
7680
}
7781

7882
if (strcmp(param->u.crypt.alg, "WEP") == 0) {
@@ -84,9 +88,6 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
8488
wep_key_idx = param->u.crypt.idx;
8589
wep_key_len = param->u.crypt.key_len;
8690

87-
if (wep_key_idx > WEP_KEYS)
88-
return -EINVAL;
89-
9091
if (wep_key_len > 0) {
9192
wep_key_len = wep_key_len <= 5 ? 5 : 13;
9293
wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, key_material);

0 commit comments

Comments
 (0)