net: sched: Annotate struct tc_pedit with __counted_by
Subsystems (3)
PATCH 1/1 net: sched: Annotate struct tc_pedit 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 tc_pedit. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.
---
Cc: Jakub Kicinski <[email protected]>
Cc: Jamal Hadi Salim <[email protected]>
Cc: Cong Wang <[email protected]>
Cc: Jiri Pirko <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- include/uapi/linux/tc_act/tc_pedit.h | 2 +- net/sched/act_pedit.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/uapi/linux/tc_act/tc_pedit.h +1 -1
@@ -62,7 +62,7 @@ struct tc_pedit_sel { tc_gen;unsigned char nkeys;unsigned char flags; -struct tc_pedit_key keys[0 ]; + struct tc_pedit_key keys[] __counted_by(nkeys); };#define tc_pedit tc_pedit_sel
net/sched/act_pedit.c +1 -1
@@ -515,11 +515,11 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a,spin_unlock_bh (&p->tcf_lock);return -ENOBUFS ; } + opt->nkeys = parms->tcfp_nkeys;memcpy (opt->keys, parms->tcfp_keys,flex_array_size (opt, keys, parms->tcfp_nkeys)); opt->index = p->tcf_index; - opt->nkeys = parms->tcfp_nkeys; opt->flags = parms->tcfp_flags; opt->action = p->tcf_action; opt->refcnt =refcount_read (&p->tcf_refcnt) - ref;
Signature · 1 line
2.34.1
Quoted 12 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time checking viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structtc_pedit. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.
Quoted 11 lines
---
Cc: Jakub Kicinski <[email protected]>
Cc: Jamal Hadi Salim <[email protected]>
Cc: Cong Wang <[email protected]>
Cc: Jiri Pirko <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: [email protected]
Cc: [email protected]
opt->nkeys updated before memcpy(), looks good to me:
Thanks!
--
Gustavo
Quoted 35 lines
--- include/uapi/linux/tc_act/tc_pedit.h | 2 +- net/sched/act_pedit.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/uapi/linux/tc_act/tc_pedit.h +1
-1@@ -62,7 +62,7 @@ struct tc_pedit_sel { tc_gen;unsigned char nkeys;unsigned char flags; -struct tc_pedit_key keys[0 ]; + struct tc_pedit_key keys[] __counted_by(nkeys); };#define tc_pedit tc_pedit_selnet/sched/act_pedit.c +1
-1@@ -515,11 +515,11 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a,spin_unlock_bh (&p->tcf_lock);return -ENOBUFS ; } + opt->nkeys = parms->tcfp_nkeys;memcpy (opt->keys, parms->tcfp_keys,flex_array_size (opt, keys, parms->tcfp_nkeys)); opt->index = p->tcf_index; - opt->nkeys = parms->tcfp_nkeys; opt->flags = parms->tcfp_flags; opt->action = p->tcf_action; opt->refcnt =refcount_read (&p->tcf_refcnt) - ref;
Quoted 28 lines · Gustavo A. R. Silva
Quoted 12 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time checking viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structtc_pedit. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.Quoted 11 lines
---
Cc: Jakub Kicinski <[email protected]>
Cc: Jamal Hadi Salim <[email protected]>
Cc: Cong Wang <[email protected]>
Cc: Jiri Pirko <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Quoted 3 lines
opt->nkeysupdated beforememcpy(), looks good to me:Reviewed-by Gustavo A. R. Silva <[email protected]>
Looks good to me.
cheers,
jamal
Quoted 39 lines
Thanks!
--
GustavoQuoted 35 lines
--- include/uapi/linux/tc_act/tc_pedit.h | 2 +- net/sched/act_pedit.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/uapi/linux/tc_act/tc_pedit.h +1
-1@@ -62,7 +62,7 @@ struct tc_pedit_sel { tc_gen;unsigned char nkeys;unsigned char flags; -struct tc_pedit_key keys[0 ]; + struct tc_pedit_key keys[] __counted_by(nkeys); };#define tc_pedit tc_pedit_selnet/sched/act_pedit.c +1
-1@@ -515,11 +515,11 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a,spin_unlock_bh (&p->tcf_lock);return -ENOBUFS ; } + opt->nkeys = parms->tcfp_nkeys;memcpy (opt->keys, parms->tcfp_keys,flex_array_size (opt, keys, parms->tcfp_nkeys)); opt->index = p->tcf_index; - opt->nkeys = parms->tcfp_nkeys; opt->flags = parms->tcfp_flags; opt->action = p->tcf_action; opt->refcnt =refcount_read (&p->tcf_refcnt) - ref;
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 11 lines · On Fri, 16 Feb 2024 15:27:44 -0800 you wrote:
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time checking viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structtc_pedit. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.[...]
Here is the summary with links:
- net: sched: Annotate struct tc_pedit with __counted_by
https://git.kernel.org/netdev/net-next/c/1e63e5a813fa
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html