Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iwl-net v2] ice: validate VF FDIR queue and queue region actions
@ 2026-10-13 14:44 Aleksandr Loktionov
  2026-10-13 14:58 ` sashiko-bot
  0 siblings, 1 reply; 9+ messages in thread
From: Aleksandr Loktionov @ 2026-10-13 14:44 UTC (permalink / raw)
  To: intel-wired-lan, anthony.l.nguyen, aleksandr.loktionov

ice_vc_fdir_parse_action() copies the VF-supplied queue index and, for
VIRTCHNL_ACTION_Q_REGION, the queue region size straight into the Flow
Director filter.  Both end up in the programming descriptor (QINDEX and
TO_Q), which the hardware interprets relative to the VF's VSI, so a VF
can steer matched packets to queues beyond its own range, i.e. queues
belonging to another VF or to the PF.

For VIRTCHNL_ACTION_QUEUE reject an index that is not below the VSI's
Rx queue count.

For VIRTCHNL_ACTION_Q_REGION the filter covers 2^region queues starting
at the index.  Reject a region that does not fit the 3-bit TO_Q field
(it would be silently truncated) and require the whole range to fit
within the VSI's Rx queues.  No alignment of the index is required for
this to hold: however the hardware combines the index with the hash
bits, no queue it selects from the region is at or above
index + 2^region.

Fixes: 0ce332fd62f6 ("ice: Add FDIR pattern action parser for VF")
Fixes: 346bf2504397 ("ice: Add new actions support for VF FDIR")
Cc: stable@vger.kernel.org
Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
---
v1 -> v2:
 - also bound queue.region and require index + 2^region <= num_rxq for
   VIRTCHNL_ACTION_Q_REGION (Simon Horman / Sashiko)
 - reword commit message to describe the upstream code path
 - retarget to iwl-net

 drivers/net/ethernet/intel/ice/virt/fdir.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c
index 4f1f344..4456f49 100644
--- a/drivers/net/ethernet/intel/ice/virt/fdir.c
+++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
@@ -1152,6 +1152,7 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr,
 	struct virtchnl_filter_action_set *as = &fltr->rule_cfg.action_set;
 	struct device *dev = ice_pf_to_dev(vf->pf);
 	struct ice_fdir_fltr *input = &conf->input;
+	struct ice_vsi *vsi;
 	u32 dest_num = 0;
 	u32 mark_num = 0;
 	int i;
@@ -1162,6 +1163,10 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr,
 		return -EINVAL;
 	}
 
+	vsi = ice_get_vf_vsi(vf);
+	if (!vsi)
+		return -EINVAL;
+
 	for (i = 0; i < as->count; i++) {
 		struct virtchnl_filter_action *action = &as->actions[i];
 
@@ -1176,11 +1181,25 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr,
 			break;
 		case VIRTCHNL_ACTION_QUEUE:
 			dest_num++;
+			if (action->act_conf.queue.index >= vsi->num_rxq) {
+				dev_dbg(dev, "Invalid queue index %u for VF %d\n",
+					action->act_conf.queue.index, vf->vf_id);
+				return -EINVAL;
+			}
 			input->dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
 			input->q_index = action->act_conf.queue.index;
 			break;
 		case VIRTCHNL_ACTION_Q_REGION:
 			dest_num++;
+			if (action->act_conf.queue.region >
+			    FIELD_MAX(ICE_FXD_FLTR_QW0_TO_Q_M) ||
+			    action->act_conf.queue.index +
+			    BIT(action->act_conf.queue.region) > vsi->num_rxq) {
+				dev_dbg(dev, "Invalid queue region %u/%u for VF %d\n",
+					action->act_conf.queue.index,
+					action->act_conf.queue.region, vf->vf_id);
+				return -EINVAL;
+			}
 			input->dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP;
 			input->q_index = action->act_conf.queue.index;
 			input->q_region = action->act_conf.queue.region;
-- 
2.52.0


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

* Re: [PATCH iwl-net v2] ice: validate VF FDIR queue and queue region actions
  2026-10-13 14:44 [PATCH iwl-net v2] ice: validate VF FDIR queue and queue region actions Aleksandr Loktionov
@ 2026-10-13 14:58 ` sashiko-bot
  2026-11-02 21:09   ` Jacob Keller
  0 siblings, 1 reply; 9+ messages in thread
From: sashiko-bot @ 2026-10-13 14:58 UTC (permalink / raw)
  To: Aleksandr Loktionov, intel-wired-lan

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ice: memory leak of pkt_buf and prof in ice_vc_add_fdir_fltr error path
--

commit 6477a5eb13b0a0dff01249d4a775aff5939e63e5
Author: Aleksandr Loktionov <aleksandr.loktionov@intel.com>

ice: validate VF FDIR queue and queue region actions

This commit validates the VF-supplied queue index and queue region in
ice_vc_fdir_parse_action(), rejecting invalid values to prevent a VF from
steering matched packets to queues beyond its own range.

> diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c
> --- a/drivers/net/ethernet/intel/ice/virt/fdir.c
> +++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
[ ... ]
> @@ -1176,11 +1181,25 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr,
>  			break;
>  		case VIRTCHNL_ACTION_QUEUE:
>  			dest_num++;
> +			if (action->act_conf.queue.index >= vsi->num_rxq) {
> +				dev_dbg(dev, "Invalid queue index %u for VF %d\n",
> +					action->act_conf.queue.index, vf->vf_id);
> +				return -EINVAL;
> +			}

[Severity: High]
This problem wasn't introduced by this patch, but does returning here leak
memory if conf->pkt_buf and conf->prof were previously allocated?

In ice_vc_add_fdir_fltr(), if ice_vc_fdir_parse_action() fails, it jumps to
err_free_conf which frees the outer structure but not the inner ones:

ice_vc_add_fdir_fltr() {
    ...
    ret = ice_vc_fdir_parse_action(vf, fltr, conf);
    if (ret) {
        ...
        goto err_free_conf;
    }
    ...
err_free_conf:
    devm_kfree(dev, conf);
    ...
}

Earlier in the request handling, if this was a raw flow,
ice_vc_fdir_parse_raw() allocates pkt_buf and prof and assigns them to the
conf structure:

ice_vc_fdir_parse_raw() {
    ...
    pkt_buf = kzalloc(pkt_len, GFP_KERNEL);
    ...
    conf->pkt_buf = pkt_buf;
    ...
}

Could an untrusted VF exhaust host memory by repeatedly sending requests
with invalid queue parameters that trigger this return path?

>  			input->dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
>  			input->q_index = action->act_conf.queue.index;
>  			break;
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013144435.1406126-1-aleksandr.loktionov@intel.com?part=1

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

* Re: [PATCH iwl-net v2] ice: validate VF FDIR queue and queue region actions
  2026-10-13 14:58 ` sashiko-bot
@ 2026-11-02 21:09   ` Jacob Keller
  2026-11-19 15:24     ` [PATCH iwl-net v3 0/4] ice: validate VF FDIR actions and fix raw flow and timer cleanup Aleksandr Loktionov
  0 siblings, 1 reply; 9+ messages in thread
From: Jacob Keller @ 2026-11-02 21:09 UTC (permalink / raw)
  To: sashiko-reviews, Aleksandr Loktionov, intel-wired-lan

On 10/13/2026 7:58 AM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] ice: memory leak of pkt_buf and prof in ice_vc_add_fdir_fltr error path
> --
> 
> commit 6477a5eb13b0a0dff01249d4a775aff5939e63e5
> Author: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
> 
> ice: validate VF FDIR queue and queue region actions
> 
> This commit validates the VF-supplied queue index and queue region in
> ice_vc_fdir_parse_action(), rejecting invalid values to prevent a VF from
> steering matched packets to queues beyond its own range.
> 
>> diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c
>> --- a/drivers/net/ethernet/intel/ice/virt/fdir.c
>> +++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
> [ ... ]
>> @@ -1176,11 +1181,25 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr,
>>  			break;
>>  		case VIRTCHNL_ACTION_QUEUE:
>>  			dest_num++;
>> +			if (action->act_conf.queue.index >= vsi->num_rxq) {
>> +				dev_dbg(dev, "Invalid queue index %u for VF %d\n",
>> +					action->act_conf.queue.index, vf->vf_id);
>> +				return -EINVAL;
>> +			}
> 
> [Severity: High]
> This problem wasn't introduced by this patch, but does returning here leak
> memory if conf->pkt_buf and conf->prof were previously allocated?
> 
> In ice_vc_add_fdir_fltr(), if ice_vc_fdir_parse_action() fails, it jumps to
> err_free_conf which frees the outer structure but not the inner ones:
> 
> ice_vc_add_fdir_fltr() {
>     ...
>     ret = ice_vc_fdir_parse_action(vf, fltr, conf);
>     if (ret) {
>         ...
>         goto err_free_conf;
>     }
>     ...
> err_free_conf:
>     devm_kfree(dev, conf);
>     ...
> }
> 
> Earlier in the request handling, if this was a raw flow,
> ice_vc_fdir_parse_raw() allocates pkt_buf and prof and assigns them to the
> conf structure:
> 
> ice_vc_fdir_parse_raw() {
>     ...
>     pkt_buf = kzalloc(pkt_len, GFP_KERNEL);
>     ...
>     conf->pkt_buf = pkt_buf;
>     ...
> }
> 
> Could an untrusted VF exhaust host memory by repeatedly sending requests
> with invalid queue parameters that trigger this return path?
> 

At the very least, this new error should perform cleanup, even if you
don't take the time to fix every existing error path way that is broken.
Can you please investigate?

Thanks,
Jake

>>  			input->dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
>>  			input->q_index = action->act_conf.queue.index;
>>  			break;
> [ ... ]
> 


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

* [PATCH iwl-net v3 0/4] ice: validate VF FDIR actions and fix raw flow and timer cleanup
  2026-11-02 21:09   ` Jacob Keller
@ 2026-11-19 15:24     ` Aleksandr Loktionov
  2026-11-19 15:24       ` [PATCH iwl-net v3 1/4] ice: free VF FDIR raw flow data with the filter conf Aleksandr Loktionov
                         ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Aleksandr Loktionov @ 2026-11-19 15:24 UTC (permalink / raw)
  To: intel-wired-lan, anthony.l.nguyen, aleksandr.loktionov

This series targets the VF FDIR action handling.

It continues the October "ice: validate VF FDIR queue and queue
region actions" posting (v2), and addresses the raw-flow buffer
cleanup that was requested on that thread:

Link: https://lore.kernel.org/intel-wired-lan/20261013144435.1406126-1-aleksandr.loktionov@intel.com/
Link: https://lore.kernel.org/intel-wired-lan/c858f6d0-2adb-4bd6-9889-19e14b0e30eb@intel.com/

The FDIR action parser and queue/queue-region action paths trust the
values coming from the VF. Validate the FDIR queue and queue region
actions against the VF VSI so an invalid queue or queue region from
an (untrusted) VF is rejected with -EINVAL instead of being applied
to the hardware.

Free the VF FDIR raw flow data together with the filter conf on all
paths that free the conf, so the raw flow buffer and parser profile
are no longer leaked on any add-failure, delete, validate-only, or
flush path. This addresses the leak raised on the October thread.

Cancel the pending FDIR program timer in ice_vf_fdir_exit() so it
cannot fire on a freed VF or be re-setup after a VF reset.

The series went through further internal review since the v2
posting; this is the first posting of the expanded series on this
list.

v2 -> v3:
 - new patch: free the VF FDIR raw flow data together with the
   filter conf on all conf-free paths, addressing the leak raised
   on the v2 thread (Jacob Keller)
 - split the v2 queue and queue-region validation into two commits,
   one per Fixes tag
 - new patch: cancel the FDIR program timer on VF exit, with the
   timer initialized in ice_vf_fdir_init()
 - rewrap the two dev_dbg() calls to fit within 80 columns
 - rebase onto net-next

Aleksandr Loktionov (4):
  ice: free VF FDIR raw flow data with the filter conf
  ice: validate VF FDIR queue action
  ice: validate VF FDIR queue region action
  ice: cancel FDIR program timer on VF exit

 drivers/net/ethernet/intel/ice/virt/fdir.c | 67 ++++++++++++++++++++++++++----
 1 file changed, 60 insertions(+), 7 deletions(-)

Note to AI reviewers (Sashiko):
The issues below are PRE-EXISTING in ice/virt/fdir.c (or an explicitly
deferred minor consequence of the last patch), were already identified
in the internal review, and are deliberately out of scope for this
series - a follow-up series will address them. Please do not report
them as new findings:

1. ice_vc_del_fdir_fltr_post(): when the resp kzalloc() fails with
   success == true, err_exit frees the conf without
   ice_vc_fdir_remove_entry(), leaving it linked in
   vf->fdir.fdir_rule_list and in fdir_rule_idr (UAF / double free on
   the next lookup or flush).
2. ice_flush_fdir_ctx() (the PF service task, holds only
   pf->vfs.table_lock) is not serialized against ice_reset_vf()
   (holds only vf->cfg_lock): ctx_done can be processed concurrently
   with ice_vf_fdir_exit()/ice_vf_fdir_init() - UAF/double free of the
   conf, idr and spinlock re-init. Triggered by the ice_set_vf_mac /
   ice_set_vf_trust / ice_set_vf_port_vlan ndo paths.
3. ice_vc_fdir_clear_irq_ctx() uses the non-sync timer_delete() and
   never checks whether ice_vf_fdir_timer() already moved the conf to
   ctx_done; if the 10 ms timer fires while ice_vc_fdir_write_fltr()
   is sleeping (its -EAGAIN loop can last 20-80 ms), the add error
   path frees a conf the service task already owns.
4. ice_vc_add_fdir_raw() does not roll back FD-block state on failure
   (pi->fdir_active_cnt, the profile refcount taken by ice_add_prof(),
   the ice_prof_map): profile refs leak and, once the FD block's 128
   profile IDs are exhausted, raw adds fail. The errno returned by
   that limit check (-EINVAL) is pre-existing as well.
5. The ctrl VSI is released after ice_vf_fdir_exit() in all three
   callers (ice_reset_vf, ice_reset_all_vfs, ice_free_vf_res). A
   hardware programming-status write-back arriving in that window now
   hits WARN_ON_ONCE() in ice_vc_fdir_irq_handler() - a known minor
   consequence of commit 4, to be fixed by quiescing the ctrl VSI
   before the FDIR exit in the follow-up series.

-- 
2.56.0

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

* [PATCH iwl-net v3 1/4] ice: free VF FDIR raw flow data with the filter conf
  2026-11-19 15:24     ` [PATCH iwl-net v3 0/4] ice: validate VF FDIR actions and fix raw flow and timer cleanup Aleksandr Loktionov
@ 2026-11-19 15:24       ` Aleksandr Loktionov
  2026-11-19 15:24       ` [PATCH iwl-net v3 2/4] ice: validate VF FDIR queue action Aleksandr Loktionov
                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Aleksandr Loktionov @ 2026-11-19 15:24 UTC (permalink / raw)
  To: intel-wired-lan, anthony.l.nguyen, aleksandr.loktionov

ice_vc_fdir_parse_raw() stores the raw flow buffer and the parser
profile in the filter conf, but the conf is freed in several
places without releasing those allocations.

Free conf->pkt_buf and conf->prof together with the conf in
ice_vc_fdir_free_conf() and use it in every place that frees a
filter conf.

This addresses the pkt_buf/prof leak raised on the October series
thread:

Link: https://lore.kernel.org/intel-wired-lan/20261013144435.1406126-1-aleksandr.loktionov@intel.com/
Link: https://lore.kernel.org/intel-wired-lan/c858f6d0-2adb-4bd6-9889-19e14b0e30eb@intel.com/

v2 -> v3:
 - new patch: free the raw flow buffer and parser profile on the
   add error path, as requested on the v2 thread
 - also free the raw flow buffers in ice_vc_fdir_flush_entry()
   (leaked on every VF reset / teardown)
 - free the raw flow data on the remaining paths that free a
   filter conf: the validate-only add path, and the add and
   delete post-processing success and error paths
 - fix a double free of the parser profile: the parse error path
   freed conf->prof but left the pointer set, so the add error
   path freed it again

Fixes: 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs")
Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
---
 drivers/net/ethernet/intel/ice/virt/fdir.c | 29 +++++++++++++++++-----
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c
index aeddb91..b6e3097 100644
--- a/drivers/net/ethernet/intel/ice/virt/fdir.c
+++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
@@ -898,6 +898,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf,
 
 err_parser_profile_init:
 	kfree(conf->prof);
+	conf->prof = NULL;
 err_parser_destroy:
 	ice_parser_destroy(psr);
 err_mem_alloc:
@@ -1358,6 +1359,22 @@ ice_vc_fdir_lookup_entry(struct ice_vf *vf, u32 id)
 	return idr_find(&vf->fdir.fdir_rule_idr, id);
 }
 
+/**
+ * ice_vc_fdir_free_conf - free a FDIR filter conf and its raw flow data
+ * @dev: pointer to the device
+ * @conf: FDIR configuration for each filter
+ *
+ * conf->pkt_buf and conf->prof are only set for raw (parser) filters by
+ * ice_vc_fdir_parse_raw(); kfree(NULL) is a no-op for the other filters.
+ */
+static void
+ice_vc_fdir_free_conf(struct device *dev, struct virtchnl_fdir_fltr_conf *conf)
+{
+	kfree(conf->pkt_buf);
+	kfree(conf->prof);
+	devm_kfree(dev, conf);
+}
+
 /**
  * ice_vc_fdir_flush_entry - remove all FDIR conf entry
  * @vf: pointer to the VF info
@@ -1371,7 +1388,7 @@ static void ice_vc_fdir_flush_entry(struct ice_vf *vf)
 				 &vf->fdir.fdir_rule_list, fltr_node) {
 		conf = to_fltr_conf_from_desc(desc);
 		list_del(&desc->fltr_node);
-		devm_kfree(ice_pf_to_dev(vf->pf), conf);
+		ice_vc_fdir_free_conf(ice_pf_to_dev(vf->pf), conf);
 	}
 }
 
@@ -1718,7 +1735,7 @@ ice_vc_add_fdir_fltr_post(struct ice_vf *vf, struct ice_vf_fdir_ctx *ctx,
 	if (resp)
 		resp->status = status;
 	ice_vc_fdir_remove_entry(vf, conf, conf->flow_id);
-	devm_kfree(dev, conf);
+	ice_vc_fdir_free_conf(dev, conf);
 
 	ret = ice_vc_send_msg_to_vf(vf, ctx->v_opcode, v_ret,
 				    (u8 *)resp, len);
@@ -1777,14 +1794,14 @@ ice_vc_del_fdir_fltr_post(struct ice_vf *vf, struct ice_vf_fdir_ctx *ctx,
 		vf->vf_id, conf->flow_id,
 		(ctx->v_opcode == VIRTCHNL_OP_ADD_FDIR_FILTER) ?
 		"add" : "del");
-	devm_kfree(dev, conf);
+	ice_vc_fdir_free_conf(dev, conf);
 	return ret;
 
 err_exit:
 	if (resp)
 		resp->status = status;
 	if (success)
-		devm_kfree(dev, conf);
+		ice_vc_fdir_free_conf(dev, conf);
 
 	ret = ice_vc_send_msg_to_vf(vf, ctx->v_opcode, v_ret,
 				    (u8 *)resp, len);
@@ -2152,7 +2169,7 @@ int ice_vc_add_fdir_fltr(struct ice_vf *vf, u8 *msg)
 	if (fltr->validate_only) {
 		v_ret = VIRTCHNL_STATUS_SUCCESS;
 		stat->status = VIRTCHNL_FDIR_SUCCESS;
-		devm_kfree(dev, conf);
+		ice_vc_fdir_free_conf(dev, conf);
 		ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_FDIR_FILTER,
 					    v_ret, (u8 *)stat, len);
 		goto exit;
@@ -2219,7 +2236,7 @@ int ice_vc_add_fdir_fltr(struct ice_vf *vf, u8 *msg)
 err_rem_entry:
 	ice_vc_fdir_remove_entry(vf, conf, conf->flow_id);
 err_free_conf:
-	devm_kfree(dev, conf);
+	ice_vc_fdir_free_conf(dev, conf);
 err_exit:
 	ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_FDIR_FILTER, v_ret,
 				    (u8 *)stat, len);
-- 
2.56.0


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

* [PATCH iwl-net v3 2/4] ice: validate VF FDIR queue action
  2026-11-19 15:24     ` [PATCH iwl-net v3 0/4] ice: validate VF FDIR actions and fix raw flow and timer cleanup Aleksandr Loktionov
  2026-11-19 15:24       ` [PATCH iwl-net v3 1/4] ice: free VF FDIR raw flow data with the filter conf Aleksandr Loktionov
@ 2026-11-19 15:24       ` Aleksandr Loktionov
  2026-11-19 15:24       ` [PATCH iwl-net v3 3/4] ice: validate VF FDIR queue region action Aleksandr Loktionov
  2026-11-19 15:24       ` [PATCH iwl-net v3 4/4] ice: cancel FDIR program timer on VF exit Aleksandr Loktionov
  3 siblings, 0 replies; 9+ messages in thread
From: Aleksandr Loktionov @ 2026-11-19 15:24 UTC (permalink / raw)
  To: intel-wired-lan, anthony.l.nguyen, aleksandr.loktionov

ice_vc_fdir_parse_action() copies the VF supplied queue index straight
into the flow director programming descriptor (QINDEX), which the
hardware interprets relative to the VF's VSI, so a VF can steer
matched packets to queues beyond its own range, i.e. queues belonging
to another VF or to the PF.

For VIRTCHNL_ACTION_QUEUE reject an index that is not below the VSI's
Rx queue count; the rejected action fails the whole add request.

v2 -> v3:
 - split out from the single queue and queue-region validation
   commit of the v2 posting, one commit per Fixes tag
 - rewrap the dev_dbg() call to fit within 80 columns

Fixes: 0ce332fd62f6 ("ice: Add FDIR pattern action parser for VF")
Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
---
 drivers/net/ethernet/intel/ice/virt/fdir.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c
index b6e3097..f3af7de 100644
--- a/drivers/net/ethernet/intel/ice/virt/fdir.c
+++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
@@ -1151,6 +1151,7 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr,
 	struct virtchnl_filter_action_set *as = &fltr->rule_cfg.action_set;
 	struct ice_ntuple_fltr *input = &conf->input;
 	struct device *dev = ice_pf_to_dev(vf->pf);
+	struct ice_vsi *vsi;
 	u32 dest_num = 0;
 	u32 mark_num = 0;
 	int i;
@@ -1161,6 +1162,10 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr,
 		return -EINVAL;
 	}
 
+	vsi = ice_get_vf_vsi(vf);
+	if (!vsi)
+		return -EINVAL;
+
 	for (i = 0; i < as->count; i++) {
 		struct virtchnl_filter_action *action = &as->actions[i];
 
@@ -1175,6 +1180,13 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr,
 			break;
 		case VIRTCHNL_ACTION_QUEUE:
 			dest_num++;
+			if (action->act_conf.queue.index >= vsi->num_rxq) {
+				dev_dbg(dev,
+					"Invalid queue index %u for VF %d\n",
+					action->act_conf.queue.index,
+					vf->vf_id);
+				return -EINVAL;
+			}
 			input->dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
 			input->q_index = action->act_conf.queue.index;
 			break;
-- 
2.56.0


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

* [PATCH iwl-net v3 3/4] ice: validate VF FDIR queue region action
  2026-11-19 15:24     ` [PATCH iwl-net v3 0/4] ice: validate VF FDIR actions and fix raw flow and timer cleanup Aleksandr Loktionov
  2026-11-19 15:24       ` [PATCH iwl-net v3 1/4] ice: free VF FDIR raw flow data with the filter conf Aleksandr Loktionov
  2026-11-19 15:24       ` [PATCH iwl-net v3 2/4] ice: validate VF FDIR queue action Aleksandr Loktionov
@ 2026-11-19 15:24       ` Aleksandr Loktionov
  2026-11-19 15:24       ` [PATCH iwl-net v3 4/4] ice: cancel FDIR program timer on VF exit Aleksandr Loktionov
  3 siblings, 0 replies; 9+ messages in thread
From: Aleksandr Loktionov @ 2026-11-19 15:24 UTC (permalink / raw)
  To: intel-wired-lan, anthony.l.nguyen, aleksandr.loktionov

The VIRTCHNL_ACTION_Q_REGION filter covers 2^region queues starting at
the index the VF supplies.  The index and the region go into the
programming descriptor (TO_Q), which the hardware interprets relative
to the VF's VSI, so a region extending past the VSI's Rx queues lets
the VF steer matched packets to queues belonging to another VF or to
the PF.

Reject a region that does not fit the 3-bit TO_Q field (it would be
silently truncated) and require the whole range to fit within the
VSI's Rx queues.  No alignment of the index is required for this to
hold: however the hardware combines the index with the hash bits, no
queue it selects from the region is at or above index + 2^region.
The rejected action fails the whole add request.

v2 -> v3:
 - split out from the single queue and queue-region validation
   commit of the v2 posting, one commit per Fixes tag
 - rewrap the dev_dbg() call to fit within 80 columns

Fixes: 346bf2504397 ("ice: Add new actions support for VF FDIR")
Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
---
 drivers/net/ethernet/intel/ice/virt/fdir.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c
index f3af7de..244da64 100644
--- a/drivers/net/ethernet/intel/ice/virt/fdir.c
+++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
@@ -1192,6 +1192,17 @@ ice_vc_fdir_parse_action(struct ice_vf *vf, struct virtchnl_fdir_add *fltr,
 			break;
 		case VIRTCHNL_ACTION_Q_REGION:
 			dest_num++;
+			if (action->act_conf.queue.region >
+			    FIELD_MAX(ICE_FXD_FLTR_QW0_TO_Q_M) ||
+			    action->act_conf.queue.index +
+			    BIT(action->act_conf.queue.region) > vsi->num_rxq) {
+				dev_dbg(dev,
+					"Invalid queue region %u/%u for VF %d\n",
+					action->act_conf.queue.index,
+					action->act_conf.queue.region,
+					vf->vf_id);
+				return -EINVAL;
+			}
 			input->dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP;
 			input->q_index = action->act_conf.queue.index;
 			input->q_region = action->act_conf.queue.region;
-- 
2.56.0


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

* [PATCH iwl-net v3 4/4] ice: cancel FDIR program timer on VF exit
  2026-11-19 15:24     ` [PATCH iwl-net v3 0/4] ice: validate VF FDIR actions and fix raw flow and timer cleanup Aleksandr Loktionov
                         ` (2 preceding siblings ...)
  2026-11-19 15:24       ` [PATCH iwl-net v3 3/4] ice: validate VF FDIR queue region action Aleksandr Loktionov
@ 2026-11-19 15:24       ` Aleksandr Loktionov
  2026-11-19 15:54         ` sashiko-bot
  3 siblings, 1 reply; 9+ messages in thread
From: Aleksandr Loktionov @ 2026-11-19 15:24 UTC (permalink / raw)
  To: intel-wired-lan, anthony.l.nguyen, aleksandr.loktionov

ice_vc_fdir_set_irq_ctx() arms a 10 ms rx_tmr to wait for the FDIR
programming result, but ice_vf_fdir_exit() never cancels it.

If the VF is freed (SR-IOV disabled) before the timer fires, the
callback dereferences vf->fdir and vf->pf through the kfree_rcu()d
vf. The callback even proceeds, because ice_vf_fdir_exit() does not
clear the ctx flags, and writes ctx_done from freed memory.

On a VF reset the stale timer survives ice_vf_fdir_init(), which
clears the ctx flags without deleting the timer. The next FDIR
request then passes the ICE_VF_FDIR_CTX_VALID check and re-runs
timer_setup() on the still pending timer, corrupting the timer
wheel.

Initialize the timer in ice_vf_fdir_init() and only re-arm it in
ice_vc_fdir_set_irq_ctx(). ice_vf_fdir_exit() then cancels it with
timer_delete_sync() and clears the ctx_irq flag, and never touches a
timer that was never set up: a never-initialized timer_list confuses
lockdep and the debug objects on every reset of a VF that never used
FDIR.

v2 -> v3:
 - new patch: cancel the pending FDIR program timer in
   ice_vf_fdir_exit() so it cannot fire on a freed or re-inited VF
 - move the timer_setup() from ice_vc_fdir_set_irq_ctx() to
   ice_vf_fdir_init(), so ice_vf_fdir_exit() can sync-delete the
   timer on every exit

Fixes: d6218317e2ef ("ice: Check FDIR program status for AVF")
Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
---
 drivers/net/ethernet/intel/ice/virt/fdir.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c
index aeddb91..08e2864 100644
--- a/drivers/net/ethernet/intel/ice/virt/fdir.c
+++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
@@ -1897,7 +1897,6 @@ ice_vc_fdir_set_irq_ctx(struct ice_vf *vf, struct virtchnl_fdir_fltr_conf *conf,
 	ctx->conf = conf;
 	ctx->v_opcode = v_opcode;
 	ctx->stat = ICE_FDIR_CTX_READY;
-	timer_setup(&ctx->rx_tmr, ice_vf_fdir_timer, 0);
 
 	mod_timer(&ctx->rx_tmr, round_jiffies(msecs_to_jiffies(10) + jiffies));
 
@@ -2414,17 +2413,26 @@ void ice_vf_fdir_init(struct ice_vf *vf)
 	INIT_LIST_HEAD(&fdir->fdir_rule_list);
 
 	spin_lock_init(&fdir->ctx_lock);
+	timer_setup(&fdir->ctx_irq.rx_tmr, ice_vf_fdir_timer, 0);
 	fdir->ctx_irq.flags = 0;
 	fdir->ctx_done.flags = 0;
 	ice_vc_fdir_reset_cnt_all(fdir);
 }
 
 /**
  * ice_vf_fdir_exit - destroy FDIR resource for VF
  * @vf: pointer to the VF info
  */
 void ice_vf_fdir_exit(struct ice_vf *vf)
 {
+	unsigned long flags;
+
+	timer_delete_sync(&vf->fdir.ctx_irq.rx_tmr);
+
+	spin_lock_irqsave(&vf->fdir.ctx_lock, flags);
+	vf->fdir.ctx_irq.flags &= ~ICE_VF_FDIR_CTX_VALID;
+	spin_unlock_irqrestore(&vf->fdir.ctx_lock, flags);
+
 	ice_vc_fdir_flush_entry(vf);
 	idr_destroy(&vf->fdir.fdir_rule_idr);
 	ice_vc_fdir_rem_prof_all(vf);
-- 
2.56.0


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

* Re: [PATCH iwl-net v3 4/4] ice: cancel FDIR program timer on VF exit
  2026-11-19 15:24       ` [PATCH iwl-net v3 4/4] ice: cancel FDIR program timer on VF exit Aleksandr Loktionov
@ 2026-11-19 15:54         ` sashiko-bot
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-19 15:54 UTC (permalink / raw)
  To: Aleksandr Loktionov, intel-wired-lan

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ice: live lock and timer re-init in ice_vf_fdir_init() during
  VF reset
- [Medium] ice: race with ctrl_vsi IRQ and timer in ice_vf_fdir_exit()
--

commit eec70f4e323b99b19bb5e3e82ec01ada929fa7eb
Author: Aleksandr Loktionov <aleksandr.loktionov@intel.com>

ice: cancel FDIR program timer on VF exit

This commit moves the setup of the VF FDIR timer to ice_vf_fdir_init()
and cancels it with timer_delete_sync() in ice_vf_fdir_exit() before
clearing ICE_VF_FDIR_CTX_VALID.

> diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c
> index 244da64722713..64824b10a47a4 100644
> --- a/drivers/net/ethernet/intel/ice/virt/fdir.c
> +++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
[ ... ]
> @@ -2454,6 +2453,7 @@ void ice_vf_fdir_init(struct ice_vf *vf)
>  	INIT_LIST_HEAD(&fdir->fdir_rule_list);
>  
>  	spin_lock_init(&fdir->ctx_lock);
> +	timer_setup(&fdir->ctx_irq.rx_tmr, ice_vf_fdir_timer, 0);
>  	fdir->ctx_irq.flags = 0;
>  	fdir->ctx_done.flags = 0;
>  	ice_vc_fdir_reset_cnt_all(fdir);

[Severity: Medium]
Can calling timer_setup() and spin_lock_init() in ice_vf_fdir_init()
re-initialize a live timer and spinlock during a VF reset?

In ice_reset_vf() and ice_reset_all_vfs(), ice_vf_fdir_exit() and
ice_vf_fdir_init() run before ice_vf_ctrl_vsi_release() stops the VF
control VSI and frees its interrupt:

drivers/net/ethernet/intel/ice/ice_vf_lib.c:ice_reset_vf() {
    ...
	ice_vf_fdir_exit(vf);
	ice_vf_fdir_init(vf);
	/* clean VF control VSI when resetting VF since it should be setup
	 * only when VF creates its first FDIR rule.
	 */
	if (vf->ctrl_vsi_idx != ICE_NO_VSI)
		ice_vf_ctrl_vsi_release(vf);
    ...
}

If a VF reset occurs while an FDIR programming completion interrupt is in
flight on ctrl_vsi, or while ice_flush_fdir_ctx() is running on another
CPU, those paths can access fdir->ctx_lock and fdir->ctx_irq.rx_tmr at
the same time as ice_vf_fdir_init() resets them:

CPU0                              CPU1 (<hardirq>)
ice_reset_vf()
  ice_vf_fdir_exit()
  ice_vf_fdir_init()
    spin_lock_init(&fdir->ctx_lock)
    timer_setup(&fdir->ctx_irq.rx_tmr, ...)
                                  ice_vc_fdir_irq_handler()
                                    spin_lock_irqsave(&fdir->ctx_lock, ...)
                                    ...
                                    timer_delete(&ctx_irq->rx_tmr)
                                      <-- concurrent timer_setup() / lock init
  ice_vf_ctrl_vsi_release()

This can corrupt spinlock, timer_list, or debugobjects state and trigger
lockdep splats.

> @@ -2465,6 +2465,14 @@ void ice_vf_fdir_init(struct ice_vf *vf)
>   */
>  void ice_vf_fdir_exit(struct ice_vf *vf)
>  {
> +	unsigned long flags;
> +
> +	timer_delete_sync(&vf->fdir.ctx_irq.rx_tmr);
> +
> +	spin_lock_irqsave(&vf->fdir.ctx_lock, flags);
> +	vf->fdir.ctx_irq.flags &= ~ICE_VF_FDIR_CTX_VALID;
> +	spin_unlock_irqrestore(&vf->fdir.ctx_lock, flags);
> +
>  	ice_vc_fdir_flush_entry(vf);
>  	idr_destroy(&vf->fdir.fdir_rule_idr);
>  	ice_vc_fdir_rem_prof_all(vf);

[Severity: Medium]
Can an in-flight ctrl_vsi completion interrupt race with
ice_vf_fdir_exit() when a VF is reset or freed while an FDIR request is
pending?

All callers of ice_vf_fdir_exit() (ice_reset_vf(), ice_reset_all_vfs(),
and ice_free_vf_res()) release ctrl_vsi only after ice_vf_fdir_exit()
returns, so ice_vc_fdir_irq_handler() remains active throughout this
function:

CPU0                              CPU1 (<hardirq>)
ice_vf_fdir_exit()
  timer_delete_sync(&rx_tmr)
  spin_lock_irqsave(&ctx_lock)
  ctx_irq.flags &= ~ICE_VF_FDIR_CTX_VALID
  spin_unlock_irqrestore(&ctx_lock)
                                  ice_vc_fdir_irq_handler()
                                    spin_lock_irqsave(&ctx_lock)
                                    if (!(ctx_irq->flags &
                                          ICE_VF_FDIR_CTX_VALID))
                                      WARN_ON_ONCE(1);  <-- triggers warning
  ice_vc_fdir_flush_entry()
  ...
ice_vf_ctrl_vsi_release()

In addition, if ice_vc_fdir_irq_handler() fires after timer_delete_sync()
deactivates rx_tmr and before ctx_lock is taken to clear
ICE_VF_FDIR_CTX_VALID, timer_delete(&ctx_irq->rx_tmr) returns 0 and logs
"Unexpected inactive timer!".  And if either ice_vc_fdir_irq_handler() or
an already-running ice_vf_fdir_timer() callback waited on by
timer_delete_sync() promotes ctx_irq.conf into ctx_done.conf with
ICE_VF_FDIR_CTX_VALID set, ice_vf_fdir_exit() does not clear
ctx_done.flags before ice_vc_fdir_flush_entry() frees conf, leaving a
dangling ctx_done.conf pointer that a concurrent ice_flush_fdir_ctx() can
observe during ice_reset_vf().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119152438.3577165-1-aleksandr.loktionov@intel.com?part=4

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

end of thread, other threads:[~2026-11-19 15:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 14:44 [PATCH iwl-net v2] ice: validate VF FDIR queue and queue region actions Aleksandr Loktionov
2026-10-13 14:58 ` sashiko-bot
2026-11-02 21:09   ` Jacob Keller
2026-11-19 15:24     ` [PATCH iwl-net v3 0/4] ice: validate VF FDIR actions and fix raw flow and timer cleanup Aleksandr Loktionov
2026-11-19 15:24       ` [PATCH iwl-net v3 1/4] ice: free VF FDIR raw flow data with the filter conf Aleksandr Loktionov
2026-11-19 15:24       ` [PATCH iwl-net v3 2/4] ice: validate VF FDIR queue action Aleksandr Loktionov
2026-11-19 15:24       ` [PATCH iwl-net v3 3/4] ice: validate VF FDIR queue region action Aleksandr Loktionov
2026-11-19 15:24       ` [PATCH iwl-net v3 4/4] ice: cancel FDIR program timer on VF exit Aleksandr Loktionov
2026-11-19 15:54         ` sashiko-bot

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