Skip to content

Commit 7b6d708

Browse files
keesjmberg-intel
authored andcommitted
wifi: cfg80211: Annotate struct cfg80211_rnr_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_rnr_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 342bc7c commit 7b6d708

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
@@ -1204,7 +1204,7 @@ struct cfg80211_rnr_elems {
12041204
struct {
12051205
const u8 *data;
12061206
size_t len;
1207-
} elem[];
1207+
} elem[] __counted_by(cnt);
12081208
};
12091209

12101210
/**

net/wireless/nl80211.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5470,13 +5470,13 @@ nl80211_parse_rnr_elems(struct wiphy *wiphy, struct nlattr *attrs,
54705470
elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL);
54715471
if (!elems)
54725472
return ERR_PTR(-ENOMEM);
5473+
elems->cnt = num_elems;
54735474

54745475
nla_for_each_nested(nl_elems, attrs, rem_elems) {
54755476
elems->elem[i].data = nla_data(nl_elems);
54765477
elems->elem[i].len = nla_len(nl_elems);
54775478
i++;
54785479
}
5479-
elems->cnt = num_elems;
54805480
return elems;
54815481
}
54825482

0 commit comments

Comments
 (0)