diff options
| author | Alexander Lobakin <[email protected]> | 2023-07-28 15:52:06 +0000 |
|---|---|---|
| committer | Tony Nguyen <[email protected]> | 2023-08-16 16:05:04 +0000 |
| commit | 5e7f59fa07f86f554c301c7a383bba54d5ef9819 (patch) | |
| tree | c987be526d4fc90adbcbc409ab18bdb3d651774b /drivers/net/ethernet/intel/ice/ice_virtchnl.c | |
| parent | virtchnl: fix fake 1-elem arrays in structs allocated as `nents + 1` - 1 (diff) | |
| download | kernel-5e7f59fa07f86f554c301c7a383bba54d5ef9819.tar.gz kernel-5e7f59fa07f86f554c301c7a383bba54d5ef9819.zip | |
virtchnl: fix fake 1-elem arrays in structures allocated as `nents + 1`
There are five virtchnl structures, which are allocated and checked in
the code as `nents + 1`, meaning that they always have memory for one
excessive element regardless of their actual number. This comes from
that their sizeof() includes space for 1 element and then they get
allocated via struct_size() or its open-coded equivalents, passing
the actual number of elements.
Expand virtchnl_struct_size() to handle such structures and replace
those 1-elem arrays with proper flex ones. Also fix several places
which open-code %IAVF_VIRTCHNL_VF_RESOURCE_SIZE. Finally, let the
virtchnl_ether_addr_list size be computed automatically when there's
no enough space for the whole list, otherwise we have to open-code
reverse struct_size() logics.
Signed-off-by: Alexander Lobakin <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Tested-by: Rafal Romanowski <[email protected]>
Signed-off-by: Tony Nguyen <[email protected]>
Diffstat (limited to 'drivers/net/ethernet/intel/ice/ice_virtchnl.c')
| -rw-r--r-- | drivers/net/ethernet/intel/ice/ice_virtchnl.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c index 85d996531502..4a02ed91ba73 100644 --- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c @@ -428,7 +428,7 @@ static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg) goto err; } - len = sizeof(struct virtchnl_vf_resource); + len = virtchnl_struct_size(vfres, vsi_res, 0); vfres = kzalloc(len, GFP_KERNEL); if (!vfres) { |
