From: sashiko-bot@kernel.org
To: "Long Li" <longli@microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH net-next 2/7] net: mana: fix HWC RQ/SQ buffer size swap
Date: Thu, 16 Jul 2026 03:30:21 +0000 [thread overview]
Message-ID: <20260716033022.32C681F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260715032942.3945317-3-longli@microsoft.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free and data corruption due to premature timeout return in mana_hwc_send_request without canceling hardware transaction.
- [High] Missing locking allows concurrent WQE ring corruption in mana_hwc_send_request.
--
--- Patch [2]: [PATCH net-next 2/7] net: mana: fix HWC RQ/SQ buffer size swap ---
commit a1baa394548fbd57903fe3f07805307884c7c9c0
Author: Long Li <longli@microsoft.com>
net: mana: fix HWC RQ/SQ buffer size swap
The HWC RQ receives responses and the SQ sends requests, but
mana_hwc_init_queues() sized the RQ with max_req_msg_size and the SQ with
max_resp_msg_size -- backwards. A response larger than the undersized RQ
buffer could overflow it, and mana_hwc_rx_event_handler() recovered the
RX slot index by dividing by the wrong size.
> diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
> index 409e20caeccdc..3f011ebbe7b3e 100644
> --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
> +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
[ ... ]
> @@ -749,6 +749,7 @@ static int mana_hwc_init_queues(struct hw_channel_context *hwc, u16 q_depth,
>
> hwc->num_inflight_msg = q_depth;
> hwc->max_req_msg_size = max_req_msg_size;
> + hwc->max_resp_msg_size = max_resp_msg_size;
>
> return 0;
> out:
[Severity: High]
This isn't a bug introduced by this patch, but could this timeout path lead
to a use-after-free and data corruption?
If a caller invokes mana_hwc_send_request() and it times out, it frees the
msg_id slot and returns without canceling the hardware transaction:
mana_hwc_send_request() {
if (!wait_for_completion_timeout(&ctx->comp_event, ...)) {
err = -ETIMEDOUT;
goto out;
}
...
out:
mana_hwc_put_msg_index(hwc, msg_id);
}
If the caller provided a stack-allocated response buffer, its stack frame
will be popped when mana_hwc_send_request() returns. When the delayed
hardware response eventually arrives, will mana_hwc_handle_resp() blindly
accept it and overwrite the now-freed stack address?
mana_hwc_handle_resp() {
...
memcpy(ctx->output_buf, resp_msg, resp_len);
}
Alternatively, if another thread reuses the freed msg_id, could it receive
this delayed response instead of its own?
[Severity: High]
This is also a pre-existing issue, but does this code allow concurrent
WQE ring corruption?
Multiple threads can concurrently invoke mana_hwc_send_request(), such as
from parallel InfiniBand requests. This leads to mana_hwc_post_tx_wqe(),
which appears to call mana_gd_post_and_ring() locklessly:
mana_hwc_post_tx_wqe() {
...
err = mana_gd_post_and_ring(hwc_txq->gdma_wq, &req->wqe_req, NULL);
}
If multiple threads execute this concurrently, won't they read the same
wq->head in mana_gd_post_work_request(), overwrite the exact same WQE
slots, and corrupt the shared queue state?
mana_gd_post_work_request() {
wqe_ptr = mana_gd_get_wqe_ptr(wq, wq->head);
...
mana_gd_write_sgl(wq, wqe_ptr, wqe_req);
wq->head += wqe_size / GDMA_WQE_BU_SIZE;
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260715032942.3945317-1-longli@microsoft.com?part=2
next prev parent reply other threads:[~2026-07-16 3:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 3:29 [PATCH net-next 0/7] net: mana: harden the HWC and add dynamic queue depth Long Li
2026-07-15 3:29 ` [PATCH net-next 1/7] net: mana: RCU-protect gc->cq_table lookups against concurrent CQ destroy Long Li
2026-07-15 3:29 ` [PATCH net-next 2/7] net: mana: fix HWC RQ/SQ buffer size swap Long Li
2026-07-16 3:30 ` sashiko-bot [this message]
2026-07-15 3:29 ` [PATCH net-next 3/7] net: mana: free HWC comp_buf after destroying the EQ Long Li
2026-07-16 3:30 ` sashiko-bot
2026-07-15 3:29 ` [PATCH net-next 4/7] net: mana: validate hardware-supplied values in the HWC RX path Long Li
2026-07-16 3:30 ` sashiko-bot
2026-07-15 3:29 ` [PATCH net-next 5/7] net: mana: fix HWC teardown safety with setup_active flag and destroy ordering Long Li
2026-07-16 3:30 ` sashiko-bot
2026-07-15 3:29 ` [PATCH net-next 6/7] net: mana: support concurrent HWC requests with proper synchronization Long Li
2026-07-16 3:30 ` sashiko-bot
2026-07-15 3:29 ` [PATCH net-next 7/7] net: mana: add dynamic HWC queue depth with reinit path Long Li
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=20260716033022.32C681F00A3D@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 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.