Revision 118154bdf54ca79e4b5f3ce6d4a8a7c6b7c2c76f authored by Liran Alon on 16 July 2019, 23:56:58 UTC, committed by Paolo Bonzini on 20 July 2019, 07:00:44 UTC
When CPU raise #NPF on guest data access and guest CR4.SMAP=1, it is
possible that CPU microcode implementing DecodeAssist will fail
to read bytes of instruction which caused #NPF. This is AMD errata
1096 and it happens because CPU microcode reading instruction bytes
incorrectly attempts to read code as implicit supervisor-mode data
accesses (that is, just like it would read e.g. a TSS), which are
susceptible to SMAP faults. The microcode reads CS:RIP and if it is
a user-mode address according to the page tables, the processor
gives up and returns no instruction bytes.  In this case,
GuestIntrBytes field of the VMCB on a VMEXIT will incorrectly
return 0 instead of the correct guest instruction bytes.

Current KVM code attemps to detect and workaround this errata, but it
has multiple issues:

1) It mistakenly checks if guest CR4.SMAP=0 instead of guest CR4.SMAP=1,
which is required for encountering a SMAP fault.

2) It assumes SMAP faults can only occur when guest CPL==3.
However, in case guest CR4.SMEP=0, the guest can execute an instruction
which reside in a user-accessible page with CPL<3 priviledge. If this
instruction raise a #NPF on it's data access, then CPU DecodeAssist
microcode will still encounter a SMAP violation.  Even though no sane
OS will do so (as it's an obvious priviledge escalation vulnerability),
we still need to handle this semanticly correct in KVM side.

Note that (2) *is* a useful optimization, because CR4.SMAP=1 is an easy
triggerable condition and guests usually enable SMAP together with SMEP.
If the vCPU has CR4.SMEP=1, the errata could indeed be encountered onlt
at guest CPL==3; otherwise, the CPU would raise a SMEP fault to guest
instead of #NPF.  We keep this condition to avoid false positives in
the detection of the errata.

In addition, to avoid future confusion and improve code readbility,
include details of the errata in code and not just in commit message.

Fixes: 05d5a4863525 ("KVM: SVM: Workaround errata#1096 (insn_len maybe zero on SMAP violation)")
Cc: Singh Brijesh <brijesh.singh@amd.com>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 0c5f81d
History
File Mode Size
partitions
Kconfig -rw-r--r-- 5.8 KB
Kconfig.iosched -rw-r--r-- 1.3 KB
Makefile -rw-r--r-- 1.5 KB
badblocks.c -rw-r--r-- 14.1 KB
bfq-cgroup.c -rw-r--r-- 35.1 KB
bfq-iosched.c -rw-r--r-- 232.5 KB
bfq-iosched.h -rw-r--r-- 36.1 KB
bfq-wf2q.c -rw-r--r-- 52.3 KB
bio-integrity.c -rw-r--r-- 12.2 KB
bio.c -rw-r--r-- 53.5 KB
blk-cgroup.c -rw-r--r-- 44.9 KB
blk-core.c -rw-r--r-- 47.5 KB
blk-exec.c -rw-r--r-- 2.6 KB
blk-flush.c -rw-r--r-- 14.3 KB
blk-integrity.c -rw-r--r-- 11.4 KB
blk-ioc.c -rw-r--r-- 10.2 KB
blk-iolatency.c -rw-r--r-- 27.9 KB
blk-lib.c -rw-r--r-- 10.2 KB
blk-map.c -rw-r--r-- 6.0 KB
blk-merge.c -rw-r--r-- 20.6 KB
blk-mq-cpumap.c -rw-r--r-- 1.9 KB
blk-mq-debugfs-zoned.c -rw-r--r-- 435 bytes
blk-mq-debugfs.c -rw-r--r-- 24.4 KB
blk-mq-debugfs.h -rw-r--r-- 2.7 KB
blk-mq-pci.c -rw-r--r-- 1.3 KB
blk-mq-rdma.c -rw-r--r-- 1.3 KB
blk-mq-sched.c -rw-r--r-- 14.1 KB
blk-mq-sched.h -rw-r--r-- 2.7 KB
blk-mq-sysfs.c -rw-r--r-- 8.6 KB
blk-mq-tag.c -rw-r--r-- 14.4 KB
blk-mq-tag.h -rw-r--r-- 2.3 KB
blk-mq-virtio.c -rw-r--r-- 1.3 KB
blk-mq.c -rw-r--r-- 85.7 KB
blk-mq.h -rw-r--r-- 6.5 KB
blk-pm.c -rw-r--r-- 6.6 KB
blk-pm.h -rw-r--r-- 1.4 KB
blk-rq-qos.c -rw-r--r-- 6.4 KB
blk-rq-qos.h -rw-r--r-- 4.4 KB
blk-settings.c -rw-r--r-- 26.8 KB
blk-softirq.c -rw-r--r-- 3.7 KB
blk-stat.c -rw-r--r-- 4.6 KB
blk-stat.h -rw-r--r-- 4.6 KB
blk-sysfs.c -rw-r--r-- 26.2 KB
blk-throttle.c -rw-r--r-- 67.9 KB
blk-timeout.c -rw-r--r-- 3.8 KB
blk-wbt.c -rw-r--r-- 20.0 KB
blk-wbt.h -rw-r--r-- 3.0 KB
blk-zoned.c -rw-r--r-- 11.7 KB
blk.h -rw-r--r-- 10.5 KB
bounce.c -rw-r--r-- 9.3 KB
bsg-lib.c -rw-r--r-- 9.8 KB
bsg.c -rw-r--r-- 11.1 KB
cmdline-parser.c -rw-r--r-- 4.9 KB
compat_ioctl.c -rw-r--r-- 10.9 KB
elevator.c -rw-r--r-- 16.4 KB
genhd.c -rw-r--r-- 50.2 KB
ioctl.c -rw-r--r-- 15.4 KB
ioprio.c -rw-r--r-- 5.1 KB
kyber-iosched.c -rw-r--r-- 27.8 KB
mq-deadline.c -rw-r--r-- 20.6 KB
opal_proto.h -rw-r--r-- 9.3 KB
partition-generic.c -rw-r--r-- 17.4 KB
scsi_ioctl.c -rw-r--r-- 18.5 KB
sed-opal.c -rw-r--r-- 58.3 KB
t10-pi.c -rw-r--r-- 7.2 KB

back to top