mirror_ubuntu-kernels/Documentation
Daniel Sneddon 6faeb619d1 x86/speculation: Add RSB VM Exit protections
BugLink: https://bugs.launchpad.net/bugs/1989221

commit 2b12993220 upstream.

tl;dr: The Enhanced IBRS mitigation for Spectre v2 does not work as
documented for RET instructions after VM exits. Mitigate it with a new
one-entry RSB stuffing mechanism and a new LFENCE.

== Background ==

Indirect Branch Restricted Speculation (IBRS) was designed to help
mitigate Branch Target Injection and Speculative Store Bypass, i.e.
Spectre, attacks. IBRS prevents software run in less privileged modes
from affecting branch prediction in more privileged modes. IBRS requires
the MSR to be written on every privilege level change.

To overcome some of the performance issues of IBRS, Enhanced IBRS was
introduced.  eIBRS is an "always on" IBRS, in other words, just turn
it on once instead of writing the MSR on every privilege level change.
When eIBRS is enabled, more privileged modes should be protected from
less privileged modes, including protecting VMMs from guests.

== Problem ==

Here's a simplification of how guests are run on Linux' KVM:

void run_kvm_guest(void)
{
	// Prepare to run guest
	VMRESUME();
	// Clean up after guest runs
}

The execution flow for that would look something like this to the
processor:

1. Host-side: call run_kvm_guest()
2. Host-side: VMRESUME
3. Guest runs, does "CALL guest_function"
4. VM exit, host runs again
5. Host might make some "cleanup" function calls
6. Host-side: RET from run_kvm_guest()

Now, when back on the host, there are a couple of possible scenarios of
post-guest activity the host needs to do before executing host code:

* on pre-eIBRS hardware (legacy IBRS, or nothing at all), the RSB is not
touched and Linux has to do a 32-entry stuffing.

* on eIBRS hardware, VM exit with IBRS enabled, or restoring the host
IBRS=1 shortly after VM exit, has a documented side effect of flushing
the RSB except in this PBRSB situation where the software needs to stuff
the last RSB entry "by hand".

IOW, with eIBRS supported, host RET instructions should no longer be
influenced by guest behavior after the host retires a single CALL
instruction.

However, if the RET instructions are "unbalanced" with CALLs after a VM
exit as is the RET in #6, it might speculatively use the address for the
instruction after the CALL in #3 as an RSB prediction. This is a problem
since the (untrusted) guest controls this address.

Balanced CALL/RET instruction pairs such as in step #5 are not affected.

== Solution ==

The PBRSB issue affects a wide variety of Intel processors which
support eIBRS. But not all of them need mitigation. Today,
X86_FEATURE_RSB_VMEXIT triggers an RSB filling sequence that mitigates
PBRSB. Systems setting RSB_VMEXIT need no further mitigation - i.e.,
eIBRS systems which enable legacy IBRS explicitly.

However, such systems (X86_FEATURE_IBRS_ENHANCED) do not set RSB_VMEXIT
and most of them need a new mitigation.

Therefore, introduce a new feature flag X86_FEATURE_RSB_VMEXIT_LITE
which triggers a lighter-weight PBRSB mitigation versus RSB_VMEXIT.

The lighter-weight mitigation performs a CALL instruction which is
immediately followed by a speculative execution barrier (INT3). This
steers speculative execution to the barrier -- just like a retpoline
-- which ensures that speculation can never reach an unbalanced RET.
Then, ensure this CALL is retired before continuing execution with an
LFENCE.

In other words, the window of exposure is opened at VM exit where RET
behavior is troublesome. While the window is open, force RSB predictions
sampling for RET targets to a dead end at the INT3. Close the window
with the LFENCE.

There is a subset of eIBRS systems which are not vulnerable to PBRSB.
Add these systems to the cpu_vuln_whitelist[] as NO_EIBRS_PBRSB.
Future systems that aren't vulnerable will set ARCH_CAP_PBRSB_NO.

  [ bp: Massage, incorporate review comments from Andy Cooper. ]

Signed-off-by: Daniel Sneddon <daniel.sneddon@linux.intel.com>
Co-developed-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2022-09-16 10:53:54 +02:00
..
ABI iio: adc: vf610: fix conversion mode sysfs node name 2022-08-26 10:53:53 +02:00
accounting sched/psi: report zeroes for CPU full at the system level 2022-08-10 09:24:10 +02:00
admin-guide x86/speculation: Add RSB VM Exit protections 2022-09-16 10:53:54 +02:00
arm
arm64 arm64: Enable repeat tlbi workaround on KRYO4XX gold CPUs 2022-08-10 09:22:45 +02:00
block
bpf
cdrom
cgroups
core-api Reinstate some of "swiotlb: rework "fix info leak with DMA_FROM_DEVICE"" 2022-05-20 14:40:19 +02:00
cpu-freq cpufreq: Remove ready() callback 2021-09-02 18:04:17 +02:00
crypto
dev-tools kfence: default to dynamic branch instead of static keys mode 2021-12-07 07:32:24 +01:00
devicetree dt-bindings: bluetooth: broadcom: Add BCM4349B1 DT binding 2022-09-16 10:53:53 +02:00
doc-guide
driver-api firmware: sysfb: Add sysfb_disable() helper function 2022-09-16 10:52:56 +02:00
fault-injection
fb
features
filesystems docs: update mapping documentation 2022-08-26 10:54:06 +02:00
firmware_class
firmware-guide
fpga
gpu drm/i915/display: Move DRRS code its own file 2022-03-09 15:17:50 +01:00
hid
hwmon
i2c
ia64
ide
iio
infiniband
input
isdn
kbuild
kernel-hacking
leds
litmus-tests
livepatch
locking
m68k docs: archis: add a per-architecture features list 2020-12-03 15:10:15 -07:00
maintainer
mhi
mips
misc-devices
netlabel docs: add some directories to the main documentation index 2019-07-15 11:03:03 -03:00
networking Documentation: fix sctp_wmem in ip-sysctl.rst 2022-09-16 10:53:43 +02:00
nios2
nvdimm
openrisc
parisc
PCI
pcmcia
power
powerpc
process docs: submitting-patches: Fix crossref to 'The canonical patch format' 2022-08-10 09:23:26 +02:00
RCU
riscv
s390
scheduler
scsi
security
sh
sound ALSA: usb-audio: Add quirk bits for enabling/disabling generic implicit fb 2022-08-10 09:23:56 +02:00
sparc
sphinx docs: sphinx/requirements: Limit jinja2<3.1 2022-05-20 14:37:23 +02:00
sphinx-static
spi
staging
target
timers
trace tracing: Add ustring operation to filtering string pointers 2022-03-09 15:17:45 +01:00
translations
usb
userspace-api landlock: Reduce the maximum number of layers to 16 2022-08-10 09:25:18 +02:00
virt KVM: s390: Clarify key argument for MEM_OP in api docs 2022-02-24 14:27:49 +01:00
vm
w1
watchdog
x86 Documentation/x86: Add documentation for using dynamic XSTATE features 2022-05-05 09:14:19 +02:00
xtensa
.gitignore
arch.rst
asm-annotations.rst
atomic_bitops.txt
atomic_t.txt
Changes
CodingStyle
conf.py docs/conf.py: Cope with removal of language=None in Sphinx 5.0.0 2022-08-10 09:25:29 +02:00
COPYING-logo
docutils.conf
dontdiff
index.rst
Kconfig
logo.gif
Makefile
memory-barriers.txt
SubmittingPatches
watch_queue.rst