Re: [PATCH 10/45] KVM: x86: Introduce memory fault on invalid hypercalls reads/writes

From: David Woodhouse

Date: Mon Nov 09 2026 - 19:35:19 EST


On Mon, 2026-11-02 at 12:40 -0500, Paolo Bonzini wrote:
>
> +7.48 KVM_CAP_HCALL_FAULT_EXIT
> +------------------------------------
> +
> +:Architectures: x86
> +:Parameters: args[0] is 0 to disable, 1 to enable
> +
> +When enabled, KVM checks the memory that is read or written by
> +hypercalls (including slow Hyper-V hypercalls and KVM_HC_CLOCK_PAIRING).
> +An inaccessible input page causes a KVM_EXIT_MEMORY_FAULT with
> +KVM_MEMORY_EXIT_FLAG_READ.  An inaccessible or read-only output page causes
> +a KVM_EXIT_MEMORY_FAULT with KVM_MEMORY_EXIT_FLAG_WRITE.  The reported
> +range identifies the page containing the parameter GPA.
> +
> +Hypercall parameters that are unused by the selected hypercall are not checked.
> +
> +For Hyper-V, unknown hypercalls are passed to userspace without checking their
> +parameter pages. 

Is that true? I have a patch in my VSM tree to pass unknown hypercalls
to userspace for the default: case, but nothing *yet* does so?

Also, Xen hypercalls (the ones that are handled in-kernel) aren't
covered here, and probably should be.

Can we have the selftests check for corner cases like the hypercall
argument pointing at the last word of a page, extending onto the next
page (which is absent). Not sure that one is working right as you have
it either.

I wonder if we want a generic kvm_hcall_copy_from_guest() which returns
-EFAULT as appropriate, and its callers can then handle it consistently
without having to worry about TOCTOU issues? Or is that just
kvm_read_guest()?

Attachment: smime.p7s
Description: S/MIME cryptographic signature