From: Simon Horman <horms@kernel.org>
To: netdev-bot+sashiko@kernel.org
Cc: liguangshuo@mail.sdu.edu.cn, sgoutham@marvell.com,
gakula@marvell.com, rkannoth@marvell.com, sbhatta@marvell.com,
bbhushan2@marvell.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] octeontx2-pf: Fix potential use-after-free in representor teardown
Date: Fri, 20 Nov 2026 11:06:21 +0000 [thread overview]
Message-ID: <20261120110621.GB860048@horms.kernel.org> (raw)
In-Reply-To: <179501121429.3136.3547762606402557223@kernel.org>
On Wed, Nov 18, 2026 at 02:13:34PM +0000, netdev-bot+sashiko@kernel.org 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@kernel.org>
prev parent reply other threads:[~2026-11-20 11:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 14:12 [PATCH net] octeontx2-pf: Fix potential use-after-free in representor teardown Guangshuo Li
2026-11-16 14:18 ` netdev-bot+sinfo
2026-11-17 8:37 ` Ratheesh Kannoth
2026-11-18 14:13 ` netdev-bot+sashiko
2026-11-20 11:06 ` Simon Horman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120110621.GB860048@horms.kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=bbhushan2@marvell.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=gakula@marvell.com \
--cc=kuba@kernel.org \
--cc=liguangshuo@mail.sdu.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rkannoth@marvell.com \
--cc=sbhatta@marvell.com \
--cc=sgoutham@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.