1. 07 Oct, 2022 3 commits
  2. 05 Sep, 2022 1 commit
  3. 11 Aug, 2022 1 commit
    • Daniel Sneddon's avatar
      x86/speculation: Add RSB VM Exit protections · f2f41ef0
      Daniel Sneddon authored
      commit 2b129932
      
       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_RETPOLINE triggers an RSB filling sequence that mitigates
      PBRSB. Systems setting RETPOLINE need no further mitigation - i.e.,
      eIBRS systems which enable retpoline explicitly.
      
      However, such systems (X86_FEATURE_IBRS_ENHANCED) do not set RETPOLINE
      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 Filling at
      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. ]
        [ Pawan: Update commit message to replace RSB_VMEXIT with RETPOLINE ]
      Signed-off-by: default avatarDaniel Sneddon <daniel.sneddon@linux.intel.com>
      Co-developed-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f2f41ef0
  4. 16 Jun, 2022 7 commits
  5. 11 Mar, 2022 8 commits
  6. 02 Dec, 2020 1 commit
    • Anand K Mistry's avatar
      x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb · e799c00a
      Anand K Mistry authored
      commit 33fc379d upstream.
      
      When spectre_v2_user={seccomp,prctl},ibpb is specified on the command
      line, IBPB is force-enabled and STIPB is conditionally-enabled (or not
      available).
      
      However, since
      
        21998a35 ("x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS.")
      
      the spectre_v2_user_ibpb variable is set to SPECTRE_V2_USER_{PRCTL,SECCOMP}
      instead of SPECTRE_V2_USER_STRICT, which is the actual behaviour.
      Because the issuing of IBPB relies on the switch_mm_*_ibpb static
      branches, the mitigations behave as expected.
      
      Since
      
        1978b3a5 ("x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP")
      
      this discrepency caused the misreporting of IB speculation via prctl().
      
      On CPUs with STIBP always-on and spectre_v2_user=seccomp,ibpb,
      prctl(PR_GET_SPECULATION_CTRL) would return PR_SPEC_PRCTL |
      PR_SPEC_ENABLE instead of PR_SPEC_DISABLE since both IBPB and STIPB are
      always on. It also allowed prctl(PR_SET_SPECULATION_CTRL) to set the IB
      speculation mode, even though the flag is ignored.
      
      Similarly, for CPUs without SMT, prctl(PR_GET_SPECULATION_CTRL) should
      also return PR_SPEC_DISABLE since IBPB is always on and STIBP is not
      available.
      
       [ bp: Massage commit message. ]
      
      Fixes: 21998a35 ("x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS.")
      Fixes: 1978b3a5
      
       ("x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP")
      Signed-off-by: default avatarAnand K Mistry <amistry@google.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: <stable@vger.kernel.org>
      Link: https://lkml.kernel.org/r/20201110123349.1.Id0cbf996d2151f4c143c90f9028651a5b49a5908@changeid
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e799c00a
  7. 18 Nov, 2020 1 commit
    • Anand K Mistry's avatar
      x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP · b74fe318
      Anand K Mistry authored
      commit 1978b3a5 upstream.
      
      On AMD CPUs which have the feature X86_FEATURE_AMD_STIBP_ALWAYS_ON,
      STIBP is set to on and
      
        spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED
      
      At the same time, IBPB can be set to conditional.
      
      However, this leads to the case where it's impossible to turn on IBPB
      for a process because in the PR_SPEC_DISABLE case in ib_prctl_set() the
      
        spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED
      
      condition leads to a return before the task flag is set. Similarly,
      ib_prctl_get() will return PR_SPEC_DISABLE even though IBPB is set to
      conditional.
      
      More generally, the following cases are possible:
      
      1. STIBP = conditional && IBPB = on for spectre_v2_user=seccomp,ibpb
      2. STIBP = on && IBPB = conditional for AMD CPUs with
         X86_FEATURE_AMD_STIBP_ALWAYS_ON
      
      The first case functions correctly today, but only because
      spectre_v2_user_ibpb isn't updated to reflect the IBPB mode.
      
      At a high level, this change does one thing. If either STIBP or IBPB
      is set to conditional, allow the prctl to change the task flag.
      Also, reflect that capability when querying the state. This isn't
      perfect since it doesn't take into account if only STIBP or IBPB is
      unconditionally on. But it allows the conditional feature to work as
      expected, without affecting the unconditional one.
      
       [ bp: Massage commit message and comment; space out statements for
         better readability. ]
      
      Fixes: 21998a35
      
       ("x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS.")
      Signed-off-by: default avatarAnand K Mistry <amistry@google.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Acked-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Link: https://lkml.kernel.org/r/20201105163246.v2.1.Ifd7243cd3e2c2206a893ad0a5b9a4f19549e22c6@changeid
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      b74fe318
  8. 17 Jun, 2020 2 commits
    • Anthony Steinhauser's avatar
      x86/speculation: PR_SPEC_FORCE_DISABLE enforcement for indirect branches. · e1545848
      Anthony Steinhauser authored
      commit 4d8df8cb upstream.
      
      Currently, it is possible to enable indirect branch speculation even after
      it was force-disabled using the PR_SPEC_FORCE_DISABLE option. Moreover, the
      PR_GET_SPECULATION_CTRL command gives afterwards an incorrect result
      (force-disabled when it is in fact enabled). This also is inconsistent
      vs. STIBP and the documention which cleary states that
      PR_SPEC_FORCE_DISABLE cannot be undone.
      
      Fix this by actually enforcing force-disabled indirect branch
      speculation. PR_SPEC_ENABLE called after PR_SPEC_FORCE_DISABLE now fails
      with -EPERM as described in the documentation.
      
      Fixes: 9137bb27
      
       ("x86/speculation: Add prctl() control for indirect branch speculation")
      Signed-off-by: default avatarAnthony Steinhauser <asteinhauser@google.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e1545848
    • Anthony Steinhauser's avatar
      x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS. · 6d60d546
      Anthony Steinhauser authored
      commit 21998a35 upstream.
      
      When STIBP is unavailable or enhanced IBRS is available, Linux
      force-disables the IBPB mitigation of Spectre-BTB even when simultaneous
      multithreading is disabled. While attempts to enable IBPB using
      prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH, ...) fail with
      EPERM, the seccomp syscall (or its prctl(PR_SET_SECCOMP, ...) equivalent)
      which are used e.g. by Chromium or OpenSSH succeed with no errors but the
      application remains silently vulnerable to cross-process Spectre v2 attacks
      (classical BTB poisoning). At the same time the SYSFS reporting
      (/sys/devices/system/cpu/vulnerabilities/spectre_v2) displays that IBPB is
      conditionally enabled when in fact it is unconditionally disabled.
      
      STIBP is useful only when SMT is enabled. When SMT is disabled and STIBP is
      unavailable, it makes no sense to force-disable also IBPB, because IBPB
      protects against cross-process Spectre-BTB attacks regardless of the SMT
      state. At the same time since missing STIBP was only observed on AMD CPUs,
      AMD does not recommend using STIBP, but recommends using IBPB, so disabling
      IBPB because of missing STIBP goes directly against AMD's advice:
      https://developer.amd.com/wp-content/resources/Architecture_Guidelines_Update_Indirect_Branch_Control.pdf
      
      Similarly, enhanced IBRS is designed to protect cross-core BTB poisoning
      and BTB-poisoning attacks from user space against kernel (and
      BTB-poisoning attacks from guest against hypervisor), it is not designed
      to prevent cross-process (or cross-VM) BTB poisoning between processes (or
      VMs) running on the same core. Therefore, even with enhanced IBRS it is
      necessary to flush the BTB during context-switches, so there is no reason
      to force disable IBPB when enhanced IBRS is available.
      
      Enable the prctl control of IBPB even when STIBP is unavailable or enhanced
      IBRS is available.
      
      Fixes: 7cc765a6
      
       ("x86/speculation: Enable prctl mode for spectre_v2_user")
      Signed-off-by: default avatarAnthony Steinhauser <asteinhauser@google.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6d60d546
  9. 10 Jun, 2020 1 commit
  10. 29 Nov, 2019 2 commits
    • Waiman Long's avatar
      x86/speculation: Fix redundant MDS mitigation message · 7b77206a
      Waiman Long authored
      commit cd5a2aa8
      
       upstream.
      
      Since MDS and TAA mitigations are inter-related for processors that are
      affected by both vulnerabilities, the followiing confusing messages can
      be printed in the kernel log:
      
        MDS: Vulnerable
        MDS: Mitigation: Clear CPU buffers
      
      To avoid the first incorrect message, defer the printing of MDS
      mitigation after the TAA mitigation selection has been done. However,
      that has the side effect of printing TAA mitigation first before MDS
      mitigation.
      
       [ bp: Check box is affected/mitigations are disabled first before
         printing and massage. ]
      Suggested-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarWaiman Long <longman@redhat.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Mark Gross <mgross@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Tim Chen <tim.c.chen@linux.intel.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Cc: x86-ml <x86@kernel.org>
      Link: https://lkml.kernel.org/r/20191115161445.30809-3-longman@redhat.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7b77206a
    • Waiman Long's avatar
      x86/speculation: Fix incorrect MDS/TAA mitigation status · 75cad94d
      Waiman Long authored
      commit 64870ed1 upstream.
      
      For MDS vulnerable processors with TSX support, enabling either MDS or
      TAA mitigations will enable the use of VERW to flush internal processor
      buffers at the right code path. IOW, they are either both mitigated
      or both not. However, if the command line options are inconsistent,
      the vulnerabilites sysfs files may not report the mitigation status
      correctly.
      
      For example, with only the "mds=off" option:
      
        vulnerabilities/mds:Vulnerable; SMT vulnerable
        vulnerabilities/tsx_async_abort:Mitigation: Clear CPU buffers; SMT vulnerable
      
      The mds vulnerabilities file has wrong status in this case. Similarly,
      the taa vulnerability file will be wrong with mds mitigation on, but
      taa off.
      
      Change taa_select_mitigation() to sync up the two mitigation status
      and have them turned off if both "mds=off" and "tsx_async_abort=off"
      are present.
      
      Update documentation to emphasize the fact that both "mds=off" and
      "tsx_async_abort=off" have to be specified together for processors that
      are affected by both TAA and MDS to be effective.
      
       [ bp: Massage and add kernel-parameters.txt change too. ]
      
      Fixes: 1b42f017
      
       ("x86/speculation/taa: Add mitigation for TSX Async Abort")
      Signed-off-by: default avatarWaiman Long <longman@redhat.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Kosina <jkosina@suse.cz>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: linux-doc@vger.kernel.org
      Cc: Mark Gross <mgross@linux.intel.com>
      Cc: <stable@vger.kernel.org>
      Cc: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Tim Chen <tim.c.chen@linux.intel.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Cc: x86-ml <x86@kernel.org>
      Link: https://lkml.kernel.org/r/20191115161445.30809-2-longman@redhat.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      75cad94d
  11. 07 Nov, 2019 1 commit
    • Josh Poimboeuf's avatar
      x86/speculation/taa: Fix printing of TAA_MSG_SMT on IBRS_ALL CPUs · 012206a8
      Josh Poimboeuf authored
      For new IBRS_ALL CPUs, the Enhanced IBRS check at the beginning of
      cpu_bugs_smt_update() causes the function to return early, unintentionally
      skipping the MDS and TAA logic.
      
      This is not a problem for MDS, because there appears to be no overlap
      between IBRS_ALL and MDS-affected CPUs.  So the MDS mitigation would be
      disabled and nothing would need to be done in this function anyway.
      
      But for TAA, the TAA_MSG_SMT string will never get printed on Cascade
      Lake and newer.
      
      The check is superfluous anyway: when 'spectre_v2_enabled' is
      SPECTRE_V2_IBRS_ENHANCED, 'spectre_v2_user' is always
      SPECTRE_V2_USER_NONE, and so the 'spectre_v2_user' switch statement
      handles it appropriately by doing nothing.  So just remove the check.
      
      Fixes: 1b42f017
      
       ("x86/speculation/taa: Add mitigation for TSX Async Abort")
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarTyler Hicks <tyhicks@canonical.com>
      Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
      012206a8
  12. 04 Nov, 2019 2 commits
    • Paolo Bonzini's avatar
      kvm: mmu: ITLB_MULTIHIT mitigation · b8e8c830
      Paolo Bonzini authored
      
      With some Intel processors, putting the same virtual address in the TLB
      as both a 4 KiB and 2 MiB page can confuse the instruction fetch unit
      and cause the processor to issue a machine check resulting in a CPU lockup.
      
      Unfortunately when EPT page tables use huge pages, it is possible for a
      malicious guest to cause this situation.
      
      Add a knob to mark huge pages as non-executable. When the nx_huge_pages
      parameter is enabled (and we are using EPT), all huge pages are marked as
      NX. If the guest attempts to execute in one of those pages, the page is
      broken down into 4K pages, which are then marked executable.
      
      This is not an issue for shadow paging (except nested EPT), because then
      the host is in control of TLB flushes and the problematic situation cannot
      happen.  With nested EPT, again the nested guest can cause problems shadow
      and direct EPT is treated in the same way.
      
      [ tglx: Fixup default to auto and massage wording a bit ]
      Originally-by: default avatarJunaid Shahid <junaids@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      b8e8c830
    • Vineela Tummalapalli's avatar
      x86/bugs: Add ITLB_MULTIHIT bug infrastructure · db4d30fb
      Vineela Tummalapalli authored
      Some processors may incur a machine check error possibly resulting in an
      unrecoverable CPU lockup when an instruction fetch encounters a TLB
      multi-hit in the instruction TLB. This can occur when the page size is
      changed along with either the physical address or cache type. The relevant
      erratum can be found here:
      
         https://bugzilla.kernel.org/show_bug.cgi?id=205195
      
      
      
      There are other processors affected for which the erratum does not fully
      disclose the impact.
      
      This issue affects both bare-metal x86 page tables and EPT.
      
      It can be mitigated by either eliminating the use of large pages or by
      using careful TLB invalidations when changing the page size in the page
      tables.
      
      Just like Spectre, Meltdown, L1TF and MDS, a new bit has been allocated in
      MSR_IA32_ARCH_CAPABILITIES (PSCHANGE_MC_NO) and will be set on CPUs which
      are mitigated against this issue.
      Signed-off-by: default avatarVineela Tummalapalli <vineela.tummalapalli@intel.com>
      Co-developed-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      db4d30fb
  13. 28 Oct, 2019 2 commits
    • Pawan Gupta's avatar
      x86/speculation/taa: Add sysfs reporting for TSX Async Abort · 6608b45a
      Pawan Gupta authored
      
      Add the sysfs reporting file for TSX Async Abort. It exposes the
      vulnerability and the mitigation state similar to the existing files for
      the other hardware vulnerabilities.
      
      Sysfs file path is:
      /sys/devices/system/cpu/vulnerabilities/tsx_async_abort
      Signed-off-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Tested-by: default avatarNeelima Krishnan <neelima.krishnan@intel.com>
      Reviewed-by: default avatarMark Gross <mgross@linux.intel.com>
      Reviewed-by: default avatarTony Luck <tony.luck@intel.com>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      6608b45a
    • Pawan Gupta's avatar
      x86/speculation/taa: Add mitigation for TSX Async Abort · 1b42f017
      Pawan Gupta authored
      TSX Async Abort (TAA) is a side channel vulnerability to the internal
      buffers in some Intel processors similar to Microachitectural Data
      Sampling (MDS). In this case, certain loads may speculatively pass
      invalid data to dependent operations when an asynchronous abort
      condition is pending in a TSX transaction.
      
      This includes loads with no fault or assist condition. Such loads may
      speculatively expose stale data from the uarch data structures as in
      MDS. Scope of exposure is within the same-thread and cross-thread. This
      issue affects all current processors that support TSX, but do not have
      ARCH_CAP_TAA_NO (bit 8) set in MSR_IA32_ARCH_CAPABILITIES.
      
      On CPUs which have their IA32_ARCH_CAPABILITIES MSR bit MDS_NO=0,
      CPUID.MD_CLEAR=1 and the MDS mitigation is clearing the CPU buffers
      using VERW or L1D_FLUSH, there is no additional mitigation needed for
      TAA. On affected CPUs with MDS_NO=1 this issue can be mitigated by
      disabling the Transactional Synchronization Extensions (TSX) feature.
      
      A new MSR IA32_TSX_CTRL in future and current processors after a
      microcode update can be used to control the TSX feature. There are two
      bits in that MSR:
      
      * TSX_CTRL_RTM_DISABLE disables the TSX sub-feature Restricted
      Transactional Memory (RTM).
      
      * TSX_CTRL_CPUID_CLEAR clears the RTM enumeration in CPUID. The other
      TSX sub-feature, Hardware Lock Elision (HLE), is unconditionally
      disabled with updated microcode but still enumerated as present by
      CPUID(EAX=7).EBX{bit4}.
      
      The second mitigation approach is similar to MDS which is clearing the
      affected CPU buffers on return to user space and when entering a guest.
      Relevant microcode update is required for the mitigation to work.  More
      details on this approach can be found here:
      
        https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html
      
      
      
      The TSX feature can be controlled by the "tsx" command line parameter.
      If it is force-enabled then "Clear CPU buffers" (MDS mitigation) is
      deployed. The effective mitigation state can be read from sysfs.
      
       [ bp:
         - massage + comments cleanup
         - s/TAA_MITIGATION_TSX_DISABLE/TAA_MITIGATION_TSX_DISABLED/g - Josh.
         - remove partial TAA mitigation in update_mds_branch_idle() - Josh.
         - s/tsx_async_abort_cmdline/tsx_async_abort_parse_cmdline/g
       ]
      Signed-off-by: default avatarPawan Gupta <pawan.kumar.gupta@linux.intel.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      1b42f017
  14. 28 Aug, 2019 3 commits
  15. 28 Jul, 2019 1 commit
  16. 25 Jul, 2019 2 commits
  17. 09 Jul, 2019 1 commit
    • Josh Poimboeuf's avatar
      x86/speculation: Enable Spectre v1 swapgs mitigations · a2059825
      Josh Poimboeuf authored
      
      
      The previous commit added macro calls in the entry code which mitigate the
      Spectre v1 swapgs issue if the X86_FEATURE_FENCE_SWAPGS_* features are
      enabled.  Enable those features where applicable.
      
      The mitigations may be disabled with "nospectre_v1" or "mitigations=off".
      
      There are different features which can affect the risk of attack:
      
      - When FSGSBASE is enabled, unprivileged users are able to place any
        value in GS, using the wrgsbase instruction.  This means they can
        write a GS value which points to any value in kernel space, which can
        be useful with the following gadget in an interrupt/exception/NMI
        handler:
      
      	if (coming from user space)
      		swapgs
      	mov %gs:<percpu_offset>, %reg1
      	// dependent load or store based on the value of %reg
      	// for example: mov %(reg1), %reg2
      
        If an interrupt is coming from user space, and the entry code
        speculatively skips the swapgs (due to user branch mistraining), it
        may speculatively execute the GS-based load and a subsequent dependent
        load or store, exposing the kernel data to an L1 side channel leak.
      
        Note that, on Intel, a similar attack exists in the above gadget when
        coming from kernel space, if the swapgs gets speculatively executed to
        switch back to the user GS.  On AMD, this variant isn't possible
        because swapgs is serializing with respect to future GS-based
        accesses.
      
        NOTE: The FSGSBASE patch set hasn't been merged yet, so the above case
      	doesn't exist quite yet.
      
      - When FSGSBASE is disabled, the issue is mitigated somewhat because
        unprivileged users must use prctl(ARCH_SET_GS) to set GS, which
        restricts GS values to user space addresses only.  That means the
        gadget would need an additional step, since the target kernel address
        needs to be read from user space first.  Something like:
      
      	if (coming from user space)
      		swapgs
      	mov %gs:<percpu_offset>, %reg1
      	mov (%reg1), %reg2
      	// dependent load or store based on the value of %reg2
      	// for example: mov %(reg2), %reg3
      
        It's difficult to audit for this gadget in all the handlers, so while
        there are no known instances of it, it's entirely possible that it
        exists somewhere (or could be introduced in the future).  Without
        tooling to analyze all such code paths, consider it vulnerable.
      
        Effects of SMAP on the !FSGSBASE case:
      
        - If SMAP is enabled, and the CPU reports RDCL_NO (i.e., not
          susceptible to Meltdown), the kernel is prevented from speculatively
          reading user space memory, even L1 cached values.  This effectively
          disables the !FSGSBASE attack vector.
      
        - If SMAP is enabled, but the CPU *is* susceptible to Meltdown, SMAP
          still prevents the kernel from speculatively reading user space
          memory.  But it does *not* prevent the kernel from reading the
          user value from L1, if it has already been cached.  This is probably
          only a small hurdle for an attacker to overcome.
      
      Thanks to Dave Hansen for contributing the speculative_smap() function.
      
      Thanks to Andrew Cooper for providing the inside scoop on whether swapgs
      is serializing on AMD.
      
      [ tglx: Fixed the USER fence decision and polished the comment as suggested
        	by Dave Hansen ]
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarDave Hansen <dave.hansen@intel.com>
      a2059825
  18. 26 Jun, 2019 1 commit