Linux-HyperV List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Long Li" <longli@microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH net v4 1/7] net: mana: RCU-protect gc->cq_table lookups against concurrent CQ destroy
Date: Sun, 09 Aug 2026 02:34:59 +0000	[thread overview]
Message-ID: <20260809023500.69AE51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260808023417.1746886-2-longli@microsoft.com>

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

Pre-existing issues:
- [Critical] The NAPI struct for an RX/TX queue is scheduled before it is fully initialized, leading to a NULL pointer dereference (Kernel Panic).
- [High] Dangling `cq_table` entries after RAW/RSS QP destruction cause memory leaks and prevent future QP creation (Cross-process DoS).
--

--- Patch [1]: [PATCH net v4 1/7] net: mana: RCU-protect gc->cq_table lookups against concurrent CQ destroy ---
commit 855b59e3efafe6690d7dd204468e072eef10cb49
Author: Long Li <longli@microsoft.com>

net: mana: RCU-protect gc->cq_table lookups against concurrent CQ destroy

This commit puts the cq_table under RCU protection to prevent a
use-after-free race between the EQ interrupt handler and CQ teardown. It
ensures the slot is cleared and an RCU grace period elapses before freeing
the CQ memory.

> diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c
> index f2547989f4229..2bf4be21cede7 100644
> --- a/drivers/infiniband/hw/mana/cq.c
> +++ b/drivers/infiniband/hw/mana/cq.c
> @@ -131,12 +131,20 @@ static void mana_ib_cq_handler(void *ctx, struct gdma_queue *gdma_cq)
>  int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq)
>  {
>  	struct gdma_context *gc = mdev_to_gc(mdev);
> +	struct gdma_queue __rcu **cq_table;
>  	struct gdma_queue *gdma_cq;
>  
> -	if (cq->queue.id >= gc->max_num_cqs)
> +	/* No rcu_read_lock(): install/remove run within the IB device
> +	 * lifetime, which mana_rdma_remove() (ib_unregister_device) drains
> +	 * before the base cq_table can be freed.  See gdma_context::cq_table
> +	 * in gdma.h for why "true" is sound.
> +	 */
> +	cq_table = rcu_dereference_protected(gc->cq_table, true);
> +	if (!cq_table || cq->queue.id >= gc->max_num_cqs)
>  		return -EINVAL;
> +
>  	/* Create CQ table entry, sharing a CQ between WQs is not supported */
> -	if (gc->cq_table[cq->queue.id])
> +	if (rcu_access_pointer(cq_table[cq->queue.id]))
[Severity: High]
This isn't a bug introduced by this patch, but could this fail permanently due
to a dangling pointer?

If a userspace application creates an RDMA QP with an existing CQ,
mana_ib_create_qp_raw() allocates a WQ/CQ pair and overwrites
send_cq->queue.id. When the QP is destroyed, mana_ib_destroy_qp_raw() tears
down the WQ/CQ in hardware but does not call mana_ib_remove_cq_cb().

This leaves a dangling pointer in cq_table. If the hardware reallocates the
same CQ ID to another process or queue, won't this check see the leaked entry
and prevent further QP creation?

>  		return -EINVAL;
>  	if (cq->queue.kmem)
>  		gdma_cq = cq->queue.kmem;

[ ... ]

> diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
> index 92bb55935c1c4..5d215981bba83 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_en.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c

[ ... ]

> @@ -2596,12 +2619,18 @@ static int mana_create_txq(struct mana_port_context *apc,
>  
>  		cq->gdma_id = cq->gdma_cq->id;
>  
> -		if (WARN_ON(cq->gdma_id >= gc->max_num_cqs)) {
> +		/* No rcu_read_lock(): mana_create_txq runs under RTNL during
> +		 * netdev bring-up, inside the netdev lifetime that
> +		 * mana_remove() drains before the base cq_table can be freed.
> +		 * See gdma_context::cq_table in gdma.h for why "true" is sound.
> +		 */
> +		cq_table = rcu_dereference_protected(gc->cq_table, true);
> +		if (WARN_ON(!cq_table || cq->gdma_id >= gc->max_num_cqs)) {
>  			err = -EINVAL;
>  			goto out;
>  		}
>  
> -		gc->cq_table[cq->gdma_id] = cq->gdma_cq;
> +		rcu_assign_pointer(cq_table[cq->gdma_id], cq->gdma_cq);
[Severity: Critical]
This is a pre-existing issue, but by publishing the CQ to cq_table before the
NAPI struct is initialized, does this open a race window that could lead to a
crash?

Once rcu_assign_pointer() publishes the CQ to cq_table, an early hardware
completion could trigger the EQ interrupt handler mana_gd_process_eqe(), which
can access the published CQ and call mana_schedule_napi().

>  
>  		mana_create_txq_debugfs(apc, i);
>  
> @@ -2621,25 +2650,20 @@ static int mana_create_txq(struct mana_port_context *apc,

[ ... ]

> @@ -2905,12 +2966,18 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
>  	if (err)
>  		goto out;
>  
> -	if (WARN_ON(cq->gdma_id >= gc->max_num_cqs)) {
> +	/* No rcu_read_lock(): mana_create_rxq runs under RTNL during netdev
> +	 * bring-up, inside the netdev lifetime that mana_remove() drains
> +	 * before the base cq_table can be freed.  See gdma_context::cq_table
> +	 * in gdma.h for why "true" is sound.
> +	 */
> +	cq_table = rcu_dereference_protected(gc->cq_table, true);
> +	if (WARN_ON(!cq_table || cq->gdma_id >= gc->max_num_cqs)) {
>  		err = -EINVAL;
>  		goto out;
>  	}
>  
> -	gc->cq_table[cq->gdma_id] = cq->gdma_cq;
> +	rcu_assign_pointer(cq_table[cq->gdma_id], cq->gdma_cq);
[Severity: Critical]
This is a pre-existing issue, but since mana_push_wqe(rxq) has already posted
buffers to the hardware just before this, couldn't a network packet be
received at this point?

Since netif_napi_add_weight_locked() hasn't run yet, would an early hardware
interrupt cause the EQ handler to invoke napi_schedule() on an uninitialized
NAPI struct?

>  
>  	netif_napi_add_weight_locked(ndev, &cq->napi, mana_poll, 1);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803234355.636038-1-longli@microsoft.com?part=1

  reply	other threads:[~2026-08-09  2:35 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 23:43 [PATCH net v3 0/6] net: mana: HW channel reliability and hardening fixes Long Li
2026-08-03 23:43 ` [PATCH net v3 1/6] net: mana: RCU-protect gc->cq_table lookups against concurrent CQ destroy Long Li
2026-08-04 23:44   ` sashiko-bot
2026-08-06 17:23   ` Jakub Kicinski
2026-08-03 23:43 ` [PATCH net v3 2/6] net: mana: fix HWC RQ/SQ buffer size swap Long Li
2026-08-04 23:44   ` sashiko-bot
2026-08-06 17:23   ` Jakub Kicinski
2026-08-03 23:43 ` [PATCH net v3 3/6] net: mana: free HWC comp_buf after destroying the EQ Long Li
2026-08-04 23:44   ` sashiko-bot
2026-08-06 17:23   ` Jakub Kicinski
2026-08-03 23:43 ` [PATCH net v3 4/6] net: mana: validate hardware-supplied values in the HWC RX path Long Li
2026-08-04 23:44   ` sashiko-bot
2026-08-06 17:24   ` Jakub Kicinski
2026-08-03 23:43 ` [PATCH net v3 5/6] net: mana: fix HWC teardown safety with setup_active flag and destroy ordering Long Li
2026-08-04 23:44   ` sashiko-bot
2026-08-06 17:24   ` Jakub Kicinski
2026-08-03 23:43 ` [PATCH net v3 6/6] net: mana: fix stale HWC response after command timeout Long Li
2026-08-04 23:44   ` sashiko-bot
2026-08-06 17:24   ` Jakub Kicinski
2026-08-08  2:10     ` [EXTERNAL] " Long Li
2026-08-08  2:34 ` [PATCH net v4 0/7] net: mana: HW channel reliability and hardening fixes Long Li
2026-08-08  2:34 ` [PATCH net v4 1/7] net: mana: RCU-protect gc->cq_table lookups against concurrent CQ destroy Long Li
2026-08-09  2:34   ` sashiko-bot [this message]
2026-08-08  2:34 ` [PATCH net v4 2/7] net: mana: fix HWC RQ/SQ buffer size swap Long Li
2026-08-09  2:35   ` sashiko-bot
2026-08-08  2:34 ` [PATCH net v4 3/7] net: mana: free HWC comp_buf after destroying the EQ Long Li
2026-08-09  2:35   ` sashiko-bot
2026-08-08  2:34 ` [PATCH net v4 4/7] net: mana: validate hardware-supplied values in the HWC RX path Long Li
2026-08-09  2:34   ` sashiko-bot
2026-08-08  2:34 ` [PATCH net v4 5/7] net: mana: fix HWC teardown safety with setup_active flag and destroy ordering Long Li
2026-08-08  2:34 ` [PATCH net v4 6/7] net: mana: fix stale HWC response after command timeout Long Li
2026-08-09  2:34   ` sashiko-bot
2026-08-08  2:34 ` [PATCH net v4 7/7] net: mana: keep max_num_cqs immutable once cq_table is allocated Long Li
2026-08-09  2:35   ` sashiko-bot

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