Skip to content

Commit 02dc254

Browse files
committed
KVM: selftests: Explicit set #UD when *potentially* injecting exception
Explicitly set the exception vector to #UD when potentially injecting an exception in sync_regs_test's subtests that try to detect TOCTOU bugs in KVM's handling of exceptions injected by userspace. A side effect of the original KVM bug was that KVM would clear the vector, but relying on KVM to clear the vector (i.e. make it #DE) makes it less likely that the test would ever find *new* KVM bugs, e.g. because only the first iteration would run with a legal vector to start. Explicitly inject #UD for race_events_inj_pen() as well, e.g. so that it doesn't inherit the illegal 255 vector from race_events_exc(), which currently runs first. Link: https://lore.kernel.org/r/20230817233430.1416463-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 5002b11 commit 02dc254

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tools/testing/selftests/kvm/x86_64/sync_regs_test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ static void *race_events_inj_pen(void *arg)
9191
struct kvm_run *run = (struct kvm_run *)arg;
9292
struct kvm_vcpu_events *events = &run->s.regs.events;
9393

94+
WRITE_ONCE(events->exception.nr, UD_VECTOR);
95+
9496
for (;;) {
9597
WRITE_ONCE(run->kvm_dirty_regs, KVM_SYNC_X86_EVENTS);
9698
WRITE_ONCE(events->flags, 0);
@@ -115,6 +117,7 @@ static void *race_events_exc(void *arg)
115117
for (;;) {
116118
WRITE_ONCE(run->kvm_dirty_regs, KVM_SYNC_X86_EVENTS);
117119
WRITE_ONCE(events->flags, 0);
120+
WRITE_ONCE(events->exception.nr, UD_VECTOR);
118121
WRITE_ONCE(events->exception.pending, 1);
119122
WRITE_ONCE(events->exception.nr, 255);
120123

0 commit comments

Comments
 (0)