Commit fee060c
KVM: x86: avoid calling x86 emulator without a decoded instruction
Whenever x86_decode_emulated_instruction() detects a breakpoint, it
returns the value that kvm_vcpu_check_breakpoint() writes into its
pass-by-reference second argument. Unfortunately this is completely
bogus because the expected outcome of x86_decode_emulated_instruction
is an EMULATION_* value.
Then, if kvm_vcpu_check_breakpoint() does "*r = 0" (corresponding to
a KVM_EXIT_DEBUG userspace exit), it is misunderstood as EMULATION_OK
and x86_emulate_instruction() is called without having decoded the
instruction. This causes various havoc from running with a stale
emulation context.
The fix is to move the call to kvm_vcpu_check_breakpoint() where it was
before commit 4aa2691 ("KVM: x86: Factor out x86 instruction
emulation with decoding") introduced x86_decode_emulated_instruction().
The other caller of the function does not need breakpoint checks,
because it is invoked as part of a vmexit and the processor has already
checked those before executing the instruction that #GP'd.
This fixes CVE-2022-1852.
Reported-by: Qiuhao Li <qiuhao@sysec.org>
Reported-by: Gaoning Pan <pgn@zju.edu.cn>
Reported-by: Yongkang Jia <kangel@zju.edu.cn>
Fixes: 4aa2691 ("KVM: x86: Factor out x86 instruction emulation with decoding")
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20220311032801.3467418-2-seanjc@google.com>
[Rewrote commit message according to Qiuhao's report, since a patch
already existed to fix the bug. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>1 parent d22d247 commit fee060c
1 file changed
Lines changed: 19 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8296 | 8296 | | |
8297 | 8297 | | |
8298 | 8298 | | |
8299 | | - | |
| 8299 | + | |
8300 | 8300 | | |
8301 | 8301 | | |
8302 | 8302 | | |
| |||
8365 | 8365 | | |
8366 | 8366 | | |
8367 | 8367 | | |
8368 | | - | |
| 8368 | + | |
| 8369 | + | |
| 8370 | + | |
| 8371 | + | |
| 8372 | + | |
| 8373 | + | |
| 8374 | + | |
| 8375 | + | |
8369 | 8376 | | |
8370 | 8377 | | |
8371 | 8378 | | |
8372 | 8379 | | |
8373 | | - | |
8374 | 8380 | | |
| 8381 | + | |
8375 | 8382 | | |
8376 | 8383 | | |
8377 | 8384 | | |
8378 | | - | |
8379 | | - | |
8380 | | - | |
8381 | | - | |
8382 | | - | |
8383 | | - | |
8384 | | - | |
8385 | | - | |
8386 | | - | |
8387 | 8385 | | |
8388 | 8386 | | |
8389 | 8387 | | |
| |||
8416 | 8414 | | |
8417 | 8415 | | |
8418 | 8416 | | |
| 8417 | + | |
| 8418 | + | |
| 8419 | + | |
| 8420 | + | |
| 8421 | + | |
| 8422 | + | |
| 8423 | + | |
| 8424 | + | |
| 8425 | + | |
8419 | 8426 | | |
8420 | 8427 | | |
8421 | 8428 | | |
| |||
0 commit comments