Skip to contentSkip to conversation

wifi: nxpwifi: fix NULL deref and leak in authenticate

PATCH In review techyminati 2 participants 2 messages Oct 1 – Oct 5

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

PATCH 1/1 wifi: nxpwifi: fix NULL deref and leak in authenticate

From: Aryan Sinha <[email protected]>

mgmt is allocated but never checked, and the auth frame is filled in right after, so a failed kzalloc ends up dereferencing NULL. The skb error path also returns without freeing mgmt.

Hence, Check the allocation, and free mgmt when the skb alloc fails.

Fixes 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")
---
 drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/nxp/nxpwifi/cfg80211.c +3 -0
index 86304ea33..9eb809caa 100644
@@ -3403,6 +3403,8 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
 		pkt_len -= 4;
 
 	mgmt = kzalloc(pkt_len, GFP_KERNEL);
+	if (!mgmt)
+		return -ENOMEM;
 
 	skb = dev_alloc_skb(NXPWIFI_MIN_DATA_HEADER_LEN +
 			    NXPWIFI_MGMT_FRAME_HEADER_SIZE +
@@ -3410,6 +3412,7 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
 	if (!skb) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "allocate skb failed for management frame\n");
+		kfree(mgmt);
 		return -ENOMEM;
 	}
 
Signature · 1 line
2.46.0
#1 lore raw

From: Jeff Chen <[email protected]>

Quoted 16 lines · techyminati

From: Aryan Sinha <[email protected]>

drivers/net/wireless/nxp/nxpwifi/cfg80211.c +2 -0
index 86304ea33..9eb809caa 100644
@@ -3403,6 +3403,8 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
 		pkt_len -= 4;
 
 	mgmt = kzalloc(pkt_len, GFP_KERNEL);
+	if (!mgmt)
+		return -ENOMEM;
 
 	skb = dev_alloc_skb(NXPWIFI_MIN_DATA_HEADER_LEN +
 			    NXPWIFI_MGMT_FRAME_HEADER_SIZE +

drivers/net/wireless/nxp/nxpwifi/cfg80211.c nxpwifi_cfg80211_authenticate(struct wiphy *wiphy, · line 3418

Quoted 7 lines
drivers/net/wireless/nxp/nxpwifi/cfg80211.c +1 -0
@@ -3410,6 +3412,7 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
 	if (!skb) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "allocate skb failed for management frame\n");
+		kfree(mgmt);
 		return -ENOMEM;
 	}
 

Hi Aryan,

Thanks for the patch.

This issue has already been addressed by another accepted patch:
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

Thanks,
Jeff