Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1999-2000 Wichert Akkerman <wichert@cistron.nl> |
| 3 | * Copyright (c) 2002-2005 Roland McGrath <roland@redhat.com> |
| 4 | * Copyright (c) 2008 Jan Kratochvil <jan.kratochvil@redhat.com> |
| 5 | * Copyright (c) 2009-2013 Denys Vlasenko <dvlasenk@redhat.com> |
| 6 | * Copyright (c) 2006-2015 Dmitry V. Levin <ldv@altlinux.org> |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * 3. The name of the author may not be used to endorse or promote products |
| 18 | * derived from this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 23 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 29 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 32 | #include "defs.h" |
| 33 | |
Dmitry V. Levin | 14f4038 | 2015-06-17 18:36:53 +0000 | [diff] [blame] | 34 | #include <sched.h> |
| 35 | |
| 36 | #ifndef CSIGNAL |
| 37 | # define CSIGNAL 0x000000ff |
| 38 | #endif |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 39 | |
| 40 | #include "xlat/clone_flags.h" |
| 41 | |
| 42 | #if defined IA64 |
| 43 | # define ARG_FLAGS 0 |
| 44 | # define ARG_STACK 1 |
| 45 | # define ARG_STACKSIZE (tcp->scno == SYS_clone2 ? 2 : -1) |
| 46 | # define ARG_PTID (tcp->scno == SYS_clone2 ? 3 : 2) |
| 47 | # define ARG_CTID (tcp->scno == SYS_clone2 ? 4 : 3) |
| 48 | # define ARG_TLS (tcp->scno == SYS_clone2 ? 5 : 4) |
| 49 | #elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32 |
| 50 | # define ARG_STACK 0 |
| 51 | # define ARG_FLAGS 1 |
| 52 | # define ARG_PTID 2 |
| 53 | # define ARG_CTID 3 |
| 54 | # define ARG_TLS 4 |
| 55 | #elif defined X86_64 || defined X32 |
| 56 | /* x86 personality processes have the last two arguments flipped. */ |
| 57 | # define ARG_FLAGS 0 |
| 58 | # define ARG_STACK 1 |
| 59 | # define ARG_PTID 2 |
| 60 | # define ARG_CTID ((current_personality != 1) ? 3 : 4) |
| 61 | # define ARG_TLS ((current_personality != 1) ? 4 : 3) |
| 62 | #elif defined ALPHA || defined TILE || defined OR1K |
| 63 | # define ARG_FLAGS 0 |
| 64 | # define ARG_STACK 1 |
| 65 | # define ARG_PTID 2 |
| 66 | # define ARG_CTID 3 |
| 67 | # define ARG_TLS 4 |
| 68 | #else |
| 69 | # define ARG_FLAGS 0 |
| 70 | # define ARG_STACK 1 |
| 71 | # define ARG_PTID 2 |
| 72 | # define ARG_TLS 3 |
| 73 | # define ARG_CTID 4 |
| 74 | #endif |
| 75 | |
| 76 | #if defined I386 || defined X86_64 || defined X32 |
| 77 | extern void print_user_desc(struct tcb *, long); |
| 78 | #endif /* I386 || X86_64 || X32 */ |
| 79 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 80 | SYS_FUNC(clone) |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 81 | { |
| 82 | if (exiting(tcp)) { |
| 83 | const char *sep = "|"; |
| 84 | unsigned long flags = tcp->u_arg[ARG_FLAGS]; |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 85 | tprints("child_stack="); |
| 86 | printaddr(tcp->u_arg[ARG_STACK]); |
| 87 | tprints(", "); |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 88 | #ifdef ARG_STACKSIZE |
| 89 | if (ARG_STACKSIZE != -1) |
| 90 | tprintf("stack_size=%#lx, ", |
| 91 | tcp->u_arg[ARG_STACKSIZE]); |
| 92 | #endif |
| 93 | tprints("flags="); |
| 94 | if (!printflags(clone_flags, flags &~ CSIGNAL, NULL)) |
| 95 | sep = ""; |
| 96 | if ((flags & CSIGNAL) != 0) |
| 97 | tprintf("%s%s", sep, signame(flags & CSIGNAL)); |
| 98 | if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID |
| 99 | |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0) |
| 100 | return 0; |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 101 | if (flags & CLONE_PARENT_SETTID) { |
| 102 | tprints(", parent_tidptr="); |
| 103 | printaddr(tcp->u_arg[ARG_PTID]); |
| 104 | } |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 105 | if (flags & CLONE_SETTLS) { |
| 106 | #if defined I386 || defined X86_64 || defined X32 |
| 107 | # ifndef I386 |
| 108 | if (current_personality == 1) |
| 109 | # endif |
| 110 | { |
| 111 | tprints(", tls="); |
| 112 | print_user_desc(tcp, tcp->u_arg[ARG_TLS]); |
| 113 | } |
| 114 | # ifndef I386 |
| 115 | else |
| 116 | # endif |
| 117 | #endif /* I386 || X86_64 || X32 */ |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 118 | { |
| 119 | tprints(", tls="); |
| 120 | printaddr(tcp->u_arg[ARG_TLS]); |
| 121 | } |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 122 | } |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 123 | if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID)) { |
| 124 | tprints(", child_tidptr="); |
| 125 | printaddr(tcp->u_arg[ARG_CTID]); |
| 126 | } |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 127 | } |
| 128 | /* TODO on syscall entry: |
| 129 | * We can clear CLONE_PTRACE here since it is an ancient hack |
| 130 | * to allow us to catch children, and we use another hack for that. |
| 131 | * But CLONE_PTRACE can conceivably be used by malicious programs |
| 132 | * to subvert us. By clearing this bit, we can defend against it: |
| 133 | * in untraced execution, CLONE_PTRACE should have no effect. |
| 134 | * |
| 135 | * We can also clear CLONE_UNTRACED, since it allows to start |
| 136 | * children outside of our control. At the moment |
| 137 | * I'm trying to figure out whether there is a *legitimate* |
| 138 | * use of this flag which we should respect. |
| 139 | */ |
| 140 | return 0; |
| 141 | } |
| 142 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 143 | SYS_FUNC(setns) |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 144 | { |
Dmitry V. Levin | 10e407d | 2015-07-20 17:16:56 +0000 | [diff] [blame] | 145 | printfd(tcp, tcp->u_arg[0]); |
| 146 | tprints(", "); |
| 147 | printflags(clone_flags, tcp->u_arg[1], "CLONE_???"); |
| 148 | |
| 149 | return RVAL_DECODED; |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 152 | SYS_FUNC(unshare) |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 153 | { |
Dmitry V. Levin | d06fa28 | 2016-05-16 22:49:54 +0000 | [diff] [blame] | 154 | printflags_long(clone_flags, tcp->u_arg[0], "CLONE_???"); |
Dmitry V. Levin | 10e407d | 2015-07-20 17:16:56 +0000 | [diff] [blame] | 155 | return RVAL_DECODED; |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 158 | SYS_FUNC(fork) |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 159 | { |
Dmitry V. Levin | 10e407d | 2015-07-20 17:16:56 +0000 | [diff] [blame] | 160 | return RVAL_DECODED | RVAL_UDECIMAL; |
Dmitry V. Levin | 265903a | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 161 | } |