All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Harshitha Ramamurthy" <hramamurthy@google.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v2 12/15] gve: introduce new methods to handle IRQ doorbells
Date: Wed, 03 Jun 2026 23:59:30 +0000	[thread overview]
Message-ID: <20260603235931.1E4FE1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260602235900.3050782-13-hramamurthy@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] DMA memory for irq_db_indices and counter_array is freed before the hardware is guaranteed to be stopped, allowing the hardware to corrupt kernel memory if admin queue commands time out or fail.
--

commit e39d080d71706978b42ac097e883fbae5157b9ec
Author: Joshua Washington <joshwash@google.com>

gve: introduce new methods to handle IRQ doorbells

This commit introduces request_db_info and free_db_resources to
struct gve_ctrl_ops to encapsulate the configuration of device resources
(counter arrays and IRQ doorbell indices). It also manages GQ ring counters
in request_db_info.

> diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c
> index d814108deeefe..259dcd617216c 100644
> --- a/drivers/net/ethernet/google/gve/gve_adminq.c
> +++ b/drivers/net/ethernet/google/gve/gve_adminq.c
[ ... ]
> @@ -1719,3 +1719,74 @@ void gve_adminq_set_num_queues(struct gve_priv *priv)
[ ... ]
> +int gve_adminq_request_db_info(struct gve_priv *priv)
> +{
[ ... ]
> +	err = gve_adminq_configure_device_resources(priv,
> +						    priv->counter_array_bus,
> +						    priv->num_event_counters,
> +						    priv->irq_db_indices_bus,
> +						    priv->num_ntfy_blks);
> +	if (unlikely(err)) {
> +		dev_err(&priv->pdev->dev,
> +			"could not setup device_resources: err=%d\n", err);
> +		err = -ENXIO;
> +		goto abort_with_irq_db_indices;
> +	}
> +
> +	for (i = 0; i < priv->num_ntfy_blks; i++)
> +		priv->ntfy_blocks[i].irq_db_index =
> +			&priv->irq_db_indices[i].index;
> +	return 0;
> +
> +abort_with_irq_db_indices:
> +	dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks *
> +			  sizeof(*priv->irq_db_indices),
> +			  priv->irq_db_indices, priv->irq_db_indices_bus);
> +	priv->irq_db_indices = NULL;
> +abort_with_counter_array:
> +	gve_free_counter_array(priv);
> +	return err;
> +}

[Severity: High]
Does this error path introduce a use-after-free window? 

If the configure command in gve_adminq_configure_device_resources() times
out (e.g. returns -ETIME), the hardware might still be running and attempting
to access the memory.

Since we immediately free the DMA memory via dma_free_coherent() and
gve_free_counter_array() before the hardware is guaranteed to be stopped, can
the hardware overwrite reallocated kernel memory?

> +
> +void gve_adminq_free_db_resources(struct gve_priv *priv)
> +{
> +	int err;
> +
> +	/* Log error in deconfigure device, but don't fail. This is only ever
> +	 * called as a reset is about to be triggered, so it would be redundant
> +	 * to trigger a reset.
> +	 */
> +	err = gve_adminq_deconfigure_device_resources(priv);
> +	if (err)
> +		dev_err(&priv->pdev->dev,
> +			"Could not deconfigure device resources: err=%d\n",
> +			err);
> +
> +	dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks *
> +			  sizeof(*priv->irq_db_indices),
> +			  priv->irq_db_indices, priv->irq_db_indices_bus);
> +	priv->irq_db_indices = NULL;
> +	gve_free_counter_array(priv);
> +}

[Severity: High]
Could freeing the DMA memory here cause memory corruption? 

In an earlier patch in this series ('gve: simplify reset logic'), the teardown
logic was explicitly fixed to delay freeing shared resources until after
gve_adminq_free() triggers a device reset.

However, gve_teardown_device() executes gve_teardown_control_plane_resources()
(which now calls ops->free_db_resources()) before gve_adminq_free():

drivers/net/ethernet/google/gve/gve_main.c:gve_teardown_device() {
	...
	gve_teardown_notify_blocks(priv);
	gve_teardown_control_plane_resources(priv);
	gve_adminq_free(priv);
	...
}

If the deconfigure command in gve_adminq_deconfigure_device_resources() times
out or fails, the active hardware might continue writing to the freed DMA
memory since the device hasn't been reset yet.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260602235900.3050782-1-hramamurthy@google.com?part=12

  reply	other threads:[~2026-06-03 23:59 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 23:58 [PATCH net-next v2 00/15] gve: AdminQ mode related refactors Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 01/15] gve: don't pass in unused parameter to gve_adminq_free Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 02/15] gve: refactor initialization with helper functions Harshitha Ramamurthy
2026-06-03 23:59   ` sashiko-bot
2026-06-05  3:41   ` Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 03/15] gve: introduce gve_adminq_get_device_properties() Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 04/15] gve: add a few helper functions to set device properties Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 05/15] gve: add struct gve_device_info to hold " Harshitha Ramamurthy
2026-06-03 23:59   ` sashiko-bot
2026-06-05  3:44   ` Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 06/15] gve: introduce control plane operations structure Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 07/15] gve: introduce ctrl ops to set vectors and Qs Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 08/15] gve: refactor gve_init_priv for reset path Harshitha Ramamurthy
2026-06-03 23:59   ` sashiko-bot
2026-06-05  3:52   ` Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 09/15] gve: simplify reset logic Harshitha Ramamurthy
2026-06-03 23:59   ` sashiko-bot
2026-06-07 22:20   ` Joshua Washington
2026-06-02 23:58 ` [PATCH net-next v2 10/15] gve: add gve_ctrl_ops for gve initialization/teardown sequences Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 11/15] gve: split up notify block allocation and setup paths Harshitha Ramamurthy
2026-06-03 23:59   ` sashiko-bot
2026-06-07 22:29   ` Joshua Washington
2026-06-02 23:58 ` [PATCH net-next v2 12/15] gve: introduce new methods to handle IRQ doorbells Harshitha Ramamurthy
2026-06-03 23:59   ` sashiko-bot [this message]
2026-06-07 22:35   ` Joshua Washington
2026-06-02 23:58 ` [PATCH net-next v2 13/15] gve: setup and teardown management interrupts Harshitha Ramamurthy
2026-06-03 23:59   ` sashiko-bot
2026-06-07 22:39   ` Joshua Washington
2026-06-02 23:58 ` [PATCH net-next v2 14/15] gve: add ctrl ops to for queue operations Harshitha Ramamurthy
2026-06-05  3:56   ` Harshitha Ramamurthy
2026-06-02 23:58 ` [PATCH net-next v2 15/15] gve: add link status/speed ctrl ops Harshitha Ramamurthy
2026-06-03 23:59   ` sashiko-bot
2026-06-07 22:45   ` Joshua Washington

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=20260603235931.1E4FE1F00899@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=hramamurthy@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.