All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: Thara Gopinath <tgopinath@linux.microsoft.com>,
	linux-hyperv@vger.kernel.org, Wei Liu <wei.liu@kernel.org>
Subject: Re: [RFC PATCH 02/12] drivers: hv: hv_common: Allocate Hyper-V output arg page when VSM is enabled
Date: Tue, 1 Sep 2026 15:56:06 -0700	[thread overview]
Message-ID: <20260901225606.GA2583463@liuwe-devbox-debian-v2.local> (raw)
In-Reply-To: <20260901171238.834601F00A3A@smtp.kernel.org>

On Tue, Sep 01, 2026 at 05:12:38PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [High] hv_apicid_to_vp_index() unconditionally dereferences the unallocated hyperv_pcpu_output_arg pointer in standard/SNP guests.
> --
> 
> commit 0ee3313e113c9ca7969923f2af5a1ed18ddb25d2
> Author: Thara Gopinath <tgopinath@linux.microsoft.com>
> 
> drivers: hv: hv_common: Allocate Hyper-V output arg page when VSM is enabled
> 
> This commit extends hv_output_page_exists() to return true when 
> CONFIG_HYPERV_VSM is enabled. This ensures the per-CPU output argument
> page is allocated at boot for VSM hypercalls.
> 
> > diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> > index 31256cb22b39e..44f4a10984618 100644
> > --- a/drivers/hv/hv_common.c
> > +++ b/drivers/hv/hv_common.c
> > @@ -259,7 +259,8 @@ static void hv_kmsg_dump_register(void)
> >  
> >  static inline bool hv_output_page_exists(void)
> >  {
> > -	return hv_parent_partition() || IS_ENABLED(CONFIG_HYPERV_VTL_MODE);
> > +	return hv_parent_partition() || IS_ENABLED(CONFIG_HYPERV_VTL_MODE) ||
> > +		IS_ENABLED(CONFIG_HYPERV_VSM);
> 
> [Severity: High]
> This is a pre-existing issue, but modifying this function highlights a
> vulnerability for SEV-SNP guests where VSM and VTL modes are disabled.
> 
> When an SEV-SNP guest boots secondary CPUs, hv_smp_prepare_cpus() overrides
> the wakeup callback with hv_snp_boot_ap(), which then calls
> hv_apicid_to_vp_index() in arch/x86/hyperv/ivm.c.
> 
> If CONFIG_HYPERV_VSM and CONFIG_HYPERV_VTL_MODE are both disabled,
> hv_output_page_exists() evaluates to false. This means hyperv_pcpu_output_arg
> is never allocated during hv_common_init() and remains NULL.
> 
> Consequently, arch/x86/hyperv/hv_init.c:hv_apicid_to_vp_index() dereferences
> this unallocated pointer:
> 
> arch/x86/hyperv/hv_init.c:hv_apicid_to_vp_index() {
>         ...
>         output = *this_cpu_ptr(hyperv_pcpu_output_arg);
>         ...
>         status = hv_do_hypercall(HVCALL_GET_VP_ID_FROM_APIC_ID, input, output);
>         ...
> }
> 
> Since this_cpu_ptr(NULL) resolves to the base of the per-CPU area, it
> dereferences a garbage pointer. This is then passed to hv_do_hypercall(),
> causing the hypervisor to overwrite random physical memory with the hypercall
> result, and eventually oopsing the kernel when output[0] is read.
> 

This looks like a real bug. It should / will be fixed separately.

Wei

  reply	other threads:[~2026-09-01 22:56 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 [this message]
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
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=20260901225606.GA2583463@liuwe-devbox-debian-v2.local \
    --to=wei.liu@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.