Commit d5ae1c3b authored by Kees Cook's avatar Kees Cook

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 <stern@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: linux-usb@vger.kernel.org
Link: https://lore.kernel.org/r/20230915195812.never.371-kees@kernel.orgSigned-off-by: default avatarKees Cook <keescook@chromium.org>
parent 2d26302b
...@@ -337,7 +337,7 @@ typedef struct urb_priv { ...@@ -337,7 +337,7 @@ typedef struct urb_priv {
u16 length; // # tds in this request u16 length; // # tds in this request
u16 td_cnt; // tds already serviced u16 td_cnt; // tds already serviced
struct list_head pending; 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; } urb_priv_t;
......
...@@ -1666,7 +1666,7 @@ struct xhci_scratchpad { ...@@ -1666,7 +1666,7 @@ struct xhci_scratchpad {
struct urb_priv { struct urb_priv {
int num_tds; int num_tds;
int num_tds_done; int num_tds_done;
struct xhci_td td[]; struct xhci_td td[] __counted_by(num_tds);
}; };
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment