All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stan Iliev" <stani@google.com>, intel-wired-lan@lists.osuosl.org
Subject: Re: [PATCH iwl-next 08/15] idpf: psp: add support for psp rx key allocation
Date: Wed, 18 Nov 2026 16:29:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-221486@kernel.org> (raw)
In-Reply-To: <20261117145522.1910636-9-stani@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] idpf: psp: race with hard reset in idpf_psp_rx_spi_alloc()
- [Low] idpf: psp: wrong reset type in vport_id kernel-doc comment
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Medium] idpf: memory leak of tx_tstamp_caps on RSS error paths in
  idpf_vport_alloc() [1]
--

commit 579b4b79a623f0ec9c780b3ed4bd922d42ad422e
Author: Stan Iliev <stani@google.com>

idpf: psp: add support for psp rx key allocation

This commit adds virtchnl definitions and driver support for allocating
PSP V0 RX keys on demand via the rx_spi_alloc PSP device operation.

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c
> index 1385209519b25..062753a62f593 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_lib.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c
> @@ -1144,6 +1144,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
>  	/* fill vport slot in the adapter struct */
>  	adapter->vports[idx] = vport;
>  	adapter->vport_ids[idx] = idpf_get_vport_id(vport);
> +	/* Copy for the PSP requests that can run while the vports are freed */
> +	if (IS_ENABLED(CONFIG_INET_PSP) && !idx)
> +		WRITE_ONCE(adapter->psp.vport_id, adapter->vport_ids[idx]);

[Severity: Medium]
This problem wasn't introduced by this patch, but does idpf_vport_alloc()
leak vport->tx_tstamp_caps [1] if RSS initialization fails before
adapter->vports[idx] is assigned?

Earlier in idpf_vport_alloc(), idpf_vport_init() calls
idpf_ptp_get_vport_tstamps_caps(), which allocates vport->tx_tstamp_caps
and populates its latches_free list.  If allocating rss_data->rss_key or
idpf_init_rss_lut() then fails, the error path jumps to
deinit_vport_queues or free_rss_key and frees vport without releasing
vport->tx_tstamp_caps, and the caller's cleanup via idpf_ptp_release()
also misses it because adapter->vports[idx] is still NULL:

drivers/net/ethernet/intel/idpf/idpf_lib.c:idpf_vport_alloc() {
    ...
	err = idpf_vport_init(vport, max_q);
	if (err)
		goto free_vport;
    ...
	rss_data->rss_key = kzalloc(rss_data->rss_key_size, GFP_KERNEL);
	if (!rss_data->rss_key)
		goto deinit_vport_queues;
    ...
	err = idpf_init_rss_lut(vport, rss_data);
	if (err)
		goto free_rss_key;

	/* fill vport slot in the adapter struct */
	adapter->vports[idx] = vport;
    ...
free_rss_key:
	kfree(rss_data->rss_key);
	rss_data->rss_key = NULL;
deinit_vport_queues:
	idpf_vport_deinit_queue_reg_chunks(adapter->vport_config[idx]);
free_vport:
	kfree(vport);
}

Calling idpf_ptp_release_vport_tstamp(vport) on the deinit_vport_queues
error path would avoid leaking the timestamp capability structure and its
latch entries.

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp.c b/drivers/net/ethernet/intel/idpf/idpf_psp.c
> index 67f1f1d7508cf..8ce390bcd6178 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_psp.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_psp.c

[ ... ]

> @@ -136,9 +139,49 @@ static int idpf_psp_set_config(struct psp_dev *psd, struct psp_dev_config *conf,
>  	return 0;
>  }
>  
> +/**
> + * idpf_psp_rx_spi_alloc - Allocate a PSP RX SPI and key
> + * @psd: PSP device
> + * @version: PSP version
> + * @key: filled with the allocated SPI and key
> + * @extack: netlink extended ack for error reporting
> + *
> + * Allocate one RX key with a synchronous VIRTCHNL2_OP_PSP_ALLOCATE_KEYS
> + * request.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +static int idpf_psp_rx_spi_alloc(struct psp_dev *psd, u32 version,
> +				 struct psp_key_parsed *key,
> +				 struct netlink_ext_ack *extack)
> +{
> +	struct idpf_adapter *adapter = idpf_netdev_to_adapter(psd->main_netdev);
> +	struct idpf_psp_rx_key rx_key;
> +	int err;
> +
> +	/* Only version 0 keys are allocated, see idpf_psp_register() */
> +	if (psp_key_size(version) != sizeof(rx_key.key)) {
> +		NL_SET_ERR_MSG_MOD(extack, "Unsupported PSP version");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	err = idpf_send_allocate_psp_key(adapter, &rx_key);

[Severity: High]
Can idpf_psp_rx_spi_alloc() race with a hard reset and trigger a
use-after-free or NULL pointer dereference on the default mailbox queues?

idpf_psp_rx_spi_alloc() holds psd->lock, but does not acquire
adapter->vport_ctrl_lock or check idpf_is_reset_in_prog().  When a hard
reset runs, idpf_deinit_dflt_mbx() calls libie_ctlq_xn_deinit(), which
frees adapter->xnm, adapter->asq and adapter->arq before setting those
pointers to NULL:

CPU0                                  CPU1
idpf_init_hard_reset()                psp_nl_rx_assoc_doit()
  idpf_vport_ctrl_lock(adapter)         idpf_psp_rx_spi_alloc()
  idpf_vc_core_deinit(adapter)            idpf_send_allocate_psp_key()
  idpf_deinit_dflt_mbx(adapter)             idpf_send_mb_msg()
    libie_ctlq_xn_deinit(...)                 idpf_is_reset_detected()
      kfree(adapter->arq)                       readl(adapter->arq->...)
                                                  <-- use-after-free
    adapter->arq = NULL

If idpf_send_mb_msg() passes idpf_is_reset_detected() just before
idpf_deinit_dflt_mbx(), or during idpf_init_dflt_mbx() after adapter->arq
is assigned but before adapter->xnm is set, idpf_mb_clean() and
libie_ctlq_xn_send() can also dereference a freed or NULL adapter->asq or
adapter->xnm.

In addition, neither idpf_psp_rx_spi_alloc() nor
idpf_send_allocate_psp_key() checks idpf_is_psp_ena(adapter), so once
idpf_init_dflt_mbx() finishes during a reset, VIRTCHNL2_OP_PSP_ALLOCATE_KEYS
can be sent with a stale vport_id before vport recreation, or after
idpf_psp_init() has disabled PSP offload.

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
> index 0829d0bbd92b2..f21bd7de5ae8c 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
> +++ b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
> @@ -19,6 +32,10 @@
>   * @saidx_width: SA index width granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS
>   * @psp_caps: PSP capabilities granted by VIRTCHNL2_OP_PSP_GET_CAPS, see
>   *	      enum virtchnl2_psp_caps
> + * @vport_id: ID of adapter->vports[0] for the PSP requests. A copy, as the
> + *	      PSP device stays registered while the vports are freed and
> + *	      allocated again during a soft reset. Set in idpf_vport_alloc().

[Severity: Low]
This isn't a bug, but vports are freed and reallocated via
idpf_vport_alloc() during a hard reset rather than a soft reset
(idpf_initiate_soft_reset() only reallocates queue resources on the
existing vport).

[1] https://sashiko.dev/#/bug/linux-9b904fce-205d-411e-be8c-4b18ed5978ec

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117145522.1910636-1-stani@google.com?part=8

  parent reply	other threads:[~2026-11-18 16:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 14:55 [PATCH iwl-next 00/15] idpf: add PSP offload support, part 1 Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 01/15] libie: wipe copied small send buffers on release Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 02/15] idpf: wipe mailbox " Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 03/15] idpf: make the mailbox workqueue visible in sysfs Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 04/15] idpf: psp: add psp offload initialization Stan Iliev
2026-11-17 17:34   ` Daniel Zahka
2026-11-18 16:29   ` sashiko-bot
2026-11-17 14:55 ` [PATCH iwl-next 05/15] idpf: psp: add support for crypto capabilities Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 06/15] idpf: psp: add support for psp capabilities Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 07/15] idpf: psp: add support for fips compliance status Stan Iliev
2026-11-17 20:40   ` Daniel Zahka
2026-11-17 14:55 ` [PATCH iwl-next 08/15] idpf: psp: add support for psp rx key allocation Stan Iliev
2026-11-17 20:57   ` Daniel Zahka
2026-11-18 16:29   ` sashiko-bot [this message]
2026-11-17 14:55 ` [PATCH iwl-next 09/15] idpf: psp: add support for psp key rotation Stan Iliev
2026-11-17 22:15   ` Daniel Zahka
2026-11-17 14:55 ` [PATCH iwl-next 10/15] idpf: psp: add support for psp statistics Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 11/15] idpf: psp: add psp tx key state Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 12/15] idpf: psp: add support for psp tx key deletion Stan Iliev
2026-11-18 16:29   ` sashiko-bot
2026-11-17 14:55 ` [PATCH iwl-next 13/15] idpf: psp: add psp work and tx key insertion completion Stan Iliev
2026-11-18 16:29   ` sashiko-bot
2026-11-17 14:55 ` [PATCH iwl-next 14/15] idpf: psp: add support for psp tx key insertion Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 15/15] idpf: psp: add psp tx key registration Stan Iliev

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=sashiko-outbox-221486@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stani@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.