Skip to contentSkip to conversation

mt76: mt7925: main.c: Avoid possible NULL Pointer Dereference in mt7925_change_vif_links()

PATCH In review Gax-c 2 participants 2 messages Sep 30, 2024 – Oct 1, 2024

Subsystems (2)
lore
Share & tools
lore

Gax-c

author
#0 lore raw

PATCH 1/1 mt76: mt7925: main.c: Avoid possible NULL Pointer Dereference in mt7925_change_vif_links()

'mconf = devm_kzalloc()' and 'mlink = devm_kzalloc()' may return NULL.
NULL Pointer Dereference may be triggered in the statement 'mconf->link_id = link_id;' below. Add a null check for the returned pointer.

Fixes 69acd6d910b0 ("wifi: mt76: mt7925: add mt7925_change_vif_links")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +6 -0
index 791c8b00e112..ea635169497f 100644
@@ -1948,6 +1948,12 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 					     GFP_KERNEL);
 		}
 
+		if (!mconf || !mlink) {
+			err = -ENOMEM;
+			goto free;
+		}
+
+
 		mconfs[link_id] = mconf;
 		mlinks[link_id] = mlink;
 		mconf->link_id = link_id;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 18 lines · Gax-c

'mconf = devm_kzalloc()' and 'mlink = devm_kzalloc()' may return NULL.
NULL Pointer Dereference may be triggered in the statement 'mconf->link_id = link_id;' below. Add a null check for the returned pointer.

Fixes 69acd6d910b0 ("wifi: mt76: mt7925: add mt7925_change_vif_links")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +0 -0
index 791c8b00e112..ea635169497f 100644

drivers/net/wireless/mediatek/mt76/mt7925/main.c mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, · line 1955

Quoted 8 lines
drivers/net/wireless/mediatek/mt76/mt7925/main.c +5 -0
@@ -1948,6 +1948,12 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 					     GFP_KERNEL);
 		}
 
+		if (!mconf || !mlink) {
+			err = -ENOMEM;
+			goto free;
+		}
+

All previous comments apply - wrapping, commit tags, unnecessary blank lines, proper cleanup.

Best regards,
Krzysztof