2015-12-17 17:56:48 +00:00
/*
* Copyright ( c ) 1991 , 1992 Paul Kranenburg < pk @ cs . few . eur . nl >
* Copyright ( c ) 1993 Branko Lankester < branko @ hacktic . nl >
* Copyright ( c ) 1993 - 1996 Rick Sladkey < jrs @ world . std . com >
* Copyright ( c ) 1996 - 1999 Wichert Akkerman < wichert @ cistron . nl >
* Copyright ( c ) 2001 John Hughes < john @ Calva . COM >
* Copyright ( c ) 2013 Denys Vlasenko < vda . linux @ googlemail . com >
* Copyright ( c ) 2011 - 2015 Dmitry V . Levin < ldv @ altlinux . org >
* Copyright ( c ) 2015 Elvira Khabirova < lineprinter0 @ gmail . com >
2018-02-13 22:00:00 +00:00
* Copyright ( c ) 2015 - 2018 The strace developers .
2015-12-17 17:56:48 +00:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
2015-03-27 23:28:15 +00:00
# include "defs.h"
2015-08-04 02:16:40 +03:00
# include DEF_MPERS_TYPE(siginfo_t)
2015-07-17 23:56:54 +00:00
# include <signal.h>
2015-08-18 03:24:59 -04:00
# include <linux/audit.h>
2015-07-17 23:56:54 +00:00
2015-08-04 02:16:40 +03:00
# include MPERS_DEFS
2018-01-31 20:28:56 +01:00
# include "nr_prefix.c"
2015-08-04 02:16:40 +03:00
# ifndef IN_MPERS
2015-07-17 23:56:54 +00:00
# include "printsiginfo.h"
2015-08-04 02:16:40 +03:00
# endif
2015-07-17 23:56:54 +00:00
2018-11-22 10:45:02 +01:00
# define XLAT_MACROS_ONLY
/* For xlat/audit_arch.h */
2018-11-22 18:05:54 +01:00
# include "xlat / audit_arch_flags.h"
2018-11-22 10:45:02 +01:00
# include "xlat / elf_em.h"
# undef XLAT_MACROS_ONLY
2015-08-18 03:24:59 -04:00
# include "xlat/audit_arch.h"
2015-03-27 23:28:15 +00:00
# include "xlat/sigbus_codes.h"
# include "xlat/sigchld_codes.h"
# include "xlat/sigfpe_codes.h"
# include "xlat/sigill_codes.h"
# include "xlat/siginfo_codes.h"
# include "xlat/sigpoll_codes.h"
# include "xlat/sigprof_codes.h"
# include "xlat/sigsegv_codes.h"
# include "xlat/sigsys_codes.h"
# include "xlat/sigtrap_codes.h"
2018-11-25 13:38:31 +01:00
# ifdef ALPHA
# include <asm / gentrap.h>
# include "xlat / alpha_gentrap.h"
# endif /* ALPHA */
2018-11-25 14:11:54 +01:00
# ifdef IA64
# include "xlat / ia64_siginfo_si_flags.h"
# endif
2015-03-27 23:28:15 +00:00
# ifdef SIGEMT
# include "xlat / sigemt_codes.h"
# endif
# ifndef SI_FROMUSER
# define SI_FROMUSER(sip) ((sip)->si_code <= 0)
# endif
static void
printsigsource ( const siginfo_t * sip )
{
Decode UID/GID in -y mode
* defs.h (RVAL_UID, RVAL_GID): New macro constants.
(printgid): New function declaration.
* ipc_msgctl.c (print_msqid_ds, print_msqid_ds): Use printgid for
printing GID.
* ipc_shmctl.c (print_shmid_ds, print_shmid_ds): Likewise.
* keyctl.c (keyctl_chown_key): Likewise.
* nlattr.c (decode_nla_gid): Likewise.
* linux/dummy.h (sys_getgid, sys_getgid16, sys_getresgid,
sys_getresgid16, sys_setfsgid, sys_setfsgid16, sys_setgid, sys_setgid16,
sys_setregid, sys_setregid16, sys_setresgid, sys_setresgid16): Remove
macros.
(sys_getegid): Define to sys_getgid instead of sys_getuid.
(sys_getegid16): Define to sys_getgid16 instead of sys_geteuid16.
* linux/syscall.h (getresgid16, getgid16, setfsgid16, setresgid16,
setregid16, setgid16): New external SYS_FUNC declarations.
* msghdr.c (print_scm_creds); Use PRINT_FIELD_GID for printing GID.
* net.c (print_get_ucred): Likewise.
* netlink_inet_diag.c (decode_inet_diag_msg): Likewise.
* netlink_smc_diag.c (decode_smc_diag_msg): Likewise.
* print_fields.h (PRINT_FIELD_UID); Use printuid for printing UID.
(PRINT_FIELD_GID): New macro.
* print_struct_stat.c (print_struct_stat): Use printuid for printing
UID, printgid for printing GID.
* printsiginfo.c (printsigsource): Use printuid for printing UID.
* resource.c (print_priority_who): New function.
(SYS_FUNC(getpriority), SYS_FUNC(setpriority)): Use print_priority_who
for printing the second argument.
* statx.c (SYS_FUNC(statx)): Use PRINT_FIELD_UID for printing UID,
PRINT_FIELD_GID for printing GID.
* syscall.c (syscall_exiting_trace): Handle RVAL_UID and RVAL_GID.
* tests/overflowuid.c: Include stdio.h.
(printuid): New function.
* tests/setfsugid.c (printugid): Rename from printuid, update call
sites.
* tests/setgroups.c: Likewise.
* tests/setugid.c: Likewise.
* tests/tests.h (printuid): New declaration.
* uid.c (printgid, sys_getresgid, sys_getgid, sys_setfsgid,
sys_setresgid, sys_setregid, sys_setgid): Add SIZEIFY wrappers.
(gid_t, gid_t_, gid_t__): Define similarly to uid_t, uid_t_, uid_t__.
Include grp.h, pwd.h, sys/types.h.
(enum id_type): New enumeration.
(SYS_FUNC(getuid), SYS_FUNC(setfsuid), ): Return RVAL_UID flag.
(SYS_FUNC(getgid), SYS_FUNC(setfsgid), SYS_FUNC(setgid),
SYS_FUNC(getresgid), SYS_FUNC(setregid), SYS_FUNC(setresgid)): New
functions.
(get_print_id): Rename from get_print_uid, add idt argument, call
printuid or printgid depending on it. Update call sites.
(SYS_FUNC(chown), SYS_FUNC(fchown), print_gid): Use printgid
for printing GID.
(ID_CACHE_SIZE): New macro constant.
(print_id): New function.
(printuid): Implement using print_id.
(printgid): New function.
* xlat/priorities.in: Provide fallback values.
2018-10-26 02:18:41 +02:00
tprintf ( " , si_pid=%u " , ( unsigned int ) sip - > si_pid ) ;
printuid ( " , si_uid= " , ( unsigned int ) sip - > si_uid ) ;
2015-03-27 23:28:15 +00:00
}
static void
2016-05-13 14:16:12 +00:00
printsigval ( const siginfo_t * sip )
2015-03-27 23:28:15 +00:00
{
2016-06-11 01:28:21 +00:00
tprintf ( " , si_value={int=%d, ptr= " , sip - > si_int ) ;
2016-12-26 01:37:21 +00:00
printaddr ( ptr_to_kulong ( sip - > si_ptr ) ) ;
2016-06-11 01:28:21 +00:00
tprints ( " } " ) ;
2015-03-27 23:28:15 +00:00
}
static void
2016-05-14 21:46:05 +00:00
print_si_code ( int si_signo , unsigned int si_code )
2015-03-27 23:28:15 +00:00
{
2018-11-25 10:40:47 +01:00
static const struct xlat * const si_codes [ ] = {
[ SIGTRAP ] = sigtrap_codes ,
[ SIGCHLD ] = sigchld_codes ,
[ SIGPOLL ] = sigpoll_codes ,
[ SIGPROF ] = sigprof_codes ,
[ SIGILL ] = sigill_codes ,
2015-03-27 23:28:15 +00:00
# ifdef SIGEMT
2018-11-25 10:40:47 +01:00
[ SIGEMT ] = sigemt_codes ,
2015-03-27 23:28:15 +00:00
# endif
2018-11-25 10:40:47 +01:00
[ SIGFPE ] = sigfpe_codes ,
[ SIGSEGV ] = sigsegv_codes ,
[ SIGBUS ] = sigbus_codes ,
[ SIGSYS ] = sigsys_codes ,
} ;
const char * code = xlookup ( siginfo_codes , si_code ) ;
if ( ! code & & ( unsigned int ) si_signo < ARRAY_SIZE ( si_codes )
& & si_codes [ si_signo ] )
code = xlookup ( si_codes [ si_signo ] , si_code ) ;
2015-03-27 23:28:15 +00:00
2018-04-04 15:36:29 +02:00
print_xlat_ex ( si_code , code , XLAT_STYLE_DEFAULT ) ;
2015-03-27 23:28:15 +00:00
}
2018-11-25 10:48:33 +01:00
static void
print_scconst ( unsigned scno )
{
/*
* Note that we can safely use the personality set in
* current_personality here ( and don ' t have to guess it
* based on X32_SYSCALL_BIT and si_arch , for example ) :
* - The signal is delivered as a result of seccomp
* filtering to the process executing forbidden
* syscall .
* - We have set the personality for the tracee during
* the syscall entering .
* - The current_personality is reliably switched in
* the next_event routine , it is set to the
* personality of the last call made ( the one that
* triggered the signal delivery ) .
* - Looks like there are no other cases where SIGSYS
* is delivered from the kernel so far .
*/
const char * scname = syscall_name ( shuffle_scno ( scno ) ) ;
if ( ! scname | | xlat_verbose ( xlat_verbosity ) ! = XLAT_STYLE_ABBREV )
tprintf ( " %u " , scno ) ;
if ( ! scname | | xlat_verbose ( xlat_verbosity ) = = XLAT_STYLE_RAW )
return ;
( xlat_verbose ( xlat_verbosity ) = = XLAT_STYLE_ABBREV
? tprintf : tprintf_comment ) ( " %s%s " ,
nr_prefix ( scno ) , scname ) ;
}
2015-03-27 23:28:15 +00:00
static void
2018-11-25 10:53:10 +01:00
print_fasync_info ( struct tcb * tcp , const siginfo_t * sip )
{
tprintf ( " , si_band= " ) ;
if ( ( long ) sip - > si_band ! = - 1L )
printflags ( pollflags , sip - > si_band , " POLL??? " ) ;
else
tprints ( " -1 " ) ;
tprints ( " , si_fd= " ) ;
printfd ( tcp , sip - > si_fd ) ;
}
static void
print_si_info ( struct tcb * tcp , const siginfo_t * sip )
2015-03-27 23:28:15 +00:00
{
if ( sip - > si_errno ) {
tprints ( " , si_errno= " ) ;
2018-11-25 12:51:23 +01:00
print_err ( sip - > si_errno , false ) ;
2015-03-27 23:28:15 +00:00
}
if ( SI_FROMUSER ( sip ) ) {
switch ( sip - > si_code ) {
case SI_USER :
printsigsource ( sip ) ;
break ;
case SI_TKILL :
printsigsource ( sip ) ;
break ;
# if defined HAVE_SIGINFO_T_SI_TIMERID && defined HAVE_SIGINFO_T_SI_OVERRUN
case SI_TIMER :
tprintf ( " , si_timerid=%#x, si_overrun=%d " ,
sip - > si_timerid , sip - > si_overrun ) ;
2016-05-13 14:16:12 +00:00
printsigval ( sip ) ;
2015-03-27 23:28:15 +00:00
break ;
# endif
2018-11-25 10:53:10 +01:00
case SI_SIGIO :
print_fasync_info ( tcp , sip ) ;
break ;
2015-03-27 23:28:15 +00:00
default :
printsigsource ( sip ) ;
if ( sip - > si_ptr )
2016-05-13 14:16:12 +00:00
printsigval ( sip ) ;
2015-03-27 23:28:15 +00:00
break ;
}
} else {
switch ( sip - > si_signo ) {
case SIGCHLD :
printsigsource ( sip ) ;
tprints ( " , si_status= " ) ;
if ( sip - > si_code = = CLD_EXITED )
tprintf ( " %d " , sip - > si_status ) ;
else
printsignal ( sip - > si_status ) ;
2016-05-13 14:16:12 +00:00
tprintf ( " , si_utime=%llu, si_stime=%llu " ,
2016-08-23 00:24:10 +00:00
zero_extend_signed_to_ull ( sip - > si_utime ) ,
zero_extend_signed_to_ull ( sip - > si_stime ) ) ;
2015-03-27 23:28:15 +00:00
break ;
case SIGILL : case SIGFPE :
case SIGSEGV : case SIGBUS :
2018-11-25 13:38:31 +01:00
case SIGTRAP :
2018-11-25 13:25:47 +01:00
# ifdef SIGEMT
case SIGEMT :
# endif
2016-06-11 01:28:21 +00:00
tprints ( " , si_addr= " ) ;
2016-12-26 01:37:21 +00:00
printaddr ( ptr_to_kulong ( sip - > si_addr ) ) ;
2018-11-25 13:38:31 +01:00
# ifdef HAVE_SIGINFO_T_SI_TRAPNO
# if defined(SPARC)
if ( ( sip - > si_signo = = SIGILL & & sip - > si_code = = ILLTRP )
| | sip - > si_trapno )
# elif defined(ALPHA)
/*
* See arch / alpha / kernel / traps . c : do_entIF , gentrap
* handling , and arch / alpha / include / uapi / asm / gentrap . h
*/
if ( sip - > si_trapno
| | sip - > si_signo = = SIGFPE
| | ( sip - > si_signo = = SIGTRAP
& & sip - > si_code = = TRAP_UNK ) )
# endif
{
tprints ( " , si_trapno= " ) ;
# ifdef ALPHA
printxval_d ( alpha_gentraps , sip - > si_trapno ,
sip - > si_trapno ? " GEN_??? " : NULL ) ;
# else /* !ALPHA */
tprintf ( " %d " )
# endif ALPHA
}
# endif /* HAVE_SIGINFO_T_SI_TRAPNO */
2018-11-25 14:11:54 +01:00
# ifdef IA64
tprintf ( " , si_imm=%d " , sip - > si_imm ) ;
tprints ( " , si_flags= " ) ;
printflags ( ia64_siginfo_si_flags , sip - > si_flags , NULL ) ;
if ( ( sip_si_flags & __ISR_VALID ) | | sip - > si_isr )
/* See also arch/ia64/include/asm/kregs.h */
tprintf ( " , si_isr=%#lx " , sip - > si_isr ) ;
# endif
2015-03-27 23:28:15 +00:00
break ;
case SIGPOLL :
switch ( sip - > si_code ) {
2018-11-25 10:53:10 +01:00
case POLL_IN : case POLL_OUT : case POLL_MSG :
case POLL_ERR : case POLL_PRI : case POLL_HUP :
print_fasync_info ( tcp , sip ) ;
2015-03-27 23:28:15 +00:00
}
break ;
# ifdef HAVE_SIGINFO_T_SI_SYSCALL
2016-11-30 23:43:51 +03:00
case SIGSYS : {
2016-06-11 01:28:21 +00:00
tprints ( " , si_call_addr= " ) ;
2016-12-26 01:37:21 +00:00
printaddr ( ptr_to_kulong ( sip - > si_call_addr ) ) ;
2016-11-30 23:43:51 +03:00
tprints ( " , si_syscall= " ) ;
2018-11-25 10:48:33 +01:00
print_scconst ( sip - > si_syscall ) ;
2016-11-30 23:43:51 +03:00
tprints ( " , si_arch= " ) ;
2015-08-18 03:24:59 -04:00
printxval ( audit_arch , sip - > si_arch , " AUDIT_ARCH_??? " ) ;
2015-03-27 23:28:15 +00:00
break ;
2016-11-30 23:43:51 +03:00
}
2015-03-27 23:28:15 +00:00
# endif
default :
if ( sip - > si_pid | | sip - > si_uid )
printsigsource ( sip ) ;
if ( sip - > si_ptr )
2016-05-13 14:16:12 +00:00
printsigval ( sip ) ;
2015-03-27 23:28:15 +00:00
}
}
}
2015-08-04 02:16:40 +03:00
# ifdef IN_MPERS
static
# endif
2015-03-27 23:28:15 +00:00
void
2018-11-25 10:53:10 +01:00
printsiginfo ( struct tcb * tcp , const siginfo_t * sip )
2015-03-27 23:28:15 +00:00
{
if ( sip - > si_signo = = 0 ) {
tprints ( " {} " ) ;
return ;
}
tprints ( " {si_signo= " ) ;
printsignal ( sip - > si_signo ) ;
tprints ( " , si_code= " ) ;
print_si_code ( sip - > si_signo , sip - > si_code ) ;
# ifdef SI_NOINFO
if ( sip - > si_code ! = SI_NOINFO )
# endif
2018-11-25 10:53:10 +01:00
print_si_info ( tcp , sip ) ;
2015-03-27 23:28:15 +00:00
tprints ( " } " ) ;
}
2016-05-21 22:53:06 +00:00
MPERS_PRINTER_DECL ( void , printsiginfo_at ,
2016-12-26 10:26:03 +00:00
struct tcb * const tcp , const kernel_ulong_t addr )
2015-03-27 23:28:15 +00:00
{
siginfo_t si ;
2015-07-17 21:58:18 +00:00
if ( ! umove_or_printaddr ( tcp , addr , & si ) )
2018-11-25 10:53:10 +01:00
printsiginfo ( tcp , & si ) ;
2015-03-27 23:28:15 +00:00
}
2016-05-13 02:33:33 +00:00
static bool
print_siginfo_t ( struct tcb * tcp , void * elem_buf , size_t elem_size , void * data )
{
2018-11-25 10:53:10 +01:00
printsiginfo ( tcp , ( const siginfo_t * ) elem_buf ) ;
2016-05-13 02:33:33 +00:00
return true ;
}
2016-12-22 20:44:44 +00:00
MPERS_PRINTER_DECL ( void , print_siginfo_array , struct tcb * const tcp ,
2016-12-26 10:26:03 +00:00
const kernel_ulong_t addr , const kernel_ulong_t len )
2016-05-13 02:33:33 +00:00
{
siginfo_t si ;
print_array ( tcp , addr , len , & si , sizeof ( si ) ,
print_array: enhance printing of unfetchable object addresses
When umoven_func invocation fails to fetch data, it prints the faulty
address. If this happens to a subsequent umoven_func invocation,
the printed address may be undistinguishable from a valid data printed
by print_func, e.g. when the data is printed in a numeric form like
[0x1, 0x2, 0x3, 0xdefaced].
Fix this source of confusion by moving the printing of the faulty
address from umoven_func to print_array itself. This change renames
umoven_func to tfetch_mem_func and changes its semantics, so that
- tfetch_mem_func never prints anything;
- tfetch_mem_func returns true if the fetch succeeded,
and false otherwise.
* defs.h (print_array): Replace umoven_func argument with
tfetch_mem_func.
* util.c (print_array): Replace umoven_func argument with
tfetch_mem_func, document expected tfetch_mem_func return value
semantics. When tfetch_mem_func returns false, print either addr
or "... /* addr */" depending on the context (inside the array or not).
* bpf.c (print_ebpf_prog, print_bpf_prog_info,
BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): Replace umoven_or_printaddr
argument of print_array with tfetch_mem.
* bpf_filter.c (print_bpf_fprog): Likewise.
* btrfs.c (btrfs_print_logical_ino_container,
btrfs_print_ino_path_container, btrfs_print_qgroup_inherit,
btrfs_ioctl): Likewise.
* dm.c (dm_decode_dm_target_deps): Likewise.
* epoll.c (epoll_wait_common): Likewise.
* file_ioctl.c (file_ioctl): Likewise.
* ipc_sem.c (tprint_sembuf_array): Likewise.
* kexec.c (print_kexec_segments): Likewise.
* mem.c (SYS_FUNC(subpage_prot)): Likewise.
* net.c (print_getsockopt): Likewise.
* netlink.c (decode_nlmsgerr_attr_cookie): Likewise.
* netlink_netlink_diag.c (decode_netlink_diag_groups): Likewise.
* netlink_packet_diag.c (decode_packet_diag_mclist): Likewise.
* netlink_unix_diag.c (decode_unix_diag_inode): Likewise.
* nlattr.c (decode_nla_meminfo): Likewise.
* numa.c (print_nodemask, SYS_FUNC(move_pages),
* perf_ioctl.c (perf_ioctl_query_bpf): Likewise.
* poll.c (decode_poll_entering): Likewise.
* printsiginfo.c (print_siginfo_array): Likewise.
* rtnl_tc.c (decode_tca_stab_data): Likewise.
* sock.c (decode_ifconf): Likewise.
* uid.c (print_groups): Likewise.
* io.c (SYS_FUNC(io_submit), SYS_FUNC(io_getevents)): Replace
umoven_or_printaddr argument of print_array with tfetch_mem.
(tprint_iov_upto): Replace umoven_or_printaddr_ignore_syserror
with tfetch_mem_ignore_syserror.
* v4l2.c (print_v4l2_format_fmt): Replace umoven_or_printaddr argument
of print_array with tfetch_mem.
(print_v4l2_ext_controls): Replace umoven_or_printaddr_ignore_syserror
with tfetch_mem_ignore_syserror.
* mmsghdr.c (fetch_struct_mmsghdr_or_printaddr): Rename
to fetch_struct_mmsghdr_for_print, do not print address, return bool.
(decode_mmsgvec): Replace fetch_struct_mmsghdr_or_printaddr
with fetch_struct_mmsghdr_for_print.
* tests/aio.c (main): Update expected output.
* tests/bpf.c (print_BPF_PROG_QUERY_attr5): Likewise.
* tests/ioctl_perf-success.c (main): Likewise.
* tests/ioctl_v4l2.c (main): Update expected output.
* tests/kexec_load.c (main): Likewise.
* tests/mmsg_name.c (test_mmsg_name): Update expected output.
* tests/move_pages.c (print_page_array, print_node_array): Likewise.
* tests/poll.c (print_pollfd_array_entering): Likewise.
* tests/preadv-pwritev.c (main): Likewise.
* tests/preadv2-pwritev2.c (dumpio): Likewise.
* tests/process_vm_readv_writev.c (print_iov): Likewise.
* tests/pwritev.c (print_iovec): Likewise.
* tests/readv.c (main): Likewise.
* tests/seccomp-filter-v.c
* tests/semop.c (main): Likewise.
* tests/set_mempolicy.c (print_nodes): Likewise.
* tests/setgroups.c (main): Likewise.
* tests/test_nlattr.h (print_nlattr) Likewise.
Co-Authored-by: Eugene Syromyatnikov <evgsyr@gmail.com>
2018-05-29 01:15:19 +00:00
tfetch_mem , print_siginfo_t , 0 ) ;
2016-05-13 02:33:33 +00:00
}