Skip to contentSkip to conversation

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: sparse: incorrect type in assignment (different base types)

DISCUSSION kernel test robot 5 participants 9 messages Aug 28, 2023 – Feb 15, 2024 802.11 (including cfg80211/NL80211)

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   727dbda16b83600379061c4ca8270ef3e2f51922
commit: c5b331d4f550fb78bf1a553b2517616a5ea913d6 wifi: wilc1000: add WPA3 SAE support
date:   1 year, 3 months ago
config: i386-randconfig-063-20230829 (https://download.01.org/0day-ci/archive/20230829/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230829/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned int key_mgmt_suite @@     got restricted __be32 [usertype] @@

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: expected unsigned int key_mgmt_suite
drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: got restricted __be32 [usertype]

vim +361 drivers/net/wireless/microchip/wilc1000/cfg80211.c

300
301 static int connect(struct wiphy *wiphy, struct net_device *dev,
302 struct cfg80211_connect_params *sme)
303 {
304 struct wilc_vif *vif = netdev_priv(dev);
305 struct wilc_priv *priv = &vif->priv;
306 struct host_if_drv *wfi_drv = priv->hif_drv;
307 int ret;
308 u32 i;
309 u8 security = WILC_FW_SEC_NO;
310 enum authtype auth_type = WILC_FW_AUTH_ANY;
311 u32 cipher_group;
312 struct cfg80211_bss *bss;
313 void *join_params;
314 u8 ch;
315
316 vif->connecting = true;
317
318 cipher_group = sme->crypto.cipher_group;
319 if (cipher_group != 0) {
320 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
321 if (cipher_group == WLAN_CIPHER_SUITE_TKIP)
322 security = WILC_FW_SEC_WPA2_TKIP;
323 else
324 security = WILC_FW_SEC_WPA2_AES;
325 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
326 if (cipher_group == WLAN_CIPHER_SUITE_TKIP)
327 security = WILC_FW_SEC_WPA_TKIP;
328 else
329 security = WILC_FW_SEC_WPA_AES;
330 } else {
331 ret = -ENOTSUPP;
332 netdev_err(dev, "%s: Unsupported cipher\n",
333 __func__);
334 goto out_error;
335 }
336 }
337
338 if ((sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) ||
339 (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)) {
340 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++) {
341 u32 ciphers_pairwise = sme->crypto.ciphers_pairwise[i];
342
343 if (ciphers_pairwise == WLAN_CIPHER_SUITE_TKIP)
344 security |= WILC_FW_TKIP;
345 else
346 security |= WILC_FW_AES;
347 }
348 }
349
350 switch (sme->auth_type) {
351 case NL80211_AUTHTYPE_OPEN_SYSTEM:
352 auth_type = WILC_FW_AUTH_OPEN_SYSTEM;
353 break;
354
355 case NL80211_AUTHTYPE_SAE:
356 auth_type = WILC_FW_AUTH_SAE;
357 if (sme->ssid_len) {
358 memcpy(vif->auth.ssid.ssid, sme->ssid, sme->ssid_len);
359 vif->auth.ssid.ssid_len = sme->ssid_len;
360 }

 > 361			vif->auth.key_mgmt_suite = cpu_to_be32(sme->crypto.akm_suites[0]);

362 ether_addr_copy(vif->auth.bssid, sme->bssid);
363 break;
364
365 default:
366 break;
367 }
368
369 if (sme->crypto.n_akm_suites) {
370 if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_8021X)
371 auth_type = WILC_FW_AUTH_IEEE8021;
372 else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_PSK_SHA256)
373 auth_type = WILC_FW_AUTH_OPEN_SYSTEM_SHA256;
374 else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_8021X_SHA256)
375 auth_type = WILC_FW_AUTH_IEE8021X_SHA256;
376 }
377
378 if (wfi_drv->usr_scan_req.scan_result) {
379 netdev_err(vif->ndev, "%s: Scan in progress\n", __func__);
380 ret = -EBUSY;
381 goto out_error;
382 }
383
384 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, sme->ssid,
385 sme->ssid_len, IEEE80211_BSS_TYPE_ANY,
386 IEEE80211_PRIVACY(sme->privacy));
387 if (!bss) {
388 ret = -EINVAL;
389 goto out_error;
390 }
391
392 if (ether_addr_equal_unaligned(vif->bssid, bss->bssid)) {
393 ret = -EALREADY;
394 goto out_put_bss;
395 }
396
397 join_params = wilc_parse_join_bss_param(bss, &sme->crypto);
398 if (!join_params) {
399 netdev_err(dev, "%s: failed to construct join param\n",
400 __func__);
401 ret = -EINVAL;
402 goto out_put_bss;
403 }
404
405 ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
406 vif->wilc->op_ch = ch;
407 if (vif->iftype != WILC_CLIENT_MODE)
408 vif->wilc->sta_ch = ch;
409
410 wilc_wlan_set_bssid(dev, bss->bssid, WILC_STATION_MODE);
411
412 wfi_drv->conn_info.security = security;
413 wfi_drv->conn_info.auth_type = auth_type;
414 wfi_drv->conn_info.ch = ch;
415 wfi_drv->conn_info.conn_result = cfg_connect_result;
416 wfi_drv->conn_info.arg = priv;
417 wfi_drv->conn_info.param = join_params;
418
419 ret = wilc_set_join_req(vif, bss->bssid, sme->ie, sme->ie_len);
420 if (ret) {
421 netdev_err(dev, "wilc_set_join_req(): Error\n");
422 ret = -ENOENT;
423 if (vif->iftype != WILC_CLIENT_MODE)
424 vif->wilc->sta_ch = WILC_INVALID_CHANNEL;
425 wilc_wlan_set_bssid(dev, NULL, WILC_STATION_MODE);
426 wfi_drv->conn_info.conn_result = NULL;
427 kfree(join_params);
428 goto out_put_bss;
429 }
430 kfree(join_params);
431 vif->bss = bss;
432 cfg80211_put_bss(wiphy, bss);
433 return 0;
434
435 out_put_bss:
436 cfg80211_put_bss(wiphy, bss);
437
438 out_error:
439 vif->connecting = false;
440 return ret;
441 }
442

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#1 lore raw
Quoted 13 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   727dbda16b83600379061c4ca8270ef3e2f51922
commit: c5b331d4f550fb78bf1a553b2517616a5ea913d6 wifi: wilc1000: add WPA3 SAE support
date:   1 year, 3 months ago
config: i386-randconfig-063-20230829 (https://download.01.org/0day-ci/archive/20230829/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230829/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 4 lines

sparse warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int key_mgmt_suite @@ got restricted __be32 [usertype] @@

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: expected unsigned int key_mgmt_suite
drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: got restricted __be32 [usertype]

Yeah, this is an old issue but we really should try to fix this, especially so as I would like to make wireless code sparse warning free in the near future. IIRC there were some problems with nl80211 interface as well so this might not be simple fix still.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#2 lore raw
Quoted 16 lines · Kalle Valo
Quoted 14 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   727dbda16b83600379061c4ca8270ef3e2f51922
commit: c5b331d4f550fb78bf1a553b2517616a5ea913d6 wifi: wilc1000: add WPA3 SAE support
date:   1 year, 3 months ago
config: i386-randconfig-063-20230829 (https://download.01.org/0day-ci/archive/20230829/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230829/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int key_mgmt_suite @@ got restricted __be32 [usertype] @@

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: expected unsigned int key_mgmt_suite
drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: got restricted __be32 [usertype]

Yeah, this is an old issue but we really should try to fix this, especially so as I would like to make wireless code sparse warning free in the near future. IIRC there were some problems with nl80211 interface as well so this might not be simple fix still.

For reference here's the old discussion:

https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

Any volunteers to help fix this? I would prefers fixes for issues like this compared to questionable random cleanups we always get.

Maybe we should come up with a todo list somewhere and advocate the "cleaners" to work on those items instead?

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw

Hi Kalle,

Quoted 31 lines · Kalle Valo

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 16 lines · Kalle Valo
Quoted 14 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   727dbda16b83600379061c4ca8270ef3e2f51922
commit: c5b331d4f550fb78bf1a553b2517616a5ea913d6 wifi: wilc1000: add WPA3 SAE support
date:   1 year, 3 months ago
config: i386-randconfig-063-20230829 (https://download.01.org/0day-ci/archive/20230829/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230829/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int key_mgmt_suite @@ got restricted __be32 [usertype] @@

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: expected unsigned int key_mgmt_suite
drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: got restricted __be32 [usertype]

Yeah, this is an old issue but we really should try to fix this, especially so as I would like to make wireless code sparse warning free in the near future. IIRC there were some problems with nl80211 interface as well so this might not be simple fix still.

For reference here's the old discussion:

Quoted 8 lines

https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

Any volunteers to help fix this? I would prefers fixes for issues like this compared to questionable random cleanups we always get.

Maybe we should come up with a todo list somewhere and advocate the "cleaners" to work on those items instead?

It seems, the wpa_s is modified to handle the byte order for 'key_mgmt_suite' value. The changes are committed in [1] and it should work for any byte order.

Now, the above sparse warning can be fixed by just removing the byte conversion before passing to wpa_s.

vif->auth.key_mgmt_suite = cpu_to_be32(sme->crypto.akm_suites[0]);

to

vif->auth.key_mgmt_suite = sme->crypto.akm_suites[0];

I can push a patch to fix the sparse warning. However the patch will work with updated wpa_s.

1.
https://w1.fi/cgit/hostap/commit/?id=8392ea9e75eacf30cb09671e463d9a37c3eadd6a

#4 lore raw
In reply to Kalle Valo

Hello Ajay, Kalle,

Quoted 3 lines · Kalle Valo
Quoted 1 line · Kalle Valo

kernel test robot <[email protected]> writes:

[...]

Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

sparse warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int key_mgmt_suite @@ got restricted __be32 [usertype] @@

drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: expected unsigned int key_mgmt_suite
drivers/net/wireless/microchip/wilc1000/cfg80211.c:361:42: sparse: got restricted __be32 [usertype]

Yeah, this is an old issue but we really should try to fix this, especially so as I would like to make wireless code sparse warning free in the near future. IIRC there were some problems with nl80211 interface as well so this might not be simple fix still.

Quoted 6 lines

For reference here's the old discussion:

https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

Any volunteers to help fix this? I would prefers fixes for issues like this compared to questionable random cleanups we always get.

I'm bumping this old thread because it looks like the sparse warning is still present in WILC driver, and I would gladly help getting rid of it, but since there's already been a fair amount of discussions around it, I am not sure what is expected/what should be done. Here is my understanding so far:
- Ajay has proposed a patch ([1]) which indeed fixes the warning but involves many casts
- Johannes and Jouni then gave details about the original issue leading to those casts ([2]): wpa_supplicant somehow forces the AKM suites values to be be32 at some point, while it should be treated in host endianness
- as pointed by Ajay, the corresponding fix has been made since then by Jouni in wpa_supplicant ([3]). The fix make sure to handle key_mgmt_suite in host endianness AND to keep compatibility with current drivers having the be32 fix. -
- It could have allowed to simply get rid of the all casts on AKM suites in
wilc driver ([4]), but then new kernel/drivers would break with existing userspace, so it is not an option

Now, I see multiple options to fix the sparse warning:
- apply the same fix as for wpa_supplicant ([3]) in wilc driver (so basically, become compatible with both endianness)
- apply the same fix as for wpa_supplicant ([3]), not in wilc but in nl80211 (may need to update not only wilc but any driver having trailing be32 cast on AKM suites)
- take the initial quick but not-so-nice double cast fix and call it a day

What's your opinion on this ?

[1]
https://lore.kernel.org/linux-wireless/[email protected]/
[2]
https://lore.kernel.org/linux-wireless/[email protected]/
[3] https://w1.fi/cgit/hostap/commit/?id=8392ea9e75eacf30cb09671e463d9a37c3eadd6a
[4]
https://lore.kernel.org/linux-wireless/[email protected]/

Signature · 3 lines
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer
#5 lore raw

Hi,

Quoted 7 lines
Quoted 6 lines

For reference here's the old discussion:

https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

Any volunteers to help fix this? I would prefers fixes for issues like this compared to questionable random cleanups we always get.

Quoted 12 lines

I'm bumping this old thread because it looks like the sparse warning is still present in WILC driver, and I would gladly help getting rid of it, but since there's already been a fair amount of discussions around it, I am not sure what is expected/what should be done. Here is my understanding so far:
- Ajay has proposed a patch ([1]) which indeed fixes the warning but involves many casts
- Johannes and Jouni then gave details about the original issue leading to those casts ([2]): wpa_supplicant somehow forces the AKM suites values to be be32 at some point, while it should be treated in host endianness
- as pointed by Ajay, the corresponding fix has been made since then by Jouni in wpa_supplicant ([3]). The fix make sure to handle key_mgmt_suite in host endianness AND to keep compatibility with current drivers having the be32 fix. -

Am I confused, or is the change [3] in the other direction?

From what I see, the code there (now changed again, btw) is about reading the value *from the driver*.

The driver change is about getting the value *from the supplicant*.

And the _outgoing_ code (sending it to the driver) from the supplicant has - as far as I can tell - been putting it into the attribute in host byte order forever? See commit cfaab58007b4 ("nl80211: Connect API support").

Aha! So, I'm not _completely_ confused, however, the only use of this value in this driver is sending it back to the supplicant! Which seems entirely wrong, since the supplicant assumes basically anything will be handled?

(But - the firmware also has a parameter key_mgmt_suites [in struct wilc_external_auth_param] which is never even set in wilc_set_external_auth_param??)

Also note that the supplicant will *only* read RSN_AUTH_KEY_MGMT_SAE in big endian, so you've already lost here pretty much?

Quoted 3 lines

- It could have allowed to simply get rid of the all casts on AKM suites in
wilc driver ([4]), but then new kernel/drivers would break with existing userspace, so it is not an option

I am wondering if it works at all ...

Quoted 3 lines

Now, I see multiple options to fix the sparse warning:
- apply the same fix as for wpa_supplicant ([3]) in wilc driver (so basically, become compatible with both endianness)

But this cannot be done! On input to the driver, the value is in host byte order always. The question is on output - and there you cannot detect it.

Quoted 3 lines

- apply the same fix as for wpa_supplicant ([3]), not in wilc but in nl80211 (may need to update not only wilc but any driver having trailing be32 cast on AKM suites)

That might even work? Well, not the same fix, since again input vs. output, but something like this:

net/wireless/nl80211.c +19 -1
@@ -20136,9 +20136,27 @@ int cfg80211_external_auth_request(struct net_device *dev,
 	if (!hdr)
 		goto nla_put_failure;
 
+	/*
+	 * Some drivers and due to that userspace (wpa_supplicant) were
+	 * in the past interpreting this value as a big-endian value,
+	 * at a time where only WLAN_AKM_SUITE_SAE was used. This is now
+	 * fixed, but for the benefit of older wpa_supplicant versions,
+	 * send this particular value in big-endian. Note that newer
+	 * wpa_supplicant will also detect this particular value in big
+	 * endian still, so it all continues to work.
+	 */
+	if (params->key_mgmt_suite == WLAN_AKM_SUITE_SAE) {
+		if (nla_put_be32(msg, NL80211_ATTR_AKM_SUITES,
+				 cpu_to_be32(WLAN_AKM_SUITE_SAE))
+			goto nla_put_failure;
+	} else {
+		if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES,
+				params->key_mgmt_suite)))
+			goto nla_put_failure;
+	}
+
 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
-	    nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
 	    nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
 			params->action) ||
 	    nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)

||

Quoted 1 line

- take the initial quick but not-so-nice double cast fix and call it a day

but that doesn't actually work for anything other than WLAN_AKM_SUITE_SAE...

johannes

#6 lore raw
Quoted 22 lines · Johannes Berg

Hi,

Quoted 7 lines
Quoted 6 lines

For reference here's the old discussion:

https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

Any volunteers to help fix this? I would prefers fixes for issues like this compared to questionable random cleanups we always get.

Quoted 12 lines

I'm bumping this old thread because it looks like the sparse warning is still present in WILC driver, and I would gladly help getting rid of it, but since there's already been a fair amount of discussions around it, I am not sure what is expected/what should be done. Here is my understanding so far:
- Ajay has proposed a patch ([1]) which indeed fixes the warning but involves many casts
- Johannes and Jouni then gave details about the original issue leading to those casts ([2]): wpa_supplicant somehow forces the AKM suites values to be be32 at some point, while it should be treated in host endianness
- as pointed by Ajay, the corresponding fix has been made since then by Jouni in wpa_supplicant ([3]). The fix make sure to handle key_mgmt_suite in host endianness AND to keep compatibility with current drivers having the be32 fix. -

Quoted 4 lines

Am I confused, or is the change [3] in the other direction?

From what I see, the code there (now changed again, btw) is about reading the value *from the driver*.

Ah, you are right, so [3] is rather about supporting drivers sending values with host endianness, while interface historically expects big endian :/

Quoted 10 lines

The driver change is about getting the value *from the supplicant*.

And the _outgoing_ code (sending it to the driver) from the supplicant has - as far as I can tell - been putting it into the attribute in host byte order forever? See commit cfaab58007b4 ("nl80211: Connect API support").

Aha! So, I'm not _completely_ confused,

So I am the one confused :) Thanks for the clarification. I did not dig enough, and since the cast is done right at connect message reception, I assumed wrongly that the issue was on the supplicant->driver path.

Quoted 1 line

however, the only use of this value in this driver is sending it back to the supplicant!> Which seems entirely wrong, since the supplicant assumes basically anything

will be

Quoted 1 line

handled?

Not sure to fully understand why its wrong (supplicant seems to expect AKM suites to be provided) , but I may be lacking more general understanding about the external auth process.
Or do you mean that AKM suites should be enforced to RSN_AUTH_KEY_MGMT_SAE only in this driver->supplicant call (and so, not forward any possible value ?)

Quoted 7 lines

(But - the firmware also has a parameter key_mgmt_suites [in struct wilc_external_auth_param] which is never even set in wilc_set_external_auth_param??)

Also note that the supplicant will *only* read RSN_AUTH_KEY_MGMT_SAE in big endian, so you've already lost here pretty much?

So we have to keep some big endian conversion on the driver/nl80211 -> supplicant path, IIUC

Quoted 6 lines
Quoted 3 lines

- It could have allowed to simply get rid of the all casts on AKM suites in
wilc driver ([4]), but then new kernel/drivers would break with existing userspace, so it is not an option

I am wondering if it works at all ...

Quoted 7 lines
Quoted 3 lines

Now, I see multiple options to fix the sparse warning:
- apply the same fix as for wpa_supplicant ([3]) in wilc driver (so basically, become compatible with both endianness)

But this cannot be done! On input to the driver, the value is in host byte order always. The question is on output - and there you cannot detect it.

Yeah, this suggestion is wrong because of the misunderstanding clarified above.

Quoted 3 lines
Quoted 3 lines

- apply the same fix as for wpa_supplicant ([3]), not in wilc but in nl80211 (may need to update not only wilc but any driver having trailing be32 cast on AKM suites)

So to fix my initial suggestion, it is not "doing the same fix" but rather "move the be conversion from the driver to nl80211 layer". Which matches in fact what you are suggesting below.

Quoted 34 lines

That might even work? Well, not the same fix, since again input vs. output, but something like this:

net/wireless/nl80211.c +19 -1
@@ -20136,9 +20136,27 @@ int cfg80211_external_auth_request(struct net_device *dev,
 	if (!hdr)
 		goto nla_put_failure;
 
+	/*
+	 * Some drivers and due to that userspace (wpa_supplicant) were
+	 * in the past interpreting this value as a big-endian value,
+	 * at a time where only WLAN_AKM_SUITE_SAE was used. This is now
+	 * fixed, but for the benefit of older wpa_supplicant versions,
+	 * send this particular value in big-endian. Note that newer
+	 * wpa_supplicant will also detect this particular value in big
+	 * endian still, so it all continues to work.
+	 */
+	if (params->key_mgmt_suite == WLAN_AKM_SUITE_SAE) {
+		if (nla_put_be32(msg, NL80211_ATTR_AKM_SUITES,
+				 cpu_to_be32(WLAN_AKM_SUITE_SAE))
+			goto nla_put_failure;
+	} else {
+		if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES,
+				params->key_mgmt_suite)))
+			goto nla_put_failure;
+	}
+
 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
-	    nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
 	    nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
 			params->action) ||
 	    nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)
Quoted 1 line

||

If this kind of fix is ok in nl80211, I can do some tests with it, see how it would affect other drivers ( I think there's only Quantenna driver which would be affected)

Thanks,

Alexis

Quoted 9 lines
Quoted 1 line

- take the initial quick but not-so-nice double cast fix and call it a day

but that doesn't actually work for anything other than WLAN_AKM_SUITE_SAE...

johannes

Signature · 3 lines
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer
#7 lore raw
Quoted 23 lines · Alexis Lothoré
Quoted 22 lines · Johannes Berg

Hi,

Quoted 19 lines
Quoted 6 lines

For reference here's the old discussion:

https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

Any volunteers to help fix this? I would prefers fixes for issues like this compared to questionable random cleanups we always get.

I'm bumping this old thread because it looks like the sparse warning is still present in WILC driver, and I would gladly help getting rid of it, but since there's already been a fair amount of discussions around it, I am not sure what is expected/what should be done. Here is my understanding so far:
- Ajay has proposed a patch ([1]) which indeed fixes the warning but involves many casts
- Johannes and Jouni then gave details about the original issue leading to those casts ([2]): wpa_supplicant somehow forces the AKM suites values to be be32 at some point, while it should be treated in host endianness
- as pointed by Ajay, the corresponding fix has been made since then by Jouni in wpa_supplicant ([3]). The fix make sure to handle key_mgmt_suite in host endianness AND to keep compatibility with current drivers having the be32 fix. -

Quoted 7 lines
Quoted 4 lines

Am I confused, or is the change [3] in the other direction?

From what I see, the code there (now changed again, btw) is about reading the value *from the driver*.

Ah, you are right, so [3] is rather about supporting drivers sending values with host endianness, while interface historically expects big endian :/

Well it was kind of documented originally as host byte order, but (some) drivers historically did big endian ...

Anyway, same thing - but note it's only doing the big endian check for a single value.

Quoted 8 lines
Quoted 8 lines

The driver change is about getting the value *from the supplicant*.

And the _outgoing_ code (sending it to the driver) from the supplicant has - as far as I can tell - been putting it into the attribute in host byte order forever? See commit cfaab58007b4 ("nl80211: Connect API support").

Quoted 5 lines
Quoted 1 line

Aha! So, I'm not _completely_ confused,

So I am the one confused :) Thanks for the clarification. I did not dig enough, and since the cast is done right at connect message reception, I assumed wrongly that the issue was on the supplicant->driver path.

Yeah it's confusing ...

Quoted 7 lines
Quoted 3 lines

however, the only use of this value in this driver is sending it back to the supplicant! Which seems entirely wrong, since the supplicant assumes basically anything will be handled?

Not sure to fully understand why its wrong (supplicant seems to expect AKM suites to be provided) , but I may be lacking more general understanding about the external auth process.

Well the firmware cannot support arbitrary AKM here, I'd think? And anyway it's not even sent to the firmware at all, so it has to be assuming it's SAE or so?

Quoted 2 lines

Or do you mean that AKM suites should be enforced to RSN_AUTH_KEY_MGMT_SAE only in this driver->supplicant call (and so, not forward any possible value ?)

Well it's more a question of what the firmware will actually be able to do here, I'd think. IIUC the whole point of this is to let firmware know what it's expected to do.

Quoted 5 lines
Quoted 2 lines

Also note that the supplicant will *only* read RSN_AUTH_KEY_MGMT_SAE in big endian, so you've already lost here pretty much?

So we have to keep some big endian conversion on the driver/nl80211 -> supplicant path, IIUC

If we were to drop support for old wpa_supplicant, then no, we could just use host byte order everywhere.

As we want to continue supporting old wpa_supplicant, which really just checked for RSN_AUTH_KEY_MGMT_SAE in big endian (before [3], when it started checking for both big endian and host byte order), then we have to send *that particular value* in big endian. For every other value we have to send it in host byte order, because either it doesn't matter (old wpa_s) or is checked in host byte order (new wpa_s, after later patches to this code checking for other values.)

But! That actually also means the driver is wrong now, because it sends _any_ value back in big endian, when wpa_s - new or old - only checks for this one value in big endian. It's OK with old since it only checks for this value in the first place, but broken for new!

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

- apply the same fix as for wpa_supplicant ([3]), not in wilc but in nl80211 (may need to update not only wilc but any driver having trailing be32 cast on AKM suites)

So to fix my initial suggestion, it is not "doing the same fix" but rather "move the be conversion from the driver to nl80211 layer". Which matches in fact what you are suggesting below.

Well you could do the exact same thing in the driver.

But it's probably cleaner to handle the backward compat issue in nl80211 and let the driver(s) just use host byte order generally, as intended?

Quoted 36 lines
Quoted 34 lines

That might even work? Well, not the same fix, since again input vs. output, but something like this:

net/wireless/nl80211.c +19 -1
@@ -20136,9 +20136,27 @@ int cfg80211_external_auth_request(struct net_device *dev,
 	if (!hdr)
 		goto nla_put_failure;
 
+	/*
+	 * Some drivers and due to that userspace (wpa_supplicant) were
+	 * in the past interpreting this value as a big-endian value,
+	 * at a time where only WLAN_AKM_SUITE_SAE was used. This is now
+	 * fixed, but for the benefit of older wpa_supplicant versions,
+	 * send this particular value in big-endian. Note that newer
+	 * wpa_supplicant will also detect this particular value in big
+	 * endian still, so it all continues to work.
+	 */
+	if (params->key_mgmt_suite == WLAN_AKM_SUITE_SAE) {
+		if (nla_put_be32(msg, NL80211_ATTR_AKM_SUITES,
+				 cpu_to_be32(WLAN_AKM_SUITE_SAE))
+			goto nla_put_failure;
+	} else {
+		if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES,
+				params->key_mgmt_suite)))
+			goto nla_put_failure;
+	}
+
 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
-	    nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
 	    nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
 			params->action) ||
 	    nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 3 lines

If this kind of fix is ok in nl80211, I can do some tests with it, see how it would affect other drivers ( I think there's only Quantenna driver which would be affected)

I'm happy with that, sure. Please do check.

Thanks!

johannes

#8 lore raw
In reply to Johannes Berg

Hi

Quoted 37 lines · Johannes Berg

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi,

Quoted 7 lines
Quoted 6 lines

For reference here's the old discussion:

https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

Any volunteers to help fix this? I would prefers fixes for issues like this compared to questionable random cleanups we always get.

Quoted 12 lines

I'm bumping this old thread because it looks like the sparse warning is still present in WILC driver, and I would gladly help getting rid of it, but since there's already been a fair amount of discussions around it, I am not sure what is expected/what should be done. Here is my understanding so far:
- Ajay has proposed a patch ([1]) which indeed fixes the warning but involves many casts
- Johannes and Jouni then gave details about the original issue leading to those casts ([2]): wpa_supplicant somehow forces the AKM suites values to be be32 at some point, while it should be treated in host endianness
- as pointed by Ajay, the corresponding fix has been made since then by Jouni in wpa_supplicant ([3]). The fix make sure to handle key_mgmt_suite in host endianness AND to keep compatibility with current drivers having the be32 fix. -

Am I confused, or is the change [3] in the other direction?

From what I see, the code there (now changed again, btw) is about reading the value *from the driver*.

The driver change is about getting the value *from the supplicant*.

And the _outgoing_ code (sending it to the driver) from the supplicant has - as far as I can tell - been putting it into the attribute in host byte order forever? See commit cfaab58007b4 ("nl80211: Connect API support").

Quoted 10 lines

Aha! So, I'm not _completely_ confused, however, the only use of this value in this driver is sending it back to the supplicant! Which seems entirely wrong, since the supplicant assumes basically anything will be handled?

(But - the firmware also has a parameter key_mgmt_suites [in struct wilc_external_auth_param] which is never even set in wilc_set_external_auth_param??)

yeah, *key_mgmt_suites* is not passed to the firmware. It is added to *wilc_external_auth_param* but it was not necessary since SAE AUTH is offloaded to user space so it takes care of complete AUTH exchange and only confirm once it is done. key_mgmt_suites, which is received in connect(), is needs to be maintained in driver to pass back using cfg80211_external_auth_request().

Quoted 54 lines

Also note that the supplicant will *only* read RSN_AUTH_KEY_MGMT_SAE in big endian, so you've already lost here pretty much?

Quoted 3 lines

- It could have allowed to simply get rid of the all casts on AKM suites in
wilc driver ([4]), but then new kernel/drivers would break with existing userspace, so it is not an option

I am wondering if it works at all ...

Quoted 3 lines
Quoted 1 line

Now, I see multiple options to fix the sparse warning:

- apply the same fix as for wpa_supplicant ([3]) in wilc driver (so basically, become compatible with both endianness)

But this cannot be done! On input to the driver, the value is in host byte order always. The question is on output - and there you cannot detect it.

Quoted 3 lines

- apply the same fix as for wpa_supplicant ([3]), not in wilc but in nl80211 (may need to update not only wilc but any driver having trailing be32 cast on AKM suites)

That might even work? Well, not the same fix, since again input vs. output, but something like this:

net/wireless/nl80211.c +19 -1
@@ -20136,9 +20136,27 @@ int cfg80211_external_auth_request(struct net_device *dev,
        if (!hdr)
                goto nla_put_failure;
 
+       /*
+        * Some drivers and due to that userspace (wpa_supplicant) were
+        * in the past interpreting this value as a big-endian value,
+        * at a time where only WLAN_AKM_SUITE_SAE was used. This is now
+        * fixed, but for the benefit of older wpa_supplicant versions,
+        * send this particular value in big-endian. Note that newer
+        * wpa_supplicant will also detect this particular value in big
+        * endian still, so it all continues to work.
+        */
+       if (params->key_mgmt_suite == WLAN_AKM_SUITE_SAE) {
+               if (nla_put_be32(msg, NL80211_ATTR_AKM_SUITES,
+                                cpu_to_be32(WLAN_AKM_SUITE_SAE))
+                       goto nla_put_failure;
+       } else {
+               if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES,
+                               params->key_mgmt_suite)))
+                       goto nla_put_failure;
+       }
+
        if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
            nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
-           nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
            nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
                        params->action) ||
            nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)
Quoted 1 line

||

IMO this patch is better solution since it covers for both old and new wpa_s(3) and even the fixes in new wpa_s are not required with this change. After this change, the driver can be modified to use the host byte order that will also resolve the sparse warning.

Regards,
Ajay