Skip to content

Commit 342bc7c

Browse files
keesjmberg-intel
authored andcommitted
wifi: cfg80211: Annotate struct cfg80211_pmsr_request 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_pmsr_request. 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 c14679d commit 342bc7c

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

include/net/cfg80211.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3948,7 +3948,7 @@ struct cfg80211_pmsr_request {
39483948

39493949
struct list_head list;
39503950

3951-
struct cfg80211_pmsr_request_peer peers[];
3951+
struct cfg80211_pmsr_request_peer peers[] __counted_by(n_peers);
39523952
};
39533953

39543954
/**

net/wireless/pmsr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ int nl80211_pmsr_start(struct sk_buff *skb, struct genl_info *info)
291291
req = kzalloc(struct_size(req, peers, count), GFP_KERNEL);
292292
if (!req)
293293
return -ENOMEM;
294+
req->n_peers = count;
294295

295296
if (info->attrs[NL80211_ATTR_TIMEOUT])
296297
req->timeout = nla_get_u32(info->attrs[NL80211_ATTR_TIMEOUT]);
@@ -321,8 +322,6 @@ int nl80211_pmsr_start(struct sk_buff *skb, struct genl_info *info)
321322
goto out_err;
322323
idx++;
323324
}
324-
325-
req->n_peers = count;
326325
req->cookie = cfg80211_assign_cookie(rdev);
327326
req->nl_portid = info->snd_portid;
328327

0 commit comments

Comments
 (0)