Commit a6a9099
committed
KVM: x86: avoid calling x86 emulator without a decoded instruction
jira VULN-3154
cve CVE-2022-1852
commit-author Sean Christopherson <seanjc@google.com>
commit fee060c
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>
(cherry picked from commit fee060c)
Signed-off-by: Marcin Wcisło <marcin.wcislo@conclusive.pl>1 parent 20fbcdb commit a6a9099
1 file changed
Lines changed: 19 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7973 | 7973 | | |
7974 | 7974 | | |
7975 | 7975 | | |
7976 | | - | |
| 7976 | + | |
7977 | 7977 | | |
7978 | 7978 | | |
7979 | 7979 | | |
| |||
8042 | 8042 | | |
8043 | 8043 | | |
8044 | 8044 | | |
8045 | | - | |
| 8045 | + | |
| 8046 | + | |
| 8047 | + | |
| 8048 | + | |
| 8049 | + | |
| 8050 | + | |
| 8051 | + | |
| 8052 | + | |
8046 | 8053 | | |
8047 | 8054 | | |
8048 | 8055 | | |
8049 | 8056 | | |
8050 | | - | |
8051 | 8057 | | |
| 8058 | + | |
8052 | 8059 | | |
8053 | 8060 | | |
8054 | 8061 | | |
8055 | | - | |
8056 | | - | |
8057 | | - | |
8058 | | - | |
8059 | | - | |
8060 | | - | |
8061 | | - | |
8062 | | - | |
8063 | | - | |
8064 | 8062 | | |
8065 | 8063 | | |
8066 | 8064 | | |
| |||
8093 | 8091 | | |
8094 | 8092 | | |
8095 | 8093 | | |
| 8094 | + | |
| 8095 | + | |
| 8096 | + | |
| 8097 | + | |
| 8098 | + | |
| 8099 | + | |
| 8100 | + | |
| 8101 | + | |
| 8102 | + | |
8096 | 8103 | | |
8097 | 8104 | | |
8098 | 8105 | | |
| |||
0 commit comments