From: netdev-bot+sashiko@kernel.org
To: guohongyu@cmss.chinamobile.com
Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, alan.brady@intel.com,
stable@vger.kernel.org, 13057616121@163.com
Subject: Re: [PATCH v2] idpf: fix vport_id used as array index in MAC filter async handler
Date: Fri, 27 Nov 2026 09:35:39 +0000 [thread overview]
Message-ID: <179577213934.3135.4441263933524263637@kernel.org> (raw)
In-Reply-To: <20261126092627.255454-1-guohongyu@cmss.chinamobile.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · 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).
- [High] The new `test_bit(IDPF_REMOVE_IN_PROG)` check in
idpf_mac_filter_async_handler()…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the commit
message's own reasoning ('during driver removal the vports are freed…
--
idpf: fix vport_id used as array index in MAC filter async handler
This commit changes idpf_mac_filter_async_handler() so that it indexes
adapter->vport_config[] with vport->idx instead of the raw vport_id from
the message. It also returns early if IDPF_REMOVE_IN_PROG is set. It fixes
the filter removal loop so that removed entries are freed and never
deleted twice.
> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> index c89783966bae3..4ffb8f9df2797 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> @@ -3837,6 +3837,10 @@ static void idpf_mac_filter_async_handler(void *ctx,
> if (!status || status == -ETIMEDOUT)
> return;
>
> + /* vports are freed during removal, before this work is cancelled */
> + if (test_bit(IDPF_REMOVE_IN_PROG, adapter->flags))
> + return;
> +
> ma_list = buff->iov_base;
> /* make sure at least struct is there */
> if (buff->iov_len < sizeof(*ma_list))
[ ... ]
> @@ -3852,7 +3856,7 @@ static void idpf_mac_filter_async_handler(void *ctx,
> if (!vport)
> goto invalid_payload;
>
> - vport_config = adapter->vport_config[le32_to_cpu(ma_list->vport_id)];
> + vport_config = adapter->vport_config[vport->idx];
[Severity: High]
Does the IDPF_REMOVE_IN_PROG check close the removal race described in the
commit message? The test_bit() is a lockless snapshot. Nothing keeps the
vport alive once the check has passed.
The handler runs from mbx_task, and the only lock held is xn->xn_lock:
idpf_mbx_task()
libie_ctlq_xn_recv()
libie_ctlq_xn_process_recv()
xn->resp_cb() -> idpf_mac_filter_async_handler()
If the handler sees the bit clear, idpf_remove() can set it right after
and carry on:
idpf_remove()
set_bit(IDPF_REMOVE_IN_PROG, adapter->flags);
idpf_vc_core_deinit()
idpf_deinit_task()
idpf_vport_dealloc()
idpf_vport_rel()
kfree(vport);
adapter->vports[i] = NULL;
idpf_vid_to_vport() reads adapter->vports[i] without a lock. It can
therefore return a vport that has already been freed but whose slot has
not been cleared yet. The new vport->idx read would then come from freed
memory. The spin_lock_bh(), list_del() and kfree(f) that follow would act
on whatever vport_config that stale index selects.
Before this patch, the handler only NULL-checked vport and never
dereferenced it.
Normally the synchronous DESTROY_VPORT in idpf_vport_rel() bounds this
window, because only mbx_task completes sync transactions. But there are
two cases where teardown doesn't wait on mbx_task:
- idpf_send_mb_msg() returns -EBUSY right away when
idpf_is_reset_detected() is true.
- libie_ctlq_xn_send() can fail fast with -EAGAIN when no xn is free.
On PREEMPT_RT, or under vCPU preemption, the handler can also stall between
the test_bit() and the vport->idx read.
Could the handler avoid touching the vport at all? idpf_vid_to_vport()
already finds the slot i where adapter->vport_ids[i] == v_id, and
vport->idx == i. adapter->vport_config[i] stays allocated until after
mbx_task is cancelled. Using the matched slot index would fix the out of
bounds read without needing the flag check.
Another option is to shut down xn and flush mbx_task before the vports are
freed.
[Severity: High]
This isn't a bug introduced by this patch, but the commit message's
reasoning ("During driver removal the vports are freed before the mailbox
work is cancelled") applies equally to idpf_handle_event_link(). That
handler runs from the same mbx_task, via idpf_recv_event_msg(), for
VIRTCHNL2_EVENT_LINK_CHANGE:
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c:idpf_handle_event_link() {
vport = idpf_vid_to_vport(adapter, le32_to_cpu(v2e->vport_id));
...
np = netdev_priv(vport->netdev);
np->link_speed_mbps = le32_to_cpu(v2e->link_speed);
...
vport->link_up = v2e->link_status;
...
}
In idpf_vport_dealloc(), idpf_decfg_netdev() frees the netdev and sets
vport->netdev = NULL. adapter->vports[i] stays published until
idpf_vport_rel() returns:
drivers/net/ethernet/intel/idpf/idpf_lib.c:idpf_vport_dealloc() {
...
idpf_decfg_netdev(vport);
...
idpf_vport_rel(vport);
adapter->vports[i] = NULL;
...
}
That window includes the synchronous DESTROY_VPORT round trip, and mbx_task
keeps dispatching ARQ events during it.
Could a link change event processed in that window hit netdev_priv(NULL)
and oops on the np->link_speed_mbps write? If the event arrives after
kfree(vport) in idpf_vport_rel(), the vport->link_up write would also land
in freed memory.
Neither idpf_mbx_task() nor idpf_recv_event_msg() checks
IDPF_REMOVE_IN_PROG. Copying the test_bit() check here would leave the same
race as above.
Either of these might cover both handlers:
- clear adapter->vports[i] before tearing down the netdev and the vport
- stop mbx event dispatch before the vports are freed
> ma_list_head = &vport_config->user_config.mac_filter_list;
>
> /* We can't do much to reconcile bad filters at this point, however we
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126092627.255454-1-guohongyu%40cmss.chinamobile.com
next prev parent reply other threads:[~2026-11-27 9:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 2:08 [PATCH] idpf: fix vport_id used as array index in MAC filter async handler guohongyu
2026-11-26 2:18 ` netdev-bot+sinfo
2026-11-26 2:35 ` guohongyu
2026-11-26 5:09 ` Przemek Kitszel
2026-11-26 9:26 ` [PATCH v2] " Hongyu Guo
2026-11-26 9:38 ` netdev-bot+sinfo
2026-11-27 8:44 ` Przemek Kitszel
2026-11-27 9:35 ` netdev-bot+sashiko [this message]
2026-11-27 2:17 ` [PATCH] " netdev-bot+sashiko
2026-11-27 2:32 ` [PATCH v2] " Hongyu Guo
2026-11-27 2:33 ` Hongyu Guo
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=179577213934.3135.4441263933524263637@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=13057616121@163.com \
--cc=alan.brady@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=guohongyu@cmss.chinamobile.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=stable@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox