Add retguard to amd64 syscalls.
authormortimer <mortimer@openbsd.org>
Wed, 11 Jan 2023 01:55:17 +0000 (01:55 +0000)
committermortimer <mortimer@openbsd.org>
Wed, 11 Jan 2023 01:55:17 +0000 (01:55 +0000)
Since we got rid of padded syscalls we have enough registers to do this.

ok deraadt@ ok kettenis@

lib/libc/arch/amd64/SYS.h
lib/libc/arch/amd64/sys/Ovfork.S
lib/libc/arch/amd64/sys/brk.S
lib/libc/arch/amd64/sys/sbrk.S
lib/libc/arch/amd64/sys/sigpending.S
lib/libc/arch/amd64/sys/sigprocmask.S
lib/libc/arch/amd64/sys/sigsuspend.S
lib/libc/arch/amd64/sys/tfork_thread.S
libexec/ld.so/amd64/SYS.h

index e20e50c..ce67ad0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: SYS.h,v 1.20 2016/09/06 18:33:35 kettenis Exp $       */
+/*     $OpenBSD: SYS.h,v 1.21 2023/01/11 01:55:17 mortimer Exp $       */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
        HANDLE_ERRNO
 
 
-/* return, handling errno for failed calls */
-#define _RSYSCALL_RET                                                  \
-       jc      99f;                                                    \
-       ret;                                                            \
-       99: SET_ERRNO;                                                  \
-       ret
-
 #define PSEUDO_NOERROR(x,y)                                            \
-       _SYSCALL_NOERROR(x,y);                                          \
+       SYSENTRY(x);                                                    \
+       RETGUARD_SETUP(_thread_sys_##x, r11);                           \
+       RETGUARD_PUSH(r11);                                             \
+       SYSTRAP(y);                                                     \
+       RETGUARD_POP(r11);                                              \
+       RETGUARD_CHECK(_thread_sys_##x, r11);                           \
        ret;                                                            \
        SYSCALL_END(x)
 
 #define PSEUDO(x,y)                                                    \
-       _SYSCALL_NOERROR(x,y);                                          \
-       _RSYSCALL_RET;                                                  \
+       SYSENTRY(x);                                                    \
+       RETGUARD_SETUP(_thread_sys_##x, r11);                           \
+       RETGUARD_PUSH(r11);                                             \
+       SYSTRAP(y);                                                     \
+       HANDLE_ERRNO;                                                   \
+       RETGUARD_POP(r11);                                              \
+       RETGUARD_CHECK(_thread_sys_##x, r11);                           \
+       ret;                                                            \
        SYSCALL_END(x)
+
 #define PSEUDO_HIDDEN(x,y)                                             \
-       _SYSCALL_HIDDEN_NOERROR(x,y);                                   \
-       _RSYSCALL_RET;                                                  \
+       SYSENTRY_HIDDEN(x);                                             \
+       RETGUARD_SETUP(_thread_sys_##x, r11);                           \
+       RETGUARD_PUSH(r11);                                             \
+       SYSTRAP(y);                                                     \
+       HANDLE_ERRNO;                                                   \
+       RETGUARD_POP(r11);                                              \
+       RETGUARD_CHECK(_thread_sys_##x , r11);                          \
+       ret;                                                            \
        SYSCALL_END_HIDDEN(x)
 
 #define RSYSCALL_NOERROR(x)                                            \
index e42649e..3d129ee 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: Ovfork.S,v 1.8 2016/05/07 19:05:21 guenther Exp $     */
+/*     $OpenBSD: Ovfork.S,v 1.9 2023/01/11 01:55:17 mortimer Exp $     */
 /*     $NetBSD: Ovfork.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $  */
 
 /*-
 
 SYSENTRY_HIDDEN(vfork)
        popq    %r9             /* my rta into r9 */
+       RETGUARD_SETUP(_thread_sys_vfork, r11);
+       RETGUARD_PUSH(r11);
        SYSTRAP(vfork)
+       RETGUARD_POP(r11)
        jc      1f
        jmp     *%r9
 1:
        pushq   %r9
        SET_ERRNO
+       RETGUARD_CHECK(_thread_sys_vfork, r11);
        ret
 SYSCALL_END_HIDDEN(vfork)
index e00f740..0fa17db 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: brk.S,v 1.12 2022/01/01 23:47:14 guenther Exp $       */
+/*     $OpenBSD: brk.S,v 1.13 2023/01/11 01:55:17 mortimer Exp $       */
 /*     $NetBSD: brk.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $     */
 
 /*-
@@ -49,6 +49,8 @@ __minbrk:
        .type   __minbrk,@object
 
 ENTRY_NB(brk)
+       RETGUARD_SETUP(brk, r11);
+       RETGUARD_PUSH(r11);
        cmpq    %rdi,__minbrk(%rip)
        jb      1f
        movq    __minbrk(%rip),%rdi
@@ -57,9 +59,12 @@ ENTRY_NB(brk)
        jc      1f
        movq    %rdi,__curbrk(%rip)
        xorl    %eax,%eax
-       ret
+       jmp     2f
 1:
        SET_ERRNO
+2:
+       RETGUARD_POP(r11);
+       RETGUARD_CHECK(brk, r11);
        ret
 END(brk)
        .weak   brk
index 80a6a16..836f40a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sbrk.S,v 1.12 2022/01/01 23:47:14 guenther Exp $      */
+/*     $OpenBSD: sbrk.S,v 1.13 2023/01/11 01:55:17 mortimer Exp $      */
 /*     $NetBSD: sbrk.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $    */
 
 /*-
@@ -54,6 +54,8 @@ __curbrk:
        .type   __curbrk,@object
 
 ENTRY_NB(sbrk)
+       RETGUARD_SETUP(sbrk, r11);
+       RETGUARD_PUSH(r11);
        movq    __curbrk(%rip),%rax
        movslq  %edi,%rsi
        movq    %rsi,%rdi
@@ -62,9 +64,12 @@ ENTRY_NB(sbrk)
        jc      1f
        movq    __curbrk(%rip),%rax
        addq    %rsi,__curbrk(%rip)
-       ret
+       jmp     2f
 1:
        SET_ERRNO
+2:
+       RETGUARD_POP(r11);
+       RETGUARD_CHECK(sbrk, r11);
        ret
 END(sbrk)
        .weak   sbrk
index 6d8a220..576eff0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sigpending.S,v 1.3 2015/06/17 03:04:50 uebayasi Exp $ */
+/*     $OpenBSD: sigpending.S,v 1.4 2023/01/11 01:55:17 mortimer Exp $ */
 /*     $NetBSD: sigpending.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $      */
 
 /*-
 #include "SYS.h"
 
 SYSCALL(sigpending)
+       RETGUARD_SETUP(_thread_sys_sigpending, r11);
+       RETGUARD_PUSH(r11);
        movl    %eax,(%rdi)             # store old mask
        xorl    %eax,%eax
+       RETGUARD_POP(r11)
+       RETGUARD_CHECK(_thread_sys_sigpending, r11);
        ret
 SYSCALL_END(sigpending)
index 308c580..ddcae14 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sigprocmask.S,v 1.9 2016/05/07 19:05:21 guenther Exp $        */
+/*     $OpenBSD: sigprocmask.S,v 1.10 2023/01/11 01:55:17 mortimer Exp $       */
 /*     $NetBSD: sigprocmask.S,v 1.1 2001/06/19 00:25:06 fvdl Exp $     */
 
 /*-
@@ -40,6 +40,8 @@
 #include "SYS.h"
 
 SYSENTRY_HIDDEN(sigprocmask)
+       RETGUARD_SETUP(_thread_sys_sigprocmask, r11);
+       RETGUARD_PUSH(r11);
        testq   %rsi,%rsi               # check new sigset pointer
        jnz     1f                      # if not null, indirect
        movl    $1,%edi                 # SIG_BLOCK
@@ -52,8 +54,11 @@ SYSENTRY_HIDDEN(sigprocmask)
        movl    %eax,(%rdx)             # store old mask
 3:
        xorl    %eax,%eax
-       ret
+       jmp     2f
 1:
        SET_ERRNO
+2:
+       RETGUARD_POP(r11);
+       RETGUARD_CHECK(_thread_sys_sigprocmask, r11);
        ret
 SYSCALL_END_HIDDEN(sigprocmask)
index 9abb04e..2a08beb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sigsuspend.S,v 1.7 2016/05/07 19:05:21 guenther Exp $ */
+/*     $OpenBSD: sigsuspend.S,v 1.8 2023/01/11 01:55:17 mortimer Exp $ */
 /*     $NetBSD: sigsuspend.S,v 1.1 2001/06/19 00:25:07 fvdl Exp $      */
 
 /*-
 #include "SYS.h"
 
 SYSENTRY_HIDDEN(sigsuspend)
+       RETGUARD_SETUP(_thread_sys_sigsuspend, r11);
+       RETGUARD_PUSH(r11);
        movl    (%rdi),%edi             # indirect to mask arg
        SYSTRAP(sigsuspend)
        SET_ERRNO
+       RETGUARD_POP(r11);
+       RETGUARD_CHECK(_thread_sys_sigsuspend, r11);
        ret
 SYSCALL_END_HIDDEN(sigsuspend)
index b543296..8de236b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tfork_thread.S,v 1.10 2020/10/18 14:28:17 deraadt Exp $ */
+/*     $OpenBSD: tfork_thread.S,v 1.11 2023/01/11 01:55:17 mortimer Exp $ */
 /*-
  * Copyright (c) 2000 Peter Wemm <peter@FreeBSD.org>
  * Copyright (c) 2003 Alan L. Cox <alc@cs.rice.edu>
@@ -46,6 +46,8 @@
 
 ENTRY(__tfork_thread)
        .cfi_startproc
+       RETGUARD_SETUP(__tfork_thread, r11);
+       RETGUARD_PUSH(r11);
        movq    %rdx, %r8
        movq    %rcx, %r9
 
@@ -62,7 +64,7 @@ ENTRY(__tfork_thread)
         */
        cmpl    $0, %eax
        jz      1f
-       ret
+       jmp     3f
 
        /* the retpoline we'll use to call the child's main */
        _ALIGN_TRAPS
@@ -96,6 +98,9 @@ ENTRY(__tfork_thread)
         */
 2:
        SET_ERRNO
+3:
+       RETGUARD_POP(r11);
+       RETGUARD_CHECK(__tfork_thread, r11);
        ret
        .cfi_endproc
 END(__tfork_thread)
index 724c9f5..ed1f207 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: SYS.h,v 1.1 2017/08/27 21:59:52 deraadt Exp $ */
+/*     $OpenBSD: SYS.h,v 1.2 2023/01/11 01:55:17 mortimer Exp $        */
 
 /*
  * Copyright (c) 2002,2004 Dale Rahn
        .type   __CONCAT(_dl_,n), @function             ;\
        .align  16,0xcc                                 ;\
 __CONCAT(_dl_,n):                                      ;\
+       RETGUARD_SETUP(_dl_##n, r11)                    ;\
+       RETGUARD_PUSH(r11)                              ;\
        movl    $(__CONCAT(SYS_,n)), %eax               ;\
        movq    %rcx, %r10                              ;\
        syscall                                         ;\
-       jb      1f                                      ;\
-       ret                                             ;\
-1:     neg     %rax                                    ;\
+       jnc     1f                                      ;\
+       neg     %rax                                    ;\
+1:     RETGUARD_POP(r11)                               ;\
+       RETGUARD_CHECK(_dl_##n, r11)                    ;\
        ret