Skip to contentSkip to conversation

net: mac80211: cfg: Initialize cnt before accessing elem in ieee80211_copy_mbssid_beacon

PATCH New Haoyu Li 1 participant 1 message Nov 23, 2024 mac80211

lore
Share & tools
lore

Haoyu Li

author
#0 lore raw

PATCH 1/1 net: mac80211: cfg: Initialize cnt before accessing elem in ieee80211_copy_mbssid_beacon

With the new __counted_by annocation in cfg80211_mbssid_elems, the "cnt" struct member must be set before accessing the "elem" array. Failing to do so will trigger a runtime warning when enabling CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.

Fixes c14679d7005a ("wifi: cfg80211: Annotate struct cfg80211_mbssid_elems with __counted_by")
---
 net/mac80211/cfg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/cfg.c +1 -1
index 61a824ec33da..1dd61c9bb8f1 100644
@@ -1088,13 +1088,13 @@ ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
 {
 	int i, offset = 0;
 
+	dst->cnt = src->cnt;
 	for (i = 0; i < src->cnt; i++) {
 		memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
 		dst->elem[i].len = src->elem[i].len;
 		dst->elem[i].data = pos + offset;
 		offset += dst->elem[i].len;
 	}
-	dst->cnt = src->cnt;
 
 	return offset;
 }
Signature · 1 line
2.34.1