staging: rtl8723bs: avoid bogus gcc warning
PATCH 1/1 staging: rtl8723bs: avoid bogus gcc warning
From: Arnd Bergmann <[email protected]>
gcc gets confused by some of the type casts and produces an apparently senseless warning about an out-of-bound memcpy to an unrelated array in the same structure:
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c: In function 'rtw_cfg80211_ap_set_encryption':
cc1: error: writing 8 bytes into a region of size 0 [-Werror=stringop-overflow=] In file included from drivers/staging/rtl8723bs/include/drv_types.h:32,
from drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c:10:
drivers/staging/rtl8723bs/include/rtw_security.h:98:15: note: at offset [184, 4264] into destination object 'dot11AuthAlgrthm' of size 4
98 | u32 dot11AuthAlgrthm; /* 802.11 auth, could be open, shared, 8021x and authswitch */
| ^~~~~~~~~~~~~~~~cc1: error: writing 8 bytes into a region of size 0 [-Werror=stringop-overflow=] drivers/staging/rtl8723bs/include/rtw_security.h:98:15: note: at offset [264, 4344] into destination object 'dot11AuthAlgrthm' of size 4
This is a known gcc bug, and the patch here is only a workaround, but the approach of using a temporary variable to hold a pointer to the key also improves readability in addition to avoiding the warning, so overall this should still help.
--- .../staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 27 ++++++++++--------- .../staging/rtl8723bs/os_dep/ioctl_linux.c | 21 ++++++++------- 2 files changed, 27 insertions(+), 21 deletions(-)
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +15 -12
@@ -523,6 +523,9 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pastruct mlme_priv *pmlmepriv = &padapter->mlmepriv;struct security_priv *psecuritypriv = &(padapter->securitypriv);struct sta_priv *pstapriv = &padapter->stapriv; +char *grpkey = padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey; +char *txkey = padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey; +char *rxkey = padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey; param->u.crypt.err =0 ; param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN -1 ] ='\0' ;
@@ -605,7 +608,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa {if (strcmp (param->u.crypt.alg,"WEP" ) ==0 ) { -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); psecuritypriv->dot118021XGrpPrivacy = _WEP40_;if (param->u.crypt.key_len ==13 )
@@ -618,12 +621,12 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa { psecuritypriv->dot118021XGrpPrivacy = _TKIP_; -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len));/* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ /* set mic key */ -memcpy (psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16 ]),8 ); -memcpy (psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24 ]),8 ); +memcpy (txkey, &(param->u.crypt.key[16 ]),8 ); +memcpy (rxkey, &(param->u.crypt.key[24 ]),8 ); psecuritypriv->busetkipkey = true;
@@ -632,7 +635,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa { psecuritypriv->dot118021XGrpPrivacy = _AES_; -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); } else {
@@ -659,7 +662,6 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa goto exit; } -if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta)/* psk/802_1x */ {if (check_fwstate (pmlmepriv,WIFI_AP_STATE ))
@@ -709,7 +711,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa {if (strcmp (param->u.crypt.alg,"WEP" ) ==0 ) { -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); psecuritypriv->dot118021XGrpPrivacy = _WEP40_;if (param->u.crypt.key_len ==13 )
@@ -721,12 +723,12 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa { psecuritypriv->dot118021XGrpPrivacy = _TKIP_; -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len));/* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ /* set mic key */ -memcpy (psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16 ]),8 ); -memcpy (psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24 ]),8 ); +memcpy (txkey, &(param->u.crypt.key[16 ]),8 ); +memcpy (rxkey, &(param->u.crypt.key[24 ]),8 ); psecuritypriv->busetkipkey = true;
@@ -735,7 +737,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa { psecuritypriv->dot118021XGrpPrivacy = _AES_; -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); } else {
@@ -762,7 +764,6 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa } } - exit:return ret;
@@ -885,8 +886,10 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_paramif (strcmp (param->u.crypt.alg,"TKIP" ) ==0 ||strcmp (param->u.crypt.alg,"CCMP" ) ==0 ) {memcpy (padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +#if 1 memcpy (padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16 ]),8 );memcpy (padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24 ]),8 ); +#endif padapter->securitypriv.binstallGrpkey = true; padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +12 -9
@@ -2963,6 +2963,9 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,struct mlme_priv *pmlmepriv = &padapter->mlmepriv;struct security_priv *psecuritypriv = &(padapter->securitypriv);struct sta_priv *pstapriv = &padapter->stapriv; +char *txkey = padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey; +char *rxkey = padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey; +char *grpkey = psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey; param->u.crypt.err =0 ; param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN -1 ] ='\0' ;
@@ -3064,7 +3067,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,if (!psta &&check_fwstate (pmlmepriv,WIFI_AP_STATE )) {/* group key */ if (param->u.crypt.set_tx ==1 ) {if (strcmp (param->u.crypt.alg,"WEP" ) ==0 ) { -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); psecuritypriv->dot118021XGrpPrivacy = _WEP40_;if (param->u.crypt.key_len ==13 )
@@ -3073,11 +3076,11 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, }else if (strcmp (param->u.crypt.alg,"TKIP" ) ==0 ) { psecuritypriv->dot118021XGrpPrivacy = _TKIP_; -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len));/* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ /* set mic key */ -memcpy (psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16 ]),8 ); +memcpy (txkey, &(param->u.crypt.key[16 ]),8 );memcpy (psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24 ]),8 ); psecuritypriv->busetkipkey = true;
@@ -3086,7 +3089,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,else if (strcmp (param->u.crypt.alg,"CCMP" ) ==0 ) { psecuritypriv->dot118021XGrpPrivacy = _AES_; -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); }else { psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; }
@@ -3142,7 +3145,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, }else {/* group key??? */ if (strcmp (param->u.crypt.alg,"WEP" ) ==0 ) { -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); psecuritypriv->dot118021XGrpPrivacy = _WEP40_;if (param->u.crypt.key_len ==13 )
@@ -3150,19 +3153,19 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, }else if (strcmp (param->u.crypt.alg,"TKIP" ) ==0 ) { psecuritypriv->dot118021XGrpPrivacy = _TKIP_; -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len));/* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ /* set mic key */ -memcpy (psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16 ]),8 ); -memcpy (psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24 ]),8 ); +memcpy (txkey, &(param->u.crypt.key[16 ]),8 ); +memcpy (rxkey, &(param->u.crypt.key[24 ]),8 ); psecuritypriv->busetkipkey = true; }else if (strcmp (param->u.crypt.alg,"CCMP" ) ==0 ) { psecuritypriv->dot118021XGrpPrivacy = _AES_; -memcpy (psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +memcpy (grpkey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); }else { psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; }
Signature · 1 line
2.29.2
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa · line 765
Quoted 5 lines · Arnd Bergmann
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +0
-1@@ -762,7 +764,6 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa } } -
Since you're going to need to redo this, then please don't do this unrelated whitespace change.
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param · line 889
Quoted 8 lines
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +1
-0exit:return ret;@@ -885,8 +886,10 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_paramif (strcmp (param->u.crypt.alg,"TKIP" ) ==0 ||strcmp (param->u.crypt.alg,"CCMP" ) ==0 ) {memcpy (padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len >16 ?16 : param->u.crypt.key_len)); +#if 1
These seems unintetional?
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param · line 895
Quoted 6 lines
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +1
-0memcpy (padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16 ]),8 );memcpy (padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24 ]),8 ); +#endif padapter->securitypriv.binstallGrpkey = true; padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
regards,
dan carpenter
Quoted 10 lines · Dan Carpenter
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa · line 765
Quoted 5 lines · Arnd Bergmann
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +0
-1@@ -762,7 +764,6 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa } } -Since you're going to need to redo this, then please don't do this unrelated whitespace change.
Quoted 4 lines
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param · line 889
Quoted 1 line
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +1
-0+#if 1 These seems unintetional?
Indeed, both (and another removed line) are artifacts from debugging that ended up making it into the commit by accident. Sending v2 now.
Arnd