]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use tgkill for raise
authorMichael Pratt <mpratt@google.com>
Fri, 7 Sep 2018 00:21:59 +0000 (17:21 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 7 Sep 2018 22:50:28 +0000 (22:50 +0000)
raise uses tkill to send a signal to the current thread. For this use,
tgkill is functionally equivalent to tkill expect that it also takes the
pid as the first argument.

Using tgkill makes it simpler to run a Go program in a strict sandbox.
With kill and tgkill, the sandbox policy (e.g., seccomp) can prevent the
program from sending signals to other processes by checking that the
first argument == getpid().

With tkill, the policy must whitelist all tids in the process, which is
effectively impossible given Go's dynamic thread creation.

Fixes #27548

Change-Id: I8ed282ef1f7215b02ef46de144493e36454029ea
Reviewed-on: https://go-review.googlesource.com/133975
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/sys_linux_386.s
src/runtime/sys_linux_amd64.s
src/runtime/sys_linux_arm.s
src/runtime/sys_linux_arm64.s
src/runtime/sys_linux_mips64x.s
src/runtime/sys_linux_mipsx.s
src/runtime/sys_linux_ppc64x.s
src/runtime/sys_linux_s390x.s

index 8d5a4ff9772d2171940dfb0cc2a07808f4188670..4e914f3e6013d0839e54aed9727b62c512ff6771 100644 (file)
@@ -48,7 +48,6 @@
 #define SYS_mincore            218
 #define SYS_madvise            219
 #define SYS_gettid             224
-#define SYS_tkill              238
 #define SYS_futex              240
 #define SYS_sched_getaffinity  242
 #define SYS_set_thread_area    243
@@ -57,6 +56,7 @@
 #define SYS_epoll_ctl          255
 #define SYS_epoll_wait         256
 #define SYS_clock_gettime      265
+#define SYS_tgkill             270
 #define SYS_epoll_create1      329
 
 TEXT runtime·exit(SB),NOSPLIT,$0
@@ -155,11 +155,14 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4
        RET
 
 TEXT runtime·raise(SB),NOSPLIT,$12
+       MOVL    $SYS_getpid, AX
+       INVOKE_SYSCALL
+       MOVL    AX, BX  // arg 1 pid
        MOVL    $SYS_gettid, AX
        INVOKE_SYSCALL
-       MOVL    AX, BX  // arg 1 tid
-       MOVL    sig+0(FP), CX   // arg 2 signal
-       MOVL    $SYS_tkill, AX
+       MOVL    AX, CX  // arg 2 tid
+       MOVL    sig+0(FP), DX   // arg 3 signal
+       MOVL    $SYS_tgkill, AX
        INVOKE_SYSCALL
        RET
 
index 62d80247bea525f6dd89986a419be5a24f211040..4492dad02e7a64ca9ee49d289b2af6b4afd4eedd 100644 (file)
 #define SYS_sigaltstack        131
 #define SYS_arch_prctl         158
 #define SYS_gettid             186
-#define SYS_tkill              200
 #define SYS_futex              202
 #define SYS_sched_getaffinity  204
 #define SYS_epoll_create       213
 #define SYS_exit_group         231
 #define SYS_epoll_ctl          233
+#define SYS_tgkill             234
 #define SYS_openat             257
 #define SYS_faccessat          269
 #define SYS_epoll_pwait                281
@@ -137,11 +137,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4
        RET
 
 TEXT runtime·raise(SB),NOSPLIT,$0
+       MOVL    $SYS_getpid, AX
+       SYSCALL
+       MOVL    AX, R12
        MOVL    $SYS_gettid, AX
        SYSCALL
-       MOVL    AX, DI  // arg 1 tid
-       MOVL    sig+0(FP), SI   // arg 2
-       MOVL    $SYS_tkill, AX
+       MOVL    AX, SI  // arg 2 tid
+       MOVL    R12, DI // arg 1 pid
+       MOVL    sig+0(FP), DX   // arg 3
+       MOVL    $SYS_tgkill, AX
        SYSCALL
        RET
 
index aa39732cfb66dbab004d9ac55cd64a0fd85f66e7..a709c4cbd050b7aa6d197b0f3e9d376b2838d799 100644 (file)
@@ -36,7 +36,7 @@
 #define SYS_setitimer (SYS_BASE + 104)
 #define SYS_mincore (SYS_BASE + 219)
 #define SYS_gettid (SYS_BASE + 224)
-#define SYS_tkill (SYS_BASE + 238)
+#define SYS_tgkill (SYS_BASE + 268)
 #define SYS_sched_yield (SYS_BASE + 158)
 #define SYS_nanosleep (SYS_BASE + 162)
 #define SYS_sched_getaffinity (SYS_BASE + 242)
@@ -138,11 +138,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4
        RET
 
 TEXT   runtime·raise(SB),NOSPLIT|NOFRAME,$0
+       MOVW    $SYS_getpid, R7
+       SWI     $0
+       MOVW    R0, R4
        MOVW    $SYS_gettid, R7
        SWI     $0
-       // arg 1 tid already in R0 from gettid
-       MOVW    sig+0(FP), R1   // arg 2 - signal
-       MOVW    $SYS_tkill, R7
+       MOVW    R0, R1  // arg 2 tid
+       MOVW    R4, R0  // arg 1 pid
+       MOVW    sig+0(FP), R2   // arg 3
+       MOVW    $SYS_tgkill, R7
        SWI     $0
        RET
 
index 1c8fce3db649b027d5ae60dd606534eeab6ef454..086c8ddc637fe3ab808ac23f491bb188345a8ae5 100644 (file)
@@ -36,7 +36,7 @@
 #define SYS_getpid             172
 #define SYS_gettid             178
 #define SYS_kill               129
-#define SYS_tkill              130
+#define SYS_tgkill             131
 #define SYS_futex              98
 #define SYS_sched_getaffinity  123
 #define SYS_exit_group         94
@@ -143,11 +143,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4
        RET
 
 TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
+       MOVD    $SYS_getpid, R8
+       SVC
+       MOVW    R0, R19
        MOVD    $SYS_gettid, R8
        SVC
-       MOVW    R0, R0  // arg 1 tid
-       MOVW    sig+0(FP), R1   // arg 2
-       MOVD    $SYS_tkill, R8
+       MOVW    R0, R1  // arg 2 tid
+       MOVW    R19, R0 // arg 1 pid
+       MOVW    sig+0(FP), R2   // arg 3
+       MOVD    $SYS_tgkill, R8
        SVC
        RET
 
index 8e64f1c562e642b621d6e6a767125d5f4d296ddf..337299ba5fe084556645ecd31a1b0a0e0d90fcfd 100644 (file)
 #define SYS_madvise            5027
 #define SYS_mincore            5026
 #define SYS_gettid             5178
-#define SYS_tkill              5192
 #define SYS_futex              5194
 #define SYS_sched_getaffinity  5196
 #define SYS_exit_group         5205
 #define SYS_epoll_create       5207
 #define SYS_epoll_ctl          5208
+#define SYS_tgkill             5225
 #define SYS_openat             5247
 #define SYS_epoll_pwait                5272
 #define SYS_clock_gettime      5222
@@ -137,11 +137,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4
        RET
 
 TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
+       MOVV    $SYS_getpid, R2
+       SYSCALL
+       MOVW    R2, R16
        MOVV    $SYS_gettid, R2
        SYSCALL
-       MOVW    R2, R4  // arg 1 tid
-       MOVW    sig+0(FP), R5   // arg 2
-       MOVV    $SYS_tkill, R2
+       MOVW    R2, R5  // arg 2 tid
+       MOVW    R16, R4 // arg 1 pid
+       MOVW    sig+0(FP), R6   // arg 3
+       MOVV    $SYS_tgkill, R2
        SYSCALL
        RET
 
index a6bca3bebd8b076fb8ca23b487728e482a5b36e7..dca5f1ee459a8f4d2c7a82249b382e384f6a7e6a 100644 (file)
@@ -35,7 +35,6 @@
 #define SYS_madvise            4218
 #define SYS_mincore            4217
 #define SYS_gettid             4222
-#define SYS_tkill              4236
 #define SYS_futex              4238
 #define SYS_sched_getaffinity  4240
 #define SYS_exit_group         4246
@@ -43,6 +42,7 @@
 #define SYS_epoll_ctl          4249
 #define SYS_epoll_wait         4250
 #define SYS_clock_gettime      4263
+#define SYS_tgkill             4266
 #define SYS_epoll_create1      4326
 
 TEXT runtime·exit(SB),NOSPLIT,$0-4
@@ -135,11 +135,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4
        RET
 
 TEXT runtime·raise(SB),NOSPLIT,$0-4
+       MOVW    $SYS_getpid, R2
+       SYSCALL
+       MOVW    R2, R16
        MOVW    $SYS_gettid, R2
        SYSCALL
-       MOVW    R2, R4  // arg 1 tid
-       MOVW    sig+0(FP), R5   // arg 2
-       MOVW    $SYS_tkill, R2
+       MOVW    R2, R5  // arg 2 tid
+       MOVW    R16, R4 // arg 1 pid
+       MOVW    sig+0(FP), R6   // arg 3
+       MOVW    $SYS_tgkill, R2
        SYSCALL
        RET
 
index 075adf2368439e18c003ffbb79eb89f71280702b..7c2f8ea637176872563a885d0711490388ba7d06 100644 (file)
@@ -36,7 +36,6 @@
 #define SYS_madvise            205
 #define SYS_mincore            206
 #define SYS_gettid             207
-#define SYS_tkill              208
 #define SYS_futex              221
 #define SYS_sched_getaffinity  223
 #define SYS_exit_group         234
@@ -44,6 +43,7 @@
 #define SYS_epoll_ctl          237
 #define SYS_epoll_wait         238
 #define SYS_clock_gettime      246
+#define SYS_tgkill             250
 #define SYS_epoll_create1      315
 
 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
@@ -123,10 +123,13 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4
        RET
 
 TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
+       SYSCALL $SYS_getpid
+       MOVW    R3, R14
        SYSCALL $SYS_gettid
-       MOVW    R3, R3  // arg 1 tid
-       MOVW    sig+0(FP), R4   // arg 2
-       SYSCALL $SYS_tkill
+       MOVW    R3, R4  // arg 2 tid
+       MOVW    R14, R3 // arg 1 pid
+       MOVW    sig+0(FP), R5   // arg 3
+       SYSCALL $SYS_tgkill
        RET
 
 TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
index 1ff110c232b87266669d08f76c8d5607381df4cc..95401af62ecc2e68907b32e50dd1551f6bf5417c 100644 (file)
@@ -31,9 +31,9 @@
 #define SYS_madvise             219
 #define SYS_mincore             218
 #define SYS_gettid              236
-#define SYS_tkill               237
 #define SYS_futex               238
 #define SYS_sched_getaffinity   240
+#define SYS_tgkill              241
 #define SYS_exit_group          248
 #define SYS_epoll_create        249
 #define SYS_epoll_ctl           250
@@ -129,11 +129,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4
        RET
 
 TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
+       MOVW    $SYS_getpid, R1
+       SYSCALL
+       MOVW    R2, R10
        MOVW    $SYS_gettid, R1
        SYSCALL
-       MOVW    R2, R2  // arg 1 tid
-       MOVW    sig+0(FP), R3   // arg 2
-       MOVW    $SYS_tkill, R1
+       MOVW    R2, R3  // arg 2 tid
+       MOVW    R10, R2 // arg 1 pid
+       MOVW    sig+0(FP), R4   // arg 2
+       MOVW    $SYS_tgkill, R1
        SYSCALL
        RET