* [PATCH 0/7] wifi: cfg80211: Annotate with __counted_by
@ 2023-08-17 21:15 Kees Cook
2023-08-17 21:15 ` [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data " Kees Cook
` (6 more replies)
0 siblings, 7 replies; 23+ messages in thread
From: Kees Cook @ 2023-08-17 21:15 UTC (permalink / raw)
To: Johannes Berg
Cc: Kees Cook, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Nathan Chancellor, Nick Desaulniers, Tom Rix,
linux-kernel, linux-wireless, netdev, llvm, linux-hardening
Hi,
This annotates several structures with the coming __counted_by attribute
for bounds checking of flexible arrays at run-time. As a note toward
applicability, had this mitigation been available already, the flaw
fixed in commit 6311071a0562 ("wifi: nl80211: fix integer overflow in
nl80211_parse_mbssid_elems()") would have already been unexploitable
(i.e. writes through an out-of-bounds index would have been blocked).
Thanks!
-Kees
Kees Cook (7):
wifi: cfg80211: Annotate struct cfg80211_acl_data with __counted_by
wifi: cfg80211: Annotate struct cfg80211_cqm_config with __counted_by
wifi: cfg80211: Annotate struct cfg80211_mbssid_elems with
__counted_by
wifi: cfg80211: Annotate struct cfg80211_pmsr_request with
__counted_by
wifi: cfg80211: Annotate struct cfg80211_rnr_elems with __counted_by
wifi: cfg80211: Annotate struct cfg80211_scan_request with
__counted_by
wifi: cfg80211: Annotate struct cfg80211_tid_config with __counted_by
include/net/cfg80211.h | 12 ++++++------
net/wireless/core.h | 2 +-
net/wireless/nl80211.c | 7 +++----
net/wireless/pmsr.c | 3 +--
4 files changed, 11 insertions(+), 13 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data with __counted_by
2023-08-17 21:15 [PATCH 0/7] wifi: cfg80211: Annotate with __counted_by Kees Cook
@ 2023-08-17 21:15 ` Kees Cook
2023-08-17 21:21 ` Justin Stitt
` (2 more replies)
2023-08-17 21:15 ` [PATCH 2/7] wifi: cfg80211: Annotate struct cfg80211_cqm_config " Kees Cook
` (5 subsequent siblings)
6 siblings, 3 replies; 23+ messages in thread
From: Kees Cook @ 2023-08-17 21:15 UTC (permalink / raw)
To: Johannes Berg
Cc: Kees Cook, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-wireless, netdev, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, llvm, linux-hardening
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_acl_data.
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 <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
include/net/cfg80211.h | 2 +-
net/wireless/nl80211.c | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index d6fa7c8767ad..eb73b5af5d04 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -1282,7 +1282,7 @@ struct cfg80211_acl_data {
int n_acl_entries;
/* Keep it last */
- struct mac_address mac_addrs[];
+ struct mac_address mac_addrs[] __counted_by(n_acl_entries);
};
/**
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 8bcf8e293308..80633e815311 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -4889,13 +4889,12 @@ static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
if (!acl)
return ERR_PTR(-ENOMEM);
+ acl->n_acl_entries = n_entries;
nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
i++;
}
-
- acl->n_acl_entries = n_entries;
acl->acl_policy = acl_policy;
return acl;
--
2.34.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 2/7] wifi: cfg80211: Annotate struct cfg80211_cqm_config with __counted_by
2023-08-17 21:15 [PATCH 0/7] wifi: cfg80211: Annotate with __counted_by Kees Cook
2023-08-17 21:15 ` [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data " Kees Cook
@ 2023-08-17 21:15 ` Kees Cook
2023-08-17 21:23 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 3/7] wifi: cfg80211: Annotate struct cfg80211_mbssid_elems " Kees Cook
` (4 subsequent siblings)
6 siblings, 2 replies; 23+ messages in thread
From: Kees Cook @ 2023-08-17 21:15 UTC (permalink / raw)
To: Johannes Berg
Cc: Kees Cook, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-wireless, netdev, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, llvm, linux-hardening
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_cqm_config.
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
net/wireless/core.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 8a807b609ef7..507d184b8b40 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -298,7 +298,7 @@ struct cfg80211_cqm_config {
u32 rssi_hyst;
s32 last_rssi_event_value;
int n_rssi_thresholds;
- s32 rssi_thresholds[];
+ s32 rssi_thresholds[] __counted_by(n_rssi_thresholds);
};
void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev);
--
2.34.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 3/7] wifi: cfg80211: Annotate struct cfg80211_mbssid_elems with __counted_by
2023-08-17 21:15 [PATCH 0/7] wifi: cfg80211: Annotate with __counted_by Kees Cook
2023-08-17 21:15 ` [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data " Kees Cook
2023-08-17 21:15 ` [PATCH 2/7] wifi: cfg80211: Annotate struct cfg80211_cqm_config " Kees Cook
@ 2023-08-17 21:15 ` Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 4/7] wifi: cfg80211: Annotate struct cfg80211_pmsr_request " Kees Cook
` (3 subsequent siblings)
6 siblings, 2 replies; 23+ messages in thread
From: Kees Cook @ 2023-08-17 21:15 UTC (permalink / raw)
To: Johannes Berg
Cc: Kees Cook, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-wireless, netdev, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, llvm, linux-hardening
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 <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
include/net/cfg80211.h | 2 +-
net/wireless/nl80211.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index eb73b5af5d04..5c7d091b3925 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -1187,7 +1187,7 @@ struct cfg80211_mbssid_elems {
struct {
const u8 *data;
size_t len;
- } elem[];
+ } elem[] __counted_by(cnt);
};
/**
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 80633e815311..9ba4266368db 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5438,13 +5438,13 @@ nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs)
elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL);
if (!elems)
return ERR_PTR(-ENOMEM);
+ elems->cnt = num_elems;
nla_for_each_nested(nl_elems, attrs, rem_elems) {
elems->elem[i].data = nla_data(nl_elems);
elems->elem[i].len = nla_len(nl_elems);
i++;
}
- elems->cnt = num_elems;
return elems;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 4/7] wifi: cfg80211: Annotate struct cfg80211_pmsr_request with __counted_by
2023-08-17 21:15 [PATCH 0/7] wifi: cfg80211: Annotate with __counted_by Kees Cook
` (2 preceding siblings ...)
2023-08-17 21:15 ` [PATCH 3/7] wifi: cfg80211: Annotate struct cfg80211_mbssid_elems " Kees Cook
@ 2023-08-17 21:15 ` Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 5/7] wifi: cfg80211: Annotate struct cfg80211_rnr_elems " Kees Cook
` (2 subsequent siblings)
6 siblings, 2 replies; 23+ messages in thread
From: Kees Cook @ 2023-08-17 21:15 UTC (permalink / raw)
To: Johannes Berg
Cc: Kees Cook, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-wireless, netdev, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, llvm, linux-hardening
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 <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
include/net/cfg80211.h | 2 +-
net/wireless/pmsr.c | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 5c7d091b3925..e9ca4726a732 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -3948,7 +3948,7 @@ struct cfg80211_pmsr_request {
struct list_head list;
- struct cfg80211_pmsr_request_peer peers[];
+ struct cfg80211_pmsr_request_peer peers[] __counted_by(n_peers);
};
/**
diff --git a/net/wireless/pmsr.c b/net/wireless/pmsr.c
index 77000a264855..9611aa0bd051 100644
--- a/net/wireless/pmsr.c
+++ b/net/wireless/pmsr.c
@@ -291,6 +291,7 @@ int nl80211_pmsr_start(struct sk_buff *skb, struct genl_info *info)
req = kzalloc(struct_size(req, peers, count), GFP_KERNEL);
if (!req)
return -ENOMEM;
+ req->n_peers = count;
if (info->attrs[NL80211_ATTR_TIMEOUT])
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)
goto out_err;
idx++;
}
-
- req->n_peers = count;
req->cookie = cfg80211_assign_cookie(rdev);
req->nl_portid = info->snd_portid;
--
2.34.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 5/7] wifi: cfg80211: Annotate struct cfg80211_rnr_elems with __counted_by
2023-08-17 21:15 [PATCH 0/7] wifi: cfg80211: Annotate with __counted_by Kees Cook
` (3 preceding siblings ...)
2023-08-17 21:15 ` [PATCH 4/7] wifi: cfg80211: Annotate struct cfg80211_pmsr_request " Kees Cook
@ 2023-08-17 21:15 ` Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 6/7] wifi: cfg80211: Annotate struct cfg80211_scan_request " Kees Cook
2023-08-17 21:15 ` [PATCH 7/7] wifi: cfg80211: Annotate struct cfg80211_tid_config " Kees Cook
6 siblings, 2 replies; 23+ messages in thread
From: Kees Cook @ 2023-08-17 21:15 UTC (permalink / raw)
To: Johannes Berg
Cc: Kees Cook, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-wireless, netdev, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, llvm, linux-hardening
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 <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
include/net/cfg80211.h | 2 +-
net/wireless/nl80211.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index e9ca4726a732..6efe216c01d2 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -1204,7 +1204,7 @@ struct cfg80211_rnr_elems {
struct {
const u8 *data;
size_t len;
- } elem[];
+ } elem[] __counted_by(cnt);
};
/**
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 9ba4266368db..0ffebf1a1eb6 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -5470,13 +5470,13 @@ nl80211_parse_rnr_elems(struct wiphy *wiphy, struct nlattr *attrs,
elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL);
if (!elems)
return ERR_PTR(-ENOMEM);
+ elems->cnt = num_elems;
nla_for_each_nested(nl_elems, attrs, rem_elems) {
elems->elem[i].data = nla_data(nl_elems);
elems->elem[i].len = nla_len(nl_elems);
i++;
}
- elems->cnt = num_elems;
return elems;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 6/7] wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by
2023-08-17 21:15 [PATCH 0/7] wifi: cfg80211: Annotate with __counted_by Kees Cook
` (4 preceding siblings ...)
2023-08-17 21:15 ` [PATCH 5/7] wifi: cfg80211: Annotate struct cfg80211_rnr_elems " Kees Cook
@ 2023-08-17 21:15 ` Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 7/7] wifi: cfg80211: Annotate struct cfg80211_tid_config " Kees Cook
6 siblings, 2 replies; 23+ messages in thread
From: Kees Cook @ 2023-08-17 21:15 UTC (permalink / raw)
To: Johannes Berg
Cc: Kees Cook, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-wireless, netdev, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, llvm, linux-hardening
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_scan_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 <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
include/net/cfg80211.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 6efe216c01d2..a2afc94a5408 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2544,7 +2544,7 @@ struct cfg80211_scan_request {
struct cfg80211_scan_6ghz_params *scan_6ghz_params;
/* keep last */
- struct ieee80211_channel *channels[];
+ struct ieee80211_channel *channels[] __counted_by(n_channels);
};
static inline void get_random_mask_addr(u8 *buf, const u8 *addr, const u8 *mask)
--
2.34.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 7/7] wifi: cfg80211: Annotate struct cfg80211_tid_config with __counted_by
2023-08-17 21:15 [PATCH 0/7] wifi: cfg80211: Annotate with __counted_by Kees Cook
` (5 preceding siblings ...)
2023-08-17 21:15 ` [PATCH 6/7] wifi: cfg80211: Annotate struct cfg80211_scan_request " Kees Cook
@ 2023-08-17 21:15 ` Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
6 siblings, 2 replies; 23+ messages in thread
From: Kees Cook @ 2023-08-17 21:15 UTC (permalink / raw)
To: Johannes Berg
Cc: Kees Cook, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-wireless, netdev, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, llvm, linux-hardening
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_tid_config.
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
include/net/cfg80211.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index a2afc94a5408..423fe9b85cb0 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -811,7 +811,7 @@ struct cfg80211_tid_cfg {
struct cfg80211_tid_config {
const u8 *peer;
u32 n_tid_conf;
- struct cfg80211_tid_cfg tid_conf[];
+ struct cfg80211_tid_cfg tid_conf[] __counted_by(n_tid_conf);
};
/**
--
2.34.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data with __counted_by
2023-08-17 21:15 ` [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data " Kees Cook
@ 2023-08-17 21:21 ` Justin Stitt
2023-08-17 21:23 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2 siblings, 0 replies; 23+ messages in thread
From: Justin Stitt @ 2023-08-17 21:21 UTC (permalink / raw)
To: Kees Cook
Cc: Johannes Berg, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-wireless, netdev, Nathan Chancellor,
Nick Desaulniers, Tom Rix, linux-kernel, llvm, linux-hardening
On Thu, Aug 17, 2023 at 2:16 PM Kees Cook <keescook@chromium.org> wrote:
>
> 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_acl_data.
> 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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
> include/net/cfg80211.h | 2 +-
> net/wireless/nl80211.c | 3 +--
> 2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
> index d6fa7c8767ad..eb73b5af5d04 100644
> --- a/include/net/cfg80211.h
> +++ b/include/net/cfg80211.h
> @@ -1282,7 +1282,7 @@ struct cfg80211_acl_data {
> int n_acl_entries;
>
> /* Keep it last */
> - struct mac_address mac_addrs[];
> + struct mac_address mac_addrs[] __counted_by(n_acl_entries);
> };
>
> /**
> diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
> index 8bcf8e293308..80633e815311 100644
> --- a/net/wireless/nl80211.c
> +++ b/net/wireless/nl80211.c
> @@ -4889,13 +4889,12 @@ static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
> acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
> if (!acl)
> return ERR_PTR(-ENOMEM);
> + acl->n_acl_entries = n_entries;
>
> nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
> memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
> i++;
> }
> -
> - acl->n_acl_entries = n_entries;
> acl->acl_policy = acl_policy;
>
> return acl;
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data with __counted_by
2023-08-17 21:15 ` [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data " Kees Cook
2023-08-17 21:21 ` Justin Stitt
@ 2023-08-17 21:23 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2 siblings, 0 replies; 23+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-17 21:23 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/23 15:15, Kees Cook wrote:
> 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_acl_data.
> 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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> include/net/cfg80211.h | 2 +-
> net/wireless/nl80211.c | 3 +--
> 2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
> index d6fa7c8767ad..eb73b5af5d04 100644
> --- a/include/net/cfg80211.h
> +++ b/include/net/cfg80211.h
> @@ -1282,7 +1282,7 @@ struct cfg80211_acl_data {
> int n_acl_entries;
>
> /* Keep it last */
> - struct mac_address mac_addrs[];
> + struct mac_address mac_addrs[] __counted_by(n_acl_entries);
> };
>
> /**
> diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
> index 8bcf8e293308..80633e815311 100644
> --- a/net/wireless/nl80211.c
> +++ b/net/wireless/nl80211.c
> @@ -4889,13 +4889,12 @@ static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
> acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
> if (!acl)
> return ERR_PTR(-ENOMEM);
> + acl->n_acl_entries = n_entries;
>
> nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
> memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
> i++;
> }
> -
> - acl->n_acl_entries = n_entries;
> acl->acl_policy = acl_policy;
>
> return acl;
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/7] wifi: cfg80211: Annotate struct cfg80211_cqm_config with __counted_by
2023-08-17 21:15 ` [PATCH 2/7] wifi: cfg80211: Annotate struct cfg80211_cqm_config " Kees Cook
@ 2023-08-17 21:23 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-17 21:23 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/23 15:15, Kees Cook wrote:
> 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_cqm_config.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Johannes Berg <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> net/wireless/core.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/wireless/core.h b/net/wireless/core.h
> index 8a807b609ef7..507d184b8b40 100644
> --- a/net/wireless/core.h
> +++ b/net/wireless/core.h
> @@ -298,7 +298,7 @@ struct cfg80211_cqm_config {
> u32 rssi_hyst;
> s32 last_rssi_event_value;
> int n_rssi_thresholds;
> - s32 rssi_thresholds[];
> + s32 rssi_thresholds[] __counted_by(n_rssi_thresholds);
> };
>
> void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev);
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 3/7] wifi: cfg80211: Annotate struct cfg80211_mbssid_elems with __counted_by
2023-08-17 21:15 ` [PATCH 3/7] wifi: cfg80211: Annotate struct cfg80211_mbssid_elems " Kees Cook
@ 2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-17 21:24 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/23 15:15, Kees Cook wrote:
> 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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> include/net/cfg80211.h | 2 +-
> net/wireless/nl80211.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
> index eb73b5af5d04..5c7d091b3925 100644
> --- a/include/net/cfg80211.h
> +++ b/include/net/cfg80211.h
> @@ -1187,7 +1187,7 @@ struct cfg80211_mbssid_elems {
> struct {
> const u8 *data;
> size_t len;
> - } elem[];
> + } elem[] __counted_by(cnt);
> };
>
> /**
> diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
> index 80633e815311..9ba4266368db 100644
> --- a/net/wireless/nl80211.c
> +++ b/net/wireless/nl80211.c
> @@ -5438,13 +5438,13 @@ nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs)
> elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL);
> if (!elems)
> return ERR_PTR(-ENOMEM);
> + elems->cnt = num_elems;
>
> nla_for_each_nested(nl_elems, attrs, rem_elems) {
> elems->elem[i].data = nla_data(nl_elems);
> elems->elem[i].len = nla_len(nl_elems);
> i++;
> }
> - elems->cnt = num_elems;
> return elems;
> }
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 4/7] wifi: cfg80211: Annotate struct cfg80211_pmsr_request with __counted_by
2023-08-17 21:15 ` [PATCH 4/7] wifi: cfg80211: Annotate struct cfg80211_pmsr_request " Kees Cook
@ 2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-17 21:24 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/23 15:15, Kees Cook wrote:
> 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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> include/net/cfg80211.h | 2 +-
> net/wireless/pmsr.c | 3 +--
> 2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
> index 5c7d091b3925..e9ca4726a732 100644
> --- a/include/net/cfg80211.h
> +++ b/include/net/cfg80211.h
> @@ -3948,7 +3948,7 @@ struct cfg80211_pmsr_request {
>
> struct list_head list;
>
> - struct cfg80211_pmsr_request_peer peers[];
> + struct cfg80211_pmsr_request_peer peers[] __counted_by(n_peers);
> };
>
> /**
> diff --git a/net/wireless/pmsr.c b/net/wireless/pmsr.c
> index 77000a264855..9611aa0bd051 100644
> --- a/net/wireless/pmsr.c
> +++ b/net/wireless/pmsr.c
> @@ -291,6 +291,7 @@ int nl80211_pmsr_start(struct sk_buff *skb, struct genl_info *info)
> req = kzalloc(struct_size(req, peers, count), GFP_KERNEL);
> if (!req)
> return -ENOMEM;
> + req->n_peers = count;
>
> if (info->attrs[NL80211_ATTR_TIMEOUT])
> 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)
> goto out_err;
> idx++;
> }
> -
> - req->n_peers = count;
> req->cookie = cfg80211_assign_cookie(rdev);
> req->nl_portid = info->snd_portid;
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 5/7] wifi: cfg80211: Annotate struct cfg80211_rnr_elems with __counted_by
2023-08-17 21:15 ` [PATCH 5/7] wifi: cfg80211: Annotate struct cfg80211_rnr_elems " Kees Cook
@ 2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-17 21:24 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/23 15:15, Kees Cook wrote:
> 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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> include/net/cfg80211.h | 2 +-
> net/wireless/nl80211.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
> index e9ca4726a732..6efe216c01d2 100644
> --- a/include/net/cfg80211.h
> +++ b/include/net/cfg80211.h
> @@ -1204,7 +1204,7 @@ struct cfg80211_rnr_elems {
> struct {
> const u8 *data;
> size_t len;
> - } elem[];
> + } elem[] __counted_by(cnt);
> };
>
> /**
> diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
> index 9ba4266368db..0ffebf1a1eb6 100644
> --- a/net/wireless/nl80211.c
> +++ b/net/wireless/nl80211.c
> @@ -5470,13 +5470,13 @@ nl80211_parse_rnr_elems(struct wiphy *wiphy, struct nlattr *attrs,
> elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL);
> if (!elems)
> return ERR_PTR(-ENOMEM);
> + elems->cnt = num_elems;
>
> nla_for_each_nested(nl_elems, attrs, rem_elems) {
> elems->elem[i].data = nla_data(nl_elems);
> elems->elem[i].len = nla_len(nl_elems);
> i++;
> }
> - elems->cnt = num_elems;
> return elems;
> }
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/7] wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by
2023-08-17 21:15 ` [PATCH 6/7] wifi: cfg80211: Annotate struct cfg80211_scan_request " Kees Cook
@ 2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-17 21:24 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/23 15:15, Kees Cook wrote:
> 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_scan_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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> include/net/cfg80211.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
> index 6efe216c01d2..a2afc94a5408 100644
> --- a/include/net/cfg80211.h
> +++ b/include/net/cfg80211.h
> @@ -2544,7 +2544,7 @@ struct cfg80211_scan_request {
> struct cfg80211_scan_6ghz_params *scan_6ghz_params;
>
> /* keep last */
> - struct ieee80211_channel *channels[];
> + struct ieee80211_channel *channels[] __counted_by(n_channels);
> };
>
> static inline void get_random_mask_addr(u8 *buf, const u8 *addr, const u8 *mask)
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 7/7] wifi: cfg80211: Annotate struct cfg80211_tid_config with __counted_by
2023-08-17 21:15 ` [PATCH 7/7] wifi: cfg80211: Annotate struct cfg80211_tid_config " Kees Cook
@ 2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-17 21:24 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/23 15:15, Kees Cook wrote:
> 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_tid_config.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Johannes Berg <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> include/net/cfg80211.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
> index a2afc94a5408..423fe9b85cb0 100644
> --- a/include/net/cfg80211.h
> +++ b/include/net/cfg80211.h
> @@ -811,7 +811,7 @@ struct cfg80211_tid_cfg {
> struct cfg80211_tid_config {
> const u8 *peer;
> u32 n_tid_conf;
> - struct cfg80211_tid_cfg tid_conf[];
> + struct cfg80211_tid_cfg tid_conf[] __counted_by(n_tid_conf);
> };
>
> /**
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data with __counted_by
2023-08-17 21:15 ` [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data " Kees Cook
2023-08-17 21:21 ` Justin Stitt
2023-08-17 21:23 ` Gustavo A. R. Silva
@ 2023-08-17 22:03 ` Jeff Johnson
2 siblings, 0 replies; 23+ messages in thread
From: Jeff Johnson @ 2023-08-17 22:03 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/2023 2:15 PM, Kees Cook wrote:
> 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_acl_data.
> 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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/7] wifi: cfg80211: Annotate struct cfg80211_cqm_config with __counted_by
2023-08-17 21:15 ` [PATCH 2/7] wifi: cfg80211: Annotate struct cfg80211_cqm_config " Kees Cook
2023-08-17 21:23 ` Gustavo A. R. Silva
@ 2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Jeff Johnson @ 2023-08-17 22:03 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/2023 2:15 PM, Kees Cook wrote:
> 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_cqm_config.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Johannes Berg <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 3/7] wifi: cfg80211: Annotate struct cfg80211_mbssid_elems with __counted_by
2023-08-17 21:15 ` [PATCH 3/7] wifi: cfg80211: Annotate struct cfg80211_mbssid_elems " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
@ 2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Jeff Johnson @ 2023-08-17 22:03 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/2023 2:15 PM, Kees Cook wrote:
> 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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 4/7] wifi: cfg80211: Annotate struct cfg80211_pmsr_request with __counted_by
2023-08-17 21:15 ` [PATCH 4/7] wifi: cfg80211: Annotate struct cfg80211_pmsr_request " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
@ 2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Jeff Johnson @ 2023-08-17 22:03 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/2023 2:15 PM, Kees Cook wrote:
> 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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 5/7] wifi: cfg80211: Annotate struct cfg80211_rnr_elems with __counted_by
2023-08-17 21:15 ` [PATCH 5/7] wifi: cfg80211: Annotate struct cfg80211_rnr_elems " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
@ 2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Jeff Johnson @ 2023-08-17 22:03 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/2023 2:15 PM, Kees Cook wrote:
> 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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/7] wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by
2023-08-17 21:15 ` [PATCH 6/7] wifi: cfg80211: Annotate struct cfg80211_scan_request " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
@ 2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Jeff Johnson @ 2023-08-17 22:03 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/2023 2:15 PM, Kees Cook wrote:
> 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_scan_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 <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 7/7] wifi: cfg80211: Annotate struct cfg80211_tid_config with __counted_by
2023-08-17 21:15 ` [PATCH 7/7] wifi: cfg80211: Annotate struct cfg80211_tid_config " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
@ 2023-08-17 22:03 ` Jeff Johnson
1 sibling, 0 replies; 23+ messages in thread
From: Jeff Johnson @ 2023-08-17 22:03 UTC (permalink / raw)
To: Kees Cook, Johannes Berg
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-wireless, netdev, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm, linux-hardening
On 8/17/2023 2:15 PM, Kees Cook wrote:
> 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_tid_config.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Johannes Berg <johannes@sipsolutions.net>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2023-08-17 22:39 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-17 21:15 [PATCH 0/7] wifi: cfg80211: Annotate with __counted_by Kees Cook
2023-08-17 21:15 ` [PATCH 1/7] wifi: cfg80211: Annotate struct cfg80211_acl_data " Kees Cook
2023-08-17 21:21 ` Justin Stitt
2023-08-17 21:23 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 2/7] wifi: cfg80211: Annotate struct cfg80211_cqm_config " Kees Cook
2023-08-17 21:23 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 3/7] wifi: cfg80211: Annotate struct cfg80211_mbssid_elems " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 4/7] wifi: cfg80211: Annotate struct cfg80211_pmsr_request " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 5/7] wifi: cfg80211: Annotate struct cfg80211_rnr_elems " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 6/7] wifi: cfg80211: Annotate struct cfg80211_scan_request " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
2023-08-17 21:15 ` [PATCH 7/7] wifi: cfg80211: Annotate struct cfg80211_tid_config " Kees Cook
2023-08-17 21:24 ` Gustavo A. R. Silva
2023-08-17 22:03 ` Jeff Johnson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).