Netdev List
 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, 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 5/6] idpf: fix use-after-free in the PTP auxiliary worker
Date: Thu, 26 Nov 2026 23:40:15 +0000	[thread overview]
Message-ID: <179573641527.3135.11397629327838341318@kernel.org> (raw)
In-Reply-To: <20261125225145.4126333-6-anthony.l.nguyen@intel.com>

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

Critical: 0 · High: 1 · Medium: 0 · Low: 1

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 makes idpf leak the top-level Rx queue group array
  every time a vport is stopped, and also on the allocation error path.
- [Low] idpf: inaccurate Fixes trailer citing 1a49cf814fe1 instead of
  494565a74502

--

idpf: fix use-after-free in the PTP auxiliary worker

This patch adds a per-vport rxq_grps_lock that serializes changes to
rsrc->rxq_grps against the PTP auxiliary worker. idpf_rxq_group_rel() now
clears the pointer under the lock and passes the array to a new
idpf_rxq_grps_free() helper. idpf_rxq_group_alloc() now builds the array
privately and publishes it at the end. The patch also clears the stale
pointer in the soft reset clone and fixes a NULL check in
idpf_ptp_update_phctime_rxq_grp().

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> index 281b96daa5c1a..968b62f89d873 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> @@ -1357,16 +1357,15 @@ static void idpf_rxq_sw_queue_rel(struct idpf_rxq_group *rx_qgrp)
>  }
>  
>  /**
> - * idpf_rxq_group_rel - Release all resources for rxq groups
> + * idpf_rxq_grps_free - Free an Rx queue group array and everything in it
>   * @rsrc: pointer to queue and vector resources
> + * @rxq_grps: group array to free, not reachable through @rsrc any more
>   */
> -static void idpf_rxq_group_rel(struct idpf_q_vec_rsrc *rsrc)
> +static void idpf_rxq_grps_free(struct idpf_q_vec_rsrc *rsrc,
> +			       struct idpf_rxq_group *rxq_grps)
>  {
> -	if (!rsrc->rxq_grps)
> -		return;
> -
>  	for (unsigned int i = 0; i < rsrc->num_rxq_grp; i++) {
> -		struct idpf_rxq_group *rx_qgrp = &rsrc->rxq_grps[i];
> +		struct idpf_rxq_group *rx_qgrp = &rxq_grps[i];
>  		u16 num_rxq;
>  
>  		if (idpf_is_queue_model_split(rsrc->rxq_model)) {
> @@ -1391,14 +1390,37 @@ static void idpf_rxq_group_rel(struct idpf_q_vec_rsrc *rsrc)
>  	rsrc->rxq_grps = NULL;
>  }
>  
> +/**
> + * idpf_rxq_group_rel - Release all resources for rxq groups
> + * @vport: vport the queue groups belong to
> + * @rsrc: pointer to queue and vector resources
> + */
> +static void idpf_rxq_group_rel(struct idpf_vport *vport,
> +			       struct idpf_q_vec_rsrc *rsrc)
> +{
> +	struct idpf_rxq_group *rxq_grps;
> +
> +	if (!rsrc->rxq_grps)
> +		return;
> +
> +	spin_lock(&vport->rxq_grps_lock);
> +	rxq_grps = rsrc->rxq_grps;
> +	rsrc->rxq_grps = NULL;
> +	spin_unlock(&vport->rxq_grps_lock);
> +
> +	idpf_rxq_grps_free(rsrc, rxq_grps);

[Severity: High]
Does this leak the rxq_grps array?

The last two lines of idpf_rxq_grps_free() are unchanged from the old
idpf_rxq_group_rel(). They still free through rsrc, not through the new
argument:

drivers/net/ethernet/intel/idpf/idpf_txrx.c:idpf_rxq_grps_free() {
    ...
	kfree(rsrc->rxq_grps);
	rsrc->rxq_grps = NULL;
}

By the time the helper runs here, rsrc->rxq_grps has already been set to
NULL under rxq_grps_lock, so this is kfree(NULL). The helper frees the
contents of each group through rxq_grps[i], but the array allocated by
kzalloc_objs() is never freed.

This path runs on every interface down, every soft reset (channel, ring,
MTU or GRO_HW changes) and every vport dealloc:

idpf_vport_stop()
  idpf_vport_queues_rel()
    idpf_vport_queue_grp_rel_all()
      idpf_rxq_group_rel()
        idpf_rxq_grps_free()

The error path in idpf_rxq_group_alloc() seems to have the same problem:

err_alloc:
	idpf_rxq_grps_free(rsrc, rxq_grps);

Here rxq_grps was never published to rsrc->rxq_grps, so again only
kfree(NULL) runs. The err_out path in idpf_vport_queue_grp_alloc_all()
calls idpf_vport_queue_grp_rel_all(), but that does not free it either,
because idpf_rxq_group_rel() returns early when rsrc->rxq_grps is NULL.

Also, the helper's rsrc->rxq_grps = NULL store writes the protected pointer
without holding rxq_grps_lock. The new @rxq_grps_lock kernel-doc says the
lock serializes every transition of that pointer.

The same code is still there at the end of the series (73aecc14293f).

Should idpf_rxq_grps_free() end with kfree(rxq_grps) and leave
rsrc->rxq_grps alone?

> +}
> +

[ ... ]

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_ptp.c b/drivers/net/ethernet/intel/idpf/idpf_ptp.c
> --- a/drivers/net/ethernet/intel/idpf/idpf_ptp.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_ptp.c
> @@ -348,9 +348,11 @@ idpf_ptp_update_phctime_rxq_grp(const struct idpf_rxq_group *grp, bool split,
>  		}
>  	} else {
>  		for (i = 0; i < grp->splitq.num_rxq_sets; i++) {
> +			if (!grp->splitq.rxq_sets[i])
> +				continue;
> +
>  			rxq = &grp->splitq.rxq_sets[i]->rxq;
> -			if (rxq)
> -				WRITE_ONCE(rxq->cached_phc_time, systime);
> +			WRITE_ONCE(rxq->cached_phc_time, systime);
>  		}
>  	}
>  }

[Severity: Low]
Is the Fixes tag pointing at the right commit?

As far as I can tell, in 1a49cf814fe1 ("idpf: add Tx timestamp flows")
idpf_ptp_update_cached_phctime() only refreshed
adapter->ptp->cached_phc_time and adapter->ptp->cached_phc_jiffies. It
did not walk the vports and never touched rxq_grps.

The code this patch fixes seems to come from 494565a74502 ("idpf: add
support for Rx timestamping"). That commit added the
idpf_for_each_vport() loop that reads vport->dflt_qv_rsrc.rxq_grps.
It also added idpf_ptp_update_phctime_rxq_grp(), including the
always-true test on &grp->splitq.rxq_sets[i]->rxq.

This is going to net and will be picked up for stable. Should the
trailer be the following instead?

Fixes: 494565a74502 ("idpf: add support for Rx timestamping")

As it stands, stable trees that carry 1a49cf814fe1 but not the Rx
timestamping commit would be told they need this fix. They do not
contain the Rx queue walk at all, so the patch would not apply there.

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

  reply	other threads:[~2026-11-26 23:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 22:51 [PATCH net 0/6][pull request] Intel Wired LAN Driver Updates 2026-11-25 (idpf) Tony Nguyen
2026-11-25 22:51 ` [PATCH net 1/6] idpf: Fix vport IRQ name leak on request failure Tony Nguyen
2026-11-25 22:51 ` [PATCH net 2/6] idpf: ignore Tx timestamp replies once removal has started Tony Nguyen
2026-11-25 22:51 ` [PATCH net 3/6] idpf: ignore link events " Tony Nguyen
2026-11-26 23:40   ` netdev-bot+sashiko
2026-11-25 22:51 ` [PATCH net 4/6] idpf: keep the mailbox up while tearing down vports on shutdown Tony Nguyen
2026-11-26 23:40   ` netdev-bot+sashiko
2026-11-25 22:51 ` [PATCH net 5/6] idpf: fix use-after-free in the PTP auxiliary worker Tony Nguyen
2026-11-26 23:40   ` netdev-bot+sashiko [this message]
2026-11-25 22:51 ` [PATCH net 6/6] idpf: release PTP before freeing vports on the init task error path Tony Nguyen
2026-11-25 22:58 ` [PATCH net 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=179573641527.3135.11397629327838341318@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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox