1999-02-19 03:21:36 +03:00
/*
* Copyright ( c ) 1991 , 1992 Paul Kranenburg < pk @ cs . few . eur . nl >
* Copyright ( c ) 1993 Branko Lankester < branko @ hacktic . nl >
* Copyright ( c ) 1993 , 1994 , 1995 , 1996 Rick Sladkey < jrs @ world . std . com >
1999-12-23 17:20:14 +03:00
* Copyright ( c ) 1996 - 1999 Wichert Akkerman < wichert @ cistron . nl >
* Copyright ( c ) 1999 IBM Deutschland Entwicklung GmbH , IBM Corporation
* Linux for s390 port by D . J . Barrow
* < barrow_dj @ mail . yahoo . com , djbarrow @ de . ibm . com >
2002-05-01 20:39:22 +04:00
* Copyright ( c ) 2000 PocketPenguins Inc . Linux for Hitachi SuperH
* port by Greg Banks < gbanks @ pocketpenguins . com >
2018-02-14 01:00:00 +03:00
* Copyright ( c ) 1999 - 2018 The strace developers .
1999-12-23 17:20:14 +03:00
*
1999-02-19 03:21:36 +03: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 .
*/
# include "defs.h"
2014-12-11 22:25:02 +03:00
2013-03-18 04:52:29 +04:00
# ifdef HAVE_ELF_H
# include <elf.h>
# endif
1999-02-19 03:21:36 +03:00
2015-02-13 03:26:38 +03:00
# include "ptrace.h"
2018-02-11 03:26:09 +03:00
# include "regs.h"
# include "xlat/nt_descriptor_types.h"
2014-12-11 22:25:02 +03:00
# include "xlat/ptrace_cmds.h"
# include "xlat/ptrace_setoptions_flags.h"
2016-05-12 18:45:24 +03:00
# include "xlat/ptrace_peeksiginfo_flags.h"
2014-12-11 22:25:02 +03:00
2012-03-21 17:39:22 +04:00
# define uoff(member) offsetof(struct user, member)
2014-12-11 22:25:02 +03:00
# define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" }
2012-03-21 17:39:22 +04:00
2014-12-11 22:25:02 +03:00
static const struct xlat struct_user_offsets [ ] = {
process.c: split struct_user_offsets into architecture-specific include files
* Makefile.am (EXTRA_DIST): Add linux/alpha/userent.h,
linux/arm/userent.h, linux/avr32/userent.h, linux/bfin/userent.h,
linux/crisv10/userent.h, linux/crisv32/userent.h,
linux/i386/userent.h, linux/i386/userent0.h, linux/ia64/userent.h,
linux/m68k/userent.h, linux/microblaze/userent.h,
linux/mips/userent.h, linux/or1k/userent.h, linux/powerpc/userent.h,
linux/s390/userent.h, linux/s390/userent0.h, linux/s390/userent1.h,
linux/s390x/userent.h, linux/sh/userent.h, linux/sh/userent0.h,
linux/sh64/userent.h, linux/sparc/userent.h, linux/sparc64/userent.h,
linux/tile/userent.h, linux/userent.h, linux/userent0.h,
linux/x32/userent.h, linux/x86_64/userent.h, and
linux/xtensa/userent.h.
* process.c (struct_user_offsets): Split into architecture-specific
include files, inculde userent.h.
2014-12-11 22:25:02 +03:00
# include "userent.h"
2014-02-05 06:20:51 +04:00
XLAT_END
1999-02-19 03:21:36 +03:00
} ;
2016-04-01 03:28:33 +03:00
static void
2016-12-26 13:26:03 +03:00
print_user_offset_addr ( const kernel_ulong_t addr )
1999-02-19 03:21:36 +03:00
{
2004-09-04 07:39:20 +04:00
const struct xlat * x ;
2016-04-01 03:28:33 +03:00
for ( x = struct_user_offsets ; x - > str ; + + x ) {
if ( x - > val > = addr )
break ;
}
if ( ! x - > str ) {
printaddr ( addr ) ;
} else if ( x - > val > addr ) {
if ( x = = struct_user_offsets ) {
printaddr ( addr ) ;
} else {
- - x ;
2016-12-26 13:16:35 +03:00
tprintf ( " %s + % " PRI_klu ,
2016-12-26 13:26:03 +03:00
x - > str , addr - ( kernel_ulong_t ) x - > val ) ;
2016-04-01 03:28:33 +03:00
}
} else {
tprints ( x - > str ) ;
}
}
SYS_FUNC ( ptrace )
{
2016-12-26 13:26:03 +03:00
const kernel_ulong_t request = tcp - > u_arg [ 0 ] ;
2016-04-01 03:28:33 +03:00
const int pid = tcp - > u_arg [ 1 ] ;
2016-12-26 13:26:03 +03:00
const kernel_ulong_t addr = tcp - > u_arg [ 2 ] ;
const kernel_ulong_t data = tcp - > u_arg [ 3 ] ;
1999-02-19 03:21:36 +03:00
2003-01-14 12:46:21 +03:00
if ( entering ( tcp ) ) {
2016-05-12 17:45:38 +03:00
/* request */
printxval64 ( ptrace_cmds , request , " PTRACE_??? " ) ;
2016-05-12 18:03:58 +03:00
if ( request = = PTRACE_TRACEME ) {
/* pid, addr, and data are ignored. */
return RVAL_DECODED ;
}
2016-05-12 17:45:38 +03:00
/* pid */
2016-05-12 18:10:41 +03:00
tprintf ( " , %d " , pid ) ;
2013-02-13 19:10:10 +04:00
2016-05-12 17:45:38 +03:00
/* addr */
2016-04-01 03:28:33 +03:00
switch ( request ) {
2016-05-12 18:10:41 +03:00
case PTRACE_ATTACH :
case PTRACE_INTERRUPT :
case PTRACE_KILL :
case PTRACE_LISTEN :
/* addr and data are ignored */
return RVAL_DECODED ;
2016-04-01 03:28:33 +03:00
case PTRACE_PEEKUSER :
case PTRACE_POKEUSER :
2016-05-12 18:10:41 +03:00
tprints ( " , " ) ;
2016-04-01 03:28:33 +03:00
print_user_offset_addr ( addr ) ;
break ;
case PTRACE_GETREGSET :
case PTRACE_SETREGSET :
2016-05-12 18:10:41 +03:00
tprints ( " , " ) ;
2016-04-01 03:28:33 +03:00
printxval ( nt_descriptor_types , addr , " NT_??? " ) ;
break ;
2016-05-12 18:38:35 +03:00
case PTRACE_GETSIGMASK :
case PTRACE_SETSIGMASK :
case PTRACE_SECCOMP_GET_FILTER :
2018-02-21 21:20:54 +03:00
case PTRACE_SECCOMP_GET_METADATA :
2016-12-26 13:16:35 +03:00
tprintf ( " , % " PRI_klu , addr ) ;
2016-05-12 18:38:35 +03:00
break ;
2016-05-12 18:45:24 +03:00
case PTRACE_PEEKSIGINFO : {
tprints ( " , " ) ;
struct {
uint64_t off ;
uint32_t flags ;
uint32_t nr ;
} psi ;
if ( umove_or_printaddr ( tcp , addr , & psi ) ) {
tprints ( " , " ) ;
printaddr ( data ) ;
return RVAL_DECODED ;
}
tprintf ( " {off=% " PRIu64 " , flags= " , psi . off ) ;
printflags ( ptrace_peeksiginfo_flags , psi . flags ,
" PTRACE_PEEKSIGINFO_??? " ) ;
tprintf ( " , nr=%u} " , psi . nr ) ;
break ;
}
2016-05-12 19:49:34 +03:00
default :
tprints ( " , " ) ;
printaddr ( addr ) ;
}
# if defined IA64 || defined SPARC || defined SPARC64
switch ( request ) {
# ifdef IA64
case PTRACE_PEEKDATA :
case PTRACE_PEEKTEXT :
case PTRACE_PEEKUSER :
/* data is ignored */
return RVAL_DECODED | RVAL_HEX ;
# endif /* IA64 */
# if defined SPARC || defined SPARC64
2016-05-12 18:18:05 +03:00
case PTRACE_GETREGS :
case PTRACE_SETREGS :
case PTRACE_GETFPREGS :
case PTRACE_SETFPREGS :
/* data is ignored */
return RVAL_DECODED ;
2016-05-12 19:49:34 +03:00
# endif /* SPARC || SPARC64 */
2016-04-01 03:28:33 +03:00
}
2016-05-12 19:49:34 +03:00
# endif /* IA64 || SPARC || SPARC64 */
2016-04-01 03:28:33 +03:00
2015-07-18 00:12:05 +03:00
tprints ( " , " ) ;
2013-02-13 19:10:10 +04:00
2016-05-12 18:10:41 +03:00
/* data */
2016-04-01 03:28:33 +03:00
switch ( request ) {
1999-02-19 03:21:36 +03:00
case PTRACE_CONT :
case PTRACE_DETACH :
2016-05-12 18:50:43 +03:00
case PTRACE_SYSCALL :
# ifdef PTRACE_SINGLESTEP
case PTRACE_SINGLESTEP :
# endif
# ifdef PTRACE_SINGLEBLOCK
case PTRACE_SINGLEBLOCK :
# endif
# ifdef PTRACE_SYSEMU
case PTRACE_SYSEMU :
# endif
# ifdef PTRACE_SYSEMU_SINGLESTEP
case PTRACE_SYSEMU_SINGLESTEP :
# endif
2016-04-01 03:28:33 +03:00
printsignal ( data ) ;
1999-02-19 03:21:36 +03:00
break ;
2016-05-12 18:53:28 +03:00
case PTRACE_SEIZE :
2009-01-13 21:30:55 +03:00
case PTRACE_SETOPTIONS :
2016-05-12 18:53:28 +03:00
# ifdef PTRACE_OLDSETOPTIONS
case PTRACE_OLDSETOPTIONS :
# endif
2016-05-12 19:35:54 +03:00
printflags64 ( ptrace_setoptions_flags , data , " PTRACE_O_??? " ) ;
2009-01-13 21:30:55 +03:00
break ;
2016-04-01 03:28:33 +03:00
case PTRACE_SETSIGINFO :
printsiginfo_at ( tcp , data ) ;
2009-01-13 21:30:55 +03:00
break ;
2016-05-12 19:52:49 +03:00
case PTRACE_SETSIGMASK :
print_sigset_addr_len ( tcp , data , addr ) ;
break ;
2013-02-13 19:10:10 +04:00
case PTRACE_SETREGSET :
2016-06-22 16:27:03 +03:00
tprint_iov ( tcp , /*len:*/ 1 , data , IOV_DECODE_ADDR ) ;
2013-02-13 19:10:10 +04:00
break ;
2018-02-21 21:20:54 +03:00
case PTRACE_SECCOMP_GET_METADATA :
if ( verbose ( tcp ) ) {
uint64_t filter_off ;
if ( addr < sizeof ( filter_off ) | |
umove ( tcp , data , & filter_off ) ) {
printaddr ( data ) ;
return RVAL_DECODED ;
}
tprintf ( " {filter_off=% " PRIu64 , filter_off ) ;
return 0 ;
}
printaddr ( data ) ;
break ;
2016-05-12 19:49:34 +03:00
# ifndef IA64
case PTRACE_PEEKDATA :
case PTRACE_PEEKTEXT :
case PTRACE_PEEKUSER :
# endif
2016-05-12 19:56:30 +03:00
case PTRACE_GETEVENTMSG :
2015-02-13 03:26:38 +03:00
case PTRACE_GETREGSET :
2016-05-12 19:49:34 +03:00
case PTRACE_GETSIGINFO :
2016-05-12 19:52:49 +03:00
case PTRACE_GETSIGMASK :
2016-05-13 05:33:33 +03:00
case PTRACE_PEEKSIGINFO :
2016-05-12 19:58:38 +03:00
case PTRACE_SECCOMP_GET_FILTER :
2016-05-12 19:49:34 +03:00
if ( verbose ( tcp ) ) {
/* print data on exiting syscall */
return 0 ;
}
2018-03-07 02:52:08 +03:00
ATTRIBUTE_FALLTHROUGH ;
1999-02-19 03:21:36 +03:00
default :
2016-04-01 03:28:33 +03:00
printaddr ( data ) ;
1999-02-19 03:21:36 +03:00
break ;
}
2016-05-12 19:49:34 +03:00
return RVAL_DECODED ;
1999-02-19 03:21:36 +03:00
} else {
2016-04-01 03:28:33 +03:00
switch ( request ) {
2016-05-12 19:49:34 +03:00
# ifndef IA64
1999-02-19 03:21:36 +03:00
case PTRACE_PEEKDATA :
case PTRACE_PEEKTEXT :
case PTRACE_PEEKUSER :
2016-04-01 03:28:33 +03:00
printnum_ptr ( tcp , data ) ;
1999-02-19 03:21:36 +03:00
break ;
2012-03-17 04:27:37 +04:00
# endif
2016-05-12 19:56:30 +03:00
case PTRACE_GETEVENTMSG :
printnum_ulong ( tcp , data ) ;
break ;
case PTRACE_GETREGSET :
2016-06-22 16:27:03 +03:00
tprint_iov ( tcp , /*len:*/ 1 , data , IOV_DECODE_ADDR ) ;
2016-05-12 19:56:30 +03:00
break ;
2016-04-01 03:28:33 +03:00
case PTRACE_GETSIGINFO :
printsiginfo_at ( tcp , data ) ;
2009-01-13 21:30:55 +03:00
break ;
2016-05-12 19:52:49 +03:00
case PTRACE_GETSIGMASK :
print_sigset_addr_len ( tcp , data , addr ) ;
break ;
2016-05-13 05:33:33 +03:00
case PTRACE_PEEKSIGINFO :
2016-12-24 02:05:46 +03:00
print_siginfo_array ( tcp , data , tcp - > u_rval ) ;
2016-05-13 05:33:33 +03:00
break ;
2016-05-12 19:58:38 +03:00
case PTRACE_SECCOMP_GET_FILTER :
2016-12-24 02:05:46 +03:00
print_seccomp_fprog ( tcp , data , tcp - > u_rval ) ;
2016-05-12 19:58:38 +03:00
break ;
2018-02-21 21:20:54 +03:00
case PTRACE_SECCOMP_GET_METADATA : {
const size_t offset = sizeof ( uint64_t ) ;
uint64_t flags = 0 ;
size_t ret_size = MIN ( ( kernel_ulong_t ) tcp - > u_rval ,
offset + sizeof ( flags ) ) ;
if ( syserror ( tcp ) | | ret_size < = offset ) {
tprints ( " } " ) ;
return 0 ;
}
if ( umoven ( tcp , data + offset , ret_size - offset ,
& flags ) ) {
tprints ( " , ...} " ) ;
return 0 ;
}
tprints ( " , flags= " ) ;
printflags64 ( seccomp_filter_flags , flags ,
" SECCOMP_FILTER_FLAG_??? " ) ;
if ( ( kernel_ulong_t ) tcp - > u_rval > ret_size )
tprints ( " , ... " ) ;
tprints ( " } " ) ;
}
1999-02-19 03:21:36 +03:00
}
}
return 0 ;
}