iavf: validate num_vsis in VIRTCHNL_OP_GET_VF_RESOURCES response
Subsystems (4)
PATCH 1/1 iavf: validate num_vsis in VIRTCHNL_OP_GET_VF_RESOURCES response
The VF allocates a fixed-size buffer for IAVF_MAX_VF_VSI (3) VSI entries when processing a VIRTCHNL_OP_GET_VF_RESOURCES response from the PF. However, num_vsis from the PF response is used unchecked as the loop bound when iterating over vsi_res[] in multiple functions.
A PF sending num_vsis greater than IAVF_MAX_VF_VSI leads to out-of-bounds accesses on the vsi_res[] array.
Clamp num_vsis to IAVF_MAX_VF_VSI in iavf_validate_num_queues(), following the same pattern already used for num_queue_pairs.
--- drivers/net/ethernet/intel/iavf/iavf_virtchnl.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +6 -0
@@ -254,6 +254,12 @@ int iavf_send_vf_ptp_caps_msg(struct iavf_adapter *adapter)**/ static void iavf_validate_num_queues (struct iavf_adapter *adapter) { +if (adapter->vf_res->num_vsis >IAVF_MAX_VF_VSI ) { +dev_info (&adapter->pdev->dev,"Received %d VSIs, but can only have a max of %d\n" , + adapter->vf_res->num_vsis,IAVF_MAX_VF_VSI ); + adapter->vf_res->num_vsis =IAVF_MAX_VF_VSI ; + } +if (adapter->vf_res->num_queue_pairs >IAVF_MAX_REQ_QUEUES ) {struct virtchnl_vsi_resource *vsi_res;int i;
---
base-commit: 7aaa8047eafd0bd628065b15757d9b48c5f9c07d
change-id: 20260513-fixes-26ec29fa50a5
Best regards,
Signature · 1 line
Junrui Luo <[email protected]>
Przemek Kitszel
maintainerQuoted 1 line · Junrui Luo
The VF allocates a fixed-size buffer for
IAVF_MAX_VF_VSI(3) VSI
this is the MAX that iavf sends to PF (and only usage of the variable)
Quoted 6 lines
entries when processing a
VIRTCHNL_OP_GET_VF_RESOURCESresponse from the PF. However,num_vsisfrom the PF response is used unchecked as the loop bound when iterating over vsi_res[] in multiple functions.A PF sending
num_vsisgreater thanIAVF_MAX_VF_VSIleads to out-of-bounds accesses on the vsi_res[] array.
this array is part of the same message from PF as the counter
Thank you for reaching out,
as is, this is not a fix
if you want to add some hardening for iavf receiving side, you could add some checks that passed msg lengths cover whole messages (when accounted for FAM)
Quoted 35 lines
Clamp
num_vsistoIAVF_MAX_VF_VSIiniavf_validate_num_queues(), following the same pattern already used fornum_queue_pairs.Fixes 5eae00c57f5e ("i40evf: main driver core")Reported-by Yuhao Jiang <[email protected]>Signed-off-by Junrui Luo <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_virtchnl.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +6
-1@@ -254,6 +254,12 @@ int iavf_send_vf_ptp_caps_msg(struct iavf_adapter *adapter)**/ static void iavf_validate_num_queues (struct iavf_adapter *adapter) { +if (adapter->vf_res->num_vsis >IAVF_MAX_VF_VSI ) { +dev_info (&adapter->pdev->dev,"Received %d VSIs, but can only have a max of %d\n" , + adapter->vf_res->num_vsis,IAVF_MAX_VF_VSI ); + adapter->vf_res->num_vsis =IAVF_MAX_VF_VSI ; + } +if (adapter->vf_res->num_queue_pairs >IAVF_MAX_REQ_QUEUES ) {struct virtchnl_vsi_resource *vsi_res;int i; ---base-commit:
7aaa8047eafd0bd628065b15757d9b48c5f9c07d
change-id: 20260513-fixes-26ec29fa50a5Best regards,
PATCH v2 1/1 iavf: validate num_vsis in VIRTCHNL_OP_GET_VF_RESOURCES response
In reply to Junrui LuoThe VF allocates a fixed-size buffer for IAVF_MAX_VF_VSI (3) VSI entries when processing a VIRTCHNL_OP_GET_VF_RESOURCES response from the PF. However, num_vsis from the PF response is used unchecked as the loop bound when iterating over vsi_res[] in multiple functions.
A PF sending num_vsis greater than IAVF_MAX_VF_VSI, or the received message is shorter than num_vsis claims leads to out-of-bounds accesses on the vsi_res[] array.
Clamp num_vsis based on the actual bytes copied from the PF response.
---
Changes in v2:
- Clamp num_vsis based on actual received message length instead ofIAVF_MAX_VF_VSI suggested by Przemek
- Link to v1: https://lore.kernel.org/r/SYBPR01MB7881AF11C45AEDC0D4CA89C1AF062@SYBPR01MB7881.ausprd01.prod.outlook.com
--- drivers/net/ethernet/intel/iavf/iavf_virtchnl.c | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +21 -5
@@ -248,12 +248,28 @@ int iavf_send_vf_ptp_caps_msg(struct iavf_adapter *adapter)/** * iavf_validate_num_queues * @adapter: adapter structure +* @msglen: length of the received VF resource message * -* Validate that the number of queues the PF has sent in -* VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle. +* Validate the VIRTCHNL_OP_GET_VF_RESOURCES response from the PF. Ensure +* num_vsis does not exceed what the message length can cover, and cap +* num_queue_pairs to the VF maximum. **/ -static void iavf_validate_num_queues (struct iavf_adapter *adapter) +static void iavf_validate_num_queues (struct iavf_adapter *adapter,u16 msglen) { +u16 max_vsis; + +if (msglen <sizeof (struct virtchnl_vf_resource )) + max_vsis =0 ; +else + max_vsis = (msglen -sizeof (struct virtchnl_vf_resource )) / +sizeof (struct virtchnl_vsi_resource ); + +if (adapter->vf_res->num_vsis > max_vsis) { +dev_info (&adapter->pdev->dev,"Received %d VSIs, but message can only cover %d\n" , + adapter->vf_res->num_vsis, max_vsis); + adapter->vf_res->num_vsis = max_vsis; + } +if (adapter->vf_res->num_queue_pairs >IAVF_MAX_REQ_QUEUES ) {struct virtchnl_vsi_resource *vsi_res;int i;
@@ -300,7 +316,7 @@ int iavf_get_vf_config(struct iavf_adapter *adapter)* we aren't getting too many queues */ if (!err) -iavf_validate_num_queues (adapter); +iavf_validate_num_queues (adapter,min (event.msg_len, len));iavf_vf_parse_hw_config (hw, adapter->vf_res);kfree (event.msg_buf);
@@ -2609,7 +2625,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,u16 len =IAVF_VIRTCHNL_VF_RESOURCE_SIZE ;memcpy (adapter->vf_res, msg,min (msglen, len)); -iavf_validate_num_queues (adapter); +iavf_validate_num_queues (adapter,min (msglen, len));iavf_vf_parse_hw_config (&adapter->hw, adapter->vf_res);if (is_zero_ether_addr (adapter->hw.mac.addr)) {/* restore current mac address */
---
base-commit: 7aaa8047eafd0bd628065b15757d9b48c5f9c07d
change-id: 20260514-fixes-a6c4176c0c6a
Best regards,
Signature · 1 line
Junrui Luo <[email protected]>
Quoted 111 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Junrui Luo
Sent: Thursday, May 14, 2026 8:55 AM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Mitch Williams <[email protected]>; Greg Rose <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; Yuhao Jiang <[email protected]>; [email protected]; Junrui Luo <[email protected]>
Subject: [Intel-wired-lan] [PATCH net v2] iavf: validatenum_vsisinVIRTCHNL_OP_GET_VF_RESOURCESresponseThe VF allocates a fixed-size buffer for
IAVF_MAX_VF_VSI(3) VSI entries when processing aVIRTCHNL_OP_GET_VF_RESOURCESresponse from the PF. However,num_vsisfrom the PF response is used unchecked as the loop bound when iterating over vsi_res[] in multiple functions.A PF sending
num_vsisgreater thanIAVF_MAX_VF_VSI, or the received message is shorter thannum_vsisclaims leads to out-of-bounds accesses on the vsi_res[] array.Clamp
num_vsisbased on the actual bytes copied from the PF response.Fixes 5eae00c57f5e ("i40evf: main driver core")Reported-by Yuhao Jiang <[email protected]>Signed-off-by Junrui Luo <[email protected]>---
Changes in v2:
- Clampnum_vsisbased on actual received message length instead ofIAVF_MAX_VF_VSIsuggested by Przemek
- Link to v1:
https://lore.kernel.org/r/SYBPR01MB7881AF11C45AEDC0D4CA89C1AF062@SYBPR
01MB7881.ausprd01.prod.outlook.com--- drivers/net/ethernet/intel/iavf/iavf_virtchnl.c | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +4
-2@@ -248,12 +248,28 @@ int iavf_send_vf_ptp_caps_msg(struct iavf_adapter *adapter)/** * iavf_validate_num_queues * @adapter: adapter structure +* @msglen: length of the received VF resource message * -* Validate that the number of queues the PF has sent in -* VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle. +* Validate the VIRTCHNL_OP_GET_VF_RESOURCES response from the PF. +Ensure +* num_vsis does not exceed what the message length can cover, and cap
+ *num_queue_pairsto the VF maximum.
**/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +1
-1-static void iavf_validate_num_queues (struct iavf_adapter *adapter) +static void iavf_validate_num_queues(struct iavf_adapter *adapter,u16
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +7
-0+msglen) { +u16 max_vsis; + +if (msglen <sizeof (struct virtchnl_vf_resource )) + max_vsis =0 ; +else + max_vsis = (msglen - sizeof(struct
virtchnl_vf_resource)) /drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +4
-0+sizeof (struct virtchnl_vsi_resource ); + +if (adapter->vf_res->num_vsis > max_vsis) { + dev_info(&adapter->pdev->dev, "Received %d VSIs, butmessage can only cover %d\n",
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +5
-1+ adapter->vf_res->num_vsis, max_vsis); + adapter->vf_res->num_vsis = max_vsis; + } +if (adapter->vf_res->num_queue_pairs >IAVF_MAX_REQ_QUEUES ) {struct virtchnl_vsi_resource *vsi_res;int i;@@ -300,7 +316,7 @@ int iavf_get_vf_config(struct iavf_adapter*adapter) * we aren't getting too many queues */ if (!err) -iavf_validate_num_queues (adapter); +iavf_validate_num_queues (adapter,min (event.msg_len, len));iavf_vf_parse_hw_config (hw, adapter->vf_res);drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +1
-1kfree (event.msg_buf);@@ -2609,7 +2625,7 @@ void iavf_virtchnl_completion(structiavf_adapter *adapter, u16 len = IAVF_VIRTCHNL_VF_RESOURCE_SIZE;memcpy (adapter->vf_res, msg,min (msglen, len)); -iavf_validate_num_queues (adapter); +iavf_validate_num_queues (adapter,min (msglen, len));iavf_vf_parse_hw_config (&adapter->hw, adapter->vf_res);if (is_zero_ether_addr (adapter->hw.mac.addr)) {/* restore current mac address */
Quoted 7 lines
---
base-commit:7aaa8047eafd0bd628065b15757d9b48c5f9c07d
change-id: 20260514-fixes-a6c4176c0c6aBest regards,
--
Junrui Luo <[email protected]>
Quoted 15 lines · Junrui Luo
The VF allocates a fixed-size buffer for
IAVF_MAX_VF_VSI(3) VSI entries when processing aVIRTCHNL_OP_GET_VF_RESOURCESresponse from the PF. However,num_vsisfrom the PF response is used unchecked as the loop bound when iterating over vsi_res[] in multiple functions.A PF sending
num_vsisgreater thanIAVF_MAX_VF_VSI, or the received message is shorter thannum_vsisclaims leads to out-of-bounds accesses on the vsi_res[] array.Clamp
num_vsisbased on the actual bytes copied from the PF response.Fixes 5eae00c57f5e ("i40evf: main driver core")Reported-by Yuhao Jiang <[email protected]>Signed-off-by Junrui Luo <[email protected]>
Quoted 5 lines
---
Changes in v2:
- Clampnum_vsisbased on actual received message length instead ofIAVF_MAX_VF_VSIsuggested by Przemek
- Link to v1: https://lore.kernel.org/r/SYBPR01MB7881AF11C45AEDC0D4CA89C1AF062@SYBPR01MB7881.ausprd01.prod.outlook.com
There is an AI-generated review of this patchset available on sashiko.dev. However, I believe that the issues raised there can be considered in the context of possible follow-up. I do not believe they should block progress of this patch.
Romanowski, Rafal
Tested-byQuoted 40 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Simon Horman
Sent: Monday, May 18, 2026 8:56 PM
To: Junrui Luo <[email protected]>
Cc: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Mitch Williams <[email protected]>; Greg Rose <[email protected]>; [email protected]; [email protected]; [email protected]; Yuhao Jiang <[email protected]>; [email protected]
Subject: Re: [Intel-wired-lan] [PATCH net v2] iavf: validatenum_vsisinVIRTCHNL_OP_GET_VF_RESOURCESresponseQuoted 15 lines · Junrui Luo
The VF allocates a fixed-size buffer for
IAVF_MAX_VF_VSI(3) VSI entries when processing aVIRTCHNL_OP_GET_VF_RESOURCESresponse from the PF. However,num_vsisfrom the PF response is used unchecked as the loop bound when iterating over vsi_res[] in multiple functions.A PF sending
num_vsisgreater thanIAVF_MAX_VF_VSI, or the received message is shorter thannum_vsisclaims leads to out-of-bounds accesses on the vsi_res[] array.Clamp
num_vsisbased on the actual bytes copied from the PF response.Fixes 5eae00c57f5e ("i40evf: main driver core")Reported-by Yuhao Jiang <[email protected]>Signed-off-by Junrui Luo <[email protected]>Quoted 6 lines
---
Changes in v2:
- Clampnum_vsisbased on actual received message length instead ofIAVF_MAX_VF_VSIsuggested by Przemek
- Link to v1:https://lore.kernel.org/r/SYBPR01MB7881AF11C45AEDC0D4CA89C1AF062@SYB
PR
Quoted 7 lines
Quoted 1 line
01MB7881.ausprd01.prod.outlook.com
Reviewed-by Simon Horman <[email protected]>There is an AI-generated review of this patchset available on sashiko.dev. However, I believe that the issues raised there can be considered in the context of possible follow-up. I do not believe they should block progress of this patch.