net: mac80211: cfg: Initialize cnt before accessing elem
PATCH 1/1 net: mac80211: cfg: Initialize cnt before accessing elem
With the new __counted_by annocation in cfg80211_rnr_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 7b6d7087031b ("wifi: cfg80211: Annotate struct cfg80211_rnr_elems with __counted_by")
Signed-off-by Haoyu Li <[email protected]>
--- net/mac80211/cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/cfg.c +1 -1
@@ -1105,13 +1105,13 @@ ieee80211_copy_rnr_beacon(u8 *pos, struct cfg80211_rnr_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
Quoted 5 lines · Haoyu Li
With the new
__counted_byannocation incfg80211_rnr_elems, the "cnt" struct member must be set before accessing the "elem" array. Failing to do so will trigger a runtime warning when enablingCONFIG_UBSAN_BOUNDSandCONFIG_FORTIFY_SOURCE.
Nice catch. :)
Quoted 1 line
Fixes 7b6d7087031b ("wifi: cfg80211: Annotate struct cfg80211_rnr_elems with __counted_by")
This should be Cc'd to stable:
Quoted 1 line
Signed-off-by Haoyu Li <[email protected]>
Reviewed-by Gustavo A. R. Silva <[email protected]>
Thanks
-Gustavo
Quoted 23 lines
--- net/mac80211/cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/mac80211/cfg.c +1
-1@@ -1105,13 +1105,13 @@ ieee80211_copy_rnr_beacon(u8 *pos, struct cfg80211_rnr_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; }