Print this page
11859 need swapgs mitigation
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@fingolfin.org>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/amd64/sys/privregs.h
          +++ new/usr/src/uts/intel/amd64/sys/privregs.h
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
       27 +/*
       28 + * Copyright 2019 Joyent, Inc.
       29 + */
       30 +
  27   31  #ifndef _AMD64_SYS_PRIVREGS_H
  28   32  #define _AMD64_SYS_PRIVREGS_H
  29   33  
  30   34  #include <sys/ccompile.h>
  31   35  
  32   36  #ifdef __cplusplus
  33   37  extern "C" {
  34   38  #endif
  35   39  
  36   40  /*
↓ open down ↓ 162 lines elided ↑ open up ↑
 199  203   * Push register state onto the stack. If we've
 200  204   * interrupted userland, do a swapgs as well.
 201  205   */
 202  206  #define INTR_PUSH                               \
 203  207          subq    $REGOFF_TRAPNO, %rsp;           \
 204  208          __SAVE_REGS;                            \
 205  209          cmpw    $KCS_SEL, REGOFF_CS(%rsp);      \
 206  210          je      6f;                             \
 207  211          movq    $0, REGOFF_SAVFP(%rsp);         \
 208  212          SWAPGS;                                 \
 209      -6:      CLEAN_CS
      213 +6:      lfence; /* swapgs mitigation */         \
      214 +        CLEAN_CS
 210  215  
 211  216  #define INTR_POP                        \
 212  217          leaq    sys_lcall32(%rip), %r11;\
 213  218          cmpq    %r11, REGOFF_RIP(%rsp); \
 214  219          __RESTORE_REGS;                 \
 215  220          je      5f;                     \
 216  221          cmpw    $KCS_SEL, REGOFF_CS(%rsp);\
 217  222          je      8f;                     \
 218  223  5:      SWAPGS;                         \
 219      -8:      addq    $REGOFF_RIP, %rsp
      224 +8:      lfence; /* swapgs mitigation */ \
      225 +        addq    $REGOFF_RIP, %rsp
 220  226  
      227 +/*
      228 + * No need for swapgs mitigation: it's unconditional, and we're heading
      229 + * back to userspace.
      230 + */
 221  231  #define USER_POP                        \
 222  232          __RESTORE_REGS;                 \
 223  233          SWAPGS;                         \
 224  234          addq    $REGOFF_RIP, %rsp       /* Adjust %rsp to prepare for iretq */
 225  235  
 226  236  #define USER32_POP                      \
 227  237          movl    REGOFF_RDI(%rsp), %edi; \
 228  238          movl    REGOFF_RSI(%rsp), %esi; \
 229  239          movl    REGOFF_RDX(%rsp), %edx; \
 230  240          movl    REGOFF_RCX(%rsp), %ecx; \
↓ open down ↓ 100 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX