Print this page
11787 Kernel needs to be built with retpolines
11788 Kernel needs to generally use RSB stuffing
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: John Levon <john.levon@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/ia32/sys/asm_linkage.h
          +++ new/usr/src/uts/intel/ia32/sys/asm_linkage.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 2008 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 _IA32_SYS_ASM_LINKAGE_H
  28   32  #define _IA32_SYS_ASM_LINKAGE_H
  29   33  
  30      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  31      -
  32   34  #include <sys/stack.h>
  33   35  #include <sys/trap.h>
  34   36  
  35   37  #ifdef  __cplusplus
  36   38  extern "C" {
  37   39  #endif
  38   40  
  39   41  #ifdef _ASM     /* The remainder of this file is only for assembly files */
  40   42  
  41   43  /*
↓ open down ↓ 251 lines elided ↑ open up ↑
 293  295  
 294  296  /*CSTYLED*/
 295  297  #define NWORD   quad
 296  298  
 297  299  #elif defined(__i386)
 298  300  
 299  301  #define NWORD   long
 300  302  
 301  303  #endif  /* __i386 */
 302  304  
      305 +/*
      306 + * These macros should be used when making indirect calls in the kernel. They
      307 + * will perform a jump or call to the corresponding register in a way that knows
      308 + * about retpolines and handles whether such mitigations are enabled or not.
      309 + *
      310 + * INDIRECT_JMP_REG will jump to named register. INDIRECT_CALL_REG will instead
      311 + * do a call. These macros cannot be used to dereference a register. For
      312 + * example, if you need to do something that looks like the following:
      313 + *
      314 + *      call    *24(%rdi)
      315 + *      jmp     *(%r15)
      316 + *
      317 + * You must instead first do a movq into the corresponding location. You need to
      318 + * be careful to make sure that the register that its loaded into is safe to
      319 + * use. Often that register may be saved or used elsewhere so it may not be safe
      320 + * to clobber the value. Usually, loading into %rax would be safe. These would
      321 + * turn into something like:
      322 + *
      323 + *      movq 24(%rdi), %rdi; INDIRECT_CALL_REG(rdi)
      324 + *      movq (%r15), %r15; INDIRECT_JMP_REG(r15)
      325 + *
      326 + * If you are trying to call a global function, then use the following pattern
      327 + * (substituting the register in question):
      328 + *
      329 + *      leaq    my_favorite_function(%rip), %rax
      330 + *      INDIRECT_CALL_REG(rax)
      331 + *
      332 + * If you instead have a function pointer (say gethrtimef for example), then you
      333 + * need to do:
      334 + *
      335 + *      movq    my_favorite_function_pointer(%rip), %rax
      336 + *      INDIRECT_CALL_REG(rax)
      337 + */
      338 +
      339 +/* CSTYLED */
      340 +#define INDIRECT_JMP_REG(reg)   jmp     __x86_indirect_thunk_/**/reg;
      341 +
      342 +/* CSTYLED */
      343 +#define INDIRECT_CALL_REG(reg)  call    __x86_indirect_thunk_/**/reg;
      344 +
 303  345  #endif /* _ASM */
 304  346  
 305  347  #ifdef  __cplusplus
 306  348  }
 307  349  #endif
 308  350  
 309  351  #endif  /* _IA32_SYS_ASM_LINKAGE_H */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX