Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 08 Jul 2018 13:11:33 -0000 Received: from localhost ([127.0.0.1] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1fc9Qb-0008PE-Bt for speck@linutronix.de; Sun, 08 Jul 2018 15:08:37 +0200 Message-ID: <20180708125654.812951995@linutronix.de> Date: Sun, 08 Jul 2018 14:52:18 +0200 From: Thomas Gleixner References: <20180708125216.197406530@linutronix.de> Subject: [patch 2/2] Command line and documentation 2 Mime-Version: 1 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: From: Thomas Gleixner Subject: [patch 2/2] Documentation: Add section about CPU vulnerabilities Signed-off-by: Thomas Gleixner --- Documentation/admin-guide/index.rst | 9 Documentation/admin-guide/l1tf.rst | 356 ++++++++++++++++++++++++++++++++++++ 2 files changed, 365 insertions(+) --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -17,6 +17,15 @@ etc. kernel-parameters devices +This section describes CPU vulnerabilities and provides an overview over +the possible mitigations along with guidance for selecting mitigations if +they are configurable at compile, boot or run time. + +.. toctree:: + :maxdepth: 1 + + l1tf + Here is a set of documents aimed at users who are trying to track down problems and bugs in particular. --- /dev/null +++ b/Documentation/admin-guide/l1tf.rst @@ -0,0 +1,356 @@ +L1TF - L1 Terminal Fault +======================== + +L1 Terminal Fault is a hardware vulnerability which allows unconstrained +speculative access to data which is available in the Level 1 Data Cache +when the page table entry controlling the virtual access, which is used for +the access, has the present bit cleared. + +Affected CPUs +------------- + +This vulnerability affects a wide range of Intel processors. The +vulnerability is not present on: + + - Older models, where the CPU family is < 6 + + - A range of ATOM processors (Cedarview, Cloverview, Lincroft, Penwell, + Pineview, Slivermont, Airmont, Merrifield) + + - The Core Duo Yonah variants (2006 - 2008) + + - The XEON PHI family + + - Processors which have the ARCH_CAP_RDCL_NO bit set in the + IA32_ARCH_CAPABILITIES MSR. If the bit is set the CPU is also not + affected by the Meltdown vulnerabitly. These CPUs should become + available end of 2018. + +Related CVEs +------------ + +The following CVE entries are related to the L1TF vulnerability:: + + CVE-2018-3615: L1 Terminal Fault - SGX related aspects + CVE-2018-3620: L1 Terminal Fault - OS, SMM related aspects + CVE-2018-3646: L1 Terminal Fault - Virtualization related aspects + +Problem +------- + +If an instruction accesses a virtual address for which the relevant page +table entry (PTE) has the present bit cleared, then the speculative +execution can load the data into the speculation flow when the data from +the physical address which is referenced in the PTE address bits is +available in the Level 1 Data Cache. This is a purely speculative +mechanism and the instruction will raise a page fault when it is retired. + +This creates a window between the load and retirement where speculative +execution can operate on the data and malicious code can use this to create +a side channel to leak the speculated data which was accessed without +permission. + +This flaw is very similar to the Meltdown vulnerability, which speculates +on data which should be not accessible from user space because the +speculation ignores the permission bits. Contrary to Meltdown L1TF can not +be exploited without actually generating page faults. While Meltdown breaks +the user space to kernel space protection, L1TF has a broader scope. It +allows to attack any physical memory address in the system and the attack +works across all protection domains. It allows to attack SGX and also +works from inside virtual machines because the speculation bypasses the +extended page table (EPT) protection mechanism. + +Attack scenarios +---------------- + +1. Malicious user space: + + Operating Systems store arbitrary information in the address bits of a + PTE which is marked non present. This allows a malicious user space + application to attack the physical memory to which these PTEs resolve. + + The Linux kernel contains a mitigation for this attack vector which is + permanently enabled and has no performance impact. A system with an up + to date kernel is not vulnerable as there is no way for a malicious + application to control the content of PTEs which are not marked present. + + | + +2. Malicious guest in a virtual machine + + The fact that L1TF breaks all domain protections allows malicious guest + OSes, which can control the PTEs directly, and malicious userspace, + which runs on an unprotected guest kernel, to attack physical host + memory. + + A special aspect of L1TF in the context of virtualization is symmetric + multi threading (SMT). The Intel implementation of SMT is called + HyperThreading. The fact that Hyperthreads on the affected processors + share the L1 Data Cache (L1D) is important for this. As the flaw allows + only to attack data which is present in L1D, a malicious guest running + on one thread can attack the data which is brought into L1D by the + context which runs on the sibling thread of the same physical core. This + context can be host OS, host user space or a different guest. + + While solutions exist to mitigate these attack vectors fully, these + mitigations are not enabled by default in the Linux kernel because they + can affect performance significantly. The kernel provides several + mechanisms which can be utilized to address the problem depending on the + deployment scenario. + +L1TF system information +----------------------- + +The Linux kernel provides a sysfs interface to read out the information +about L1TF. The relevant sysfs file is: + +/sys/devices/system/cpu/vulnerabilities/l1tf + +It provides information whether the system is affected by L1TF or not and +in case it is affected it provides information about the active mitigation +mechanisms. + +Host mitigation mechanism +------------------------- + +The kernel is unconditionally protected against L1TF attacks from malicious +user space running on the host. + +Guest mitigation mechanisms +--------------------------- + +1. L1D flush on VMENTER + + To make sure that a guest cannot attack data which is present in L1D the + hypervisor flushes L1D before entering the guest. + + Flushing L1D evicts not only the data which should not be accessed by a + potentially malicious guest, it also flushes the guest data. Flushing + L1D has a performance impact as the processor has to bring the flushed + guest data back into L1D. Depending on the frequency of VMEXIT/VMENTER + and the type of computations in the guest performance degradation in the + range of 1% to 50% has been observed. For scenarios where guest + VMEXIT/VMENTER are rare the performance impact is minimal. Virtio and + mechanisms like posted interrupts are designed to confine the VMEXITs to + a bare minimum, but specific configurations and application scenarios + might still suffer from a high VMEXIT rate. + + The general recommendation is to enable L1D flush on VMENTER. + + Note, that L1D flush does not prevent the SMT problem because the + sibling thread will also bring back its data into L1D which makes it + attackable again. + + L1D flush can be controlled by the administrator. + + | + +2. Guest VCPU confinement to dedicated physical cores + + To address the SMT problem, it is possible to make a guest or a group of + guests affine to one or more physical cores. The proper mechanism for + that is to utilize cpusets and to make sure that no other guest or host + tasks can run on these cores. + + If only a single guest or related guests run on sibling SMT threads on + the same physical core then they can only attack their own memory and + restricted parts of the host memory. + + The host memory is attackable, when one of the sibling threads runs in + host OS (hypervisor) context and the other in guest context. The amount + of valuable information from the host OS context depends on the context + which the host OS executes, i.e. interrupts, soft interrupts and kernel + threads. The amount of valuable data from these contexts cannot be + declared as non interesting for an attacker without deep inspection of + the code. + + Note, that assigning guests to a fixed set of physical cores affects the + ability of the scheduler to do load balancing and might have negative + effects on CPU utilization depending on the hosting scenario. Disabling + SMT might be a viable alternative for particular scenarios. + + For further information about confining guests to a single or to a group + of cores consult the cpusets documentation. + + | + +3. Interrupt affinity + + Interrupts can be made affine to logical CPUs. This is not universally + true because there are types of interrupts which are truly per CPU + interrupts, e.g. the local timer interrupt. Aside of that multi queue + devices affine their interrupts to single CPUs or groups of CPUs per + queue without allowing the administrator to control the affinities. + + Moving the interrupts, which can be affinity controlled, away from CPUs + which run untrusted guests, reduces the attack vector space. + + Whether the interrupts with are affine to CPUs, which run untrusted + guests, provide interesting data for an attacker depends on the system + configuration and the scenarios which run on the system. While for some + of the interrupts it can be assumed that they wont expose interesting + information beyond exposing hints about the host OS memory layout, there + is no way to make general assumptions. + + Interrupt affinity can be controlled by the administrator via the + /proc/irq/$NR/smp_affinity[_list] files. + + | + +4. SMT control + + To prevent the SMT issues of L1TF it might be necessary to disable SMT + completely. Disabling SMT can have a significant performance impact, but + the impact depends on the hosting scenario and the type of workloads. + The impact of disabling SMT needs also to be weighted against the impact + of other mitigation solutions like confining guests to dedicated cores. + + The kernel provides a sysfs interface to retrieve the status of SMT and + to control it. It also provides a kernel command line interface to + control SMT. + + The kernel command line interface consists of the following options:: + + nosmt: Affects the bring up of the secondary CPUs during boot. The + kernel tries to bring all present CPUs online during the + boot process. "nosmt" makes sure that from each physical + core only one - the so called primary (hyper) thread is + activated. Due to a design flaw of Intel processors related + to Machine Check Exceptions the non primary siblings have + to be brought up at least partially and are then shut down + again. "nosmt" can be undone via the sysfs interface. + + nosmt=force: Has the same effect as "nosmt' but it does not allow to + undo the SMT disable via the sysfs interface. + + The sysfs interface provides two files: + + - /sys/devices/system/cpu/smt/control + - /sys/devices/system/cpu/smt/active + + /sys/devices/system/cpu/smt/control: + + This file allows to read out the SMT control state and provides the + ability to disable or (re)enable SMT. The possible states are:: + + on: SMT is supported by the CPU and enabled. All + logical CPUs can be onlined and offlined without + restrictions + + off: SMT is supported by the CPU and disabled. Only + the so called primary SMT threads can be onlined + and offlined without restrictions. An attempt to + online a non-primary sibling is rejected + + forceoff: Same as 'off' but the state cannot be controlled. + Attempts to write to the control file are rejected. + + notsupported: The processor does not support SMT. It's therefore + not affected by the SMT implications of L1TF. + Attempts to write to the control file are rejected. + + The possible states which can be written into this file to control SMT + state are: + + - on + - off + - forceoff + + /sys/devices/system/cpu/smt/active: + + This file reports whether SMT is enabled and active, i.e. if on any + physical core two or more sibling threads are online. + +There is ongoing research and development for other mitigation mechanisms +to address the performance impact of disabling SMT. + +Mitigation control on the kernel command line +--------------------------------------------- + +The kernel command line allows to control the L1TF mitigations at boot +time with the option "l1tf=". The valid arguments for this option are:: + + full: Provide all available mitigations for the L1TF + vulnerability. Disable SMT and enable all mitigations + in the hypervisors. SMT control is still possible + after boot. + + full,force: Same as 'full', but disables SMT control. Implies the + 'nosmt=force' command line option. + + novirt: Leaves SMT enabled and does not enable the hypervisor + mitigation. Hypervisors will issue a warning when the first + VM is being started in a potentially insecure + configuration, i.e. SMT enabled or L1D flush disabled. + + novirt,nowarn: Same as 'novirt', but hypervisors will not warn when + a VM is started in a potentially insecure configuration. + +The default is 'novirt'. + +Mitigation control for KVM - command line or module parameter +------------------------------------------------------------- + +The KVM hypervisor mitigation mechanism, flushing the L1D cache when +entering a guest, can be controlled from the kernel command line or when +the KVM-Intel hypervisor is built as a module also with a module parameter. + +The option/parameter is "kvm-intel.vmentry_l1d_flush=". It takes the +following arguments:: + + always: L1D cache flush on every VMENTER. + + cond: Flush L1D on VMENTER only when the code between VMEXIT and + VMENTER can leak host memory which is considered + interesting for an attacker. This still can leak host data + which allows e.g. to determine the hosts address space layout. + + never: Disables the mitigation + +The default is 'cond'. If 'l1tf=full' or 'l1tf=full,force' are given on the +kernel command line, these take precedence. + + +Mitigation selection guide +-------------------------- + +1. No virtualization in use + + The system is protected by the kernel unconditionally and no further + action is required. + + | + +2. Virtualization with trusted guests + + If the guest comes from a trusted source and the guest OS kernel is + guaranteed to have the L1TF mitigations in place the system is fully + protected against L1TF and no further action is required. + + | + +3. Virtualization with untrusted guests + + If SMT is not supported by the processor or disabled in the BIOS or by + the kernel, it's only required to enforce L1D flushing on VMENTER. This + can be achieved with the l1tf or the kvm-intel command line or module + parameters. + + If SMT is supported and active then various degrees of mitigations can + be employed. + + - Confinement of guests to a single or a group of physical cores which + are not running any other processes, can reduce the attack surface + significantly, but interrupts, soft interrupts and kernel threads can + still expose valuable data to a potential attacker + + - Isolating the guest CPUs from interrupts can reduce the attack surface + further, but still allows a malicious guest to explore a limited + amount of host physical memory. This can at least be used to gain + knowledge about the host address space layout. The interrupts which + have a fixed affinity to the CPUs which run the untrusted guests can + depending on the scenario still trigger soft interrupts and schedule + kernel threads which might expose valuable information. + + - Disabling SMT and enforcing the L1D flushing provides the maximum + amount of protection.