2011-04-08 00:25:40 +04:00
/*
2017-05-22 19:53:14 +03:00
* Copyright ( c ) 2011 Comtrol Corp .
2017-05-22 20:14:52 +03:00
* Copyright ( c ) 2011 - 2017 The strace developers .
2011-04-08 00:25:40 +04: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"
2011-08-30 20:05:26 +04:00
# include <sys/param.h>
2015-07-30 19:23:58 +03:00
# include <poll.h>
2011-04-08 00:25:40 +04:00
# include "syscall.h"
2018-01-06 04:45:16 +03:00
# include "xstring.h"
2011-04-08 00:25:40 +04:00
2017-07-08 11:28:56 +03:00
struct path_set global_path_set ;
2011-04-08 00:25:40 +04:00
/*
* Return true if specified path matches one that we ' re tracing .
*/
2017-07-08 11:28:56 +03:00
static bool
pathmatch ( const char * path , struct path_set * set )
2011-04-08 00:25:40 +04:00
{
2013-03-05 18:46:34 +04:00
unsigned i ;
2011-04-08 00:25:40 +04:00
2017-07-08 11:28:56 +03:00
for ( i = 0 ; i < set - > num_selected ; + + i ) {
if ( strcmp ( path , set - > paths_selected [ i ] ) = = 0 )
return true ;
2011-04-08 00:25:40 +04:00
}
2017-07-08 11:28:56 +03:00
return false ;
2011-04-08 00:25:40 +04:00
}
/*
* Return true if specified path ( in user - space ) matches .
*/
2017-07-08 11:28:56 +03:00
static bool
upathmatch ( struct tcb * const tcp , const kernel_ulong_t upath ,
struct path_set * set )
2011-04-08 00:25:40 +04:00
{
2011-06-22 16:32:43 +04:00
char path [ PATH_MAX + 1 ] ;
2011-04-08 00:25:40 +04:00
2017-06-17 21:49:58 +03:00
return umovestr ( tcp , upath , sizeof ( path ) , path ) > 0 & &
2017-07-08 11:28:56 +03:00
pathmatch ( path , set ) ;
2011-04-08 00:25:40 +04:00
}
/*
* Return true if specified fd maps to a path we ' re tracing .
*/
2017-07-08 11:28:56 +03:00
static bool
fdmatch ( struct tcb * tcp , int fd , struct path_set * set )
2011-04-08 00:25:40 +04:00
{
2013-03-06 21:24:34 +04:00
char path [ PATH_MAX + 1 ] ;
int n = getfdpath ( tcp , fd , path , sizeof ( path ) ) ;
2011-04-08 00:25:40 +04:00
2017-07-08 11:28:56 +03:00
return n > = 0 & & pathmatch ( path , set ) ;
2011-04-08 00:25:40 +04:00
}
/*
* Add a path to the set we ' re tracing .
Add decoding of sockets descriptor 'paths' for network calls
* net.c (sys_bind, sys_listen, do_accept, sys_send, sys_sendto,
sys_sendmsg, sys_sendmmsg, sys_recv, sys_recvfrom, sys_recvmsg,
sys_recvmmsg, sys_shutdown, sys_getsockopt, sys_setsockopt): Decode
socket descriptor arguments using printfd.
* pathtrace.c (pathtrace_match): Also check TRACE_NETWORK syscalls
that take socket descriptor arguments.
* tests/net-fd.test: New test for socket descriptor arguments decoding.
* tests/Makefile.am (TESTS): Add net-fd.test.
(net-fd.log): New dependency on net.log.
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-02-01 21:57:45 +04:00
* Specifying NULL will delete all paths .
2011-04-08 00:25:40 +04:00
*/
2013-03-05 18:46:34 +04:00
static void
2017-07-08 11:28:56 +03:00
storepath ( const char * path , struct path_set * set )
2011-04-08 00:25:40 +04:00
{
2017-07-08 11:28:56 +03:00
if ( pathmatch ( path , set ) )
2013-03-05 18:46:34 +04:00
return ; /* already in table */
2011-04-08 00:25:40 +04:00
2017-12-13 15:52:59 +03:00
if ( set - > num_selected > = set - > size )
set - > paths_selected =
xgrowarray ( set - > paths_selected , & set - > size ,
sizeof ( set - > paths_selected [ 0 ] ) ) ;
set - > paths_selected [ set - > num_selected + + ] = path ;
2011-04-08 00:25:40 +04:00
}
/*
* Get path associated with fd .
*/
2013-03-06 21:24:34 +04:00
int
getfdpath ( struct tcb * tcp , int fd , char * buf , unsigned bufsize )
2011-04-08 00:25:40 +04:00
{
2012-03-15 21:11:51 +04:00
char linkpath [ sizeof ( " /proc/%u/fd/%u " ) + 2 * sizeof ( int ) * 3 ] ;
2011-04-08 00:25:40 +04:00
ssize_t n ;
if ( fd < 0 )
2013-03-06 21:24:34 +04:00
return - 1 ;
2011-04-08 00:25:40 +04:00
2018-01-06 04:45:16 +03:00
xsprintf ( linkpath , " /proc/%u/fd/%u " , tcp - > pid , fd ) ;
2013-03-06 21:24:34 +04:00
n = readlink ( linkpath , buf , bufsize - 1 ) ;
/*
* NB : if buf is too small , readlink doesn ' t fail ,
* it returns truncated result ( IOW : n = = bufsize - 1 ) .
*/
if ( n > = 0 )
buf [ n ] = ' \0 ' ;
return n ;
2011-04-08 00:25:40 +04:00
}
/*
* Add a path to the set we ' re tracing . Also add the canonicalized
2017-07-21 21:14:58 +03:00
* version of the path . Specifying NULL will delete all paths .
2011-04-08 00:25:40 +04:00
*/
2013-03-05 18:46:34 +04:00
void
2017-07-08 11:28:56 +03:00
pathtrace_select_set ( const char * path , struct path_set * set )
2011-04-08 00:25:40 +04:00
{
2012-03-15 21:03:56 +04:00
char * rpath ;
2011-04-08 00:25:40 +04:00
2017-07-08 11:28:56 +03:00
storepath ( path , set ) ;
2011-04-08 00:25:40 +04:00
rpath = realpath ( path , NULL ) ;
if ( rpath = = NULL )
2013-03-05 18:46:34 +04:00
return ;
2011-04-08 00:25:40 +04:00
/* if realpath and specified path are same, we're done */
2012-03-15 21:03:56 +04:00
if ( strcmp ( path , rpath ) = = 0 ) {
2011-04-08 00:25:40 +04:00
free ( rpath ) ;
2013-03-05 18:46:34 +04:00
return ;
2011-04-08 00:25:40 +04:00
}
Consistently use error_msg instead of fprintf(stderr)
* linux/alpha/get_scno.c: Use error_msg.
* linux/arm/get_scno.c: Likewise.
* linux/mips/get_scno.c: Likewise.
* linux/sh/get_scno.c: Likewise.
* linux/x86_64/get_scno.c: Likewise.
* exit.c (sys_exit): Likewise.
* pathtrace.c (pathtrace_select, pathtrace_match): Likewise.
* strace.c (alloctcb, droptcb, detach, startup_attach,
test_ptrace_seize, init, cleanup, print_debug_info,
maybe_allocate_tcb, startup_tcb, trace): Likewise.
* syscall.c (update_personality, trace_syscall_exiting,
get_scno): Likewise.
* unwind.c (DPRINTF): Likewise.
* tests/bexecve.test: Update patterns.
* tests/detach-stopped.test: Likewise.
2015-05-26 01:51:19 +03:00
error_msg ( " Requested path '%s' resolved into '%s' " , path , rpath ) ;
2017-07-08 11:28:56 +03:00
storepath ( rpath , set ) ;
2011-04-08 00:25:40 +04:00
}
/*
* Return true if syscall accesses a selected path
* ( or if no paths have been specified for tracing ) .
*/
2017-07-08 11:28:56 +03:00
bool
pathtrace_match_set ( struct tcb * tcp , struct path_set * set )
2011-04-08 00:25:40 +04:00
{
2013-02-22 16:26:10 +04:00
const struct_sysent * s ;
2011-04-08 00:25:40 +04:00
2013-02-21 19:13:47 +04:00
s = tcp - > s_ent ;
2011-04-08 00:25:40 +04:00
Add decoding of sockets descriptor 'paths' for network calls
* net.c (sys_bind, sys_listen, do_accept, sys_send, sys_sendto,
sys_sendmsg, sys_sendmmsg, sys_recv, sys_recvfrom, sys_recvmsg,
sys_recvmmsg, sys_shutdown, sys_getsockopt, sys_setsockopt): Decode
socket descriptor arguments using printfd.
* pathtrace.c (pathtrace_match): Also check TRACE_NETWORK syscalls
that take socket descriptor arguments.
* tests/net-fd.test: New test for socket descriptor arguments decoding.
* tests/Makefile.am (TESTS): Add net-fd.test.
(net-fd.log): New dependency on net.log.
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-02-01 21:57:45 +04:00
if ( ! ( s - > sys_flags & ( TRACE_FILE | TRACE_DESC | TRACE_NETWORK ) ) )
2017-07-08 11:28:56 +03:00
return false ;
2011-04-08 00:25:40 +04:00
/*
* Check for special cases where we need to do something
* other than test arg [ 0 ] .
*/
2015-07-10 22:24:58 +03:00
switch ( s - > sen ) {
case SEN_dup2 :
case SEN_dup3 :
2015-11-22 21:51:05 +03:00
case SEN_kexec_file_load :
2015-07-10 22:24:58 +03:00
case SEN_sendfile :
case SEN_sendfile64 :
case SEN_tee :
2011-04-08 00:25:40 +04:00
/* fd, fd */
2017-07-08 11:28:56 +03:00
return fdmatch ( tcp , tcp - > u_arg [ 0 ] , set ) | |
fdmatch ( tcp , tcp - > u_arg [ 1 ] , set ) ;
2011-04-08 00:25:40 +04:00
2017-08-11 08:43:57 +03:00
case SEN_execveat :
2015-07-10 22:24:58 +03:00
case SEN_faccessat :
case SEN_fchmodat :
case SEN_fchownat :
2016-08-23 17:27:49 +03:00
case SEN_fstatat64 :
2015-07-10 22:24:58 +03:00
case SEN_futimesat :
case SEN_inotify_add_watch :
case SEN_mkdirat :
case SEN_mknodat :
2015-11-23 00:29:32 +03:00
case SEN_name_to_handle_at :
2015-07-10 22:24:58 +03:00
case SEN_newfstatat :
case SEN_openat :
case SEN_readlinkat :
2017-03-18 18:19:07 +03:00
case SEN_statx :
2015-07-10 22:24:58 +03:00
case SEN_unlinkat :
case SEN_utimensat :
2011-04-08 00:25:40 +04:00
/* fd, path */
2017-07-08 11:28:56 +03:00
return fdmatch ( tcp , tcp - > u_arg [ 0 ] , set ) | |
upathmatch ( tcp , tcp - > u_arg [ 1 ] , set ) ;
2011-04-08 00:25:40 +04:00
2015-07-10 22:24:58 +03:00
case SEN_link :
case SEN_mount :
case SEN_pivotroot :
2011-04-08 00:25:40 +04:00
/* path, path */
2017-07-08 11:28:56 +03:00
return upathmatch ( tcp , tcp - > u_arg [ 0 ] , set ) | |
upathmatch ( tcp , tcp - > u_arg [ 1 ] , set ) ;
2011-04-08 00:25:40 +04:00
2015-07-10 22:24:58 +03:00
case SEN_quotactl :
2017-08-06 15:22:06 +03:00
case SEN_symlink :
2012-10-27 03:43:13 +04:00
/* x, path */
2017-07-08 11:28:56 +03:00
return upathmatch ( tcp , tcp - > u_arg [ 1 ] , set ) ;
2012-10-27 03:43:13 +04:00
2015-07-10 22:24:58 +03:00
case SEN_linkat :
case SEN_renameat2 :
case SEN_renameat :
2011-04-08 00:25:40 +04:00
/* fd, path, fd, path */
2017-07-08 11:28:56 +03:00
return fdmatch ( tcp , tcp - > u_arg [ 0 ] , set ) | |
fdmatch ( tcp , tcp - > u_arg [ 2 ] , set ) | |
upathmatch ( tcp , tcp - > u_arg [ 1 ] , set ) | |
upathmatch ( tcp , tcp - > u_arg [ 3 ] , set ) ;
2011-04-08 00:25:40 +04:00
2018-01-17 04:38:55 +03:00
# ifdef HAVE_ARCH_OLD_MMAP
2015-07-10 22:24:58 +03:00
case SEN_old_mmap :
Add compat support for s390x
By very popular demand.
While we are here, let's refactor the condition for old_mmap_pgoff into
an arch-specific one, as it is used more than in one place.
* NEWS: Mention this.
* strace.1.in (.SH "MULTIPLE PERSONALITY SUPPORT"): Likewise.
* configure.ac (case "$host_cpu" in) <s390x>: Set arch_m32 to s390, set
cc_flags_m32 to -m31.
(st_MPERS([m32])): Add s390x.
* defs.h [S390X]: Define NEED_UID16_PARSERS.
* linux/s390/arch_sigreturn.c [!S390_FRAME_PTR] (S390_FRAME_PTR): New
macro, define to s390_frame_ptr.
[!SIGNAL_FRAMESIZE] (SIGNAL_FRAMESIZE): New macro, define to
__SIGNAL_FRAMESIZE.
[!PTR_TYPE] (PTR_TYPE): New macro, define to unsigned long.
(arch_sigreturn): Use S390_FRAME_PTR, SIGNAL_FRAMESIZE, and PTR_TYPE
instead of s390_frame_ptr, __SIGNAL_FRAMESIZE, and pointer-sized type,
respectively.
* linux/s390/get_error.c [!ARCH_REGSET] (ARCH_REGSET): New macro, define
* to s390_regset.
(get_error): Use it instead of s390_regset.
* linux/s390/get_scno.c (arch_get_scno): Likewise.
* linux/s390/get_syscall_args.c (get_syscall_args): Likewise.
* linux/s390/set_error.c (arch_set_error, arch_set_success): Likewise.
* linux/s390/set_scno.c (arch_set_scno): Likewise.
* linux/s390x/arch_regs.c (psw_compat_t, s390_compat_regs,
s390x_regs_union, s390_frame_ptr, s390x_frame_ptr, s390x_io): New
variables.
(s390_regset, s390x_regset, ARCH_REGS_FOR_GETREGSET,
ARCH_IOVEC_FOR_GETREGSET, ARCH_PC_REG, ARCH_PERSONALITY_0_IOV_SIZE,
ARCH_PERSONALITY_1_IOV_SIZE): New macros.
* linux/s390x/arch_regs.h (s390_frame_ptr, s390x_frame_ptr): New
prototypes.
* linux/s390x/arch_rt_sigframe.c: Conditionalize on tcp->currpers.
* linux/s390x/arch_sigreturn.c: Likewise.
* linux/s390x/get_error.c: Likewise.
* linux/s390x/get_scno.c: Likewise.
* linux/s390x/get_syscall_args.c: Likewise.
* linux/s390x/set_error.c: Likewise.
* linux/s390x/set_scno.c: Likewise.
* linux/s390x/errnoent1.h: New file.
* linux/s390x/ioctls_arch1.h: Likewise.
* linux/s390x/ioctls_inc1.h: Likewise.
* linux/s390x/signalent1.h: Likewise.
* linux/s390x/syscallent1.h: Likewise.
* Makefile.am (EXTRA_DIST): Add new files added to linux/s390x.
* supported_personalities.h [S390X] (SUPPORTED_PERSONALITIES): Define
to 2.
* tests/strace-V.test: Add s390 to the list of architectures that have
m32 personality.
* linux/s390/arch_defs.h (HAVE_ARCH_OLD_MMAP_PGOFF): New macro.
* linux/s390x/arch_defs.h: Likewise.
* mem.c: Replace #ifdef S390 with #ifdef HAVE_ARCH_OLD_MMAP_PGOFF.
* pathtrace.c: Likewise.
2018-01-10 23:20:06 +03:00
# ifdef HAVE_ARCH_OLD_MMAP_PGOFF
2015-07-10 22:24:58 +03:00
case SEN_old_mmap_pgoff :
2018-01-17 04:38:55 +03:00
# endif
{
kernel_ulong_t * args = fetch_old_mmap_args ( tcp ) ;
return args & & fdmatch ( tcp , args [ 4 ] , set ) ;
}
# endif /* HAVE_ARCH_OLD_MMAP */
2015-07-10 22:24:58 +03:00
case SEN_mmap :
case SEN_mmap_4koff :
case SEN_mmap_pgoff :
2015-12-24 18:40:55 +03:00
case SEN_ARCH_mmap :
2011-04-08 00:25:40 +04:00
/* x, x, x, x, fd */
2017-07-08 11:28:56 +03:00
return fdmatch ( tcp , tcp - > u_arg [ 4 ] , set ) ;
2011-04-08 00:25:40 +04:00
2015-07-10 22:24:58 +03:00
case SEN_symlinkat :
2017-08-06 15:39:56 +03:00
/* x, fd, path */
2017-07-08 11:28:56 +03:00
return fdmatch ( tcp , tcp - > u_arg [ 1 ] , set ) | |
upathmatch ( tcp , tcp - > u_arg [ 2 ] , set ) ;
2011-04-08 00:25:40 +04:00
2016-02-13 06:45:32 +03:00
case SEN_copy_file_range :
2015-07-10 22:24:58 +03:00
case SEN_splice :
2016-02-13 06:45:32 +03:00
/* fd, x, fd, x, x, x */
2017-07-08 11:28:56 +03:00
return fdmatch ( tcp , tcp - > u_arg [ 0 ] , set ) | |
fdmatch ( tcp , tcp - > u_arg [ 2 ] , set ) ;
2011-04-08 00:25:40 +04:00
2015-07-10 22:24:58 +03:00
case SEN_epoll_ctl :
2011-04-08 00:25:40 +04:00
/* x, x, fd, x */
2017-07-08 11:28:56 +03:00
return fdmatch ( tcp , tcp - > u_arg [ 2 ] , set ) ;
2011-04-08 00:25:40 +04:00
2015-07-10 22:24:58 +03:00
case SEN_fanotify_mark :
2017-07-23 07:44:36 +03:00
{
/* x, x, mask (64 bit), fd, path */
unsigned long long mask = 0 ;
int argn = getllval ( tcp , & mask , 2 ) ;
return fdmatch ( tcp , tcp - > u_arg [ argn ] , set ) | |
upathmatch ( tcp , tcp - > u_arg [ argn + 1 ] , set ) ;
}
2015-07-10 22:24:58 +03:00
case SEN_oldselect :
case SEN_pselect6 :
case SEN_select :
2011-04-08 00:25:40 +04:00
{
2011-09-01 18:35:44 +04:00
int i , j ;
2013-11-09 23:46:55 +04:00
int nfds ;
2016-12-26 13:26:03 +03:00
kernel_ulong_t * args ;
kernel_ulong_t select_args [ 5 ] ;
2016-12-19 14:49:58 +03:00
unsigned int oldselect_args [ 5 ] ;
unsigned int fdsize ;
2011-04-08 00:25:40 +04:00
fd_set * fds ;
2015-07-10 22:24:58 +03:00
if ( SEN_oldselect = = s - > sen ) {
2016-12-19 14:49:58 +03:00
if ( sizeof ( * select_args ) = = sizeof ( * oldselect_args ) ) {
if ( umove ( tcp , tcp - > u_arg [ 0 ] , & select_args ) ) {
2017-07-08 11:28:56 +03:00
return false ;
2016-12-19 14:49:58 +03:00
}
} else {
unsigned int n ;
if ( umove ( tcp , tcp - > u_arg [ 0 ] , & oldselect_args ) ) {
2017-07-08 11:28:56 +03:00
return false ;
2016-12-19 14:49:58 +03:00
}
for ( n = 0 ; n < 5 ; + + n ) {
select_args [ n ] = oldselect_args [ n ] ;
}
2011-04-08 00:25:40 +04:00
}
2016-12-19 14:49:58 +03:00
args = select_args ;
} else {
args = tcp - > u_arg ;
2013-11-09 23:46:55 +04:00
}
2011-04-08 00:25:40 +04:00
2013-11-09 23:46:55 +04:00
/* Kernel truncates arg[0] to int, we do the same. */
nfds = ( int ) args [ 0 ] ;
/* Kernel rejects negative nfds, so we don't parse it either. */
if ( nfds < = 0 )
2017-07-08 11:28:56 +03:00
return false ;
2011-09-01 18:35:44 +04:00
/* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
2013-11-09 23:46:55 +04:00
if ( nfds > 1024 * 1024 )
2011-09-01 18:35:44 +04:00
nfds = 1024 * 1024 ;
2013-11-09 23:46:55 +04:00
fdsize = ( ( ( nfds + 7 ) / 8 ) + current_wordsize - 1 ) & - current_wordsize ;
Introduce memory allocation wrappers
Introduce wrappers to the following functions that do memory allocation:
malloc, calloc, realloc, strdup.
This commit is a follow-up to the related discussions in strace-devel ML:
http://sourceforge.net/p/strace/mailman/message/33618180/
http://sourceforge.net/p/strace/mailman/message/33733470/
* defs.h (xmalloc, xcalloc, xreallocarray, xstrdup): New prototypes.
* xmalloc.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* count.c (count_syscall, call_summary_pers): Use xcalloc.
* desc.c (decode_select): Use xmalloc.
* dirent.c (sys_getdents, sys_getdents64): Likewise.
* net.c (sys_recvmmsg): Use xstrdup.
* pathtrace.c (storepath): Use xreallocarray.
(pathtrace_match): Use xmalloc.
* strace.c (die_out_of_memory): Move to xmalloc.c.
(expand_tcbtab): Use xcalloc and xreallocarray.
(startup_child): Use xstrdup.
(init): Use xmalloc, xcalloc, and xstrdup.
* syscall.c (reallocate_qual): Use xreallocarray.
(qualify): Use xstrdup.
* unwind.c (unwind_tcb_init): Use xmalloc.
(build_mmap_cache): Use xcalloc, xreallocarray, and xstrdup.
(get_symbol_name): Use xreallocarray.
(stacktrace_walk, queue_put): Use xmalloc.
* util.c (printstr): Use xmalloc.
* vsprintf.c (strace_vfprintf): Likewise.
2015-05-25 23:41:02 +03:00
fds = xmalloc ( fdsize ) ;
2011-04-08 00:25:40 +04:00
2011-06-22 16:32:43 +04:00
for ( i = 1 ; i < = 3 ; + + i ) {
2011-04-08 00:25:40 +04:00
if ( args [ i ] = = 0 )
continue ;
2015-03-21 21:50:53 +03:00
if ( umoven ( tcp , args [ i ] , fdsize , fds ) < 0 ) {
2011-04-08 00:25:40 +04:00
continue ;
}
2013-11-09 23:46:55 +04:00
for ( j = 0 ; ; j + + ) {
j = next_set_bit ( fds , j , nfds ) ;
if ( j < 0 )
break ;
2017-07-08 11:28:56 +03:00
if ( fdmatch ( tcp , j , set ) ) {
2011-04-08 00:25:40 +04:00
free ( fds ) ;
2017-07-08 11:28:56 +03:00
return true ;
2011-04-08 00:25:40 +04:00
}
2013-11-09 23:46:55 +04:00
}
2011-04-08 00:25:40 +04:00
}
free ( fds ) ;
2017-07-08 11:28:56 +03:00
return false ;
2011-04-08 00:25:40 +04:00
}
2015-07-10 22:24:58 +03:00
case SEN_poll :
case SEN_ppoll :
2011-04-08 00:25:40 +04:00
{
struct pollfd fds ;
unsigned nfds ;
2016-12-26 13:26:03 +03:00
kernel_ulong_t start , cur , end ;
2011-04-08 00:25:40 +04:00
start = tcp - > u_arg [ 0 ] ;
nfds = tcp - > u_arg [ 1 ] ;
2017-07-21 21:15:24 +03:00
if ( nfds > 1024 * 1024 )
nfds = 1024 * 1024 ;
2011-04-08 00:25:40 +04:00
end = start + sizeof ( fds ) * nfds ;
if ( nfds = = 0 | | end < start )
2017-07-08 11:28:56 +03:00
return false ;
2011-04-08 00:25:40 +04:00
2017-07-20 22:14:42 +03:00
for ( cur = start ; cur < end ; cur + = sizeof ( fds ) ) {
if ( umove ( tcp , cur , & fds ) )
break ;
if ( fdmatch ( tcp , fds . fd , set ) )
2017-07-08 11:28:56 +03:00
return true ;
2017-07-20 22:14:42 +03:00
}
2011-04-08 00:25:40 +04:00
2017-07-08 11:28:56 +03:00
return false ;
2011-04-08 00:25:40 +04:00
}
2018-01-16 02:33:18 +03:00
case SEN_accept4 :
case SEN_accept :
2015-07-26 02:55:51 +03:00
case SEN_bpf :
2015-07-10 22:24:58 +03:00
case SEN_epoll_create :
2015-08-02 02:07:19 +03:00
case SEN_epoll_create1 :
2015-07-10 22:24:58 +03:00
case SEN_eventfd2 :
case SEN_eventfd :
case SEN_fanotify_init :
2017-08-06 15:22:06 +03:00
case SEN_inotify_init :
2015-07-10 22:24:58 +03:00
case SEN_inotify_init1 :
2015-07-29 02:03:41 +03:00
case SEN_memfd_create :
Enhance decoding of mq_* syscalls
* mq.c (SYS_FUNC(mq_open)): Add RVAL_FD to return value.
(SYS_FUNC(mq_timedsend), SYS_FUNC(mq_timedreceive), SYS_FUNC(mq_notify),
SYS_FUNC(mq_getsetattr)): Print the first argument using printfd.
* NEWS: Mention this change.
* pathtrace.c (pathtrace_match_set) <SEN_mq_getsetattr, SEN_mq_notify,
SEN_mq_open, SEN_mq_timedreceive, SEN_mq_timedsend>: Skip matching.
* linux/32/syscallent.h (mq_getsetattr, mq_notify, mq_open,
mq_timedreceive, mq_timedsend): Add TD flag.
* linux/64/syscallent.h: Likewise.
* linux/alpha/syscallent.h: Likewise.
* linux/arm/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/crisv10/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent-n32.h: Likewise.
* linux/mips/syscallent-n64.h: Likewise.
* linux/mips/syscallent-o32.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/powerpc64/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/sparc64/syscallent.h: Likewise.
* linux/x32/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.
* linux/xtensa/syscallent.h: Likewise.
2018-01-16 01:47:38 +03:00
case SEN_mq_getsetattr :
case SEN_mq_notify :
case SEN_mq_open :
case SEN_mq_timedreceive :
case SEN_mq_timedsend :
2015-07-10 22:24:58 +03:00
case SEN_perf_event_open :
case SEN_pipe :
2016-02-12 19:15:23 +03:00
case SEN_pipe2 :
2015-07-10 22:24:58 +03:00
case SEN_printargs :
2018-01-16 02:33:18 +03:00
case SEN_signalfd4 :
case SEN_signalfd :
2015-07-10 22:24:58 +03:00
case SEN_socket :
case SEN_socketpair :
case SEN_timerfd_create :
case SEN_timerfd_gettime :
case SEN_timerfd_settime :
2015-11-22 22:56:00 +03:00
case SEN_userfaultfd :
2011-04-08 00:25:40 +04:00
/*
Add decoding of sockets descriptor 'paths' for network calls
* net.c (sys_bind, sys_listen, do_accept, sys_send, sys_sendto,
sys_sendmsg, sys_sendmmsg, sys_recv, sys_recvfrom, sys_recvmsg,
sys_recvmmsg, sys_shutdown, sys_getsockopt, sys_setsockopt): Decode
socket descriptor arguments using printfd.
* pathtrace.c (pathtrace_match): Also check TRACE_NETWORK syscalls
that take socket descriptor arguments.
* tests/net-fd.test: New test for socket descriptor arguments decoding.
* tests/Makefile.am (TESTS): Add net-fd.test.
(net-fd.log): New dependency on net.log.
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-02-01 21:57:45 +04:00
* These have TRACE_FILE or TRACE_DESCRIPTOR or TRACE_NETWORK set ,
* but they don ' t have any file descriptor or path args to test .
2011-04-08 00:25:40 +04:00
*/
2017-07-08 11:28:56 +03:00
return false ;
2011-04-08 00:25:40 +04:00
}
/*
* Our fallback position for calls that haven ' t already
* been handled is to just check arg [ 0 ] .
*/
if ( s - > sys_flags & TRACE_FILE )
2017-07-08 11:28:56 +03:00
return upathmatch ( tcp , tcp - > u_arg [ 0 ] , set ) ;
2011-04-08 00:25:40 +04:00
Add decoding of sockets descriptor 'paths' for network calls
* net.c (sys_bind, sys_listen, do_accept, sys_send, sys_sendto,
sys_sendmsg, sys_sendmmsg, sys_recv, sys_recvfrom, sys_recvmsg,
sys_recvmmsg, sys_shutdown, sys_getsockopt, sys_setsockopt): Decode
socket descriptor arguments using printfd.
* pathtrace.c (pathtrace_match): Also check TRACE_NETWORK syscalls
that take socket descriptor arguments.
* tests/net-fd.test: New test for socket descriptor arguments decoding.
* tests/Makefile.am (TESTS): Add net-fd.test.
(net-fd.log): New dependency on net.log.
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-02-01 21:57:45 +04:00
if ( s - > sys_flags & ( TRACE_DESC | TRACE_NETWORK ) )
2017-07-08 11:28:56 +03:00
return fdmatch ( tcp , tcp - > u_arg [ 0 ] , set ) ;
2011-04-08 00:25:40 +04:00
2017-07-08 11:28:56 +03:00
return false ;
2011-04-08 00:25:40 +04:00
}