2015-12-17 20:56:48 +03:00
/*
* Copyright ( c ) 1994 - 1996 Rick Sladkey < jrs @ world . std . com >
* Copyright ( c ) 1996 - 2000 Wichert Akkerman < wichert @ cistron . nl >
* Copyright ( c ) 2005 - 2007 Roland McGrath < roland @ redhat . com >
* Copyright ( c ) 2008 - 2015 Dmitry V . Levin < ldv @ altlinux . org >
* 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 .
*/
2014-12-11 22:25:02 +03:00
# include "defs.h"
# include <sys/prctl.h>
# include "xlat/prctl_options.h"
2015-12-06 18:33:53 +03:00
# include "xlat/pr_cap_ambient.h"
2015-02-14 04:51:03 +03:00
# include "xlat/pr_mce_kill.h"
# include "xlat/pr_mce_kill_policy.h"
# include "xlat/pr_set_mm.h"
# include "xlat/pr_tsc.h"
2015-12-06 18:33:53 +03:00
# include "xlat/pr_unalign_flags.h"
2014-12-11 22:25:02 +03:00
2015-02-14 04:51:03 +03:00
# ifndef TASK_COMM_LEN
# define TASK_COMM_LEN 16
2014-12-11 22:25:02 +03:00
# endif
2015-02-05 02:50:50 +03:00
# ifdef HAVE_LINUX_SECCOMP_H
# include <linux / seccomp.h>
# endif
# include "xlat/seccomp_mode.h"
2015-02-14 04:51:03 +03:00
# ifdef HAVE_LINUX_SECUREBITS_H
# include <linux / securebits.h>
# endif
# include "xlat/secbits.h"
/* these constants are the same as in <linux/capability.h> */
enum {
# include "caps0.h"
# include "caps1.h"
} ;
# include "xlat/cap.h"
2015-07-25 12:43:01 +03:00
static void
print_prctl_args ( struct tcb * tcp , const unsigned int first )
{
unsigned int i ;
for ( i = first ; i < tcp - > s_ent - > nargs ; + + i )
tprintf ( " , %#lx " , tcp - > u_arg [ i ] ) ;
}
2015-07-18 00:49:17 +03:00
SYS_FUNC ( prctl )
2014-12-11 22:25:02 +03:00
{
2016-05-17 01:19:31 +03:00
const unsigned int option = tcp - > u_arg [ 0 ] ;
2014-12-11 22:25:02 +03:00
unsigned int i ;
2015-07-18 00:49:17 +03:00
if ( entering ( tcp ) )
2016-05-17 01:19:31 +03:00
printxval ( prctl_options , option , " PR_??? " ) ;
2015-02-14 04:51:03 +03:00
2016-05-17 01:19:31 +03:00
switch ( option ) {
2015-02-14 04:51:03 +03:00
case PR_GET_DUMPABLE :
2015-07-18 00:49:17 +03:00
case PR_GET_KEEPCAPS :
case PR_GET_SECCOMP :
case PR_GET_TIMERSLACK :
case PR_GET_TIMING :
2015-12-06 18:29:04 +03:00
return RVAL_DECODED ;
2015-07-18 00:49:17 +03:00
case PR_GET_CHILD_SUBREAPER :
2015-02-14 04:51:03 +03:00
case PR_GET_ENDIAN :
case PR_GET_FPEMU :
case PR_GET_FPEXC :
2015-07-18 00:49:17 +03:00
if ( entering ( tcp ) )
tprints ( " , " ) ;
else
printnum_int ( tcp , tcp - > u_arg [ 1 ] , " %u " ) ;
break ;
2015-02-14 04:51:03 +03:00
case PR_GET_NAME :
2015-07-18 00:49:17 +03:00
if ( entering ( tcp ) )
tprints ( " , " ) ;
else {
if ( syserror ( tcp ) )
printaddr ( tcp - > u_arg [ 1 ] ) ;
else
printstr ( tcp , tcp - > u_arg [ 1 ] , - 1 ) ;
}
break ;
2015-02-14 04:51:03 +03:00
case PR_GET_PDEATHSIG :
2015-07-18 00:49:17 +03:00
if ( entering ( tcp ) )
tprints ( " , " ) ;
else if ( ! umove_or_printaddr ( tcp , tcp - > u_arg [ 1 ] , & i ) ) {
tprints ( " [ " ) ;
tprints ( signame ( i ) ) ;
tprints ( " ] " ) ;
}
break ;
2015-02-14 04:51:03 +03:00
case PR_GET_SECUREBITS :
2015-07-18 00:49:17 +03:00
if ( entering ( tcp ) )
break ;
if ( syserror ( tcp ) | | tcp - > u_rval = = 0 )
return 0 ;
2016-05-15 17:23:06 +03:00
tcp - > auxstr = sprintflags ( " " , secbits ,
( unsigned long ) tcp - > u_rval ) ;
2015-07-18 00:49:17 +03:00
return RVAL_STR ;
2015-02-14 04:51:03 +03:00
case PR_GET_TID_ADDRESS :
2015-07-18 00:49:17 +03:00
if ( entering ( tcp ) )
tprints ( " , " ) ;
else
Fix printing tracee's long integers
Replace ambiguous printnum_long that used to fetch native long integers
from tracee's memory with printnum_ptr, printnum_slong, and printnum_ulong
that fetch tracee's pointer, signed long, and unsigned long integers.
* defs.h (printnum_long, printpair_long): Remove prototypes.
(printnum_int64, printpair_int64): Remove macros, declare functions
unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New prototype.
(printnum_ptr, printnum_slong, printnum_ulong): New macros.
* aio.c (sys_io_setup): Use printnum_ulong.
* block.c (block_ioctl): Use printnum_slong and printnum_ulong.
* get_robust_list.c (sys_get_robust_list): Use printnum_ptr
and printnum_ulong.
* io.c (print_off_t): Remove.
(sys_sendfile): Use printnum_ulong.
* ipc.c (sys_semctl): Use printnum_ptr.
* prctl.c (sys_prctl): Likewise.
* process.c (sys_ptrace): Likewise.
* rtc.c (rtc_ioctl): Use printnum_ulong.
* util.c (printnum_long, printpair_long): Remove.
(printnum_int64, printpair_int64): Define unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New function.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Elvira Khabirova <lineprinter0@gmail.com>
2015-08-18 17:58:27 +03:00
printnum_ptr ( tcp , tcp - > u_arg [ 1 ] ) ;
2015-07-18 00:49:17 +03:00
break ;
2015-02-14 04:51:03 +03:00
case PR_GET_TSC :
2015-07-18 00:49:17 +03:00
if ( entering ( tcp ) )
tprints ( " , " ) ;
else if ( ! umove_or_printaddr ( tcp , tcp - > u_arg [ 1 ] , & i ) ) {
tprints ( " [ " ) ;
printxval ( pr_tsc , i , " PR_TSC_??? " ) ;
tprints ( " ] " ) ;
}
break ;
2015-02-14 04:51:03 +03:00
case PR_GET_UNALIGN :
2015-07-18 00:49:17 +03:00
if ( entering ( tcp ) )
tprints ( " , " ) ;
else if ( ! umove_or_printaddr ( tcp , tcp - > u_arg [ 1 ] , & i ) ) {
tprints ( " [ " ) ;
printflags ( pr_unalign_flags , i , " PR_UNALIGN_??? " ) ;
tprints ( " ] " ) ;
}
break ;
/* PR_TASK_PERF_EVENTS_* take no arguments. */
2015-02-14 04:51:03 +03:00
case PR_TASK_PERF_EVENTS_DISABLE :
case PR_TASK_PERF_EVENTS_ENABLE :
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-05 02:50:50 +03:00
2015-02-14 04:51:03 +03:00
case PR_SET_CHILD_SUBREAPER :
case PR_SET_DUMPABLE :
case PR_SET_ENDIAN :
case PR_SET_FPEMU :
case PR_SET_FPEXC :
case PR_SET_KEEPCAPS :
case PR_SET_TIMING :
tprintf ( " , %lu " , tcp - > u_arg [ 1 ] ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_CAPBSET_DROP :
2015-12-06 18:29:04 +03:00
case PR_CAPBSET_READ :
2015-02-14 04:51:03 +03:00
tprints ( " , " ) ;
2016-05-17 02:22:11 +03:00
printxval_long ( cap , tcp - > u_arg [ 1 ] , " CAP_??? " ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-12-06 18:33:53 +03:00
case PR_CAP_AMBIENT :
tprints ( " , " ) ;
2016-05-17 02:22:11 +03:00
printxval_long ( pr_cap_ambient , tcp - > u_arg [ 1 ] ,
" PR_CAP_AMBIENT_??? " ) ;
2015-12-06 18:33:53 +03:00
switch ( tcp - > u_arg [ 1 ] ) {
case PR_CAP_AMBIENT_RAISE :
case PR_CAP_AMBIENT_LOWER :
case PR_CAP_AMBIENT_IS_SET :
tprints ( " , " ) ;
2016-05-17 02:22:11 +03:00
printxval_long ( cap , tcp - > u_arg [ 2 ] , " CAP_??? " ) ;
2015-12-06 18:33:53 +03:00
print_prctl_args ( tcp , 3 ) ;
break ;
default :
print_prctl_args ( tcp , 2 ) ;
break ;
}
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_MCE_KILL :
tprints ( " , " ) ;
2016-05-17 02:22:11 +03:00
printxval_long ( pr_mce_kill , tcp - > u_arg [ 1 ] , " PR_MCE_KILL_??? " ) ;
2015-02-14 04:51:03 +03:00
tprints ( " , " ) ;
if ( PR_MCE_KILL_SET = = tcp - > u_arg [ 1 ] )
2016-05-17 02:22:11 +03:00
printxval_long ( pr_mce_kill_policy , tcp - > u_arg [ 2 ] ,
2015-02-14 04:51:03 +03:00
" PR_MCE_KILL_??? " ) ;
else
tprintf ( " %#lx " , tcp - > u_arg [ 2 ] ) ;
2015-07-25 12:43:01 +03:00
print_prctl_args ( tcp , 3 ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_SET_NAME :
tprints ( " , " ) ;
printstr ( tcp , tcp - > u_arg [ 1 ] , TASK_COMM_LEN ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
2015-07-30 01:49:38 +03:00
# ifdef __ANDROID__
# ifndef PR_SET_VMA_ANON_NAME
# define PR_SET_VMA_ANON_NAME 0
# endif
case PR_SET_VMA :
if ( tcp - > u_arg [ 1 ] = = PR_SET_VMA_ANON_NAME ) {
2016-04-07 00:41:36 +03:00
tprintf ( " , PR_SET_VMA_ANON_NAME, %#lx " , tcp - > u_arg [ 2 ] ) ;
2015-07-30 01:49:38 +03:00
tprintf ( " , %lu, " , tcp - > u_arg [ 3 ] ) ;
printstr ( tcp , tcp - > u_arg [ 4 ] , - 1 ) ;
} else {
/* There are no other sub-options now, but there
* might be in future . . . */
print_prctl_args ( tcp , 1 ) ;
}
return RVAL_DECODED ;
# endif
2015-02-14 04:51:03 +03:00
case PR_SET_MM :
tprints ( " , " ) ;
printxval ( pr_set_mm , tcp - > u_arg [ 1 ] , " PR_SET_MM_??? " ) ;
2015-07-25 12:43:01 +03:00
print_prctl_args ( tcp , 2 ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_SET_PDEATHSIG :
tprints ( " , " ) ;
if ( ( unsigned long ) tcp - > u_arg [ 1 ] > 128 )
tprintf ( " %lu " , tcp - > u_arg [ 1 ] ) ;
else
tprints ( signame ( tcp - > u_arg [ 1 ] ) ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_SET_PTRACER :
tprints ( " , " ) ;
if ( tcp - > u_arg [ 1 ] = = - 1 )
tprints ( " PR_SET_PTRACER_ANY " ) ;
else
tprintf ( " %lu " , tcp - > u_arg [ 1 ] ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_SET_SECCOMP :
tprints ( " , " ) ;
2016-05-17 02:22:11 +03:00
printxval_long ( seccomp_mode , tcp - > u_arg [ 1 ] ,
2015-02-14 04:51:03 +03:00
" SECCOMP_MODE_??? " ) ;
if ( SECCOMP_MODE_STRICT = = tcp - > u_arg [ 1 ] )
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
if ( SECCOMP_MODE_FILTER = = tcp - > u_arg [ 1 ] ) {
2015-02-05 02:50:50 +03:00
tprints ( " , " ) ;
2015-02-14 04:51:03 +03:00
print_seccomp_filter ( tcp , tcp - > u_arg [ 2 ] ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
}
2015-07-25 12:43:01 +03:00
print_prctl_args ( tcp , 2 ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-05 02:50:50 +03:00
2015-02-14 04:51:03 +03:00
case PR_SET_SECUREBITS :
tprints ( " , " ) ;
2016-05-17 02:22:11 +03:00
printflags_long ( secbits , tcp - > u_arg [ 1 ] , " SECBIT_??? " ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_SET_TIMERSLACK :
tprintf ( " , %ld " , tcp - > u_arg [ 1 ] ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_SET_TSC :
tprints ( " , " ) ;
printxval ( pr_tsc , tcp - > u_arg [ 1 ] , " PR_TSC_??? " ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_SET_UNALIGN :
tprints ( " , " ) ;
printflags ( pr_unalign_flags , tcp - > u_arg [ 1 ] , " PR_UNALIGN_??? " ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_SET_NO_NEW_PRIVS :
case PR_SET_THP_DISABLE :
tprintf ( " , %lu " , tcp - > u_arg [ 1 ] ) ;
2015-07-25 12:43:01 +03:00
print_prctl_args ( tcp , 2 ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2015-02-14 04:51:03 +03:00
case PR_MCE_KILL_GET :
2015-07-25 12:43:01 +03:00
if ( entering ( tcp ) ) {
print_prctl_args ( tcp , 1 ) ;
return 0 ;
}
2015-02-14 04:51:03 +03:00
if ( syserror ( tcp ) )
return 0 ;
2016-05-15 00:46:05 +03:00
tcp - > auxstr = xlookup ( pr_mce_kill_policy ,
( unsigned long ) tcp - > u_rval ) ;
2015-02-14 04:51:03 +03:00
return tcp - > auxstr ? RVAL_STR : RVAL_UDECIMAL ;
2015-12-06 18:29:04 +03:00
case PR_GET_NO_NEW_PRIVS :
case PR_GET_THP_DISABLE :
2015-07-18 00:49:17 +03:00
case PR_MPX_DISABLE_MANAGEMENT :
case PR_MPX_ENABLE_MANAGEMENT :
2015-02-14 04:51:03 +03:00
default :
2015-07-25 12:43:01 +03:00
print_prctl_args ( tcp , 1 ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2014-12-11 22:25:02 +03:00
}
return 0 ;
}
# if defined X86_64 || defined X32
# include <asm / prctl.h>
# include "xlat / archvals.h"
2015-04-07 04:36:50 +03:00
SYS_FUNC ( arch_prctl )
2014-12-11 22:25:02 +03:00
{
2016-05-17 01:19:31 +03:00
const unsigned int option = tcp - > u_arg [ 0 ] ;
2015-02-14 04:51:03 +03:00
if ( entering ( tcp ) )
2016-05-17 01:19:31 +03:00
printxval ( archvals , option , " ARCH_??? " ) ;
2015-02-14 04:51:03 +03:00
2016-05-17 01:19:31 +03:00
switch ( option ) {
2015-02-14 04:51:03 +03:00
case ARCH_GET_GS :
case ARCH_GET_FS :
2015-07-18 00:49:17 +03:00
if ( entering ( tcp ) )
2015-02-14 04:51:03 +03:00
tprints ( " , " ) ;
2015-07-18 00:49:17 +03:00
else
Fix printing tracee's long integers
Replace ambiguous printnum_long that used to fetch native long integers
from tracee's memory with printnum_ptr, printnum_slong, and printnum_ulong
that fetch tracee's pointer, signed long, and unsigned long integers.
* defs.h (printnum_long, printpair_long): Remove prototypes.
(printnum_int64, printpair_int64): Remove macros, declare functions
unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New prototype.
(printnum_ptr, printnum_slong, printnum_ulong): New macros.
* aio.c (sys_io_setup): Use printnum_ulong.
* block.c (block_ioctl): Use printnum_slong and printnum_ulong.
* get_robust_list.c (sys_get_robust_list): Use printnum_ptr
and printnum_ulong.
* io.c (print_off_t): Remove.
(sys_sendfile): Use printnum_ulong.
* ipc.c (sys_semctl): Use printnum_ptr.
* prctl.c (sys_prctl): Likewise.
* process.c (sys_ptrace): Likewise.
* rtc.c (rtc_ioctl): Use printnum_ulong.
* util.c (printnum_long, printpair_long): Remove.
(printnum_int64, printpair_int64): Define unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New function.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Elvira Khabirova <lineprinter0@gmail.com>
2015-08-18 17:58:27 +03:00
printnum_ptr ( tcp , tcp - > u_arg [ 1 ] ) ;
2015-02-14 04:51:03 +03:00
return 0 ;
2014-12-11 22:25:02 +03:00
}
2015-02-14 04:51:03 +03:00
tprintf ( " , %#lx " , tcp - > u_arg [ 1 ] ) ;
2015-07-18 00:49:17 +03:00
return RVAL_DECODED ;
2014-12-11 22:25:02 +03:00
}
# endif /* X86_64 || X32 */