From: sashiko-bot@kernel.org
To: "Long Li" <longli@microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH net v4 4/7] net: mana: validate hardware-supplied values in the HWC RX path
Date: Sun, 09 Aug 2026 02:34:57 +0000 [thread overview]
Message-ID: <20260809023458.0B6D61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260808023417.1746886-5-longli@microsoft.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Race condition leading to stack memory corruption and Use-After-Free (ABA) on hardware command timeout.
--
--- Patch [4]: [PATCH net v4 4/7] net: mana: validate hardware-supplied values in the HWC RX path ---
commit 3dd532e8ebcefe4a1f19044be675c58a1504e9c6
Author: Long Li <longli@microsoft.com>
net: mana: validate hardware-supplied values in the HWC RX path
This commit adds validation for hardware-supplied lengths and indices in the
MANA hardware channel RX handler. It ensures the inline OOB size, SGE addresses,
and response lengths are checked before use. Out-of-bounds or untrusted RX WQEs
are leaked and, if exhausted, the channel goes into a terminal state.
> diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
> index 19896bb5ce1a4..5db8cfe2d8443 100644
> --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
> +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
> @@ -83,6 +83,19 @@ static void mana_hwc_handle_resp(struct hw_channel_context *hwc, u32 resp_len,
> struct hwc_caller_ctx *ctx;
> int err;
>
> + /* Defence in depth: the sole caller, mana_hwc_rx_event_handler(),
> + * already rejects msg_id >= hwc->num_inflight_msg with the value it
> + * passes here by value, so this cannot be reached out of range. Keep
> + * the guard at the indexing site so the bitmap and caller_ctx array
> + * are never indexed without a bound in view.
> + */
> + if (msg_id >= hwc->num_inflight_msg) {
> + dev_err(hwc->dev, "hwc_rx: msg_id %u >= max %u\n",
> + msg_id, hwc->num_inflight_msg);
> + mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
> + return;
> + }
> +
> if (!test_bit(msg_id, hwc->inflight_msg_res.map)) {
> dev_err(hwc->dev, "hwc_rx: invalid msg_id = %u\n", msg_id);
> mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
[Severity: Critical]
This is a pre-existing issue, but is there a race condition between this
test_bit() check and the command timeout path that could corrupt stack memory?
If a thread calling mana_hwc_send_request() times out, it takes this path:
if (!wait_for_completion_timeout(&ctx->comp_event,
(hwc->hwc_timeout * HZ) / 1000)) {
dev_err(hwc->dev, "HWC: Request timed out!\n");
err = -ETIMEDOUT;
goto out;
}
...
out:
mana_hwc_put_msg_index(hwc, msg_id);
return err;
The timeout path clears the message ID bit and returns without synchronizing
with the interrupt handler.
Concurrently, if a delayed hardware response arrives here in
mana_hwc_handle_resp(), it could pass the test_bit() check right before the
timeout path clears it.
The timeout thread then clears the bit and returns, popping its stack.
Then mana_hwc_handle_resp() proceeds and executes:
if (!err && ctx->output_buf) {
ctx->status_code = resp_msg->status;
memcpy(ctx->output_buf, resp_msg, resp_len);
Since ctx->output_buf points to the now-freed stack frame, could this memcpy()
write hardware data into a freed stack frame or to the stack frame of a new
thread reusing the message ID?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260803234355.636038-1-longli@microsoft.com?part=4
next prev parent reply other threads:[~2026-08-09 2:34 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
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 [this message]
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=20260809023458.0B6D61F000E9@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.