Add endbr64 instructions to most of the ENTRY() macros.
authorderaadt <deraadt@openbsd.org>
Mon, 17 Apr 2023 00:02:14 +0000 (00:02 +0000)
committerderaadt <deraadt@openbsd.org>
Mon, 17 Apr 2023 00:02:14 +0000 (00:02 +0000)
The IDTVEC() and KIDTVEC() macros also get a endbr64, and therefore we need
to change the way that vectors are aliased with a new IDTVEC_ALIAS() macro.
with guenther, jsg

sys/arch/amd64/amd64/vector.S
sys/arch/amd64/include/asm.h
sys/arch/amd64/include/frameasm.h

index c56c4b0..a7c1d5d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vector.S,v 1.91 2023/04/16 05:39:33 guenther Exp $    */
+/*     $OpenBSD: vector.S,v 1.92 2023/04/17 00:02:14 deraadt Exp $     */
 /*     $NetBSD: vector.S,v 1.5 2004/06/28 09:13:11 fvdl Exp $  */
 
 /*
@@ -348,7 +348,7 @@ IDTVEC(trap0d)
 IDTVEC(trap0e)
        TRAP(T_PAGEFLT)
 IDTVEC(intrspurious)
-IDTVEC_NOALIGN(trap0f)
+IDTVEC_ALIAS(trap0f, intrspurious)
        iretq
 IDTVEC(trap10)
        ZTRAP(T_ARITHTRAP)
@@ -362,16 +362,16 @@ IDTVEC(trap14)
        ZTRAP(T_VE)
 IDTVEC(trap15)
        TRAP(T_CP)
-IDTVEC(trap16)
-IDTVEC_NOALIGN(trap17)
-IDTVEC_NOALIGN(trap18)
-IDTVEC_NOALIGN(trap19)
-IDTVEC_NOALIGN(trap1a)
-IDTVEC_NOALIGN(trap1b)
-IDTVEC_NOALIGN(trap1c)
-IDTVEC_NOALIGN(trap1d)
-IDTVEC_NOALIGN(trap1e)
-IDTVEC_NOALIGN(trap1f)
+IDTVEC(trap1f)
+IDTVEC_ALIAS(trap16, trap1f)
+IDTVEC_ALIAS(trap17, trap1f)
+IDTVEC_ALIAS(trap18, trap1f)
+IDTVEC_ALIAS(trap19, trap1f)
+IDTVEC_ALIAS(trap1a, trap1f)
+IDTVEC_ALIAS(trap1b, trap1f)
+IDTVEC_ALIAS(trap1c, trap1f)
+IDTVEC_ALIAS(trap1d, trap1f)
+IDTVEC_ALIAS(trap1e, trap1f)
        /* 22 - 31 reserved for future exp */
        ZTRAP(T_RESERVED)
 
index b4053a0..86806e6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: asm.h,v 1.23 2022/12/01 00:26:15 guenther Exp $       */
+/*     $OpenBSD: asm.h,v 1.24 2023/04/17 00:02:14 deraadt Exp $        */
 /*     $NetBSD: asm.h,v 1.2 2003/05/02 18:05:47 yamt Exp $     */
 
 /*-
 #define        KTEXT_PAGE_END          .popsection
 
 #define        IDTVEC(name) \
-       KUTEXT; _ALIGN_TRAPS; IDTVEC_NOALIGN(name)
+       KUTEXT; _ALIGN_TRAPS; IDTVEC_NOALIGN(name); endbr64
 #define        GENTRY(x)               .globl x; _FENTRY(x)
 #define        IDTVEC_NOALIGN(name)    GENTRY(X ## name)
+#define        IDTVEC_ALIAS(alias,sym)                                         \
+       .global X ## alias;                                             \
+       X ## alias = X ## sym;
 #define        KIDTVEC(name) \
-       .text; _ALIGN_TRAPS; IDTVEC_NOALIGN(name)
+       .text; _ALIGN_TRAPS; IDTVEC_NOALIGN(name); endbr64
 #define        KIDTVEC_FALLTHROUGH(name) \
        _ALIGN_TEXT; IDTVEC_NOALIGN(name)
 #define KUENTRY(x) \
 # define RETGUARD_SYMBOL(x)
 #endif
 
-#define        ENTRY(y)        _ENTRY(y); _PROF_PROLOGUE
+#define        ENTRY(y)        _ENTRY(y); endbr64; _PROF_PROLOGUE
 #define        NENTRY(y)       _NENTRY(y)
-#define        ASENTRY(y)      _NENTRY(y); _PROF_PROLOGUE
-#define        ENTRY_NB(y)     _ENTRY_NB(y); _PROF_PROLOGUE
+#define        ASENTRY(y)      _NENTRY(y); endbr64; _PROF_PROLOGUE
+#define        ENTRY_NB(y)     _ENTRY_NB(y); endbr64; _PROF_PROLOGUE
 #define        END(y)          .size y, . - y
 
 #define        STRONG_ALIAS(alias,sym)                                         \
index a3274bc..5f1de16 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: frameasm.h,v 1.25 2020/11/12 23:29:16 guenther Exp $  */
+/*     $OpenBSD: frameasm.h,v 1.26 2023/04/17 00:02:14 deraadt Exp $   */
 /*     $NetBSD: frameasm.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $        */
 
 #ifndef _AMD64_MACHINE_FRAMEASM_H
@@ -63,6 +63,7 @@
  */
 #define INTRENTRY_LABEL(label) X##label##_untramp
 #define        INTRENTRY(label) \
+       endbr64                         ; \
        testb   $SEL_RPL,IRETQ_CS(%rsp) ; \
        je      INTRENTRY_LABEL(label)  ; \
        swapgs                          ; \