* Re: [PATCH v1 5/9] KVM: x86: Add new hypercall to lock control registers
[not found] ` <901ff104-215c-8e81-fbae-5ecd8fa94449@digikod.net>
@ 2023-05-30 23:16 ` Kees Cook
0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2023-05-30 23:16 UTC (permalink / raw)
To: Mickaël Salaün
Cc: linux-hyperv, Wanpeng Li, kvm, Nicușor Cîțu,
Dave Hansen, John Andersen, qemu-devel, virtualization,
linux-hardening, H . Peter Anvin, Will Deacon, Thomas Gleixner,
Wei Liu, Mihai Donțu, x86, James Morris,
Madhavan T . Venkataraman, Marian Rotariu, Ingo Molnar, xen-devel,
Forrest Yuan Yu, dev, Thara Gopinath, Ștefan Șicleru,
Borislav Petkov, Paolo Bonzini, Zahra Tarkhani,
Sean Christopherson, linux-kernel, linux-security-module,
Alexander Graf, Rick Edgecombe
On Mon, May 29, 2023 at 06:48:03PM +0200, Mickaël Salaün wrote:
>
> On 08/05/2023 23:11, Wei Liu wrote:
> > On Fri, May 05, 2023 at 05:20:42PM +0200, Mickaël Salaün wrote:
> > > This enables guests to lock their CR0 and CR4 registers with a subset of
> > > X86_CR0_WP, X86_CR4_SMEP, X86_CR4_SMAP, X86_CR4_UMIP, X86_CR4_FSGSBASE
> > > and X86_CR4_CET flags.
> > >
> > > The new KVM_HC_LOCK_CR_UPDATE hypercall takes two arguments. The first
> > > is to identify the control register, and the second is a bit mask to
> > > pin (i.e. mark as read-only).
> > >
> > > These register flags should already be pinned by Linux guests, but once
> > > compromised, this self-protection mechanism could be disabled, which is
> > > not the case with this dedicated hypercall.
> > >
> > > Cc: Borislav Petkov <bp@alien8.de>
> > > Cc: Dave Hansen <dave.hansen@linux.intel.com>
> > > Cc: H. Peter Anvin <hpa@zytor.com>
> > > Cc: Ingo Molnar <mingo@redhat.com>
> > > Cc: Kees Cook <keescook@chromium.org>
> > > Cc: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
> > > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > > Cc: Sean Christopherson <seanjc@google.com>
> > > Cc: Thomas Gleixner <tglx@linutronix.de>
> > > Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> > > Cc: Wanpeng Li <wanpengli@tencent.com>
> > > Signed-off-by: Mickaël Salaün <mic@digikod.net>
> > > Link: https://lore.kernel.org/r/20230505152046.6575-6-mic@digikod.net
> > [...]
> > > hw_cr4 = (cr4_read_shadow() & X86_CR4_MCE) | (cr4 & ~X86_CR4_MCE);
> > > if (is_unrestricted_guest(vcpu))
> > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > > index ffab64d08de3..a529455359ac 100644
> > > --- a/arch/x86/kvm/x86.c
> > > +++ b/arch/x86/kvm/x86.c
> > > @@ -7927,11 +7927,77 @@ static unsigned long emulator_get_cr(struct x86_emulate_ctxt *ctxt, int cr)
> > > return value;
> > > }
> > > +#ifdef CONFIG_HEKI
> > > +
> > > +extern unsigned long cr4_pinned_mask;
> > > +
> >
> > Can this be moved to a header file?
>
> Yep, but I'm not sure which one. Any preference Kees?
Uh, er, I was never expecting that mask to be non-static. ;) To that
end, how about putting it in arch/x86/kvm/x86.h ?
--
Kees Cook
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] only message in thread