Skip to content

Commit d5ae1c3

Browse files
committed
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 Cc: Alan Stern <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Mathias Nyman <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 2d26302 commit d5ae1c3

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

drivers/usb/host/ohci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ typedef struct urb_priv {
337337
u16 length; // # tds in this request
338338
u16 td_cnt; // tds already serviced
339339
struct list_head pending;
340-
struct td *td[]; // all TDs in this request
340+
struct td *td[] __counted_by(length); // all TDs in this request
341341

342342
} urb_priv_t;
343343

drivers/usb/host/xhci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ struct xhci_scratchpad {
16661666
struct urb_priv {
16671667
int num_tds;
16681668
int num_tds_done;
1669-
struct xhci_td td[];
1669+
struct xhci_td td[] __counted_by(num_tds);
16701670
};
16711671

16721672
/*

0 commit comments

Comments
 (0)