Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 7 | * Linux for s390 port by D.J. Barrow |
| 8 | * <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com> |
Wichert Akkerman | ccef637 | 2002-05-01 16:39:22 +0000 | [diff] [blame] | 9 | * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH |
| 10 | * port by Greg Banks <gbanks@pocketpenguins.com> |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 11 | * |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 12 | * All rights reserved. |
| 13 | * |
| 14 | * Redistribution and use in source and binary forms, with or without |
| 15 | * modification, are permitted provided that the following conditions |
| 16 | * are met: |
| 17 | * 1. Redistributions of source code must retain the above copyright |
| 18 | * notice, this list of conditions and the following disclaimer. |
| 19 | * 2. Redistributions in binary form must reproduce the above copyright |
| 20 | * notice, this list of conditions and the following disclaimer in the |
| 21 | * documentation and/or other materials provided with the distribution. |
| 22 | * 3. The name of the author may not be used to endorse or promote products |
| 23 | * derived from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 26 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 27 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 28 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 34 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | */ |
| 36 | |
| 37 | #include "defs.h" |
Dmitry V. Levin | 6eee4e0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 38 | |
Dmitry V. Levin | c41808b | 2013-03-18 00:52:29 +0000 | [diff] [blame] | 39 | #ifdef HAVE_ELF_H |
| 40 | # include <elf.h> |
| 41 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 42 | |
Dmitry V. Levin | 6eee4e0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 43 | #include "xlat/nt_descriptor_types.h" |
| 44 | |
Dmitry V. Levin | 7211dbc | 2015-02-28 12:20:21 +0000 | [diff] [blame] | 45 | #include "regs.h" |
Dmitry V. Levin | fadf379 | 2015-02-13 00:26:38 +0000 | [diff] [blame] | 46 | #include "ptrace.h" |
Dmitry V. Levin | 6eee4e0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 47 | #include "xlat/ptrace_cmds.h" |
| 48 | #include "xlat/ptrace_setoptions_flags.h" |
Dmitry V. Levin | 809ee3e | 2016-05-12 15:45:24 +0000 | [diff] [blame] | 49 | #include "xlat/ptrace_peeksiginfo_flags.h" |
Dmitry V. Levin | 6eee4e0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 50 | |
Denys Vlasenko | 513e9c2 | 2012-03-21 14:39:22 +0100 | [diff] [blame] | 51 | #define uoff(member) offsetof(struct user, member) |
Dmitry V. Levin | c6ce4fd | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 52 | #define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" } |
Denys Vlasenko | 513e9c2 | 2012-03-21 14:39:22 +0100 | [diff] [blame] | 53 | |
Dmitry V. Levin | 8c0ef94 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 54 | static const struct xlat struct_user_offsets[] = { |
Dmitry V. Levin | fced7b0 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 55 | #include "userent.h" |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 56 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 59 | static void |
| 60 | print_user_offset_addr(const unsigned long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 61 | { |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 62 | const struct xlat *x; |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 63 | |
| 64 | for (x = struct_user_offsets; x->str; ++x) { |
| 65 | if (x->val >= addr) |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | if (!x->str) { |
| 70 | printaddr(addr); |
| 71 | } else if (x->val > addr) { |
| 72 | if (x == struct_user_offsets) { |
| 73 | printaddr(addr); |
| 74 | } else { |
| 75 | --x; |
| 76 | tprintf("%s + %lu", |
| 77 | x->str, addr - (unsigned long) x->val); |
| 78 | } |
| 79 | } else { |
| 80 | tprints(x->str); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | SYS_FUNC(ptrace) |
| 85 | { |
Dmitry V. Levin | 73a8e97 | 2016-05-12 14:45:38 +0000 | [diff] [blame] | 86 | const unsigned long request = tcp->u_arg[0]; |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 87 | const int pid = tcp->u_arg[1]; |
| 88 | const unsigned long addr = tcp->u_arg[2]; |
| 89 | const unsigned long data = tcp->u_arg[3]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 90 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 91 | if (entering(tcp)) { |
Dmitry V. Levin | 73a8e97 | 2016-05-12 14:45:38 +0000 | [diff] [blame] | 92 | /* request */ |
| 93 | printxval64(ptrace_cmds, request, "PTRACE_???"); |
| 94 | |
Dmitry V. Levin | 89ca4aa | 2016-05-12 15:03:58 +0000 | [diff] [blame] | 95 | if (request == PTRACE_TRACEME) { |
| 96 | /* pid, addr, and data are ignored. */ |
| 97 | return RVAL_DECODED; |
| 98 | } |
| 99 | |
Dmitry V. Levin | 73a8e97 | 2016-05-12 14:45:38 +0000 | [diff] [blame] | 100 | /* pid */ |
Dmitry V. Levin | 91bd125 | 2016-05-12 15:10:41 +0000 | [diff] [blame] | 101 | tprintf(", %d", pid); |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 102 | |
Dmitry V. Levin | 73a8e97 | 2016-05-12 14:45:38 +0000 | [diff] [blame] | 103 | /* addr */ |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 104 | switch (request) { |
Dmitry V. Levin | 91bd125 | 2016-05-12 15:10:41 +0000 | [diff] [blame] | 105 | case PTRACE_ATTACH: |
| 106 | case PTRACE_INTERRUPT: |
| 107 | case PTRACE_KILL: |
| 108 | case PTRACE_LISTEN: |
| 109 | /* addr and data are ignored */ |
| 110 | return RVAL_DECODED; |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 111 | case PTRACE_PEEKUSER: |
| 112 | case PTRACE_POKEUSER: |
Dmitry V. Levin | 91bd125 | 2016-05-12 15:10:41 +0000 | [diff] [blame] | 113 | tprints(", "); |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 114 | print_user_offset_addr(addr); |
| 115 | break; |
| 116 | case PTRACE_GETREGSET: |
| 117 | case PTRACE_SETREGSET: |
Dmitry V. Levin | 91bd125 | 2016-05-12 15:10:41 +0000 | [diff] [blame] | 118 | tprints(", "); |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 119 | printxval(nt_descriptor_types, addr, "NT_???"); |
| 120 | break; |
Dmitry V. Levin | 3a5cd34 | 2016-05-12 15:38:35 +0000 | [diff] [blame] | 121 | case PTRACE_GETSIGMASK: |
| 122 | case PTRACE_SETSIGMASK: |
| 123 | case PTRACE_SECCOMP_GET_FILTER: |
| 124 | tprintf(", %lu", addr); |
| 125 | break; |
Dmitry V. Levin | 809ee3e | 2016-05-12 15:45:24 +0000 | [diff] [blame] | 126 | case PTRACE_PEEKSIGINFO: { |
| 127 | tprints(", "); |
| 128 | struct { |
| 129 | uint64_t off; |
| 130 | uint32_t flags; |
| 131 | uint32_t nr; |
| 132 | } psi; |
| 133 | if (umove_or_printaddr(tcp, addr, &psi)) { |
| 134 | tprints(", "); |
| 135 | printaddr(data); |
| 136 | return RVAL_DECODED; |
| 137 | } |
| 138 | tprintf("{off=%" PRIu64 ", flags=", psi.off); |
| 139 | printflags(ptrace_peeksiginfo_flags, psi.flags, |
| 140 | "PTRACE_PEEKSIGINFO_???"); |
| 141 | tprintf(", nr=%u}", psi.nr); |
| 142 | break; |
| 143 | } |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 144 | default: |
Dmitry V. Levin | 91bd125 | 2016-05-12 15:10:41 +0000 | [diff] [blame] | 145 | tprints(", "); |
Dmitry V. Levin | 14446eb | 2015-07-17 21:12:05 +0000 | [diff] [blame] | 146 | printaddr(addr); |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Dmitry V. Levin | 8bd7f31 | 2016-05-12 16:49:34 +0000 | [diff] [blame] | 149 | # if defined IA64 || defined SPARC || defined SPARC64 |
| 150 | switch (request) { |
| 151 | # ifdef IA64 |
| 152 | case PTRACE_PEEKDATA: |
| 153 | case PTRACE_PEEKTEXT: |
| 154 | case PTRACE_PEEKUSER: |
| 155 | /* data is ignored */ |
| 156 | return RVAL_DECODED | RVAL_HEX; |
| 157 | # endif /* IA64 */ |
| 158 | # if defined SPARC || defined SPARC64 |
| 159 | case PTRACE_GETREGS: |
| 160 | case PTRACE_SETREGS: |
| 161 | case PTRACE_GETFPREGS: |
| 162 | case PTRACE_SETFPREGS: |
| 163 | /* data is ignored */ |
| 164 | return RVAL_DECODED; |
| 165 | # endif /* SPARC || SPARC64 */ |
| 166 | } |
| 167 | # endif /* IA64 || SPARC || SPARC64 */ |
| 168 | |
Dmitry V. Levin | 14446eb | 2015-07-17 21:12:05 +0000 | [diff] [blame] | 169 | tprints(", "); |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 170 | |
Dmitry V. Levin | 91bd125 | 2016-05-12 15:10:41 +0000 | [diff] [blame] | 171 | /* data */ |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 172 | switch (request) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 173 | case PTRACE_CONT: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 174 | case PTRACE_DETACH: |
Dmitry V. Levin | caa2bc3 | 2016-05-12 15:50:43 +0000 | [diff] [blame] | 175 | case PTRACE_SYSCALL: |
| 176 | #ifdef PTRACE_SINGLESTEP |
| 177 | case PTRACE_SINGLESTEP: |
| 178 | #endif |
| 179 | #ifdef PTRACE_SINGLEBLOCK |
| 180 | case PTRACE_SINGLEBLOCK: |
| 181 | #endif |
| 182 | #ifdef PTRACE_SYSEMU |
| 183 | case PTRACE_SYSEMU: |
| 184 | #endif |
| 185 | #ifdef PTRACE_SYSEMU_SINGLESTEP |
| 186 | case PTRACE_SYSEMU_SINGLESTEP: |
| 187 | #endif |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 188 | printsignal(data); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 189 | break; |
Dmitry V. Levin | 7c8e330 | 2016-05-12 15:53:28 +0000 | [diff] [blame] | 190 | case PTRACE_SEIZE: |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 191 | case PTRACE_SETOPTIONS: |
Dmitry V. Levin | 7c8e330 | 2016-05-12 15:53:28 +0000 | [diff] [blame] | 192 | #ifdef PTRACE_OLDSETOPTIONS |
| 193 | case PTRACE_OLDSETOPTIONS: |
| 194 | #endif |
Dmitry V. Levin | 388aca6 | 2016-05-12 16:35:54 +0000 | [diff] [blame] | 195 | printflags64(ptrace_setoptions_flags, data, "PTRACE_O_???"); |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 196 | break; |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 197 | case PTRACE_SETSIGINFO: |
| 198 | printsiginfo_at(tcp, data); |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 199 | break; |
Dmitry V. Levin | 1634de7 | 2016-05-12 16:52:49 +0000 | [diff] [blame] | 200 | case PTRACE_SETSIGMASK: |
| 201 | print_sigset_addr_len(tcp, data, addr); |
| 202 | break; |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 203 | case PTRACE_SETREGSET: |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 204 | tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0); |
Denys Vlasenko | be99497 | 2013-02-13 16:10:10 +0100 | [diff] [blame] | 205 | break; |
Dmitry V. Levin | 8bd7f31 | 2016-05-12 16:49:34 +0000 | [diff] [blame] | 206 | #ifndef IA64 |
| 207 | case PTRACE_PEEKDATA: |
| 208 | case PTRACE_PEEKTEXT: |
| 209 | case PTRACE_PEEKUSER: |
| 210 | #endif |
Dmitry V. Levin | 846f617 | 2016-05-12 16:56:30 +0000 | [diff] [blame] | 211 | case PTRACE_GETEVENTMSG: |
Dmitry V. Levin | fadf379 | 2015-02-13 00:26:38 +0000 | [diff] [blame] | 212 | case PTRACE_GETREGSET: |
Dmitry V. Levin | 8bd7f31 | 2016-05-12 16:49:34 +0000 | [diff] [blame] | 213 | case PTRACE_GETSIGINFO: |
Dmitry V. Levin | 1634de7 | 2016-05-12 16:52:49 +0000 | [diff] [blame] | 214 | case PTRACE_GETSIGMASK: |
Dmitry V. Levin | 76b4c33 | 2016-05-13 02:33:33 +0000 | [diff] [blame] | 215 | case PTRACE_PEEKSIGINFO: |
Dmitry V. Levin | d9fb4a4 | 2016-05-12 16:58:38 +0000 | [diff] [blame] | 216 | case PTRACE_SECCOMP_GET_FILTER: |
Dmitry V. Levin | 8bd7f31 | 2016-05-12 16:49:34 +0000 | [diff] [blame] | 217 | if (verbose(tcp)) { |
| 218 | /* print data on exiting syscall */ |
| 219 | return 0; |
| 220 | } |
| 221 | /* fall through */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 222 | default: |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 223 | printaddr(data); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 224 | break; |
| 225 | } |
Dmitry V. Levin | 8bd7f31 | 2016-05-12 16:49:34 +0000 | [diff] [blame] | 226 | |
| 227 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 228 | } else { |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 229 | switch (request) { |
Dmitry V. Levin | 8bd7f31 | 2016-05-12 16:49:34 +0000 | [diff] [blame] | 230 | #ifndef IA64 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 231 | case PTRACE_PEEKDATA: |
| 232 | case PTRACE_PEEKTEXT: |
| 233 | case PTRACE_PEEKUSER: |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 234 | printnum_ptr(tcp, data); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 235 | break; |
Denys Vlasenko | 3e3490a | 2012-03-17 01:27:37 +0100 | [diff] [blame] | 236 | #endif |
Dmitry V. Levin | 846f617 | 2016-05-12 16:56:30 +0000 | [diff] [blame] | 237 | case PTRACE_GETEVENTMSG: |
| 238 | printnum_ulong(tcp, data); |
| 239 | break; |
| 240 | case PTRACE_GETREGSET: |
| 241 | tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0); |
| 242 | break; |
Dmitry V. Levin | ccdc82a | 2016-04-01 00:28:33 +0000 | [diff] [blame] | 243 | case PTRACE_GETSIGINFO: |
| 244 | printsiginfo_at(tcp, data); |
Denys Vlasenko | f535b54 | 2009-01-13 18:30:55 +0000 | [diff] [blame] | 245 | break; |
Dmitry V. Levin | 1634de7 | 2016-05-12 16:52:49 +0000 | [diff] [blame] | 246 | case PTRACE_GETSIGMASK: |
| 247 | print_sigset_addr_len(tcp, data, addr); |
| 248 | break; |
Dmitry V. Levin | 76b4c33 | 2016-05-13 02:33:33 +0000 | [diff] [blame] | 249 | case PTRACE_PEEKSIGINFO: |
| 250 | if (syserror(tcp)) |
| 251 | printaddr(data); |
| 252 | else |
| 253 | print_siginfo_array(tcp, data, tcp->u_rval); |
| 254 | break; |
Dmitry V. Levin | d9fb4a4 | 2016-05-12 16:58:38 +0000 | [diff] [blame] | 255 | case PTRACE_SECCOMP_GET_FILTER: |
| 256 | if (syserror(tcp)) |
| 257 | printaddr(data); |
| 258 | else |
| 259 | print_seccomp_fprog(tcp, data, tcp->u_rval); |
| 260 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 261 | } |
| 262 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 263 | return 0; |
| 264 | } |