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 <[email protected]>
---
 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

Reply via email to