* [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