Re: [PATCH 3/4] KVM: VMX: Re-inject an ICEBP #DB as a privileged software exception
From: Sohil Mehta
Date: Thu Dec 03 2026 - 03:25:44 EST
+ Everyone from the main thread (because I am not sure how to dispose this)
On 12/2/2026 12:35 AM, sashiko-bot@xxxxxxxxxx wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] KVM: x86: unhandled ICEBP payload in
> kvm_vcpu_ioctl_x86_get_vcpu_events()
> --
> [Severity: Medium]
> Can queueing an ICEBP #DB with a payload and EVENT_TYPE_PRIV_SWEXC corrupt
> guest state if KVM exits to userspace (for example on a pending signal)
> before injecting the exception?
>
The window seems real. It happens because patch 2 leaves a queued INT1
out of the vCPU events like INT3 and INTO, but those don't carry a
payload. So the payload of a #DB that isn't saved still leaks out, to
userspace or into DR6. However, I don't see how the guest state can be
corrupted.
My LLM says:
- Without KVM_CAP_EXCEPTION_PAYLOAD, KVM writes the payload to DR6 when
userspace saves the vCPU state. After a restore, the guest
re-executes the ICEBP, and the new #DB writes the same DR6 bits
again.
- With KVM_CAP_EXCEPTION_PAYLOAD, KVM_GET_VCPU_EVENTS reports the
payload without a pending or injected exception, and
KVM_SET_VCPU_EVENTS drops it.
IIUC, the fix would be to leave the payload of a queued INT1 out of the
vCPU events too, and not deliver it early when userspace saves the vCPU
state. Maybe something like this (tested with a throwaway selftest),
folded into patch 2:
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2978,6 +2978,17 @@ static struct kvm_queued_exception *kvm_
return &vcpu->arch.exception;
}
+/*
+ * The vCPU events API doesn't provide the instruction length that software
+ * exceptions and INT1 need, so KVM doesn't report them. As long as the
guest
+ * RIP isn't advanced, the guest encounters the exception again.
+ */
+static bool kvm_exception_is_reportable(struct kvm_queued_exception *ex)
+{
+ return !kvm_exception_is_soft(ex->vector) &&
+ ex->event_type != EVENT_TYPE_PRIV_SWEXC;
+}
+
void kvm_handle_exception_payload_quirk(struct kvm_vcpu *vcpu)
{
struct kvm_queued_exception *ex = kvm_get_exception_to_save(vcpu);
@@ -2996,7 +3007,7 @@ void kvm_handle_exception_payload_quirk(
* safely defer delivery of the payload.
*/
if (!vcpu->kvm->arch.exception_payload_enabled &&
- ex->pending && ex->has_payload)
+ ex->pending && ex->has_payload && kvm_exception_is_reportable(ex))
kvm_deliver_exception_payload(vcpu, ex);
}
@@ -3016,14 +3027,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_
memset(events, 0, sizeof(*events));
- /*
- * The API doesn't provide the instruction length that software
- * exceptions and INT1 need, so don't report them. As long as the
- * guest RIP isn't advanced, we should expect to encounter the
- * exception again.
- */
- if (!kvm_exception_is_soft(ex->vector) &&
- ex->event_type != EVENT_TYPE_PRIV_SWEXC) {
+ if (kvm_exception_is_reportable(ex)) {
events->exception.injected = ex->injected;
events->exception.pending = ex->pending;
/*
@@ -3033,12 +3037,12 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_
*/
if (!vcpu->kvm->arch.exception_payload_enabled)
events->exception.injected |= ex->pending;
+ events->exception_has_payload = ex->has_payload;
+ events->exception_payload = ex->payload;
}
events->exception.nr = ex->vector;
events->exception.has_error_code = ex->has_error_code;
events->exception.error_code = ex->error_code;
- events->exception_has_payload = ex->has_payload;
- events->exception_payload = ex->payload;
events->interrupt.injected =
vcpu->arch.interrupt.injected && !vcpu->arch.interrupt.soft;
I think even though it doesn't fix a guest-visible problem, it does make
the handling of exception payloads more consistent with the API's
limitations. KVM_GET_VCPU_EVENTS stops reporting a payload without an
exception, and saving the vCPU state no longer writes DR6 for a #DB that
isn't saved.
This isn't really my area of expertise, so I would appreciate feedback
on this. Does this seem worth fixing?