* Re: [PATCH net] octeontx2-pf: Fix potential use-after-free in representor teardown
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
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-16 14:18 UTC (permalink / raw)
To: Guangshuo Li
Cc: Sunil Goutham, Geetha sowjanya, Ratheesh Kannoth,
Subbaraya Sundeep, Bharat Bhushan, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] octeontx2-pf: Fix potential use-after-free in representor teardown
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
2 siblings, 0 replies; 4+ messages in thread
From: Ratheesh Kannoth @ 2026-11-17 8:37 UTC (permalink / raw)
To: Guangshuo Li
Cc: Sunil Goutham, Geetha sowjanya, Subbaraya Sundeep, Bharat Bhushan,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
On 2026-11-16 at 19:42:10, Guangshuo Li (liguangshuo@mail.sdu.edu.cn) wrote:
> The representor private data resides in its netdev allocation.
> rvu_rep_destroy() frees that allocation before reading rep->flow_cfg to
> release the flow configuration.
>
> Release the configuration while the representor is still alive.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: 6c40ca957fe5 ("octeontx2-pf: Adds TC offload support")
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
> ---
> drivers/net/ethernet/marvell/octeontx2/nic/rep.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
> index 0f5d5642d3f7..662da7fc3953 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);
> }
> kfree(priv->reps);
> rvu_rep_rsrc_free(priv);
>
> base-commit: 2e54b3e187300893688c2c7517894f5d96732e05
Reviewed-by: Ratheesh Kannoth <rkannoth@marvell.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] octeontx2-pf: Fix potential use-after-free in representor teardown
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
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 14:13 UTC (permalink / raw)
To: liguangshuo
Cc: sgoutham, gakula, rkannoth, sbhatta, bbhushan2, andrew+netdev,
davem, edumazet, kuba, pabeni, netdev, linux-kernel
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?
> }
> kfree(priv->reps);
[Severity: High]
This isn't a bug introduced by this patch, but can
rvu_rep_state_evt_handler() still run against the freed reps here?
It runs from the AF->PF up-mbox work on pf->mbox_wq:
otx2_mbox_up_handler_rep_event_up_notify()
rvu_event_up_notify()
rvu_rep_state_evt_handler()
It looks up the rep and does a read-modify-write without a lock:
rep = priv->reps[rep_id];
if (info->evt_data.vf_state)
rep->flags |= RVU_REP_VF_INITIALIZED;
else
rep->flags &= ~RVU_REP_VF_INITIALIZED;
rvu_rep_destroy() frees each rep with free_netdev() and then frees
priv->reps. It does not flush pf->mbox_wq, does not clear priv->reps, and
shares no lock with that handler.
rvu_eswitch_config(priv, false) doesn't seem to order this either. On
the AF side, the NIX LF start/stop handlers check rvu->rep_mode without
synchronization and send the PFVF_STATE up message without waiting for a
response. rvu_mbox_handler_esw_cfg() also updates rep_mode without
synchronization.
Suppose a VF's NIX LF starts or stops while the eswitch is being switched
to legacy or the device is being removed. Could the handler then read the
freed priv->reps array and modify flags in a freed rep_dev?
> rvu_rep_rsrc_free(priv);
[Severity: Critical]
This is a pre-existing issue, but are priv->netdev and priv->flow_cfg
left dangling after the loop above?
rvu_rep_setup_tc_cb() copies the per-representor pointers into the
representor PF's otx2_nic:
priv->netdev = rep->netdev;
priv->flags = rep->flags;
priv->pcifunc = rep->pcifunc;
priv->flow_cfg = rep->flow_cfg;
Nothing restores or clears these fields, and the loop frees both objects.
Several paths use the stale pointers afterwards.
The first is in rvu_rep_destroy() itself, when SQEs are still pending:
rvu_rep_rsrc_free()
otx2_free_hw_resources()
otx2_free_pending_sqe()
txq = netdev_get_tx_queue(pfvf->netdev, sq_idx);
netdev_tx_completed_queue(txq, tx_pkts, tx_bytes);
This writes into the TX queue array that free_netdev() already freed.
The second is devlink. The params stay registered after the switch to
legacy mode. otx2_dl_mcam_count_get() and otx2_dl_ucast_flt_cnt_get()
read the freed flow_cfg, and otx2_dl_mcam_count_set() writes to it:
pfvf->flow_cfg->ntuple_cnt = ctx->val.vu16;
otx2_alloc_mcam_entries(pfvf, ctx->val.vu16);
DEVLINK_CMD_PARAM_GET doesn't require GENL_ADMIN_PERM, so any user can
trigger the reads.
The third is switching back to switchdev. That goes through
rvu_rep_create()->rvu_rep_rsrc_init()->otx2_init_hw_resources()->
otx2_pool_aq_init(), which does:
pp_params.netdev = pfvf->netdev;
pool->page_pool = page_pool_create(&pp_params);
page_pool_list() then does hlist_add_head() into the freed
netdev->page_pools and sends a netlink event for the freed net_device.
Should this teardown also clear priv->netdev, priv->flow_cfg and the
copied flags?
[Severity: High]
This is a pre-existing issue, but the flow_cfg freed above is set up by
rvu_rep_mcam_flow_init(), which seems to have locking and error handling
problems.
rvu_rep_mcam_flow_init() sends NPC_MCAM_ALLOC_ENTRY messages without
holding priv->mbox.lock, and then always unlocks it:
if (allocated)
sort(&rep->flow_cfg->flow_ent[0], allocated,
sizeof(rep->flow_cfg->flow_ent[0]), mcam_entry_cmp, NULL);
mutex_unlock(&priv->mbox.lock);
Neither this function nor rvu_rep_setup_tc_cb() takes the mutex. Lockdep
would report a bad unlock balance on the first flower setup.
Without lockdep, can this release the mutex while another user holds it,
such as the rvu_rep_get_stats() worker, rvu_rep_notify_pfvf() or
rvu_eswitch_config()?
The caller also ignores the return value:
if (!(rep->flags & OTX2_FLAG_TC_FLOWER_SUPPORT))
rvu_rep_mcam_flow_init(rep);
...
priv->flow_cfg = rep->flow_cfg;
If the kzalloc fails, rep->flow_cfg is NULL. If the flow_ent kcalloc
fails, the early return skips INIT_LIST_HEAD() on flow_list and
flow_list_tc.
otx2_tc_add_flow() checks OTX2_FLAG_TC_FLOWER_SUPPORT, but
otx2_tc_del_flow() and otx2_tc_get_flow_stats() do not. Both reach
otx2_tc_get_entry_by_cookie(), which walks flow_cfg->flow_list_tc. Can
that dereference a NULL or uninitialized list head?
Finally, the flower support flags are only set when allocated is non-zero.
If the AF allocates no MCAM entries, every later TC callback re-runs the
init and overwrites rep->flow_cfg. Does that leak the previous flow_cfg
and flow_ent each time? The FLOW_CLS_STATS callbacks from filter dumps
don't need CAP_NET_ADMIN.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-c29ba55625-net-otx2-representor%40mail.sdu.edu.cn
^ permalink raw reply [flat|nested] 4+ messages in thread