idpf: sprinkle __counted_by{,_le}() in the virtchnl2 header
authorAlexander Lobakin <aleksander.lobakin@intel.com>
Wed, 27 Mar 2024 14:22:41 +0000 (15:22 +0100)
committerJakub Kicinski <kuba@kernel.org>
Fri, 29 Mar 2024 01:50:47 +0000 (18:50 -0700)
commit93d24acfa05ebe954ec1782bca374de2501a5830
tree1da137ec4c75662d71f257e3591dd8c406caf23a
parentc00d33f1fc7958e6e7f461c994fa025aa2273c13
idpf: sprinkle __counted_by{,_le}() in the virtchnl2 header

Both virtchnl2.h and its consumer idpf_virtchnl.c are very error-prone.
There are 10 structures with flexible arrays at the end, but 9 of them
has flex member counter in Little Endian.
Make the code a bit more robust by applying __counted_by_le() to those
9. LE platforms is the main target for this driver, so they would
receive additional protection.
While we're here, add __counted_by() to virtchnl2_ptype::proto_id, as
its counter is `u8` regardless of the Endianness.
Compile test on x86_64 (LE) didn't reveal any new issues after applying
the attributes.

Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Link: https://lore.kernel.org/r/20240327142241.1745989-4-aleksander.lobakin@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/intel/idpf/virtchnl2.h