wifi: brcmfmac: cyw: clean up PMKID and cookie code
PATCH 1/1 wifi: brcmfmac: cyw: clean up PMKID and cookie code
Avoid setting packet_id to cookie, which is always 0. Instead, use an increasing atomic counter. Avoids mismatches of completion events later in brcmf_notify_mgmt_tx_status, where packet_id != vif->mgmt_tx_id is checked.
Also, zero out auth_status on initialization. Otherwise, garbage will leak from the stack to the firmware (when bssid is less than 32 bytes and/or when params->pmkid is set). Then, pass the params->pmkid to the firmware (without it, the firmware caches a garbage PMKID on successful authentication and denies a subsequent association request that includes the PMKID).
--- .../net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +6 -2
@@ -23,6 +23,8 @@#define MGMT_AUTH_FRAME_DWELL_TIME 4000#define MGMT_AUTH_FRAME_WAIT_TIME (MGMT_AUTH_FRAME_DWELL_TIME + 100) +static atomic_t brcmf_cyw_mgmt_tx_id =ATOMIC_INIT (0 ); +static int brcmf_cyw_set_sae_pwd (struct brcmf_if *ifp,struct cfg80211_crypto_settings *crypto) {
@@ -155,7 +157,7 @@ int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,memcpy (&mf_params->da[0 ], &mgmt->da[0 ],ETH_ALEN );memcpy (&mf_params->bssid[0 ], &mgmt->bssid[0 ],ETH_ALEN ); - mf_params->packet_id =cpu_to_le32 (*cookie); + mf_params->packet_id =cpu_to_le32 (atomic_inc_return (&brcmf_cyw_mgmt_tx_id));memcpy (mf_params->data, &buf[DOT11_MGMT_HDR_LEN ],le16_to_cpu (mf_params->len));
@@ -200,7 +202,7 @@ brcmf_cyw_external_auth(struct wiphy *wiphy, struct net_device *dev, {struct brcmf_if *ifp;struct brcmf_pub *drvr; -struct brcmf_auth_req_status_le auth_status; +struct brcmf_auth_req_status_le auth_status = {};int ret =0 ;brcmf_dbg (TRACE ,"Enter\n" );
@@ -208,6 +210,8 @@ brcmf_cyw_external_auth(struct wiphy *wiphy, struct net_device *dev, ifp =netdev_priv (dev); drvr = ifp->drvr;if (params->status ==WLAN_STATUS_SUCCESS ) { +if (params->pmkid) +memcpy (auth_status.pmkid, params->pmkid,WLAN_PMKID_LEN ); auth_status.flags =cpu_to_le16 (BRCMF_EXTAUTH_SUCCESS ); }else { bphy_err(drvr, "External authentication failed: status=%d\n",
Signature · 1 line
2.55.0
Arend van Spriel
maintainerQuoted 5 lines · Bogdan Nicolae
Avoid setting
packet_idto cookie, which is always 0. Instead, use an increasing atomic counter. Avoids mismatches of completion events later inbrcmf_notify_mgmt_tx_status, wherepacket_id!=vif->mgmt_tx_idis checked.
Quoted 8 lines
Also, zero out
auth_statuson initialization. Otherwise, garbage will leak from the stack to the firmware (when bssid is less than 32 bytes and/or whenparams->pmkidis set). Then, pass theparams->pmkidto the firmware (without it, the firmware caches a garbage PMKID on successful authentication and denies a subsequent association request that includes the PMKID).Signed-off-by Bogdan Nicolae <[email protected]>
I always get a bit confused when people use different email addresses to send and sign-off patches.
Quoted 18 lines
--- .../net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +2
-0@@ -23,6 +23,8 @@#define MGMT_AUTH_FRAME_DWELL_TIME 4000#define MGMT_AUTH_FRAME_WAIT_TIME (MGMT_AUTH_FRAME_DWELL_TIME + 100) +static atomic_t brcmf_cyw_mgmt_tx_id =ATOMIC_INIT (0 ); +static int brcmf_cyw_set_sae_pwd (struct brcmf_if *ifp,struct cfg80211_crypto_settings *crypto) {
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 160
Quoted 5 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +1
-1@@ -155,7 +157,7 @@ int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,memcpy (&mf_params->da[0 ], &mgmt->da[0 ],ETH_ALEN );memcpy (&mf_params->bssid[0 ], &mgmt->bssid[0 ],ETH_ALEN ); - mf_params->packet_id =cpu_to_le32 (*cookie); + mf_params->packet_id =cpu_to_le32 (atomic_inc_return (&brcmf_cyw_mgmt_tx_id));
As I understand things the cookie value here is an output parameter. The driver should assign it:
+ *cookie = atomic_inc_return(&brcmf_cyw_mgmt_tx_id); mf_params->packet_id = cpu_to_le32(*cookie);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 163
Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +0
-0memcpy (mf_params->data, &buf[DOT11_MGMT_HDR_LEN ],le16_to_cpu (mf_params->len));
Regards,
Arend
Hi Arend,
The code already sets *cookie=0 in the beginning, which according to my understanding tells the driver it does not require async tracking upstream. This is correct, because the function calls wait_for_completion_timeout, so mgmt tx completes by the time we exit the function and doesn't need to be tracked upstream. However, while we are waiting for mgmt tx to finish, the firmware may generate non-matching completion events captured by notify_mgmt_tx_status. That's why setting a non-zero packed_id (sent to and returned by firmware as part of a completion event) and checking against vif->mgmt_tx_id is important.
Cheers,
Bogdan
Quoted 53 lines · Arend van Spriel
Quoted 5 lines · Bogdan Nicolae
Avoid setting
packet_idto cookie, which is always 0. Instead, use an increasing atomic counter. Avoids mismatches of completion events later inbrcmf_notify_mgmt_tx_status, wherepacket_id!=vif->mgmt_tx_idis checked.Quoted 8 lines
Also, zero out
auth_statuson initialization. Otherwise, garbage will leak from the stack to the firmware (when bssid is less than 32 bytes and/or whenparams->pmkidis set). Then, pass theparams->pmkidto the firmware (without it, the firmware caches a garbage PMKID on successful authentication and denies a subsequent association request that includes the PMKID).Signed-off-by Bogdan Nicolae <[email protected]>I always get a bit confused when people use different email addresses to send and sign-off patches.
Quoted 18 lines
--- .../net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +2
-0@@ -23,6 +23,8 @@#define MGMT_AUTH_FRAME_DWELL_TIME 4000#define MGMT_AUTH_FRAME_WAIT_TIME (MGMT_AUTH_FRAME_DWELL_TIME + 100) +static atomic_t brcmf_cyw_mgmt_tx_id =ATOMIC_INIT (0 ); +static int brcmf_cyw_set_sae_pwd (struct brcmf_if *ifp,struct cfg80211_crypto_settings *crypto) {drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 160
Quoted 5 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +1
-1@@ -155,7 +157,7 @@ int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,memcpy (&mf_params->da[0 ], &mgmt->da[0 ],ETH_ALEN );memcpy (&mf_params->bssid[0 ], &mgmt->bssid[0 ],ETH_ALEN ); - mf_params->packet_id =cpu_to_le32 (*cookie); + mf_params->packet_id =cpu_to_le32 (atomic_inc_return (&brcmf_cyw_mgmt_tx_id));As I understand things the cookie value here is an output parameter. The driver should assign it:
+ *cookie = atomic_inc_return(&brcmf_cyw_mgmt_tx_id); mf_params->packet_id = cpu_to_le32(*cookie);drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 163
Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +0
-0memcpy (mf_params->data, &buf[DOT11_MGMT_HDR_LEN ],le16_to_cpu (mf_params->len));Regards,
Arend
Quoted 12 lines · Bogdan Nicolae
Hi Arend,
The code already sets *cookie=0 in the beginning, which according to my understanding tells the driver it does not require async tracking upstream. This is correct, because the function calls
wait_for_completion_timeout, so mgmt tx completes by the time we exit the function and doesn't need to be tracked upstream. However, while we are waiting for mgmt tx to finish, the firmware may generate non-matching completion events captured bynotify_mgmt_tx_status. That's why setting a non-zeropacked_id(sent to and returned by firmware as part of a completion event) and checking againstvif->mgmt_tx_idis important.
Avoid top-posting. Need to use interleaved style.
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
Quoted 14 lines
Cheers,
BogdanQuoted 9 lines · Arend van Spriel
Quoted 7 lines · Bogdan Nicolae
Avoid setting
packet_idto cookie, which is always 0. Instead, use an increasing atomic counter. Avoids mismatches of completion events later inbrcmf_notify_mgmt_tx_status, wherepacket_id!=vif->mgmt_tx_idis checked.Also, zero out
auth_statuson initialization. Otherwise, garbage will leak from the stack to the firmware (when bssid is less than 32 bytes
BSSID will always be less than 32, you must have meant to say "ssid" here instead of "bssid". Also the auth_req_status struct does not have any "bssid" member, it only has an "ssid" struct member. Need to fix in commit message.
Quoted 36 lines
Quoted 36 lines
Quoted 6 lines
and/or when
params->pmkidis set). Then, pass theparams->pmkidto the firmware (without it, the firmware caches a garbage PMKID on successful authentication and denies a subsequent association request that includes the PMKID).Signed-off-by Bogdan Nicolae <[email protected]>I always get a bit confused when people use different email addresses to send and sign-off patches.
Quoted 18 lines
--- .../net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +2
-0@@ -23,6 +23,8 @@#define MGMT_AUTH_FRAME_DWELL_TIME 4000#define MGMT_AUTH_FRAME_WAIT_TIME (MGMT_AUTH_FRAME_DWELL_TIME + 100) +static atomic_t brcmf_cyw_mgmt_tx_id =ATOMIC_INIT (0 ); +static int brcmf_cyw_set_sae_pwd (struct brcmf_if *ifp,struct cfg80211_crypto_settings *crypto) {drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 160
Quoted 5 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +1
-1@@ -155,7 +157,7 @@ int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,memcpy (&mf_params->da[0 ], &mgmt->da[0 ],ETH_ALEN );memcpy (&mf_params->bssid[0 ], &mgmt->bssid[0 ],ETH_ALEN ); - mf_params->packet_id =cpu_to_le32 (*cookie); + mf_params->packet_id =cpu_to_le32 (atomic_inc_return (&brcmf_cyw_mgmt_tx_id));As I understand things the cookie value here is an output parameter. The driver should assign it:
Quoted 2 lines
Quoted 2 lines
+ *cookie = atomic_inc_return(&brcmf_cyw_mgmt_tx_id); mf_params->packet_id = cpu_to_le32(*cookie);
Agree with Arend's suggestion here. It is not correct to leave *cookie = 0 as it is and only assign a different packet_id while sending requst to firmware, because in that case the driver will not return the real cookie for this TX to cfg80211. Driver should assign the generated ID to *cookie and then copy that into packet_id.
Gokul
Quoted 6 lines
Quoted 5 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 163
Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +0
-0memcpy (mf_params->data, &buf[DOT11_MGMT_HDR_LEN ],le16_to_cpu (mf_params->len));Regards,
Arend
Quoted 30 lines · Gokul Sivakumar
Quoted 12 lines · Bogdan Nicolae
Hi Arend,
The code already sets *cookie=0 in the beginning, which according to my understanding tells the driver it does not require async tracking upstream. This is correct, because the function calls
wait_for_completion_timeout, so mgmt tx completes by the time we exit the function and doesn't need to be tracked upstream. However, while we are waiting for mgmt tx to finish, the firmware may generate non-matching completion events captured bynotify_mgmt_tx_status. That's why setting a non-zeropacked_id(sent to and returned by firmware as part of a completion event) and checking againstvif->mgmt_tx_idis important.Avoid top-posting. Need to use interleaved style.
https://en.wikipedia.org/wiki/Posting_style#Interleaved_styleQuoted 12 lines
Cheers,
BogdanQuoted 7 lines · Arend van Spriel
Quoted 5 lines · Bogdan Nicolae
Avoid setting
packet_idto cookie, which is always 0. Instead, use an increasing atomic counter. Avoids mismatches of completion events later inbrcmf_notify_mgmt_tx_status, wherepacket_id!=vif->mgmt_tx_idis checked.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Also, zero out
auth_statuson initialization. Otherwise, garbage will leak from the stack to the firmware (when bssid is less than 32 bytesBSSID will always be less than 32, you must have meant to say "ssid" here instead of "bssid". Also the
auth_req_statusstruct does not have any "bssid" member, it only has an "ssid" struct member. Need to fix in commit message.
Fixed
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 6 lines
and/or when
params->pmkidis set). Then, pass theparams->pmkidto the firmware (without it, the firmware caches a garbage PMKID on successful authentication and denies a subsequent association request that includes the PMKID).Signed-off-by Bogdan Nicolae <[email protected]>I always get a bit confused when people use different email addresses to send and sign-off patches.
Quoted 18 lines
--- .../net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +2
-0@@ -23,6 +23,8 @@#define MGMT_AUTH_FRAME_DWELL_TIME 4000#define MGMT_AUTH_FRAME_WAIT_TIME (MGMT_AUTH_FRAME_DWELL_TIME + 100) +static atomic_t brcmf_cyw_mgmt_tx_id =ATOMIC_INIT (0 ); +static int brcmf_cyw_set_sae_pwd (struct brcmf_if *ifp,struct cfg80211_crypto_settings *crypto) {drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 160
Quoted 5 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +1
-1@@ -155,7 +157,7 @@ int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,memcpy (&mf_params->da[0 ], &mgmt->da[0 ],ETH_ALEN );memcpy (&mf_params->bssid[0 ], &mgmt->bssid[0 ],ETH_ALEN ); - mf_params->packet_id =cpu_to_le32 (*cookie); + mf_params->packet_id =cpu_to_le32 (atomic_inc_return (&brcmf_cyw_mgmt_tx_id));As I understand things the cookie value here is an output parameter. The driver should assign it:
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
+ *cookie = atomic_inc_return(&brcmf_cyw_mgmt_tx_id); mf_params->packet_id = cpu_to_le32(*cookie);Agree with Arend's suggestion here. It is not correct to leave *cookie = 0 as it is and only assign a different
packet_idwhile sending requst to firmware, because in that case the driver will not return the real cookie for this TX to cfg80211. Driver should assign the generated ID to *cookie and then copy that intopacket_id.
Fixed
Quoted 9 lines
Gokul
Quoted 5 lines
Quoted 5 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c int brcmf_cyw_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 163
Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +0
-0memcpy (mf_params->data, &buf[DOT11_MGMT_HDR_LEN ],le16_to_cpu (mf_params->len));Regards,
Arend
Regards,
Bogdan