Skip to contentSkip to conversation

wifi: cap a few SSID lengths

PATCH New Dan Carpenter 1 participant 4 messages Aug 29, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover wifi: cap a few SSID lengths

These patches are based on static analysis and review. The other places which get the ssid from ieee80211_bss_get_ie() do bounds checking to ensure that the ssid length isn't more than IEEE80211_MAX_SSID_LEN (32).

Dan Carpenter (3):
wifi: cw1200: cap SSID length in cw1200_do_join()
wifi: libertas: cap SSID len in lbs_associate()
wifi: cfg80211: sme: capp SSID length in __cfg80211_connect_result()

 drivers/net/wireless/marvell/libertas/cfg.c | 9 ++++++---
 drivers/net/wireless/st/cw1200/sta.c        | 2 +-
 net/wireless/sme.c                          | 5 ++++-
 3 files changed, 11 insertions(+), 5 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/3 wifi: cw1200: cap SSID length in cw1200_do_join()

If the ssidie[1] length is more that 32 it leads to memory corruption.

Fixes a910e4a94f69 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")
---
 drivers/net/wireless/st/cw1200/sta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/st/cw1200/sta.c +1 -1
index b1dd76e8aecb..5d8eaa700779 100644
@@ -1291,7 +1291,7 @@ static void cw1200_do_join(struct cw1200_common *priv)
 		rcu_read_lock();
 		ssidie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
 		if (ssidie) {
-			join.ssid_len = ssidie[1];
+			join.ssid_len = min(ssidie[1], IEEE80211_MAX_SSID_LEN);
 			memcpy(join.ssid, &ssidie[2], join.ssid_len);
 		}
 		rcu_read_unlock();
Signature · 1 line
2.47.2
#2 lore raw

PATCH 2/3 wifi: libertas: cap SSID len in lbs_associate()

In reply to Dan Carpenter

If the ssid_eid[1] length is more that 32 it leads to memory corruption.

Fixes a910e4a94f69 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")
---
 drivers/net/wireless/marvell/libertas/cfg.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/wireless/marvell/libertas/cfg.c +6 -3
index 94dd488becaf..caba7491cd5a 100644
@@ -1151,10 +1151,13 @@ static int lbs_associate(struct lbs_private *priv,
 	/* add SSID TLV */
 	rcu_read_lock();
 	ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
-	if (ssid_eid)
-		pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
-	else
+	if (ssid_eid) {
+		u32 ssid_len = min(ssid_eid[1], IEEE80211_MAX_SSID_LEN);
+
+		pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_len);
+	} else {
 		lbs_deb_assoc("no SSID\n");
+	}
 	rcu_read_unlock();
 
 	/* add DS param TLV */
Signature · 1 line
2.47.2
#3 lore raw

PATCH 3/3 wifi: cfg80211: sme: capp SSID length in __cfg80211_connect_result()

In reply to Dan Carpenter

If the ssid->datalen is more than IEEE80211_MAX_SSID_LEN (32) it would lead to memory corruption so add some bounds checking.

Fixes c38c70185101 ("wifi: cfg80211: Set SSID if it is not already set")
---
 net/wireless/sme.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/wireless/sme.c +4 -1
index 826ec0a6355f..3a028ff287fb 100644
@@ -900,13 +900,16 @@ void __cfg80211_connect_result(struct net_device *dev,
 	if (!wdev->u.client.ssid_len) {
 		rcu_read_lock();
 		for_each_valid_link(cr, link) {
+			u32 ssid_len;
+
 			ssid = ieee80211_bss_get_elem(cr->links[link].bss,
 						      WLAN_EID_SSID);
 
 			if (!ssid || !ssid->datalen)
 				continue;
 
-			memcpy(wdev->u.client.ssid, ssid->data, ssid->datalen);
+			ssid_len = min(ssid->datalen, IEEE80211_MAX_SSID_LEN);
+			memcpy(wdev->u.client.ssid, ssid->data, ssid_len);
 			wdev->u.client.ssid_len = ssid->datalen;
 			break;
 		}
Signature · 1 line
2.47.2