Skip to content

Commit c14679d

Browse files
keesjmberg-intel
authored andcommitted
wifi: cfg80211: Annotate struct cfg80211_mbssid_elems with __counted_by
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct cfg80211_mbssid_elems. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Johannes Berg <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Paolo Abeni <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Jeff Johnson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent d4d3aaf commit c14679d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

include/net/cfg80211.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ struct cfg80211_mbssid_elems {
11871187
struct {
11881188
const u8 *data;
11891189
size_t len;
1190-
} elem[];
1190+
} elem[] __counted_by(cnt);
11911191
};
11921192

11931193
/**

net/wireless/nl80211.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5438,13 +5438,13 @@ nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs)
54385438
elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL);
54395439
if (!elems)
54405440
return ERR_PTR(-ENOMEM);
5441+
elems->cnt = num_elems;
54415442

54425443
nla_for_each_nested(nl_elems, attrs, rem_elems) {
54435444
elems->elem[i].data = nla_data(nl_elems);
54445445
elems->elem[i].len = nla_len(nl_elems);
54455446
i++;
54465447
}
5447-
elems->cnt = num_elems;
54485448
return elems;
54495449
}
54505450

0 commit comments

Comments
 (0)