From: sashiko-bot@kernel.org
To: "Long Li" <longli@microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH net v7 5/7] net: mana: fix HWC teardown safety with setup_active flag and destroy ordering
Date: Fri, 14 Aug 2026 17:43:20 +0000 [thread overview]
Message-ID: <20260814174320.C026C1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260813174243.3044348-6-longli@microsoft.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] A timed-out HWC request recycles its msg_id immediately, which can cause a delayed hardware response to corrupt the memory of a subsequent request that reused the same msg_id.
- [High] The dynamically allocated `mana_serv_work` item is not cancelled during device removal, leading to a race condition where the work item can access a freed `gdma_context` (`gc`).
--
--- Patch [5]: [PATCH net v7 5/7] net: mana: fix HWC teardown safety with setup_active flag and destroy ordering ---
commit f7262210dd3ba2257a4ad8d7840cc3065a491ae1
Author: Long Li <longli@microsoft.com>
net: mana: fix HWC teardown safety with setup_active flag and destroy ordering
This patch addresses teardown hazards that could allow the hardware to access
freed memory. It introduces a setup_active flag to ensure teardowns only occur
when necessary, reorders queue destruction to prevent interrupts from accessing
freed buffers, and intentionally leaks resources if the teardown itself fails.
> diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
> --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
> +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
[ ... ]
> @@ -837,6 +844,16 @@ int mana_hwc_create_channel(struct gdma_context *gc)
> u16 q_depth_max;
> int err;
>
> + /* A previous teardown may have failed and left the old context
> + * reachable. Retry it before building a new channel; if it still
> + * fails, return an error so mana_serv_reset() does a full PCI rescan.
> + */
[Severity: High]
This isn't a bug introduced by this patch, but since mana_serv_reset() is
mentioned here, is there a use-after-free risk during device removal?
If an error triggers mana_schedule_serv_work(), it schedules a dynamically
allocated work item on the system workqueue:
drivers/net/ethernet/microsoft/mana/gdma_main.c:mana_schedule_serv_work() {
...
INIT_WORK(&mns_wk->serv_work, mana_serv_func);
schedule_work(&mns_wk->serv_work);
...
}
If the driver is unbound concurrently, mana_gd_remove() frees the gdma_context
without waiting for or cancelling this work item:
drivers/net/ethernet/microsoft/mana/gdma_main.c:mana_gd_remove() {
...
vfree(gc);
...
}
Could the pending work item then execute mana_serv_reset(), read the context
via pci_get_drvdata(), and dereference the freed gc pointer?
[ ... ]
> @@ -914,6 +953,12 @@ void mana_hwc_destroy_channel(struct gdma_context *gc)
> */
> gc->max_num_cqs = 0;
>
> + if (hwc->txq)
> + mana_hwc_destroy_wq(hwc, hwc->txq);
> +
> + if (hwc->rxq)
> + mana_hwc_destroy_wq(hwc, hwc->rxq);
> +
> kfree(hwc->caller_ctx);
> hwc->caller_ctx = NULL;
[Severity: High]
This is a pre-existing issue, but while reviewing the caller context cleanup,
is there a memory corruption risk if a hardware channel request times out?
If a request times out in mana_hwc_send_request(), the msg_id is immediately
recycled:
drivers/net/ethernet/microsoft/mana/hw_channel.c:mana_hwc_send_request() {
...
out:
mana_hwc_put_msg_index(hwc, msg_id);
return err;
}
If another thread allocates the same msg_id, and the hardware later sends a
delayed response for the original timed-out request, could
mana_hwc_handle_resp() overwrite the new request's memory?
drivers/net/ethernet/microsoft/mana/hw_channel.c:mana_hwc_handle_resp() {
...
memcpy(ctx->output_buf, resp_msg, resp_len);
...
complete(&ctx->comp_event);
}
Could this delayed response blindly overwrite the newly allocated caller's
output_buf and prematurely wake it up?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260813174243.3044348-1-longli@microsoft.com?part=5
next prev parent reply other threads:[~2026-08-14 17:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 17:42 [PATCH net v7 0/7] net: mana: HW channel reliability and hardening fixes Long Li
2026-08-13 17:42 ` [PATCH net v7 1/7] net: mana: reference-count CQs looked up from the EQ handler Long Li
2026-08-14 17:43 ` sashiko-bot
2026-08-13 17:42 ` [PATCH net v7 2/7] net: mana: fix HWC RQ/SQ buffer size swap Long Li
2026-08-14 17:43 ` sashiko-bot
2026-08-13 17:42 ` [PATCH net v7 3/7] net: mana: free HWC comp_buf after destroying the EQ Long Li
2026-08-14 17:43 ` sashiko-bot
2026-08-13 17:42 ` [PATCH net v7 4/7] net: mana: validate hardware-supplied values in the HWC RX path Long Li
2026-08-14 17:43 ` sashiko-bot
2026-08-13 17:42 ` [PATCH net v7 5/7] net: mana: fix HWC teardown safety with setup_active flag and destroy ordering Long Li
2026-08-14 17:43 ` sashiko-bot [this message]
2026-08-13 17:42 ` [PATCH net v7 6/7] net: mana: fix stale HWC response after command timeout Long Li
2026-08-14 17:43 ` sashiko-bot
2026-08-13 17:42 ` [PATCH net v7 7/7] net: mana: keep max_num_cqs immutable once cq_table is allocated Long Li
2026-08-14 17:43 ` 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=20260814174320.C026C1F00A3A@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