From: sashiko-bot@kernel.org
To: "Thara Gopinath" <tgopinath@linux.microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [RFC PATCH 03/12] drivers: hv: Reserve memory for VSM secure kernel during early boot
Date: Tue, 01 Sep 2026 17:10:14 +0000 [thread overview]
Message-ID: <20260901171014.A14DE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901165647.3160413-4-tgopinath@linux.microsoft.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The automatic memory reservation fallback is never executed if the `securekernel` parameter is omitted from the kernel command line.
- [High] Manual string parsing of boot_command_line uses a fragile substring match, misparsing unrelated parameters and ignoring the pre-parsed setup argument.
- [Medium] The `__setup` handler returns 0 on success and -EINVAL on failure, inverting the API contract and leaking the parameter to the init process.
- [Low] parse_securekernel_simple fails to validate trailing characters after parsing the base address.
--
commit c057f006b3a9db9a754349283e3c7dd23550b133
Author: Thara Gopinath <tgopinath@linux.microsoft.com>
Date: Tue Sep 1 16:55:17 2026 +0000
drivers: hv: Reserve memory for VSM secure kernel during early boot
The VSM secure kernel runs in VTL1 and requires its memory to be reserved
early. This commit introduces a driver to handle early boot reservation of
this memory, either parsed from the securekernel= command line parameter or
calculated automatically as a fallback.
> diff --git a/drivers/hv/hv_vsm_securekernel.c b/drivers/hv/hv_vsm_securekernel.c
> new file mode 100644
> index 0000000000000..f90f6204b4d18
> --- /dev/null
> +++ b/drivers/hv/hv_vsm_securekernel.c
[ ... ]
> +static int __init parse_securekernel_simple(char *cmdline,
> + unsigned long long *securekernel_size,
> + unsigned long long *securekernel_base)
> +{
> + char *cur = cmdline;
> +
> + *securekernel_size = memparse(cmdline, &cur);
> + if (cmdline == cur) {
> + pr_warn("securekernel: memory value expected\n");
> + return -EINVAL;
> + }
> +
> + if (*cur == '@') {
> + *securekernel_base = memparse(cur + 1, &cur);
> + } else if (*cur != ' ' && *cur != '\0') {
[Severity: Low]
Does this code skip trailing character validation if @ was found?
Because the validation is inside an else if, if a user specifies a base
address with trailing non-space characters (e.g., securekernel=16M@2G_foo),
memparse() consumes the valid number, but the remaining garbage characters
are silently ignored without raising an error.
> + pr_warn("securekernel: unrecognized char: %c\n", *cur);
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +static __init char *get_last_securekernel(char *cmdline, const char *name)
> +{
> + char *p = cmdline, *sk_cmdline = NULL;
> +
> + /* find securekernel and use the last one if there are more */
> + p = strstr(p, name);
> + while (p) {
> + sk_cmdline = p;
> + p = strstr(p + 1, name);
[Severity: High]
Does this unbounded substring search misparse unrelated parameters?
Because it lacks word-boundary or prefix validation, strstr() will match
the substring anywhere in the command line. The driver could misparse
independent kernel parameters (e.g., nosecurekernel=100M).
Furthermore, since it explicitly searches for the last occurrence, an unrelated
parameter at the end of the command line containing the substring securekernel=
could overwrite a valid reservation parameter.
> + }
> +
> + if (!sk_cmdline)
> + return NULL;
> +
> + return sk_cmdline;
> +}
[ ... ]
> +static int __init hv_vsm_seckernel_mem_init(char *__unused)
[Severity: High]
Is it intentional to discard the correctly pre-parsed parameter value provided
by the __setup infrastructure?
The __setup() macro already does exact matching and provides the specific
parameter value to the callback via its argument. By explicitly ignoring this
argument (naming it __unused) and implementing a custom parser over the global
boot_command_line, the driver uses a fragile manual parsing routine instead
of the established API.
> +{
> + unsigned long long securekernel_size = 0, securekernel_base = 0;
> + int ret;
[ ... ]
> + /* Default: Find the base address automatically */
> + if (!securekernel_base) {
> + securekernel_base = memblock_phys_alloc_range(securekernel_size, SECKERNEL_ALIGN,
> + 0, SECKERNEL_ADDR_MAX);
> + if (!securekernel_base) {
> + pr_err("%s: Securekernel reservation failed-VSM will not be enabled.\n",
> + __func__);
> + return -EINVAL;
[Severity: Medium]
Will returning -EINVAL (non-zero) on the error path incorrectly tell the
kernel's parser that the parameter was successfully handled?
The kernel API documentation requires __setup handlers to return 1 (or
non-zero) if handled and 0 if not. Returning a non-zero error code treats
the failed parameter as successfully consumed.
> + }
> + }
> +
> + pr_info("Reserving %ldMB of memory at 0x%llx(%ld MB) for securekernel(System RAM:%ldMB)\n",
> + (unsigned long)(securekernel_size >> 20),
> + securekernel_base,
> + (unsigned long)(securekernel_base >> 20),
> + (unsigned long)(memblock_phys_mem_size() >> 20));
> +
> + sk_res.start = securekernel_base;
> + sk_res.end = securekernel_base + securekernel_size - 1;
> + insert_resource(&iomem_resource, &sk_res);
> +
> + return 0;
[Severity: Medium]
Will returning 0 on the success path inform the kernel's setup infrastructure
that the parameter was not handled?
This causes the kernel to erroneously pass the securekernel=... parameter as
an environment variable to the init process. The handler should return 1 when
the parameter is successfully handled.
> +}
> +__setup("securekernel", hv_vsm_seckernel_mem_init);
[Severity: High]
Can the automatic memory reservation fallback ever execute if the parameter is
omitted from the kernel command line?
Functions registered with __setup() are only invoked by init/main.c if the
target string matches a command-line parameter. If absent, the initialization
function is completely bypassed, meaning the core feature (automatic memory
reservation) fails entirely by default, and the VSM secure kernel will not boot
due to lack of reserved memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260901165647.3160413-1-tgopinath@linux.microsoft.com?part=3
next prev parent reply other threads:[~2026-09-01 17:10 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 16:55 [RFC PATCH 00/12] Introduce LVBS support for Hyper-V guests Thara Gopinath
2026-09-01 16:55 ` [RFC PATCH 01/12] drivers: hv: Add HYPERV_VSM kconfig option Thara Gopinath
2026-09-01 16:55 ` [RFC PATCH 02/12] drivers: hv: hv_common: Allocate Hyper-V output arg page when VSM is enabled Thara Gopinath
2026-09-01 17:12 ` sashiko-bot
2026-09-01 22:56 ` Wei Liu
2026-09-01 16:55 ` [RFC PATCH 03/12] drivers: hv: Reserve memory for VSM secure kernel during early boot Thara Gopinath
2026-09-01 17:10 ` sashiko-bot [this message]
2026-09-02 0:59 ` Wei Liu
2026-09-02 13:38 ` Thara Gopinath
2026-09-01 16:55 ` [RFC PATCH 04/12] firmware: efi: libstub: x86-stub: Enable VSM awareness in efi os indications variable Thara Gopinath
2026-09-01 17:09 ` sashiko-bot
2026-09-02 1:09 ` Wei Liu
2026-09-02 14:23 ` Thara Gopinath
2026-09-01 16:55 ` [RFC PATCH 05/12] include: hyperv: hvgdk_mini.h: Add VTL-specific structures and bits Thara Gopinath
2026-09-01 16:55 ` [RFC PATCH 06/12] drivers: hv: Add VSM boot driver and enable VTL1 at the partition level Thara Gopinath
2026-09-01 17:24 ` sashiko-bot
2026-09-02 1:16 ` Wei Liu
2026-09-02 14:28 ` Thara Gopinath
2026-09-02 4:43 ` Wei Liu
2026-09-04 13:23 ` Thara Gopinath
2026-09-01 16:55 ` [RFC PATCH 07/12] drivers: hv: hv_vsm_boot: load secure kernel image from firmware Thara Gopinath
2026-09-01 17:20 ` sashiko-bot
2026-09-02 4:37 ` Wei Liu
2026-09-02 16:22 ` Thara Gopinath
2026-09-02 22:58 ` Wei Liu
2026-09-01 16:55 ` [RFC PATCH 08/12] arch: x86: hyperv: Build initial vCPU context for VTL1 secure kernel Thara Gopinath
2026-09-01 17:25 ` sashiko-bot
2026-09-01 16:55 ` [RFC PATCH 09/12] drivers: hv: hv_vsm_boot: Enable VTL1 on the boot processor Thara Gopinath
2026-09-01 17:36 ` sashiko-bot
2026-09-01 16:55 ` [RFC PATCH 10/12] arch: x86: hyperv: hv_vtl_vsm: Introduce vtlcall Thara Gopinath
2026-09-01 16:55 ` [RFC PATCH 11/12] drivers: hv: hv_vsm_boot: Boot primary processor in VTL1 Thara Gopinath
2026-09-01 17:35 ` sashiko-bot
2026-09-01 16:55 ` [RFC PATCH 12/12] drivers: hv: hv_vsm_boot: Boot secondary processors " Thara Gopinath
2026-09-01 17:44 ` 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=20260901171014.A14DE1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tgopinath@linux.microsoft.com \
/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.