Skip to contentSkip to conversation

ice: fix validation issues in virtchnl parameters

PATCH Superseded Martyna Szapar-Mudlaw 3 participants 17 messages Feb 25, 2025 – Mar 5, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ice: fix validation issues in virtchnl parameters

This patch series addresses validation issues in the virtchnl interface of the ice driver. These fixes correct improper value checking, ensuring that the driver can properly handle and reject invalid inputs from potentially malicious VFs. By fixing validation mechanisms, these patches strictly enforce existing constraints to prevent out-of-bounds scenarios, making the system more robust against incorrect or unexpected data.

---

v2 -> v1:
attached Mateusz's related patch
rephrase some commit messages to indicate that this are feixes and should target net

---

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

Mateusz Polchlopek (1):
ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()

 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 39 +++++++++++++++----
 .../ethernet/intel/ice/ice_virtchnl_fdir.c    | 25 ++++++++----
 include/linux/avf/virtchnl.h                  |  4 +-
 3 files changed, 50 insertions(+), 18 deletions(-)
Signature · 1 line
2.47.0
#1 lore raw

PATCH v2 1/5 virtchnl: make proto and filter action count unsigned

From: Jan Glaza <[email protected]>

The count field in virtchnl_proto_hdrs and virtchnl_filter_action_set should never be negative while still being valid. Changing it from int to u32 ensures proper handling of values in virtchnl messages in driverrs and prevents unintended behavior.
In its current signed form, a negative count does not trigger an error in ice driver but instead results in it being treated as 0. This can lead to unexpected outcomes when processing messages. By using u32, any invalid values will correctly trigger -EINVAL, making error detection more robust.

Fixes 1f7ea1cd6a374 ("ice: Enable FDIR Configure for AVF")
---
 include/linux/avf/virtchnl.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/avf/virtchnl.h +2 -2
index 4811b9a14604..cf0afa60e4a7 100644
@@ -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];
 };
 
Signature · 1 line
2.47.0
reviewer Reviewed-by on v2 1/5
#2 lore raw

Re: [iwl-net v2 1/5] virtchnl: make proto and filter action count unsigned

Quoted 12 lines · Martyna Szapar-Mudlaw

From: Jan Glaza <[email protected]>

The count field in virtchnl_proto_hdrs and virtchnl_filter_action_set should never be negative while still being valid. Changing it from int to u32 ensures proper handling of values in virtchnl messages in driverrs and prevents unintended behavior.
In its current signed form, a negative count does not trigger an error in ice driver but instead results in it being treated as 0. This can lead to unexpected outcomes when processing messages. By using u32, any invalid values will correctly trigger -EINVAL, making error detection more robust.

Quoted 4 lines
Fixes 1f7ea1cd6a374 ("ice: Enable FDIR Configure for AVF")
#3 lore raw

PATCH v2 2/5 ice: stop truncating queue ids when checking

In reply to Martyna Szapar-Mudlaw

From: Jan Glaza <[email protected]>

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

Fixes bf93bf791cec8 ("ice: introduce ice_virtchnl.c and ice_virtchnl.h")
---
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_virtchnl.c +1 -1
index b6285433307c..343f2b4b0dc5 100644
@@ -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;
Signature · 1 line
2.47.0
reviewer Reviewed-by on v2 2/5
#4 lore raw

Re: [iwl-net v2 2/5] ice: stop truncating queue ids when checking

Quoted 10 lines · Martyna Szapar-Mudlaw

From: Jan Glaza <[email protected]>

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

Fixes bf93bf791cec8 ("ice: introduce ice_virtchnl.c and ice_virtchnl.h")
#5 lore raw

PATCH v2 3/5 ice: validate queue quanta parameters to prevent OOB access

In reply to Martyna Szapar-Mudlaw

From: Jan Glaza <[email protected]>

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")
---
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl.c +9 -4
index 343f2b4b0dc5..adb1bf12542f 100644
@@ -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;
 
Signature · 1 line
2.47.0
reviewer Reviewed-by on v2 3/5
#6 lore raw

Re: [iwl-net v2 3/5] ice: validate queue quanta parameters to prevent OOB access

Quoted 9 lines · Martyna Szapar-Mudlaw

From: Jan Glaza <[email protected]>

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")
#7 lore raw

PATCH v2 4/5 ice: fix input validation for virtchnl BW

In reply to Martyna Szapar-Mudlaw

From: Lukasz Czapnik <[email protected]>

Add missing 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 correct 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")
---
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 24 ++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl.c +21 -3
index adb1bf12542f..824ef849b0ea 100644
@@ -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++) {
Signature · 1 line
2.47.0
reviewer Reviewed-by on v2 4/5
#8 lore raw

Re: [iwl-net v2 4/5] ice: fix input validation for virtchnl BW

Quoted 9 lines · Martyna Szapar-Mudlaw

From: Lukasz Czapnik <[email protected]>

Add missing 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 correct error handling in this function by properly exiting when invalid configuration is detected.

Quoted 5 lines
Fixes 015307754a19 ("ice: Support VF queue rate limit and quanta size configuration")
#9 lore raw

PATCH v2 5/5 ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()

In reply to Martyna Szapar-Mudlaw

From: Mateusz Polchlopek <[email protected]>

Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value.

Fixes 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs")
---
 .../ethernet/intel/ice/ice_virtchnl_fdir.c    | 25 +++++++++++++------
 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +17 -8
index 14e3f0f89c78..6250629ee8f9 100644
@@ -835,18 +835,27 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
 	u8 *pkt_buf, *msk_buf __free(kfree);
 	struct ice_parser_result rslt;
 	struct ice_pf *pf = vf->pf;
+	u16 pkt_len, udp_port = 0;
 	struct ice_parser *psr;
 	int status = -ENOMEM;
 	struct ice_hw *hw;
-	u16 udp_port = 0;
 
-	pkt_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
-	msk_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
+	if (!proto->raw.pkt_len)
+		return -EINVAL;
+
+	pkt_len = proto->raw.pkt_len;
+
+	if (!pkt_len || pkt_len > VIRTCHNL_MAX_SIZE_RAW_PACKET)
+		return -EINVAL;
+
+	pkt_buf = kzalloc(pkt_len, GFP_KERNEL);
+	msk_buf = kzalloc(pkt_len, GFP_KERNEL);
+
 	if (!pkt_buf || !msk_buf)
 		goto err_mem_alloc;
 
-	memcpy(pkt_buf, proto->raw.spec, proto->raw.pkt_len);
-	memcpy(msk_buf, proto->raw.mask, proto->raw.pkt_len);
+	memcpy(pkt_buf, proto->raw.spec, pkt_len);
+	memcpy(msk_buf, proto->raw.mask, pkt_len);
 
 	hw = &pf->hw;
 
@@ -862,7 +871,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
 	if (ice_get_open_tunnel_port(hw, &udp_port, TNL_VXLAN))
 		ice_parser_vxlan_tunnel_set(psr, udp_port, true);
 
-	status = ice_parser_run(psr, pkt_buf, proto->raw.pkt_len, &rslt);
+	status = ice_parser_run(psr, pkt_buf, pkt_len, &rslt);
 	if (status)
 		goto err_parser_destroy;
 
@@ -876,7 +885,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
 	}
 
 	status = ice_parser_profile_init(&rslt, pkt_buf, msk_buf,
-					 proto->raw.pkt_len, ICE_BLK_FD,
+					 pkt_len, ICE_BLK_FD,
 					 conf->prof);
 	if (status)
 		goto err_parser_profile_init;
@@ -885,7 +894,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
 		ice_parser_profile_dump(hw, conf->prof);
 
 	/* Store raw flow info into @conf */
-	conf->pkt_len = proto->raw.pkt_len;
+	conf->pkt_len = pkt_len;
 	conf->pkt_buf = pkt_buf;
 	conf->parser_ena = true;
 
Signature · 1 line
2.47.0
maintainer Reviewed-by on v2 5/5
#10 lore raw

Re: [Intel-wired-lan] [iwl-net v2 5/5] ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()

Quoted 6 lines · Martyna Szapar-Mudlaw

From: Mateusz Polchlopek <[email protected]>

Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value.

Quoted 7 lines
Fixes 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs")
---
  .../ethernet/intel/ice/ice_virtchnl_fdir.c    | 25 +++++++++++++------
  1 file changed, 17 insertions(+), 8 deletions(-)
reviewer
#11 lore raw

Re: [iwl-net v2 5/5] ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()

In reply to Martyna Szapar-Mudlaw
Quoted 23 lines · Martyna Szapar-Mudlaw

From: Mateusz Polchlopek <[email protected]>

Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value.

Fixes 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs")
---
 .../ethernet/intel/ice/ice_virtchnl_fdir.c    | 25 +++++++++++++------
 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +1 -0
index 14e3f0f89c78..6250629ee8f9 100644
@@ -835,18 +835,27 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
 	u8 *pkt_buf, *msk_buf __free(kfree);
 	struct ice_parser_result rslt;
 	struct ice_pf *pf = vf->pf;
+	u16 pkt_len, udp_port = 0;
 	struct ice_parser *psr;

drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c ice_vc_fdir_parse_raw(struct ice_vf *vf, · line 846

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +4 -3
 	int status = -ENOMEM;
 	struct ice_hw *hw;
-	u16 udp_port = 0;
 
-	pkt_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
-	msk_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
+	if (!proto->raw.pkt_len)
+		return -EINVAL;
+
+	pkt_len = proto->raw.pkt_len;

Hi Martyna,

A check is made for !proto->raw.pkt_len above.
And a check is made for !pkt_len below.

This seems redundant.

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +3 -0
+
+	if (!pkt_len || pkt_len > VIRTCHNL_MAX_SIZE_RAW_PACKET)
+		return -EINVAL;

...

#12 lore raw

Re: [iwl-net v2 5/5] ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()

Quoted 37 lines · Simon Horman
Quoted 23 lines · Martyna Szapar-Mudlaw

From: Mateusz Polchlopek <[email protected]>

Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value.

Fixes 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs")
---
  .../ethernet/intel/ice/ice_virtchnl_fdir.c    | 25 +++++++++++++------
  1 file changed, 17 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +1 -0
index 14e3f0f89c78..6250629ee8f9 100644
@@ -835,18 +835,27 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
  	u8 *pkt_buf, *msk_buf __free(kfree);
  	struct ice_parser_result rslt;
  	struct ice_pf *pf = vf->pf;
+	u16 pkt_len, udp_port = 0;
  	struct ice_parser *psr;

drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c ice_vc_fdir_parse_raw(struct ice_vf *vf, · line 846

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +4 -3
  	int status = -ENOMEM;
  	struct ice_hw *hw;
-	u16 udp_port = 0;
 
-	pkt_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
-	msk_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
+	if (!proto->raw.pkt_len)
+		return -EINVAL;
+
+	pkt_len = proto->raw.pkt_len;

Hi Martyna,

Quoted 4 lines

A check is made for !proto->raw.pkt_len above.
And a check is made for !pkt_len below.

This seems redundant.

Right, thank you for spotting it, will fix

Quoted 6 lines
Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +3 -0
+
+	if (!pkt_len || pkt_len > VIRTCHNL_MAX_SIZE_RAW_PACKET)
+		return -EINVAL;

...

reviewer
#13 lore raw

Re: [iwl-net v2 5/5] ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()

In reply to Martyna Szapar-Mudlaw
Quoted 21 lines · Martyna Szapar-Mudlaw

From: Mateusz Polchlopek <[email protected]>

Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value.

Fixes 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs")
---
 .../ethernet/intel/ice/ice_virtchnl_fdir.c    | 25 +++++++++++++------
 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +0 -0
index 14e3f0f89c78..6250629ee8f9 100644
@@ -835,18 +835,27 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
 	u8 *pkt_buf, *msk_buf __free(kfree);
 	struct ice_parser_result rslt;
 	struct ice_pf *pf = vf->pf;

drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c ice_vc_fdir_parse_raw(struct ice_vf *vf, · line 844

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +3 -3
+	u16 pkt_len, udp_port = 0;
 	struct ice_parser *psr;
 	int status = -ENOMEM;
 	struct ice_hw *hw;
-	u16 udp_port = 0;
 
-	pkt_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
-	msk_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
+	if (!proto->raw.pkt_len)
+		return -EINVAL;

Hi Martyna,

It seems to me that the use of __free() above will result in kfree(msk_buf) being called here. But msk_buf is not initialised at this point.

My suggest would be to drop the use of __free().
But if not, I think that in order to be safe it would be best to do this (completely untested;

	u8 *pkt_buf, *msk_buf __free(kfree) = NULL;

...

maintainer
#14 lore raw

Re: [iwl-net v2 5/5] ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()

Quoted 39 lines · Simon Horman
Quoted 21 lines · Martyna Szapar-Mudlaw

From: Mateusz Polchlopek <[email protected]>

Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value.

Fixes 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs")
---
  .../ethernet/intel/ice/ice_virtchnl_fdir.c    | 25 +++++++++++++------
  1 file changed, 17 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +0 -0
index 14e3f0f89c78..6250629ee8f9 100644
@@ -835,18 +835,27 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
  	u8 *pkt_buf, *msk_buf __free(kfree);
  	struct ice_parser_result rslt;
  	struct ice_pf *pf = vf->pf;

drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c ice_vc_fdir_parse_raw(struct ice_vf *vf, · line 844

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +3 -3
+	u16 pkt_len, udp_port = 0;
  	struct ice_parser *psr;
  	int status = -ENOMEM;
  	struct ice_hw *hw;
-	u16 udp_port = 0;
 
-	pkt_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
-	msk_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
+	if (!proto->raw.pkt_len)
+		return -EINVAL;

Hi Martyna,

It seems to me that the use of __free() above will result in kfree(msk_buf) being called here. But msk_buf is not initialised at this point.

Quoted 5 lines

My suggest would be to drop the use of __free().
But if not, I think that in order to be safe it would be best to do this (completely untested;

	u8 *pkt_buf, *msk_buf __free(kfree) = NULL;

Oh yeah!, thank you Simon for catching that.

I would say "naked __free()" was harmful here.

#15 lore raw

Re: [iwl-net v2 5/5] ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()

Quoted 43 lines · Przemek Kitszel
Quoted 42 lines · Simon Horman
Quoted 20 lines · Martyna Szapar-Mudlaw

From: Mateusz Polchlopek <[email protected]>

Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value.

Fixes 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs")
Signed-off-by Martyna Szapar-Mudlaw <martyna.szapar- [email protected]>

---
  .../ethernet/intel/ice/ice_virtchnl_fdir.c    | 25 +++++++++++++------

  1 file changed, 17 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +0 -0
index 14e3f0f89c78..6250629ee8f9 100644
@@ -835,18 +835,27 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
       u8 *pkt_buf, *msk_buf __free(kfree);
       struct ice_parser_result rslt;

drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c ice_vc_fdir_parse_raw(struct ice_vf *vf, · line 843

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +3 -3
       struct ice_pf *pf = vf->pf;
+    u16 pkt_len, udp_port = 0;
       struct ice_parser *psr;
       int status = -ENOMEM;
       struct ice_hw *hw;
-    u16 udp_port = 0;
-    pkt_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
-    msk_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
+    if (!proto->raw.pkt_len)
+        return -EINVAL;

Hi Martyna,

It seems to me that the use of __free() above will result in kfree(msk_buf) being called here. But msk_buf is not initialised at this point.

My suggest would be to drop the use of __free().
But if not, I think that in order to be safe it would be best to do this (completely untested;

Quoted 6 lines
Quoted 1 line

    u8 *pkt_buf, *msk_buf __free(kfree) = NULL;

Oh yeah!, thank you Simon for catching that.

I would say "naked __free()" was harmful here.

Thank you for suggestions, will send fixed v3

reviewer
#16 lore raw

Re: [iwl-net v2 5/5] ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw()

In reply to Przemek Kitszel
Quoted 43 lines · Przemek Kitszel
Quoted 42 lines · Simon Horman
Quoted 20 lines · Martyna Szapar-Mudlaw

From: Mateusz Polchlopek <[email protected]>

Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value.

Fixes 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs")
---
  .../ethernet/intel/ice/ice_virtchnl_fdir.c    | 25 +++++++++++++------
  1 file changed, 17 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +0 -0
index 14e3f0f89c78..6250629ee8f9 100644
@@ -835,18 +835,27 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
  	u8 *pkt_buf, *msk_buf __free(kfree);
  	struct ice_parser_result rslt;

drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c ice_vc_fdir_parse_raw(struct ice_vf *vf, · line 843

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +3 -3
  	struct ice_pf *pf = vf->pf;
+	u16 pkt_len, udp_port = 0;
  	struct ice_parser *psr;
  	int status = -ENOMEM;
  	struct ice_hw *hw;
-	u16 udp_port = 0;
-	pkt_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
-	msk_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL);
+	if (!proto->raw.pkt_len)
+		return -EINVAL;

Hi Martyna,

It seems to me that the use of __free() above will result in kfree(msk_buf) being called here. But msk_buf is not initialised at this point.

My suggest would be to drop the use of __free().
But if not, I think that in order to be safe it would be best to do this (completely untested;

Quoted 5 lines
Quoted 1 line
	u8 *pkt_buf, *msk_buf __free(kfree) = NULL;

Oh yeah!, thank you Simon for catching that.

I would say "naked __free()" was harmful here.

Yes, quite.