Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

printsiginfo.c 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. * Copyright (c) 2015-2018 The strace developers.
  11. * All rights reserved.
  12. *
  13. * SPDX-License-Identifier: LGPL-2.1-or-later
  14. */
  15. #include "defs.h"
  16. #include DEF_MPERS_TYPE(siginfo_t)
  17. #include <signal.h>
  18. #include <linux/audit.h>
  19. #include MPERS_DEFS
  20. #include "nr_prefix.c"
  21. #ifndef IN_MPERS
  22. # include "printsiginfo.h"
  23. #endif
  24. #include "xlat/audit_arch.h"
  25. #include "xlat/sigbus_codes.h"
  26. #include "xlat/sigchld_codes.h"
  27. #include "xlat/sigfpe_codes.h"
  28. #include "xlat/sigill_codes.h"
  29. #include "xlat/siginfo_codes.h"
  30. #include "xlat/sigpoll_codes.h"
  31. #include "xlat/sigprof_codes.h"
  32. #include "xlat/sigsegv_codes.h"
  33. #include "xlat/sigsys_codes.h"
  34. #include "xlat/sigtrap_codes.h"
  35. #ifdef SIGEMT
  36. # include "xlat/sigemt_codes.h"
  37. #endif
  38. #ifndef SI_FROMUSER
  39. # define SI_FROMUSER(sip) ((sip)->si_code <= 0)
  40. #endif
  41. static void
  42. printsigsource(const siginfo_t *sip)
  43. {
  44. tprintf(", si_pid=%u, si_uid=%u",
  45. (unsigned int) sip->si_pid,
  46. (unsigned int) sip->si_uid);
  47. }
  48. static void
  49. printsigval(const siginfo_t *sip)
  50. {
  51. tprintf(", si_value={int=%d, ptr=", sip->si_int);
  52. printaddr(ptr_to_kulong(sip->si_ptr));
  53. tprints("}");
  54. }
  55. static void
  56. print_si_code(int si_signo, unsigned int si_code)
  57. {
  58. const char *code = xlookup(siginfo_codes, si_code);
  59. if (!code) {
  60. switch (si_signo) {
  61. case SIGTRAP:
  62. code = xlookup(sigtrap_codes, si_code);
  63. break;
  64. case SIGCHLD:
  65. code = xlookup(sigchld_codes, si_code);
  66. break;
  67. case SIGPOLL:
  68. code = xlookup(sigpoll_codes, si_code);
  69. break;
  70. case SIGPROF:
  71. code = xlookup(sigprof_codes, si_code);
  72. break;
  73. case SIGILL:
  74. code = xlookup(sigill_codes, si_code);
  75. break;
  76. #ifdef SIGEMT
  77. case SIGEMT:
  78. code = xlookup(sigemt_codes, si_code);
  79. break;
  80. #endif
  81. case SIGFPE:
  82. code = xlookup(sigfpe_codes, si_code);
  83. break;
  84. case SIGSEGV:
  85. code = xlookup(sigsegv_codes, si_code);
  86. break;
  87. case SIGBUS:
  88. code = xlookup(sigbus_codes, si_code);
  89. break;
  90. case SIGSYS:
  91. code = xlookup(sigsys_codes, si_code);
  92. break;
  93. }
  94. }
  95. print_xlat_ex(si_code, code, XLAT_STYLE_DEFAULT);
  96. }
  97. static void
  98. print_si_info(const siginfo_t *sip)
  99. {
  100. if (sip->si_errno) {
  101. tprints(", si_errno=");
  102. if ((unsigned) sip->si_errno < nerrnos
  103. && errnoent[sip->si_errno])
  104. tprints(errnoent[sip->si_errno]);
  105. else
  106. tprintf("%d", sip->si_errno);
  107. }
  108. if (SI_FROMUSER(sip)) {
  109. switch (sip->si_code) {
  110. case SI_USER:
  111. printsigsource(sip);
  112. break;
  113. case SI_TKILL:
  114. printsigsource(sip);
  115. break;
  116. #if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
  117. case SI_TIMER:
  118. tprintf(", si_timerid=%#x, si_overrun=%d",
  119. sip->si_timerid, sip->si_overrun);
  120. printsigval(sip);
  121. break;
  122. #endif
  123. default:
  124. printsigsource(sip);
  125. if (sip->si_ptr)
  126. printsigval(sip);
  127. break;
  128. }
  129. } else {
  130. switch (sip->si_signo) {
  131. case SIGCHLD:
  132. printsigsource(sip);
  133. tprints(", si_status=");
  134. if (sip->si_code == CLD_EXITED)
  135. tprintf("%d", sip->si_status);
  136. else
  137. printsignal(sip->si_status);
  138. tprintf(", si_utime=%llu, si_stime=%llu",
  139. zero_extend_signed_to_ull(sip->si_utime),
  140. zero_extend_signed_to_ull(sip->si_stime));
  141. break;
  142. case SIGILL: case SIGFPE:
  143. case SIGSEGV: case SIGBUS:
  144. tprints(", si_addr=");
  145. printaddr(ptr_to_kulong(sip->si_addr));
  146. break;
  147. case SIGPOLL:
  148. switch (sip->si_code) {
  149. case POLL_IN: case POLL_OUT: case POLL_MSG:
  150. tprintf(", si_band=%ld",
  151. (long) sip->si_band);
  152. break;
  153. }
  154. break;
  155. #ifdef HAVE_SIGINFO_T_SI_SYSCALL
  156. case SIGSYS: {
  157. /*
  158. * Note that we can safely use the personlity set in
  159. * current_personality here (and don't have to guess it
  160. * based on X32_SYSCALL_BIT and si_arch, for example):
  161. * - The signal is delivered as a result of seccomp
  162. * filtering to the process executing forbidden
  163. * syscall.
  164. * - We have set the personality for the tracee during
  165. * the syscall entering.
  166. * - The current_personality is reliably switched in
  167. * the next_event routine, it is set to the
  168. * personality of the last call made (the one that
  169. * triggered the signal delivery).
  170. * - Looks like there are no other cases where SIGSYS
  171. * is delivered from the kernel so far.
  172. */
  173. const char *scname = syscall_name(shuffle_scno(
  174. (unsigned) sip->si_syscall));
  175. tprints(", si_call_addr=");
  176. printaddr(ptr_to_kulong(sip->si_call_addr));
  177. tprints(", si_syscall=");
  178. if (scname)
  179. tprintf("%s%s",
  180. nr_prefix(sip->si_syscall), scname);
  181. else
  182. tprintf("%u", (unsigned) sip->si_syscall);
  183. tprints(", si_arch=");
  184. printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???");
  185. break;
  186. }
  187. #endif
  188. default:
  189. if (sip->si_pid || sip->si_uid)
  190. printsigsource(sip);
  191. if (sip->si_ptr)
  192. printsigval(sip);
  193. }
  194. }
  195. }
  196. #ifdef IN_MPERS
  197. static
  198. #endif
  199. void
  200. printsiginfo(const siginfo_t *sip)
  201. {
  202. if (sip->si_signo == 0) {
  203. tprints("{}");
  204. return;
  205. }
  206. tprints("{si_signo=");
  207. printsignal(sip->si_signo);
  208. tprints(", si_code=");
  209. print_si_code(sip->si_signo, sip->si_code);
  210. #ifdef SI_NOINFO
  211. if (sip->si_code != SI_NOINFO)
  212. #endif
  213. print_si_info(sip);
  214. tprints("}");
  215. }
  216. MPERS_PRINTER_DECL(void, printsiginfo_at,
  217. struct tcb *const tcp, const kernel_ulong_t addr)
  218. {
  219. siginfo_t si;
  220. if (!umove_or_printaddr(tcp, addr, &si))
  221. printsiginfo(&si);
  222. }
  223. static bool
  224. print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  225. {
  226. printsiginfo((const siginfo_t *) elem_buf);
  227. return true;
  228. }
  229. MPERS_PRINTER_DECL(void, print_siginfo_array, struct tcb *const tcp,
  230. const kernel_ulong_t addr, const kernel_ulong_t len)
  231. {
  232. siginfo_t si;
  233. print_array(tcp, addr, len, &si, sizeof(si),
  234. tfetch_mem, print_siginfo_t, 0);
  235. }