Skip to content

Commit 11f8dba

Browse files
lczapnikopsiff
authored andcommitted
i40e: add validation for ring_len param
[ Upstream commit 55d2256 ] The `ring_len` parameter provided by the virtual function (VF) is assigned directly to the hardware memory context (HMC) without any validation. To address this, introduce an upper boundary check for both Tx and Rx queue lengths. The maximum number of descriptors supported by the hardware is 8k-32. Additionally, enforce alignment constraints: Tx rings must be a multiple of 8, and Rx rings must be a multiple of 32. Fixes: 5c3c48a ("i40e: implement virtual device interface") Cc: [email protected] Signed-off-by: Lukasz Czapnik <[email protected]> Reviewed-by: Aleksandr Loktionov <[email protected]> Signed-off-by: Przemek Kitszel <[email protected]> Reviewed-by: Simon Horman <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit c0c83f4cd074b75cecef107bfc349be7d516c9c4)
1 parent 871c94f commit 11f8dba

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,13 @@ static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
657657

658658
/* only set the required fields */
659659
tx_ctx.base = info->dma_ring_addr / 128;
660+
661+
/* ring_len has to be multiple of 8 */
662+
if (!IS_ALIGNED(info->ring_len, 8) ||
663+
info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) {
664+
ret = -EINVAL;
665+
goto error_context;
666+
}
660667
tx_ctx.qlen = info->ring_len;
661668
tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
662669
tx_ctx.rdylist_act = 0;
@@ -722,6 +729,13 @@ static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
722729

723730
/* only set the required fields */
724731
rx_ctx.base = info->dma_ring_addr / 128;
732+
733+
/* ring_len has to be multiple of 32 */
734+
if (!IS_ALIGNED(info->ring_len, 32) ||
735+
info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) {
736+
ret = -EINVAL;
737+
goto error_param;
738+
}
725739
rx_ctx.qlen = info->ring_len;
726740

727741
if (info->splithdr_enabled) {

0 commit comments

Comments
 (0)