Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters
@ 2025-02-17 10:27 Martyna Szapar-Mudlaw
  2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 1/4] virtchnl: make proto and filter action count unsigned Martyna Szapar-Mudlaw
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Martyna Szapar-Mudlaw @ 2025-02-17 10:27 UTC (permalink / raw)
  To: intel-wired-lan; +Cc: netdev, Martyna Szapar-Mudlaw

This patch series introduces improvements to the `ice` driver and `virtchnl`
interface by adding stricter validation checks and preventing potential
out-of-bounds scenarios.

Jan Glaza (3):
  virtchnl: make proto and filter action count unsigned
  ice: stop truncating queue ids when checking
  ice: validate queue quanta parameters to prevent OOB access

Lukasz Czapnik (1):
  ice: fix input validation for virtchnl BW

 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 39 +++++++++++++++----
 include/linux/avf/virtchnl.h                  |  4 +-
 2 files changed, 33 insertions(+), 10 deletions(-)

-- 
2.47.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Intel-wired-lan] [iwl-net 1/4] virtchnl: make proto and filter action count unsigned
  2025-02-17 10:27 [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Martyna Szapar-Mudlaw
@ 2025-02-17 10:27 ` Martyna Szapar-Mudlaw
  2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 2/4] ice: stop truncating queue ids when checking Martyna Szapar-Mudlaw
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Martyna Szapar-Mudlaw @ 2025-02-17 10:27 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: netdev, Jan Glaza, Jedrzej Jagielski, Martyna Szapar-Mudlaw

From: Jan Glaza <jan.glaza@intel.com>

Count can never be negative and valid. Change it to unsigned
to simplify handling virtchnl messages in drivers.

Fixes: 1f7ea1cd6a374 ("ice: Enable FDIR Configure for AVF")
Reviewed-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>
Signed-off-by: Jan Glaza <jan.glaza@intel.com>
Signed-off-by: Martyna Szapar-Mudlaw <martyna.szapar-mudlaw@linux.intel.com>
---
 include/linux/avf/virtchnl.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/avf/virtchnl.h b/include/linux/avf/virtchnl.h
index 4811b9a14604..cf0afa60e4a7 100644
--- a/include/linux/avf/virtchnl.h
+++ b/include/linux/avf/virtchnl.h
@@ -1343,7 +1343,7 @@ struct virtchnl_proto_hdrs {
 	 * 2 - from the second inner layer
 	 * ....
 	 **/
-	int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */
+	u32 count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */
 	union {
 		struct virtchnl_proto_hdr
 			proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
@@ -1395,7 +1395,7 @@ VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action);
 
 struct virtchnl_filter_action_set {
 	/* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
-	int count;
+	u32 count;
 	struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
 };
 
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Intel-wired-lan] [iwl-net 2/4] ice: stop truncating queue ids when checking
  2025-02-17 10:27 [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Martyna Szapar-Mudlaw
  2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 1/4] virtchnl: make proto and filter action count unsigned Martyna Szapar-Mudlaw
@ 2025-02-17 10:27 ` Martyna Szapar-Mudlaw
  2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 3/4] ice: validate queue quanta parameters to prevent OOB access Martyna Szapar-Mudlaw
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Martyna Szapar-Mudlaw @ 2025-02-17 10:27 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: netdev, Jan Glaza, Aleksandr Loktionov, Jedrzej Jagielski,
	Martyna Szapar-Mudlaw

From: Jan Glaza <jan.glaza@intel.com>

Queue IDs can be up to 4096, update invalid check
to stop truncating IDs to 8 bits.

Fixes: bf93bf791cec8 ("ice: introduce ice_virtchnl.c and ice_virtchnl.h")
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Reviewed-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>
Signed-off-by: Jan Glaza <jan.glaza@intel.com>
Signed-off-by: Martyna Szapar-Mudlaw <martyna.szapar-mudlaw@linux.intel.com>
---
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
index b6285433307c..343f2b4b0dc5 100644
--- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c
+++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
@@ -565,7 +565,7 @@ bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id)
  *
  * check for the valid queue ID
  */
-static bool ice_vc_isvalid_q_id(struct ice_vsi *vsi, u8 qid)
+static bool ice_vc_isvalid_q_id(struct ice_vsi *vsi, u16 qid)
 {
 	/* allocated Tx and Rx queues should be always equal for VF VSI */
 	return qid < vsi->alloc_txq;
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Intel-wired-lan] [iwl-net 3/4] ice: validate queue quanta parameters to prevent OOB access
  2025-02-17 10:27 [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Martyna Szapar-Mudlaw
  2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 1/4] virtchnl: make proto and filter action count unsigned Martyna Szapar-Mudlaw
  2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 2/4] ice: stop truncating queue ids when checking Martyna Szapar-Mudlaw
@ 2025-02-17 10:27 ` Martyna Szapar-Mudlaw
  2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 4/4] ice: fix input validation for virtchnl BW Martyna Szapar-Mudlaw
  2025-02-18 19:44 ` [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Simon Horman
  4 siblings, 0 replies; 7+ messages in thread
From: Martyna Szapar-Mudlaw @ 2025-02-17 10:27 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: netdev, Jan Glaza, Jedrzej Jagielski, Martyna Szapar-Mudlaw

From: Jan Glaza <jan.glaza@intel.com>

Add queue wraparound prevention in quanta configuration.
Ensure end_qid does not overflow by validating start_qid and num_queues.

Fixes: 015307754a19 ("ice: Support VF queue rate limit and quanta size configuration")
Reviewed-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>
Signed-off-by: Jan Glaza <jan.glaza@intel.com>
Signed-off-by: Martyna Szapar-Mudlaw <martyna.szapar-mudlaw@linux.intel.com>
---
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
index 343f2b4b0dc5..adb1bf12542f 100644
--- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c
+++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
@@ -1903,13 +1903,21 @@ static int ice_vc_cfg_q_bw(struct ice_vf *vf, u8 *msg)
  */
 static int ice_vc_cfg_q_quanta(struct ice_vf *vf, u8 *msg)
 {
+	u16 quanta_prof_id, quanta_size, start_qid, num_queues, end_qid, i;
 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
-	u16 quanta_prof_id, quanta_size, start_qid, end_qid, i;
 	struct virtchnl_quanta_cfg *qquanta =
 		(struct virtchnl_quanta_cfg *)msg;
 	struct ice_vsi *vsi;
 	int ret;
 
+	start_qid = qquanta->queue_select.start_queue_id;
+	num_queues = qquanta->queue_select.num_queues;
+
+	if (check_add_overflow(start_qid, num_queues, &end_qid)) {
+		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
+		goto err;
+	}
+
 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
 		goto err;
@@ -1921,8 +1929,6 @@ static int ice_vc_cfg_q_quanta(struct ice_vf *vf, u8 *msg)
 		goto err;
 	}
 
-	end_qid = qquanta->queue_select.start_queue_id +
-		  qquanta->queue_select.num_queues;
 	if (end_qid > ICE_MAX_RSS_QS_PER_VF ||
 	    end_qid > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
 		dev_err(ice_pf_to_dev(vf->pf), "VF-%d trying to configure more than allocated number of queues: %d\n",
@@ -1951,7 +1957,6 @@ static int ice_vc_cfg_q_quanta(struct ice_vf *vf, u8 *msg)
 		goto err;
 	}
 
-	start_qid = qquanta->queue_select.start_queue_id;
 	for (i = start_qid; i < end_qid; i++)
 		vsi->tx_rings[i]->quanta_prof_id = quanta_prof_id;
 
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Intel-wired-lan] [iwl-net 4/4] ice: fix input validation for virtchnl BW
  2025-02-17 10:27 [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Martyna Szapar-Mudlaw
                   ` (2 preceding siblings ...)
  2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 3/4] ice: validate queue quanta parameters to prevent OOB access Martyna Szapar-Mudlaw
@ 2025-02-17 10:27 ` Martyna Szapar-Mudlaw
  2025-02-18 19:44 ` [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Simon Horman
  4 siblings, 0 replies; 7+ messages in thread
From: Martyna Szapar-Mudlaw @ 2025-02-17 10:27 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: netdev, Lukasz Czapnik, Jedrzej Jagielski, Martyna Szapar-Mudlaw

From: Lukasz Czapnik <lukasz.czapnik@intel.com>

Add validation of tc and queue id values sent by a VF in
ice_vc_cfg_q_bw().
Additionally fixed logged value in the warning message,
where max_tx_rate was incorrectly referenced instead of min_tx_rate.
Also improve error handling in this function by properly exiting
when invalid configuration is detected.

Fixes: 015307754a19 ("ice: Support VF queue rate limit and quanta size configuration")
Reviewed-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>
Signed-off-by: Lukasz Czapnik <lukasz.czapnik@intel.com>
Co-developed-by: Martyna Szapar-Mudlaw <martyna.szapar-mudlaw@linux.intel.com>
Signed-off-by: Martyna Szapar-Mudlaw <martyna.szapar-mudlaw@linux.intel.com>
---
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 24 ++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
index adb1bf12542f..824ef849b0ea 100644
--- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c
+++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
@@ -1865,15 +1865,33 @@ static int ice_vc_cfg_q_bw(struct ice_vf *vf, u8 *msg)
 
 	for (i = 0; i < qbw->num_queues; i++) {
 		if (qbw->cfg[i].shaper.peak != 0 && vf->max_tx_rate != 0 &&
-		    qbw->cfg[i].shaper.peak > vf->max_tx_rate)
+		    qbw->cfg[i].shaper.peak > vf->max_tx_rate) {
 			dev_warn(ice_pf_to_dev(vf->pf), "The maximum queue %d rate limit configuration may not take effect because the maximum TX rate for VF-%d is %d\n",
 				 qbw->cfg[i].queue_id, vf->vf_id,
 				 vf->max_tx_rate);
+			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
+			goto err;
+		}
 		if (qbw->cfg[i].shaper.committed != 0 && vf->min_tx_rate != 0 &&
-		    qbw->cfg[i].shaper.committed < vf->min_tx_rate)
+		    qbw->cfg[i].shaper.committed < vf->min_tx_rate) {
 			dev_warn(ice_pf_to_dev(vf->pf), "The minimum queue %d rate limit configuration may not take effect because the minimum TX rate for VF-%d is %d\n",
 				 qbw->cfg[i].queue_id, vf->vf_id,
-				 vf->max_tx_rate);
+				 vf->min_tx_rate);
+			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
+			goto err;
+		}
+		if (qbw->cfg[i].queue_id > vf->num_vf_qs) {
+			dev_warn(ice_pf_to_dev(vf->pf), "VF-%d trying to configure invalid queue_id\n",
+				 vf->vf_id);
+			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
+			goto err;
+		}
+		if (qbw->cfg[i].tc >= ICE_MAX_TRAFFIC_CLASS) {
+			dev_warn(ice_pf_to_dev(vf->pf), "VF-%d trying to configure a traffic class higher than allowed\n",
+				 vf->vf_id);
+			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
+			goto err;
+		}
 	}
 
 	for (i = 0; i < qbw->num_queues; i++) {
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters
  2025-02-17 10:27 [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Martyna Szapar-Mudlaw
                   ` (3 preceding siblings ...)
  2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 4/4] ice: fix input validation for virtchnl BW Martyna Szapar-Mudlaw
@ 2025-02-18 19:44 ` Simon Horman
  2025-02-25  9:24   ` Szapar-Mudlaw, Martyna
  4 siblings, 1 reply; 7+ messages in thread
From: Simon Horman @ 2025-02-18 19:44 UTC (permalink / raw)
  To: Martyna Szapar-Mudlaw; +Cc: intel-wired-lan, netdev

On Mon, Feb 17, 2025 at 11:27:41AM +0100, Martyna Szapar-Mudlaw wrote:
> This patch series introduces improvements to the `ice` driver and `virtchnl`
> interface by adding stricter validation checks and preventing potential
> out-of-bounds scenarios.

Hi Martyna,

The above talks about this patchset in terms of improvements rather than
bug fixes (that manifest). If so, I think this should be targeted at
iwl-next (i.e. net-next) rather than iwl-net (net). And the Fixes tags
should be dropped.

...

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters
  2025-02-18 19:44 ` [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Simon Horman
@ 2025-02-25  9:24   ` Szapar-Mudlaw, Martyna
  0 siblings, 0 replies; 7+ messages in thread
From: Szapar-Mudlaw, Martyna @ 2025-02-25  9:24 UTC (permalink / raw)
  To: Simon Horman; +Cc: intel-wired-lan, netdev



On 2/18/2025 8:44 PM, Simon Horman wrote:
> On Mon, Feb 17, 2025 at 11:27:41AM +0100, Martyna Szapar-Mudlaw wrote:
>> This patch series introduces improvements to the `ice` driver and `virtchnl`
>> interface by adding stricter validation checks and preventing potential
>> out-of-bounds scenarios.
> 
> Hi Martyna,
> 
> The above talks about this patchset in terms of improvements rather than
> bug fixes (that manifest). If so, I think this should be targeted at
> iwl-next (i.e. net-next) rather than iwl-net (net). And the Fixes tags
> should be dropped.
> 

Hi Simon,

Thank for looking into this. I believe these patches provide fixes and 
would fit better with iwl-net since they correct improper value 
checking, ensuring that the driver can properly handle and reject 
invalid inputs from potentially malicious VFs.
I sent v2 with rephrased cover letter and some commit messages.

Thanks.
Martyna

> ...
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-02-25  9:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-17 10:27 [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Martyna Szapar-Mudlaw
2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 1/4] virtchnl: make proto and filter action count unsigned Martyna Szapar-Mudlaw
2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 2/4] ice: stop truncating queue ids when checking Martyna Szapar-Mudlaw
2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 3/4] ice: validate queue quanta parameters to prevent OOB access Martyna Szapar-Mudlaw
2025-02-17 10:27 ` [Intel-wired-lan] [iwl-net 4/4] ice: fix input validation for virtchnl BW Martyna Szapar-Mudlaw
2025-02-18 19:44 ` [Intel-wired-lan] [iwl-net 0/4] ice: improve validation of virtchnl parameters Simon Horman
2025-02-25  9:24   ` Szapar-Mudlaw, Martyna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox