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/ia32/os/sundep.c
          +++ new/usr/src/uts/intel/ia32/os/sundep.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright 2018 Joyent, Inc.
       23 + * Copyright 2019 Joyent, Inc.
  24   24   */
  25   25  
  26   26  /*      Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
  27   27  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T   */
  28   28  /*      All Rights Reserved   */
  29   29  
  30   30  #include <sys/types.h>
  31   31  #include <sys/param.h>
  32   32  #include <sys/sysmacros.h>
  33   33  #include <sys/signal.h>
↓ open down ↓ 510 lines elided ↑ open up ↑
 544  544                  kgsbase = (ulong_t)CPU;
 545  545                  __set_gs(pcb->pcb_gs);
 546  546  
 547  547                  /*
 548  548                   * If __set_gs fails it's because the new %gs is a bad %gs,
 549  549                   * we'll be taking a trap but with the original %gs and %gsbase
 550  550                   * undamaged (i.e. pointing at curcpu).
 551  551                   *
 552  552                   * We've just mucked up the kernel's gsbase.  Oops.  In
 553  553                   * particular we can't take any traps at all.  Make the newly
 554      -                 * computed gsbase be the hidden gs via __swapgs, and fix
      554 +                 * computed gsbase be the hidden gs via swapgs, and fix
 555  555                   * the kernel's gsbase back again. Later, when we return to
 556  556                   * userland we'll swapgs again restoring gsbase just loaded
 557  557                   * above.
 558  558                   */
 559      -                __swapgs();
      559 +                __asm__ __volatile__("mfence; swapgs");
      560 +
 560  561                  rp->r_gs = pcb->pcb_gs;
 561  562  
 562  563                  /*
 563      -                 * restore kernel's gsbase
      564 +                 * Restore kernel's gsbase. Note that this also serializes any
      565 +                 * attempted speculation from loading the user-controlled
      566 +                 * %gsbase.
 564  567                   */
 565  568                  wrmsr(MSR_AMD_GSBASE, kgsbase);
 566  569  
 567  570  #endif  /* __xpv */
 568  571  
 569  572                  /*
 570  573                   * Only override the descriptor base address if
 571  574                   * r_gs == LWPGS_SEL or if r_gs == NULL. A note on
 572  575                   * NULL descriptors -- 32-bit programs take faults
 573  576                   * if they deference NULL descriptors; however,
↓ open down ↓ 462 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX