Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +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-1996 Rick Sladkey <jrs@world.std.com> |
| 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * Copyright (c) 2001 John Hughes <john@Calva.COM> |
| 7 | * Copyright (c) 2013 Denys Vlasenko <vda.linux@googlemail.com> |
| 8 | * Copyright (c) 2011-2015 Dmitry V. Levin <ldv@altlinux.org> |
| 9 | * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com> |
| 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer. |
| 17 | * 2. Redistributions in binary form must reproduce the above copyright |
| 18 | * notice, this list of conditions and the following disclaimer in the |
| 19 | * documentation and/or other materials provided with the distribution. |
| 20 | * 3. The name of the author may not be used to endorse or promote products |
| 21 | * derived from this software without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 35 | #include "defs.h" |
| 36 | |
Elvira Khabirova | a0b6249 | 2015-08-04 02:16:40 +0300 | [diff] [blame] | 37 | #include DEF_MPERS_TYPE(siginfo_t) |
| 38 | |
Dmitry V. Levin | 0e946ab | 2015-07-17 23:56:54 +0000 | [diff] [blame] | 39 | #include <signal.h> |
Mike Frysinger | d2eaf67 | 2015-08-18 03:24:59 -0400 | [diff] [blame] | 40 | #include <linux/audit.h> |
Dmitry V. Levin | 0e946ab | 2015-07-17 23:56:54 +0000 | [diff] [blame] | 41 | |
Elvira Khabirova | a0b6249 | 2015-08-04 02:16:40 +0300 | [diff] [blame] | 42 | #include MPERS_DEFS |
| 43 | |
| 44 | #ifndef IN_MPERS |
Dmitry V. Levin | 0e946ab | 2015-07-17 23:56:54 +0000 | [diff] [blame] | 45 | #include "printsiginfo.h" |
Elvira Khabirova | a0b6249 | 2015-08-04 02:16:40 +0300 | [diff] [blame] | 46 | #endif |
Dmitry V. Levin | 0e946ab | 2015-07-17 23:56:54 +0000 | [diff] [blame] | 47 | |
Mike Frysinger | d2eaf67 | 2015-08-18 03:24:59 -0400 | [diff] [blame] | 48 | #include "xlat/audit_arch.h" |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 49 | #include "xlat/sigbus_codes.h" |
| 50 | #include "xlat/sigchld_codes.h" |
| 51 | #include "xlat/sigfpe_codes.h" |
| 52 | #include "xlat/sigill_codes.h" |
| 53 | #include "xlat/siginfo_codes.h" |
| 54 | #include "xlat/sigpoll_codes.h" |
| 55 | #include "xlat/sigprof_codes.h" |
| 56 | #include "xlat/sigsegv_codes.h" |
| 57 | #include "xlat/sigsys_codes.h" |
| 58 | #include "xlat/sigtrap_codes.h" |
| 59 | |
| 60 | #ifdef SIGEMT |
| 61 | # include "xlat/sigemt_codes.h" |
| 62 | #endif |
| 63 | |
| 64 | #ifndef SI_FROMUSER |
| 65 | # define SI_FROMUSER(sip) ((sip)->si_code <= 0) |
| 66 | #endif |
| 67 | |
| 68 | static void |
| 69 | printsigsource(const siginfo_t *sip) |
| 70 | { |
Elvira Khabirova | 3595f4a | 2015-08-21 20:46:35 +0300 | [diff] [blame] | 71 | tprintf(", si_pid=%u, si_uid=%u", |
| 72 | (unsigned int) sip->si_pid, |
| 73 | (unsigned int) sip->si_uid); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static void |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 77 | printsigval(const siginfo_t *sip) |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 78 | { |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 79 | tprintf(", si_value={int=%d, ptr=", sip->si_int); |
| 80 | printaddr((unsigned long) sip->si_ptr); |
| 81 | tprints("}"); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static void |
Dmitry V. Levin | 9134aab | 2016-05-14 21:46:05 +0000 | [diff] [blame] | 85 | print_si_code(int si_signo, unsigned int si_code) |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 86 | { |
| 87 | const char *code = xlookup(siginfo_codes, si_code); |
| 88 | |
| 89 | if (!code) { |
| 90 | switch (si_signo) { |
| 91 | case SIGTRAP: |
| 92 | code = xlookup(sigtrap_codes, si_code); |
| 93 | break; |
| 94 | case SIGCHLD: |
| 95 | code = xlookup(sigchld_codes, si_code); |
| 96 | break; |
| 97 | case SIGPOLL: |
| 98 | code = xlookup(sigpoll_codes, si_code); |
| 99 | break; |
| 100 | case SIGPROF: |
| 101 | code = xlookup(sigprof_codes, si_code); |
| 102 | break; |
| 103 | case SIGILL: |
| 104 | code = xlookup(sigill_codes, si_code); |
| 105 | break; |
| 106 | #ifdef SIGEMT |
| 107 | case SIGEMT: |
| 108 | code = xlookup(sigemt_codes, si_code); |
| 109 | break; |
| 110 | #endif |
| 111 | case SIGFPE: |
| 112 | code = xlookup(sigfpe_codes, si_code); |
| 113 | break; |
| 114 | case SIGSEGV: |
| 115 | code = xlookup(sigsegv_codes, si_code); |
| 116 | break; |
| 117 | case SIGBUS: |
| 118 | code = xlookup(sigbus_codes, si_code); |
| 119 | break; |
| 120 | case SIGSYS: |
| 121 | code = xlookup(sigsys_codes, si_code); |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if (code) |
| 127 | tprints(code); |
| 128 | else |
| 129 | tprintf("%#x", si_code); |
| 130 | } |
| 131 | |
| 132 | static void |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 133 | print_si_info(const siginfo_t *sip) |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 134 | { |
| 135 | if (sip->si_errno) { |
| 136 | tprints(", si_errno="); |
| 137 | if ((unsigned) sip->si_errno < nerrnos |
| 138 | && errnoent[sip->si_errno]) |
| 139 | tprints(errnoent[sip->si_errno]); |
| 140 | else |
| 141 | tprintf("%d", sip->si_errno); |
| 142 | } |
| 143 | |
| 144 | if (SI_FROMUSER(sip)) { |
| 145 | switch (sip->si_code) { |
| 146 | case SI_USER: |
| 147 | printsigsource(sip); |
| 148 | break; |
| 149 | case SI_TKILL: |
| 150 | printsigsource(sip); |
| 151 | break; |
| 152 | #if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN |
| 153 | case SI_TIMER: |
| 154 | tprintf(", si_timerid=%#x, si_overrun=%d", |
| 155 | sip->si_timerid, sip->si_overrun); |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 156 | printsigval(sip); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 157 | break; |
| 158 | #endif |
| 159 | default: |
| 160 | printsigsource(sip); |
| 161 | if (sip->si_ptr) |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 162 | printsigval(sip); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 163 | break; |
| 164 | } |
| 165 | } else { |
| 166 | switch (sip->si_signo) { |
| 167 | case SIGCHLD: |
| 168 | printsigsource(sip); |
| 169 | tprints(", si_status="); |
| 170 | if (sip->si_code == CLD_EXITED) |
| 171 | tprintf("%d", sip->si_status); |
| 172 | else |
| 173 | printsignal(sip->si_status); |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 174 | tprintf(", si_utime=%llu, si_stime=%llu", |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 175 | widen_to_ull(sip->si_utime), |
| 176 | widen_to_ull(sip->si_stime)); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 177 | break; |
| 178 | case SIGILL: case SIGFPE: |
| 179 | case SIGSEGV: case SIGBUS: |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 180 | tprints(", si_addr="); |
| 181 | printaddr((unsigned long) sip->si_addr); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 182 | break; |
| 183 | case SIGPOLL: |
| 184 | switch (sip->si_code) { |
| 185 | case POLL_IN: case POLL_OUT: case POLL_MSG: |
| 186 | tprintf(", si_band=%ld", |
| 187 | (long) sip->si_band); |
| 188 | break; |
| 189 | } |
| 190 | break; |
| 191 | #ifdef HAVE_SIGINFO_T_SI_SYSCALL |
| 192 | case SIGSYS: |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 193 | tprints(", si_call_addr="); |
| 194 | printaddr((unsigned long) sip->si_call_addr); |
| 195 | tprintf(", si_syscall=__NR_%s, si_arch=", |
Dmitry V. Levin | 4995594 | 2016-05-12 14:27:49 +0000 | [diff] [blame] | 196 | syscall_name((unsigned) sip->si_syscall)); |
Mike Frysinger | d2eaf67 | 2015-08-18 03:24:59 -0400 | [diff] [blame] | 197 | printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???"); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 198 | break; |
| 199 | #endif |
| 200 | default: |
| 201 | if (sip->si_pid || sip->si_uid) |
| 202 | printsigsource(sip); |
| 203 | if (sip->si_ptr) |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 204 | printsigval(sip); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
Elvira Khabirova | a0b6249 | 2015-08-04 02:16:40 +0300 | [diff] [blame] | 209 | #ifdef IN_MPERS |
| 210 | static |
| 211 | #endif |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 212 | void |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 213 | printsiginfo(const siginfo_t *sip) |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 214 | { |
| 215 | if (sip->si_signo == 0) { |
| 216 | tprints("{}"); |
| 217 | return; |
| 218 | } |
| 219 | tprints("{si_signo="); |
| 220 | printsignal(sip->si_signo); |
| 221 | |
| 222 | tprints(", si_code="); |
| 223 | print_si_code(sip->si_signo, sip->si_code); |
| 224 | |
| 225 | #ifdef SI_NOINFO |
| 226 | if (sip->si_code != SI_NOINFO) |
| 227 | #endif |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 228 | print_si_info(sip); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 229 | |
| 230 | tprints("}"); |
| 231 | } |
| 232 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 233 | MPERS_PRINTER_DECL(void, printsiginfo_at, |
| 234 | struct tcb *tcp, long addr) |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 235 | { |
| 236 | siginfo_t si; |
Dmitry V. Levin | a528eb5 | 2015-07-17 21:58:18 +0000 | [diff] [blame] | 237 | |
| 238 | if (!umove_or_printaddr(tcp, addr, &si)) |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 239 | printsiginfo(&si); |
Dmitry V. Levin | 537c964 | 2015-03-27 23:28:15 +0000 | [diff] [blame] | 240 | } |
Dmitry V. Levin | 76b4c33 | 2016-05-13 02:33:33 +0000 | [diff] [blame] | 241 | |
| 242 | static bool |
| 243 | print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) |
| 244 | { |
Dmitry V. Levin | f9199ab | 2016-05-13 14:16:12 +0000 | [diff] [blame] | 245 | printsiginfo((const siginfo_t *) elem_buf); |
Dmitry V. Levin | 76b4c33 | 2016-05-13 02:33:33 +0000 | [diff] [blame] | 246 | return true; |
| 247 | } |
| 248 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 249 | MPERS_PRINTER_DECL(void, print_siginfo_array, |
| 250 | struct tcb *tcp, unsigned long addr, unsigned long len) |
Dmitry V. Levin | 76b4c33 | 2016-05-13 02:33:33 +0000 | [diff] [blame] | 251 | { |
| 252 | siginfo_t si; |
| 253 | |
| 254 | print_array(tcp, addr, len, &si, sizeof(si), |
| 255 | umoven_or_printaddr, print_siginfo_t, 0); |
| 256 | } |