Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Kees Cook and committed by
David S. Miller
1e63e5a8 da4a154c

+2 -2
+1 -1
include/uapi/linux/tc_act/tc_pedit.h
··· 62 62 tc_gen; 63 63 unsigned char nkeys; 64 64 unsigned char flags; 65 - struct tc_pedit_key keys[0]; 65 + struct tc_pedit_key keys[] __counted_by(nkeys); 66 66 }; 67 67 68 68 #define tc_pedit tc_pedit_sel
+1 -1
net/sched/act_pedit.c
··· 515 515 spin_unlock_bh(&p->tcf_lock); 516 516 return -ENOBUFS; 517 517 } 518 + opt->nkeys = parms->tcfp_nkeys; 518 519 519 520 memcpy(opt->keys, parms->tcfp_keys, 520 521 flex_array_size(opt, keys, parms->tcfp_nkeys)); 521 522 opt->index = p->tcf_index; 522 - opt->nkeys = parms->tcfp_nkeys; 523 523 opt->flags = parms->tcfp_flags; 524 524 opt->action = p->tcf_action; 525 525 opt->refcnt = refcount_read(&p->tcf_refcnt) - ref;