All of lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: anthony.l.nguyen@intel.com
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	edumazet@kernel.org, andrew+netdev@lunn.ch, willemb@google.com,
	netdev@vger.kernel.org, tianxun.ng@bytedance.com,
	oss.patchbox@gmail.com, luckilystar08@gmail.com,
	emil.s.tantilov@intel.com, richardcochran@gmail.com,
	milena.olech@intel.com, konstantin.ilichev@intel.com,
	stable@vger.kernel.org, Samuel.salin@intel.com
Subject: Re: [PATCH net v2 2/6] idpf: ignore Tx timestamp replies once removal has started
Date: Sat, 05 Dec 2026 20:47:11 +0000	[thread overview]
Message-ID: <179650363113.3148.2771200929909107480@kernel.org> (raw)
In-Reply-To: <20261204194642.3048406-3-anthony.l.nguyen@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 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] This patch closes only one of the paths that use the Tx
  timestamp trackers after they are freed on remove (and, once the later…

--

idpf: ignore Tx timestamp replies once removal has started

When IDPF_REMOVE_IN_PROG is set, this patch makes idpf_vc_core_deinit()
wait for mbx_task to finish before releasing the PTP state. It then queues
mbx_task again right away, so replies to synchronous transactions are still
handled during vport teardown. It also makes
idpf_ptp_get_tx_tstamp_async_handler() return early once
IDPF_REMOVE_IN_PROG is set.

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> index c89783966bae3..348c7875134ad 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> @@ -3262,8 +3262,18 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter)
>  
>  	/* Avoid transaction timeouts when called during reset */
>  	remove_in_prog = test_bit(IDPF_REMOVE_IN_PROG, adapter->flags);
> -	if (!remove_in_prog)
> +	if (!remove_in_prog) {
>  		libie_ctlq_xn_shutdown(adapter->xnm);
> +	} else {
> +		/* The transaction manager stays up for the teardown below, so
> +		 * async replies can still arrive. Wait for a mailbox task that
> +		 * may be running an async callback; callbacks that run later
> +		 * see IDPF_REMOVE_IN_PROG and leave the state released below
> +		 * alone.
> +		 */
> +		cancel_delayed_work_sync(&adapter->mbx_task);
> +		queue_delayed_work(adapter->mbx_wq, &adapter->mbx_task, 0);
> +	}
>  
>  	idpf_ptp_release(adapter);
>  	idpf_deinit_task(adapter);

[Severity: High]
The mailbox async handler is gated now. Are other users of the Tx
timestamp trackers still live at this point?

idpf_ptp_release() still runs before idpf_deinit_task(). NAPI and xmit for
the vports are stopped only later, in:

idpf_deinit_task()->idpf_vport_dealloc()->idpf_vport_stop()

Neither idpf_remove() nor idpf_shutdown() closes or detaches the netdevs
before this. So the datapath can still be running while
idpf_ptp_release_vport_tstamp() does this:

	cancel_work_sync(&vport->tstamp_task);
	...
	kfree(vport->tx_tstamp_caps);
	vport->tx_tstamp_caps = NULL;

Only the vport pointer is cleared. Each txq->cached_tstamp_caps, set in
idpf_vport_init_fast_path_txqs(), still points at the freed object.

On xmit, idpf_tx_tstamp()->idpf_ptp_get_txq_tstamp_capability() reads
txq->cached_tstamp_caps->access. idpf_ptp_request_ts() then does:

	spin_lock(&tx_q->cached_tstamp_caps->latches_lock);

	head = &tx_q->cached_tstamp_caps->latches_free;
	...

Can this take the lock and move list entries in freed memory?

On Tx completion, idpf_tx_clean_bufs() calls idpf_tx_read_tstamp() for an
skb that has SKBTX_IN_PROGRESS set:

	tx_tstamp_caps = txq->cached_tstamp_caps;
	spin_lock_bh(&tx_tstamp_caps->status_lock);
	...
		tx_tstamp_status->skb = skb;
		tx_tstamp_status->state = IDPF_PTP_REQUEST;
		...
		queue_work(system_dfl_wq, txq->tstamp_task);

Doesn't this write into the freed tracker? It also queues tstamp_task
again after the only cancel_work_sync().

If tstamp_task runs again, idpf_tstamp_task()->idpf_ptp_get_tx_tstamp()
has no NULL or IDPF_REMOVE_IN_PROG check:

	tx_tstamp_caps = vport->tx_tstamp_caps;
	head = &tx_tstamp_caps->latches_in_use;

	size = struct_size(send_tx_tstamp_msg, tstamp_latches,
			   tx_tstamp_caps->num_entries);

Would this oops on the NULL tx_tstamp_caps?

Nothing cancels tstamp_task again before
idpf_vport_dealloc()->idpf_vport_rel() frees the vport. Could a late run
also reach the freed vport through container_of()?

The commit message describes the bug as code that "reads
vport->tx_tstamp_caps and takes its lock after
idpf_ptp_release_vport_tstamp() may already have freed it". The new
comment says later callbacks "leave the state released below alone".

The xmit, Tx completion and tstamp_task paths reach the same object in the
same window. The later patch in this series sets IDPF_REMOVE_IN_PROG on
shutdown, so shutdown would be exposed to these paths too. This code is
also unchanged at the end of the series. The order is still
idpf_ptp_release() and then idpf_deinit_task(), cached_tstamp_caps is
never cleared, and idpf_ptp_get_tx_tstamp() has no check.

To trigger this, HW Tx timestamping has to be enabled (SIOCSHWTSTAMP) and
SO_TIMESTAMPING traffic has to be flowing when the device is removed or
shut down.

Would it work better to quiesce Tx first, or to release the trackers only
after idpf_deinit_task() has stopped the vports?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204194642.3048406-1-anthony.l.nguyen%40intel.com

  reply	other threads:[~2026-12-05 20:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 19:46 [PATCH net v2 0/6][pull request] Intel Wired LAN Driver Updates 2026-11-25 (idpf) Tony Nguyen
2026-12-04 19:46 ` [PATCH net v2 1/6] idpf: Fix vport IRQ name leak on request failure Tony Nguyen
2026-12-04 19:46 ` [PATCH net v2 2/6] idpf: ignore Tx timestamp replies once removal has started Tony Nguyen
2026-12-05 20:47   ` netdev-bot+sashiko [this message]
2026-12-04 19:46 ` [PATCH net v2 3/6] idpf: ignore link events " Tony Nguyen
2026-12-05 20:47   ` netdev-bot+sashiko
2026-12-04 19:46 ` [PATCH net v2 4/6] idpf: keep the mailbox up while tearing down vports on shutdown Tony Nguyen
2026-12-05 20:47   ` netdev-bot+sashiko
2026-12-04 19:46 ` [PATCH net v2 5/6] idpf: fix use-after-free in the PTP auxiliary worker Tony Nguyen
2026-12-05 20:47   ` netdev-bot+sashiko
2026-12-04 19:46 ` [PATCH net v2 6/6] idpf: release PTP before freeing vports on the init task error path Tony Nguyen
2026-12-05 20:47   ` netdev-bot+sashiko
2026-12-04 19:53 ` [PATCH net v2 0/6][pull request] Intel Wired LAN Driver Updates 2026-11-25 (idpf) netdev-bot+sinfo

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=179650363113.3148.2771200929909107480@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Samuel.salin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=emil.s.tantilov@intel.com \
    --cc=konstantin.ilichev@intel.com \
    --cc=kuba@kernel.org \
    --cc=luckilystar08@gmail.com \
    --cc=milena.olech@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss.patchbox@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=tianxun.ng@bytedance.com \
    --cc=willemb@google.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.