Skip to contentSkip to conversation

wifi: ath9k: add a defensive NULL check to prevent null-pointer dereference in ath9k_beacon_remove_slot()

PATCH In review Tuo Li 2 participants 3 messages Jan 7 – Jan 8 Qualcomm Atheros ATH9K wireless driver

lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 wifi: ath9k: add a defensive NULL check to prevent null-pointer dereference in ath9k_beacon_remove_slot()

In this function, bf is guarded by an if statement, indicating that it may be NULL:

  if (bf && bf->bf_mpdu) {...}

If bf is NULL, calling list_add_tail() may result in a null-pointer dereference:

  list_add_tail(&bf->list, &sc->beacon.bbuf);

Therefore, add a defensive NULL check before invoking list_add_tail() to prevent this issue.

---
 drivers/net/wireless/ath/ath9k/beacon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/beacon.c +2 -1
index 4a27e3753c03..e39e2738ba1a 100644
@@ -236,7 +236,8 @@ void ath9k_beacon_remove_slot(struct ath_softc *sc, struct ieee80211_vif *vif)
 
 	avp->av_bcbuf = NULL;
 	sc->beacon.bslot[avp->av_bslot] = NULL;
-	list_add_tail(&bf->list, &sc->beacon.bbuf);
+	if (bf)
+		list_add_tail(&bf->list, &sc->beacon.bbuf);
 
 	tasklet_enable(&sc->bcon_tasklet);
 }
Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · Tuo Li

In this function, bf is guarded by an if statement, indicating that it may be NULL:

  if (bf && bf->bf_mpdu) {...}

If bf is NULL, calling list_add_tail() may result in a null-pointer dereference:

Quoted 6 lines
  list_add_tail(&bf->list, &sc->beacon.bbuf);

Therefore, add a defensive NULL check before invoking list_add_tail() to prevent this issue.

Are you fixing an actual bug here? Otherwise, this is not worth the churn...

-Toke

author
#2 lore raw
Quoted 16 lines · Toke Høiland-Jørgensen
Quoted 13 lines · Tuo Li

In this function, bf is guarded by an if statement, indicating that it may be NULL:

  if (bf && bf->bf_mpdu) {...}

If bf is NULL, calling list_add_tail() may result in a null-pointer dereference:

  list_add_tail(&bf->list, &sc->beacon.bbuf);

Therefore, add a defensive NULL check before invoking list_add_tail() to prevent this issue.

Quoted 6 lines
Quoted 1 line

Are you fixing an actual bug here? Otherwise, this is not worth the churn...

-Toke

Thanks for pointing this out.

This issue was reported by a static analysis tool. After reviewing the code, I noticed that bf is guarded by an if statement, which indicates that it may be NULL, so I added a defensive check before the other dereference.

However, I have not been able to identify a concrete execution path in which bf would actually be NULL at that point. I'm fine with dropping this change if it is considered unnecessary.

Best regards,
Tuo