mirror_ubuntu-kernels/drivers/net/ethernet/intel
Alexander Lobakin dd2e84bb38 virtchnl: fix fake 1-elem arrays in structs allocated as nents + 1 - 1
The two most problematic virtchnl structures are virtchnl_rss_key and
virtchnl_rss_lut. Their "flex" arrays have the type of u8, thus, when
allocating / checking, the actual size is calculated as `sizeof +
nents - 1 byte`. But their sizeof() is not 1 byte larger than the size
of such structure with proper flex array, it's two bytes larger due to
the padding. That said, their size is always 1 byte larger unless
there are no tail elements -- then it's +2 bytes.
Add virtchnl_struct_size() macro which will handle this case (and later
other cases as well). Make its calling conv the same as we call
struct_size() to allow it to be drop-in, even though it's unlikely to
become possible to switch to generic API. The macro will calculate a
proper size of a structure with a flex array at the end, so that it
becomes transparent for the compilers, but add the difference from the
old values, so that the real size of sorta-ABI-messages doesn't change.
Use it on the allocation side in IAVF and the receiving side (defined
as static inline in virtchnl.h) for the mentioned two structures.

Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Rafal Romanowski <rafal.romanowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2023-08-16 08:56:56 -07:00
..
e1000 net: e1000: Remove unused declarations 2023-08-13 12:28:03 +01:00
e1000e e1000e: Use PME poll to circumvent unreliable ACPI wake 2023-08-16 12:22:22 +01:00
fm10k fm10k: Remove unnecessary aer.h include 2023-03-08 23:34:39 -08:00
i40e i40e: Replace one-element array with flex-array member in struct i40e_profile_aq_section 2023-08-10 10:41:54 -07:00
iavf virtchnl: fix fake 1-elem arrays in structs allocated as nents + 1 - 1 2023-08-16 08:56:56 -07:00
ice ice: clean up __ice_aq_get_set_rss_lut() 2023-08-07 13:01:29 -07:00
igb net: flow_dissector: Use 64bits for used_keys 2023-07-31 09:11:24 +01:00
igbvf Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2023-03-24 10:10:20 -07:00
igc Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2023-08-10 14:10:53 -07:00
ixgbe rtnetlink: remove redundant checks for nlattr IFLA_BRIDGE_MODE 2023-08-08 15:10:37 -07:00
ixgbevf ixgbevf: Remove unused function declarations 2023-08-04 18:03:00 -07:00
e100.c e100: Fix possible use after free in e100_xmit_prepare 2022-11-23 08:38:22 -08:00
Kconfig ixgb: Remove ixgb driver 2023-03-19 10:51:07 +00:00
Makefile ixgb: Remove ixgb driver 2023-03-19 10:51:07 +00:00