blob: d46003c259fc511ec31a5a106bb68b5d0c51b3a3 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
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>
Elliott Hughesb7556142018-02-20 17:03:16 -080010 * Copyright (c) 2015-2018 The strace developers.
Dmitry V. Levin38a34c92015-12-17 17:56:48 +000011 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
Dmitry V. Levin537c9642015-03-27 23:28:15 +000036#include "defs.h"
37
Elvira Khabirovaa0b62492015-08-04 02:16:40 +030038#include DEF_MPERS_TYPE(siginfo_t)
39
Dmitry V. Levin0e946ab2015-07-17 23:56:54 +000040#include <signal.h>
Mike Frysingerd2eaf672015-08-18 03:24:59 -040041#include <linux/audit.h>
Dmitry V. Levin0e946ab2015-07-17 23:56:54 +000042
Elvira Khabirovaa0b62492015-08-04 02:16:40 +030043#include MPERS_DEFS
44
Elliott Hughesb7556142018-02-20 17:03:16 -080045#include "nr_prefix.c"
46
Elvira Khabirovaa0b62492015-08-04 02:16:40 +030047#ifndef IN_MPERS
Dmitry V. Levin0e946ab2015-07-17 23:56:54 +000048#include "printsiginfo.h"
Elvira Khabirovaa0b62492015-08-04 02:16:40 +030049#endif
Dmitry V. Levin0e946ab2015-07-17 23:56:54 +000050
Mike Frysingerd2eaf672015-08-18 03:24:59 -040051#include "xlat/audit_arch.h"
Dmitry V. Levin537c9642015-03-27 23:28:15 +000052#include "xlat/sigbus_codes.h"
53#include "xlat/sigchld_codes.h"
54#include "xlat/sigfpe_codes.h"
55#include "xlat/sigill_codes.h"
56#include "xlat/siginfo_codes.h"
57#include "xlat/sigpoll_codes.h"
58#include "xlat/sigprof_codes.h"
59#include "xlat/sigsegv_codes.h"
60#include "xlat/sigsys_codes.h"
61#include "xlat/sigtrap_codes.h"
62
63#ifdef SIGEMT
64# include "xlat/sigemt_codes.h"
65#endif
66
67#ifndef SI_FROMUSER
68# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
69#endif
70
71static void
72printsigsource(const siginfo_t *sip)
73{
Elvira Khabirova3595f4a2015-08-21 20:46:35 +030074 tprintf(", si_pid=%u, si_uid=%u",
75 (unsigned int) sip->si_pid,
76 (unsigned int) sip->si_uid);
Dmitry V. Levin537c9642015-03-27 23:28:15 +000077}
78
79static void
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +000080printsigval(const siginfo_t *sip)
Dmitry V. Levin537c9642015-03-27 23:28:15 +000081{
Dmitry V. Levin484326d2016-06-11 01:28:21 +000082 tprintf(", si_value={int=%d, ptr=", sip->si_int);
Elliott Hughesd35df492017-02-15 15:19:05 -080083 printaddr(ptr_to_kulong(sip->si_ptr));
Dmitry V. Levin484326d2016-06-11 01:28:21 +000084 tprints("}");
Dmitry V. Levin537c9642015-03-27 23:28:15 +000085}
86
87static void
Dmitry V. Levin9134aab2016-05-14 21:46:05 +000088print_si_code(int si_signo, unsigned int si_code)
Dmitry V. Levin537c9642015-03-27 23:28:15 +000089{
90 const char *code = xlookup(siginfo_codes, si_code);
91
92 if (!code) {
93 switch (si_signo) {
94 case SIGTRAP:
95 code = xlookup(sigtrap_codes, si_code);
96 break;
97 case SIGCHLD:
98 code = xlookup(sigchld_codes, si_code);
99 break;
100 case SIGPOLL:
101 code = xlookup(sigpoll_codes, si_code);
102 break;
103 case SIGPROF:
104 code = xlookup(sigprof_codes, si_code);
105 break;
106 case SIGILL:
107 code = xlookup(sigill_codes, si_code);
108 break;
109#ifdef SIGEMT
110 case SIGEMT:
111 code = xlookup(sigemt_codes, si_code);
112 break;
113#endif
114 case SIGFPE:
115 code = xlookup(sigfpe_codes, si_code);
116 break;
117 case SIGSEGV:
118 code = xlookup(sigsegv_codes, si_code);
119 break;
120 case SIGBUS:
121 code = xlookup(sigbus_codes, si_code);
122 break;
123 case SIGSYS:
124 code = xlookup(sigsys_codes, si_code);
125 break;
126 }
127 }
128
Elliott Hughes03a418e2018-06-15 13:11:40 -0700129 print_xlat_ex(si_code, code, XLAT_STYLE_DEFAULT);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000130}
131
132static void
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000133print_si_info(const siginfo_t *sip)
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000134{
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. Levinf9199ab2016-05-13 14:16:12 +0000156 printsigval(sip);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000157 break;
158#endif
159 default:
160 printsigsource(sip);
161 if (sip->si_ptr)
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000162 printsigval(sip);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000163 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. Levinf9199ab2016-05-13 14:16:12 +0000174 tprintf(", si_utime=%llu, si_stime=%llu",
Dmitry V. Levin031fc802016-08-23 00:24:10 +0000175 zero_extend_signed_to_ull(sip->si_utime),
176 zero_extend_signed_to_ull(sip->si_stime));
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000177 break;
178 case SIGILL: case SIGFPE:
179 case SIGSEGV: case SIGBUS:
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000180 tprints(", si_addr=");
Elliott Hughesd35df492017-02-15 15:19:05 -0800181 printaddr(ptr_to_kulong(sip->si_addr));
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000182 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
Elliott Hughesd35df492017-02-15 15:19:05 -0800192 case SIGSYS: {
Elliott Hughesb7556142018-02-20 17:03:16 -0800193 /*
194 * Note that we can safely use the personlity set in
195 * current_personality here (and don't have to guess it
196 * based on X32_SYSCALL_BIT and si_arch, for example):
197 * - The signal is delivered as a result of seccomp
198 * filtering to the process executing forbidden
199 * syscall.
200 * - We have set the personality for the tracee during
201 * the syscall entering.
202 * - The current_personality is reliably switched in
203 * the next_event routine, it is set to the
204 * personality of the last call made (the one that
205 * triggered the signal delivery).
206 * - Looks like there are no other cases where SIGSYS
207 * is delivered from the kernel so far.
208 */
209 const char *scname = syscall_name(shuffle_scno(
210 (unsigned) sip->si_syscall));
Elliott Hughesd35df492017-02-15 15:19:05 -0800211
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000212 tprints(", si_call_addr=");
Elliott Hughesd35df492017-02-15 15:19:05 -0800213 printaddr(ptr_to_kulong(sip->si_call_addr));
214 tprints(", si_syscall=");
215 if (scname)
Elliott Hughesb7556142018-02-20 17:03:16 -0800216 tprintf("%s%s",
217 nr_prefix(sip->si_syscall), scname);
Elliott Hughesd35df492017-02-15 15:19:05 -0800218 else
219 tprintf("%u", (unsigned) sip->si_syscall);
220 tprints(", si_arch=");
Mike Frysingerd2eaf672015-08-18 03:24:59 -0400221 printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???");
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000222 break;
Elliott Hughesd35df492017-02-15 15:19:05 -0800223 }
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000224#endif
225 default:
226 if (sip->si_pid || sip->si_uid)
227 printsigsource(sip);
228 if (sip->si_ptr)
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000229 printsigval(sip);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000230 }
231 }
232}
233
Elvira Khabirovaa0b62492015-08-04 02:16:40 +0300234#ifdef IN_MPERS
235static
236#endif
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000237void
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000238printsiginfo(const siginfo_t *sip)
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000239{
240 if (sip->si_signo == 0) {
241 tprints("{}");
242 return;
243 }
244 tprints("{si_signo=");
245 printsignal(sip->si_signo);
246
247 tprints(", si_code=");
248 print_si_code(sip->si_signo, sip->si_code);
249
250#ifdef SI_NOINFO
251 if (sip->si_code != SI_NOINFO)
252#endif
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000253 print_si_info(sip);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000254
255 tprints("}");
256}
257
Dmitry V. Levina8fce092016-05-21 22:53:06 +0000258MPERS_PRINTER_DECL(void, printsiginfo_at,
Elliott Hughesd35df492017-02-15 15:19:05 -0800259 struct tcb *const tcp, const kernel_ulong_t addr)
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000260{
261 siginfo_t si;
Dmitry V. Levina528eb52015-07-17 21:58:18 +0000262
263 if (!umove_or_printaddr(tcp, addr, &si))
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000264 printsiginfo(&si);
Dmitry V. Levin537c9642015-03-27 23:28:15 +0000265}
Dmitry V. Levin76b4c332016-05-13 02:33:33 +0000266
267static bool
268print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
269{
Dmitry V. Levinf9199ab2016-05-13 14:16:12 +0000270 printsiginfo((const siginfo_t *) elem_buf);
Dmitry V. Levin76b4c332016-05-13 02:33:33 +0000271 return true;
272}
273
Elliott Hughesd35df492017-02-15 15:19:05 -0800274MPERS_PRINTER_DECL(void, print_siginfo_array, struct tcb *const tcp,
275 const kernel_ulong_t addr, const kernel_ulong_t len)
Dmitry V. Levin76b4c332016-05-13 02:33:33 +0000276{
277 siginfo_t si;
278
279 print_array(tcp, addr, len, &si, sizeof(si),
Elliott Hughes03a418e2018-06-15 13:11:40 -0700280 tfetch_mem, print_siginfo_t, 0);
Dmitry V. Levin76b4c332016-05-13 02:33:33 +0000281}