public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aditya Garg" <gargaditya@linux.microsoft.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v2 2/2] net: mana: Use kvmalloc for large RX queue and buffer allocations
Date: Tue, 28 Apr 2026 17:47:16 +0000	[thread overview]
Message-ID: <20260428174716.E8E57C2BCAF@smtp.kernel.org> (raw)
In-Reply-To: <20260427132807.1642290-3-gargaditya@linux.microsoft.com>

Sashiko AI review found 1 potential issue(s):
- [High] The error path in `mana_create_rxq()` accesses and attempts to double-free a CQ object embedded within an `rxq` structure that has already been freed, leading to a Use-After-Free and Double Free.
--

commit 2b2a9ca2dc8ac87d8832a2a8e0d3a6c8f2d70ca9
Author: Aditya Garg <gargaditya@linux.microsoft.com>

net: mana: Use kvmalloc for large RX queue and buffer allocations

This commit switches the RX path allocations for pre-allocated buffers and
queues from kmalloc to kvmalloc variants to handle fragmented contiguous
memory, and updates the free paths to use kvfree.

> diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
> index 8adf72b96145..e1d8ac3417e8 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_en.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
[ ... ]
> @@ -2564,7 +2564,7 @@ static void mana_destroy_rxq(struct mana_port_context *apc,
>  	if (rxq->gdma_rq)
>  		mana_gd_destroy_queue(gc, rxq->gdma_rq);
>  
> -	kfree(rxq);
> +	kvfree(rxq);
>  }

Does this change to kvfree() expose an existing use-after-free in the error
path of mana_create_rxq()?

In mana_create_rxq(), cq is initialized as a pointer into the rxq structure:

	cq = &rxq->rx_cq;

If an error occurs later in the function, the cleanup path calls
mana_destroy_rxq(), which frees rxq, and then it accesses cq again:

out:
	if (!err)
		return rxq;

	netdev_err(ndev, "Failed to create RXQ: err = %d\n", err);

	mana_destroy_rxq(apc, rxq, false);

	if (cq)
		mana_deinit_cq(apc, cq);

Because mana_destroy_rxq() now uses kvfree(rxq), if the allocation fell back
to vmalloc, the memory will be unmapped immediately. Can accessing cq inside
mana_deinit_cq() trigger a page fault here?

Also, since mana_destroy_rxq() already calls mana_deinit_cq(apc, &rxq->rx_cq)
before freeing rxq, does calling it a second time in the out path result in a
double-free?

> @@ -2704,7 +2704,7 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
>  
>  	gc = gd->gdma_context;
>  
> -	rxq = kzalloc_flex(*rxq, rx_oobs, apc->rx_queue_size);
> +	rxq = kvzalloc_flex(*rxq, rx_oobs, apc->rx_queue_size);
>  	if (!rxq)
>  		return NULL;
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260427132807.1642290-1-gargaditya@linux.microsoft.com?part=2

  reply	other threads:[~2026-04-28 17:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27 13:23 [PATCH net-next v2 0/2] net: mana: Avoid queue struct allocation failure under memory fragmentation Aditya Garg
2026-04-27 13:23 ` [PATCH net-next v2 1/2] net: mana: Use per-queue allocation for tx_qp to reduce allocation size Aditya Garg
2026-04-27 13:23 ` [PATCH net-next v2 2/2] net: mana: Use kvmalloc for large RX queue and buffer allocations Aditya Garg
2026-04-28 17:47   ` sashiko-bot [this message]
2026-04-27 23:19 ` [PATCH net-next v2 0/2] net: mana: Avoid queue struct allocation failure under memory fragmentation Jakub Kicinski

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=20260428174716.E8E57C2BCAF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=gargaditya@linux.microsoft.com \
    --cc=sashiko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox