Re: [PATCH net] octeontx2-pf: Fix potential use-after-free in representor teardown

From: Simon Horman

Date: Fri Nov 20 2026 - 06:06:33 EST


On Wed, Nov 18, 2026 at 02:13:34PM +0000, netdev-bot+sashiko@xxxxxxxxxx wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 1 (1) · High: 0 (2) · Medium: 0 · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [Critical] The patch is titled "Fix potential use-after-free in
> representor teardown", but rvu_rep_destroy() still frees rep_dev while…
>
> Pre-existing issues:
> - [Critical] This problem wasn't introduced by this patch, but
> rvu_rep_setup_tc_cb() copies per-representor pointers into the long-…
> - [High] This problem wasn't introduced by this patch, but the flow_cfg
> setup used by representor TC offload has broken locking and error…
> - [High] This problem wasn't introduced by this patch, but
> rvu_rep_state_evt_handler() runs from the AF->PF up-mbox work on…
>
> --
>
> octeontx2-pf: Fix potential use-after-free in representor teardown
>
> This patch reorders rvu_rep_destroy() so that rep->flow_cfg is freed
> before free_netdev() releases the netdev allocation that holds the
> representor private data.
>
> > diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
> > index 0f5d5642d3f7a..662da7fc39536 100644
> > --- a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
> > +++ b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
> > @@ -638,8 +638,8 @@ void rvu_rep_destroy(struct otx2_nic *priv)
> > rep = priv->reps[rep_id];
> > unregister_netdev(rep->netdev);
> > rvu_rep_devlink_port_unregister(rep);
> > - free_netdev(rep->netdev);
> > kfree(rep->flow_cfg);
> > + free_netdev(rep->netdev);
>
> [Severity: Critical]
> Can rep->stats_wrk still be pending when free_netdev() releases the
> rep_dev here?
>
> The rep_dev lives in the netdev private area. Nothing in rep.c ever
> cancels stats_wrk. rvu_rep_get_stats64() re-arms it on every stats read:
>
> drivers/net/ethernet/marvell/octeontx2/nic/rep.c:rvu_rep_get_stats64() {
> ...
> schedule_delayed_work(&rep->stats_wrk, msecs_to_jiffies(100));
> }
>
> The unregister_netdev() call just above seems to arm it too:
>
> unregister_netdev()
> unregister_netdevice_many_notify()
> rtmsg_ifinfo_build_skb(RTM_DELLINK, ...)
> dev_get_stats()
> rvu_rep_get_stats64()
> schedule_delayed_work(&rep->stats_wrk, ...)
>
> When the timer fires about 100ms later, rvu_rep_get_stats() would run on
> the freed allocation:
>
> rep = container_of(del_work, struct rep_dev, stats_wrk);
> priv = rep->mdev;
>
> mutex_lock(&priv->mbox.lock);
> ...
> stats = &rep->stats;
> stats->rx_bytes = rsp->rx.octs;
>
> It reads rep->mdev from freed memory, takes a mutex through that pointer,
> and writes into rep->stats. The timer embedded in the delayed_work also
> stays linked in the timer wheel after the free.
>
> This can happen on devlink eswitch mode set to legacy, PCI remove, or
> module unload, for any representor that has RVU_REP_VF_INITIALIZED set.
> After a module unload, the handler could also run after the module text
> is gone.
>
> The error unwind in rvu_rep_create() has the same pattern:
>
> while (--rep_id >= 0) {
> rep = priv->reps[rep_id];
> unregister_netdev(rep->netdev);
> rvu_rep_devlink_port_unregister(rep);
> free_netdev(rep->netdev);
> }
>
> This patch targets a use-after-free of the rep private data in this loop.
> Should it also add cancel_delayed_work_sync(&rep->stats_wrk) before
> free_netdev() in both teardown paths?

The above does seem to be a legitimate bug.
However, I believe it is also pre-existing and can be handled
separately to this patch.

Reviewed-by: Simon Horman <horms@xxxxxxxxxx>