Commit 93d24acf authored by Alexander Lobakin's avatar Alexander Lobakin Committed by Jakub Kicinski

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: default avatarKees Cook <keescook@chromium.org>
Acked-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: default avatarAlexander Lobakin <aleksander.lobakin@intel.com>
Reviewed-by: default avatarPrzemek Kitszel <przemyslaw.kitszel@intel.com>
Link: https://lore.kernel.org/r/20240327142241.1745989-4-aleksander.lobakin@intel.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c00d33f1
...@@ -555,7 +555,7 @@ VIRTCHNL2_CHECK_STRUCT_LEN(32, virtchnl2_queue_reg_chunk); ...@@ -555,7 +555,7 @@ VIRTCHNL2_CHECK_STRUCT_LEN(32, virtchnl2_queue_reg_chunk);
struct virtchnl2_queue_reg_chunks { struct virtchnl2_queue_reg_chunks {
__le16 num_chunks; __le16 num_chunks;
u8 pad[6]; u8 pad[6];
struct virtchnl2_queue_reg_chunk chunks[]; struct virtchnl2_queue_reg_chunk chunks[] __counted_by_le(num_chunks);
}; };
VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_queue_reg_chunks); VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_queue_reg_chunks);
...@@ -703,7 +703,7 @@ struct virtchnl2_config_tx_queues { ...@@ -703,7 +703,7 @@ struct virtchnl2_config_tx_queues {
__le32 vport_id; __le32 vport_id;
__le16 num_qinfo; __le16 num_qinfo;
u8 pad[10]; u8 pad[10];
struct virtchnl2_txq_info qinfo[]; struct virtchnl2_txq_info qinfo[] __counted_by_le(num_qinfo);
}; };
VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_config_tx_queues); VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_config_tx_queues);
...@@ -782,7 +782,7 @@ struct virtchnl2_config_rx_queues { ...@@ -782,7 +782,7 @@ struct virtchnl2_config_rx_queues {
__le32 vport_id; __le32 vport_id;
__le16 num_qinfo; __le16 num_qinfo;
u8 pad[18]; u8 pad[18];
struct virtchnl2_rxq_info qinfo[]; struct virtchnl2_rxq_info qinfo[] __counted_by_le(num_qinfo);
}; };
VIRTCHNL2_CHECK_STRUCT_LEN(24, virtchnl2_config_rx_queues); VIRTCHNL2_CHECK_STRUCT_LEN(24, virtchnl2_config_rx_queues);
...@@ -868,7 +868,7 @@ VIRTCHNL2_CHECK_STRUCT_LEN(32, virtchnl2_vector_chunk); ...@@ -868,7 +868,7 @@ VIRTCHNL2_CHECK_STRUCT_LEN(32, virtchnl2_vector_chunk);
struct virtchnl2_vector_chunks { struct virtchnl2_vector_chunks {
__le16 num_vchunks; __le16 num_vchunks;
u8 pad[14]; u8 pad[14];
struct virtchnl2_vector_chunk vchunks[]; struct virtchnl2_vector_chunk vchunks[] __counted_by_le(num_vchunks);
}; };
VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_vector_chunks); VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_vector_chunks);
...@@ -912,7 +912,7 @@ struct virtchnl2_rss_lut { ...@@ -912,7 +912,7 @@ struct virtchnl2_rss_lut {
__le16 lut_entries_start; __le16 lut_entries_start;
__le16 lut_entries; __le16 lut_entries;
u8 pad[4]; u8 pad[4];
__le32 lut[]; __le32 lut[] __counted_by_le(lut_entries);
}; };
VIRTCHNL2_CHECK_STRUCT_LEN(12, virtchnl2_rss_lut); VIRTCHNL2_CHECK_STRUCT_LEN(12, virtchnl2_rss_lut);
...@@ -977,7 +977,7 @@ struct virtchnl2_ptype { ...@@ -977,7 +977,7 @@ struct virtchnl2_ptype {
u8 ptype_id_8; u8 ptype_id_8;
u8 proto_id_count; u8 proto_id_count;
__le16 pad; __le16 pad;
__le16 proto_id[]; __le16 proto_id[] __counted_by(proto_id_count);
} __packed __aligned(2); } __packed __aligned(2);
VIRTCHNL2_CHECK_STRUCT_LEN(6, virtchnl2_ptype); VIRTCHNL2_CHECK_STRUCT_LEN(6, virtchnl2_ptype);
...@@ -1104,7 +1104,7 @@ struct virtchnl2_rss_key { ...@@ -1104,7 +1104,7 @@ struct virtchnl2_rss_key {
__le32 vport_id; __le32 vport_id;
__le16 key_len; __le16 key_len;
u8 pad; u8 pad;
u8 key_flex[]; u8 key_flex[] __counted_by_le(key_len);
} __packed; } __packed;
VIRTCHNL2_CHECK_STRUCT_LEN(7, virtchnl2_rss_key); VIRTCHNL2_CHECK_STRUCT_LEN(7, virtchnl2_rss_key);
...@@ -1131,7 +1131,7 @@ VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_queue_chunk); ...@@ -1131,7 +1131,7 @@ VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_queue_chunk);
struct virtchnl2_queue_chunks { struct virtchnl2_queue_chunks {
__le16 num_chunks; __le16 num_chunks;
u8 pad[6]; u8 pad[6];
struct virtchnl2_queue_chunk chunks[]; struct virtchnl2_queue_chunk chunks[] __counted_by_le(num_chunks);
}; };
VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_queue_chunks); VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_queue_chunks);
...@@ -1195,7 +1195,7 @@ struct virtchnl2_queue_vector_maps { ...@@ -1195,7 +1195,7 @@ struct virtchnl2_queue_vector_maps {
__le32 vport_id; __le32 vport_id;
__le16 num_qv_maps; __le16 num_qv_maps;
u8 pad[10]; u8 pad[10];
struct virtchnl2_queue_vector qv_maps[]; struct virtchnl2_queue_vector qv_maps[] __counted_by_le(num_qv_maps);
}; };
VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_queue_vector_maps); VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_queue_vector_maps);
...@@ -1247,7 +1247,7 @@ struct virtchnl2_mac_addr_list { ...@@ -1247,7 +1247,7 @@ struct virtchnl2_mac_addr_list {
__le32 vport_id; __le32 vport_id;
__le16 num_mac_addr; __le16 num_mac_addr;
u8 pad[2]; u8 pad[2];
struct virtchnl2_mac_addr mac_addr_list[]; struct virtchnl2_mac_addr mac_addr_list[] __counted_by_le(num_mac_addr);
}; };
VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_mac_addr_list); VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_mac_addr_list);
......
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