usb: Annotate struct urb_priv with __counted_by
Subsystems (3)
PATCH 1/1 usb: Annotate struct urb_priv 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 urb_priv.
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
--- drivers/usb/host/ohci.h | 2 +- drivers/usb/host/xhci.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/ohci.h +1 -1
@@ -337,7 +337,7 @@ typedef struct urb_priv {u16 length;// # tds in this request u16 td_cnt;// tds already serviced struct list_head pending; -struct td *td[];// all TDs in this request + struct td *td[] __counted_by(length); // all TDs in this request } urb_priv_t;
drivers/usb/host/xhci.h +1 -1
@@ -1666,7 +1666,7 @@ struct xhci_scratchpad {struct urb_priv {int num_tds;int num_tds_done; -struct xhci_td td[]; + struct xhci_td td[] __counted_by(num_tds); };/*
Signature · 1 line
2.34.1
Kees Cook
AppliedQuoted 9 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 structurb_priv.[...]
Applied to for-next/hardening, thanks!
[1/1] usb: Annotate struct urb_priv with __counted_by
https://git.kernel.org/kees/c/a5683963b3f5
Take care,
Signature · 1 line
Kees Cook
Greg Kroah-Hartman
maintainerQuoted 15 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 structurb_priv.[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc Alan Stern <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Mathias Nyman <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 4 lines
--- drivers/usb/host/ohci.h | 2 +- drivers/usb/host/xhci.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Thanks for taking these changes through your tree, I was too slow...
greg k-h