Elliott Hughes [Mon, 10 Mar 2014 19:27:22 +0000 (19:27 +0000)]
Improve SI_TIMER decoding
Decode siginfo_t more clearly for si_code SI_TIMER.
The 'pid' is actually a POSIX timer id, and the 'uid' is actually the
overrun.
Also factor out the si_value dumping so it's the same for every si_code.
Dmitry V. Levin [Mon, 3 Mar 2014 23:09:47 +0000 (23:09 +0000)]
Fix fcntl decoding
Assume that F_SETLK64, F_SETLKW64, and F_GETLK64 are either defined or
not defined altogether.
Do not assume that sizeof(off_t) < sizeof(long long) when F_SETLK64 is
undefined.
This change fixes build with musl libc on x86.
* configure.ac: Define SIZEOF_OFF_T.
* desc.c (USE_PRINTFLOCK64): New macro.
(struct flock64, printflock64): Do not define on X32.
(printflock): Replace X32 specific workaround with SIZEOF_OFF_T check.
Fix printing off_t members of struct flock.
(sys_fcntl): Use USE_PRINTFLOCK64.
Dmitry V. Levin [Sat, 1 Mar 2014 21:17:17 +0000 (21:17 +0000)]
sys_fcntl: remove F_FREESP and F_FREESP64 support
F_FREESP and F_FREESP64 fcntl commands are not available in Linux
and therefore the code implementing their decoding is useless.
Besides that, F_FREESP64 decoding is too complicated to support.
* desc.c (fcntlcmds): Remove F_FREESP and F_FREESP64.
Remove F_FREESP64 from the check whether to define struct flock64.
(sys_fcntl): Remove F_FREESP and F_FREESP64 support.
Elliott Hughes [Fri, 28 Feb 2014 23:16:32 +0000 (23:16 +0000)]
Fix decoding of arm struct stat64 by aarch64 strace.
aarch64's uapi header files have a struct stat but no struct stat64.
To correctly decode a 32-bit process' s struct stat64 we need
HAVE_STAT64, but then the build fails because there is no struct stat64.
Luckily, the aarch64 struct stat is structurally equivalent to the arm
struct stat64, so we can just reuse that.
Dmitry V. Levin [Wed, 26 Feb 2014 16:51:28 +0000 (16:51 +0000)]
Rewrite signal mask decoding without sigset_t
The sigset_t provided by libc is not quite convenient.
In glibc, sigset_t is an array with space for 1024 bits, which is much
more than required: all architectures supported by Linux have only 64
signals except MIPS, which has 128.
In bionic libc, LP32 sigset_t is only 4 bytes long, which is less than
necessary.
With this change, signal mask is decoded without use of intermediate
sigset_t structure, which saves us some cpu cycles in case of glibc with
its inflated sigset_t, and enables build with libcs where sigset_t is
broken.
Old implementation used to check each signal number in the given signal
mask twice using sigismember().
New implementation is based on popcount and next_set_bit() so it's
noticeably faster.
* configure.ac: Check for __builtin_popcount.
* signal.c: Ensure that NSIG >= 32.
(sprintsigmask, sprintsigmask_long, printsigmask): Remove.
(popcount32, sprintsigmask_n): New functions.
(tprintsigmask_addr, sprintsigmask_val, tprintsigmask_val): New macros.
(print_sigset_addr_len, sys_sigsetmask, sys_sigreturn, sys_siggetmask,
sys_sigsuspend, sys_sigprocmask, decode_new_sigaction): Update to use
new signal mask decoding interface.
* tests/sigaction.c (main): Add a test with almost filled signal mask.
* tests/sigaction.awk: Update.
Dmitry V. Levin [Wed, 26 Feb 2014 00:01:00 +0000 (00:01 +0000)]
Fix build with Bionic libc
Add generic tests for fopen64 and fputs_unlocked functions to fix build
with Bionic libc that does not provide them.
* configure.ac (AC_CHECK_FUNCS): Add fopen64 and fputs_unlocked.
* strace.c [_LARGEFILE64_SOURCE]: Use fopen instead of fopen64
if !HAVE_FOPEN64.
Use fputs instead of fputs_unlocked if !HAVE_FPUTS_UNLOCKED.
* vsprintf.c: Use fputs instead of fputs_unlocked
if !HAVE_FPUTS_UNLOCKED.
Dmitry V. Levin [Tue, 25 Feb 2014 23:04:55 +0000 (23:04 +0000)]
Do not compile scsi ioctl decoding if <scsi/sg.h> is not available
Add a generic test for <scsi/sg.h> availability to fix build with
Bionic libc that does not provide <scsi/sg.h>.
* configure.ac (AC_CHECK_HEADERS): Add scsi/sg.h.
* ioctl.c (ioctl_decode): Do not call scsi_ioctl if !HAVE_SCSI_SG_H.
* scsi.c: Do not compile scsi ioctl decoding if !HAVE_SCSI_SG_H.
Dmitry V. Levin [Sat, 8 Feb 2014 00:26:06 +0000 (00:26 +0000)]
Fix sigaction reporting on non-x86 architectures
If SA_RESTORER is not defined by libc headers but defined by kernel
headers, use the definition provided by kernel headers for proper
sigaction decoding.
* signal.c [!SA_RESTORER]: Define to ASM_SA_RESTORER if the latter is
defined, regardless of architecure.
Dmitry V. Levin [Sat, 8 Feb 2014 00:15:52 +0000 (00:15 +0000)]
Check for SA_RESTORER definition in <asm/signal.h>
Kernel header <asm/signal.h> cannot be included from regular code
because it conflicts with libc headers, but SA_RESTORER is needed in
signal.c, so SA_RESTORER value is forwarded from <asm/signal.h> to
config.h using a configure check.
* configure.ac (ASM_SA_RESTORER): Define if SA_RESTORER is defined
in <asm/signal.h>.
Ezequiel Garcia [Thu, 6 Feb 2014 17:53:54 +0000 (14:53 -0300)]
Add support for Altera's Nios-II softcore architecture
This commit adds strace support for Altera's Nios-II official
kernel port as found in git://git.rocketboards.org/linux-socfpga.git
Notice that this an out-of-tree kernel architectural port, and uses the
legacy (non-generic) system call ABI. In particular, the port doesn't
support PTRACE_GETREGSET, so the implementation is based on PTRACE_GETREGS.
Given it's mandatory for new architectures to support the generic
syscall ABI and PTRACE_GETREGSET, if the nios2 architecure is ever
mainlined, the strace support will have to be re-factored accordingly.
* linux/nios2/ioctlent.h.in: New file.
* linux/nios2/syscallent.h: Likewise.
* Makefile.am (EXTRA_DIST): Add linux/nios2/ioctlent.h.in and
linux/nios2/syscallent.h.
* configure.ac: Add NIOS2 to the list of supported architectures.
* defs.h [NIOS2]: Use register reading system.
* process.c (struct_user_offsets): Add NIOS2 support.
* syscall.c (get_regs, get_scno, get_syscall_args,
get_syscall_result, get_error): Likewise.
* util.c (change_syscall): Likewise.
* mem.c (sys_getpagesize): Define on NIOS2.
* system.c [NIOS2] (sys_cacheflush, sys_nios2cmpxchg): New functions.
Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar> Acked-by: Mike Frysinger <vapier@gentoo.org>
Dmitry V. Levin [Wed, 5 Feb 2014 02:20:51 +0000 (02:20 +0000)]
Use XLAT_END macro
Automatically update all xlat structures using the following sed regexp:
s/^[[:space:]]*{[[:space:]]*0[[:space:]]*,[[:space:]]*NULL[[:space:]]*,\?[[:space:]]*}[[:space:]]*,\?[[:space:]]*/\tXLAT_END/
Dmitry V. Levin [Wed, 5 Feb 2014 01:33:50 +0000 (01:33 +0000)]
Use XLAT macro
Automatically convert all xlat structures to XLAT form
using the following sed regexp:
s/^[[:space:]]*{[[:space:]]*\([^",}[:space:]]\+\)[[:space:]]*,[[:space:]]*"\1",\?[[:space:]]*}[[:space:]]*/\tXLAT(\1)/
Stefan Sørensen [Mon, 3 Feb 2014 09:01:27 +0000 (10:01 +0100)]
Decode dynamic posix clocks
* time.c (cpuclocknames): New xlat structure.
(printclockname): New function that decodes posix clock names,
including dynamic fd encoded clocks.
(sys_clock_settime, sys_clock_gettime, sys_clock_nanosleep,
sys_clock_adjtime, sys_timer_create, sys_timerfd, sys_timerfd_create):
Use it.
Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
Chris Dearman [Tue, 10 Dec 2013 03:58:42 +0000 (19:58 -0800)]
mips: fix sigaction reporting
MIPS userland uses the same sigaction structure with a full signal
mask for old_sigaction and new_sigaction and does does not have
an sa_restorer field.
These changes have been tested on MIPS O32 big/little endian, MIPS N64
big endian and x86-64.
* signal.c (old_sigaction) [MIPS]: Add definition for MIPS.
(decode_old_sigaction) [MIPS]: Print sa_mask according to its definition.
(new_sigaction) [MIPS]: Add definition for MIPS.
Signed-off-by: Chris Dearman <chris.dearman@imgtec.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Tue, 7 Jan 2014 22:41:30 +0000 (22:41 +0000)]
Factor out struct sigaction printing code
* signal.c [HAVE_SIGACTION] (decode_old_sigaction): New function.
[HAVE_SIGACTION] (sys_sigaction): Use it.
(decode_new_sigaction): New function.
(sys_rt_sigaction): Use it.
Dmitry V. Levin [Tue, 7 Jan 2014 19:32:32 +0000 (19:32 +0000)]
tests: add a test for rt_sigaction output
Since "struct sigaction" varies between architectures, rt_sigaction
decoding sometimes produces incorrect output. This test is expected
to catch basic rt_sigaction decoding bugs.
Mike Frysinger [Tue, 31 Dec 2013 07:43:17 +0000 (02:43 -0500)]
Delete old PTRACE_{PEEK,POKE}USR logic
The code base has settled on PTRACE_{PEEK,POKE}USER (with an E) and has
logic in defs.h to make sure it's set sanely. Delete this old logic as
the defs.h takes care of it now.
Dmitry V. Levin [Wed, 13 Nov 2013 18:09:04 +0000 (18:09 +0000)]
Assume that <sys/ptrace.h> provides a valid ptrace prototype
We used to explicitly list architectures where <sys/ptrace.h> from glibc
is known to provide a valid prototype for ptrace, and use a homegrown
replacement for all the rest. Situation seems to be better nowadays,
glibc is not the only libc available, so let's use ptrace prototype from
<sys/ptrace.h> by default, leaving the replacement for rare broken cases
if any.
* defs.h: Use ptrace prototype workaround iff
NEED_PTRACE_PROTOTYPE_WORKAROUND is defined.
Dmitry V. Levin [Tue, 12 Nov 2013 22:34:42 +0000 (22:34 +0000)]
Stop using _LFS64_LARGEFILE
There is only one place left in the code where strace guesses whether
libc provides LFS64 functions and structures. The most natural thing to
do there is to check for _LARGEFILE64_SOURCE - the macro provided by
glibc. Other libc implementations that provide nondegenerate LFS64
interfaces are expected to define this macro as well.
* defs.h (_LFS64_LARGEFILE): Remove.
* strace.c: Use _LARGEFILE64_SOURCE instead of _LFS64_LARGEFILE.
Dmitry V. Levin [Tue, 12 Nov 2013 22:25:06 +0000 (22:25 +0000)]
Define truncate64, ftruncate64, and getdents64 decoders unconditionally
These decoders are referenced by most architectures, there were no
undefined references so far because _LFS64_LARGEFILE appears to be
always defined by glibc when _GNU_SOURCE is defined.
Dmitry V. Levin [Tue, 12 Nov 2013 21:49:03 +0000 (21:49 +0000)]
Define printflock64 only if it is referenced by other code
* configure.ac (AC_CHECK_TYPES): Add struct flock64.
* desc.c (HAVE_F_SETLK64, HAVE_F_SETLKW64, HAVE_F_GETLK64): New macros.
[!HAVE_STRUCT_FLOCK64] (struct flock64): Define.
(printflock64): Define only if referenced by other code.
(sys_fcntl): Handle F_FREESP64, F_SETLK64, F_SETLKW64, and F_GETLK64 iff
these constants are defined and differ from their non-64bit versions.
Dmitry V. Levin [Tue, 12 Nov 2013 21:20:50 +0000 (21:20 +0000)]
Make PTRACE_PEEKUSER/PTRACE_POKEUSER checks less glibc specific
* configure.ac (AC_CHECK_DECLS): Add PTRACE_PEEKUSER and
PTRACE_POKEUSER.
* defs.h: Define PTRACE_PEEKUSER and PTRACE_POKEUSER only if
they are not provided by <sys/ptrace.h>.
Dmitry V. Levin [Tue, 12 Nov 2013 15:09:56 +0000 (15:09 +0000)]
Use standard names of sched_param structure members
* process.c (sys_sched_setscheduler, sys_sched_getparam,
sys_sched_setparam): Use portable struct sched_param member name
sched_priority instead of glibc specific __sched_priority.
Dmitry V. Levin [Mon, 11 Nov 2013 23:54:30 +0000 (23:54 +0000)]
Make SIGEV_THREAD_ID decoding less glibc specific
SIGEV_THREAD_ID decoding requires access to an internal member of
struct sigevent. There seems to be no portable way to do it besides
adding a configure check.
* configure.ac (AC_CHECK_MEMBERS): Check for
struct sigevent._sigev_un._pad and struct sigevent.__pad.
* time.c (printsigevent): Use an appropriate struct sigevent member
to print thread id.
Denys Vlasenko [Mon, 11 Nov 2013 11:50:47 +0000 (12:50 +0100)]
Stop using external libaio.h.
This change incorporates a partial copy instead
of using external libaio.h.
Why?
Because we want to properly decode 32-bit aio calls
by 64-bit strace. For that, we need more definitions than
libaio.h provides.
(These defs are not done yet, but will eventually be done).
Keeping our local 32-bit compat defs in sync with libaio.h
_without seeing libaio structs_ is hard/more bug prone.
A smaller benefit is that we don't need libaio installed.
Denys Vlasenko [Mon, 11 Nov 2013 11:31:18 +0000 (12:31 +0100)]
sys_io_submit: simplify iocb_cmd_lookup() helper.
This helper returns two values (a string and an enum).
The caller prints the string. It's simpler to just print
the string in the caller itself. This eliminates
"return by reference" and more importantly, an intermediate
static string buffer for the string result.
Since function of the helper is different now,
it is renamed to tprint_lio_opcode().
Denys Vlasenko [Mon, 11 Nov 2013 11:24:29 +0000 (12:24 +0100)]
sys_io_submit: stop traversing iocb vector after first failure.
The program may use a very large nr but supply either outright
invalid iocbpp[], or one with far fewer elements than nr.
We used to try reading iocbpp[i] until i == nr.
With this change, we stop on the first failure.
Denys Vlasenko [Sat, 9 Nov 2013 19:40:31 +0000 (20:40 +0100)]
Fix select decoding on e.g. 32-bit ppc process by 64-bit strace.
Added next_set_bit() function which finds the next set bit,
properly taking into account word size of the traced process.
Use it in decode_select() instead of fd_isset().
Also, properly round fdsize up to word size of traced process,
not to strace's word size.
Dmitry V. Levin [Tue, 5 Nov 2013 23:00:22 +0000 (23:00 +0000)]
Fix select decoding for glibc in _FORTIFY_SOURCE mode
glibc in _FORTIFY_SOURCE mode raises SIGABRT when descriptor greater
or equal to FD_SETSIZE is passed to FD_ISSET. Select family syscalls,
however, can legitimately accept such descriptors. To overcome this
limitation, we have to replace FD_ISSET with an equivalent that imposes
no such restrictions.
* desc.c (fd_isset): New function.
(decode_select): Use it instead of FD_ISSET.
Dmitry V. Levin [Tue, 5 Nov 2013 22:46:43 +0000 (22:46 +0000)]
More select decoding fixes
* desc.c (decode_select): Actually print arg[0] as int on entering
syscall. When arg[0] is negative, do not attempt to fetch and decode
descriptor sets on entering syscall, kernel will reject it anyway.
On exiting syscall, stop checking descriptor sets as soon as all
returned descriptors are found.
Fix select decoding with bogus (huge or negative) nfds.
We used to allocate and fetch bit arrays using a sanitized
length, but then iterate over them with "j < arg[0]" condition,
where arg[0] is not sanitized. This segfaults if arg[0] is huge
or negative. This change fixes this.
Add test/select.c to capture the case.
Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Ali Polatel [Tue, 24 Sep 2013 17:04:32 +0000 (20:04 +0300)]
Work around conflict between <sys/ptrace.h> and <linux/ptrace.h>
Since glibc-2.18~39 <sys/ptrace.h> defines ptrace_peeksiginfo_args
which collides with <linux/ptrace.h>.
* configure.ac: Check for `struct ptrace_peeksiginfo_args' in
<sys/ptrace.h>.
* process.c: Work around potential conflict between <sys/ptrace.h>
and <linux/ptrace.h> by redefining ptrace_peeksiginfo_args.
* signal.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.
Vineet Gupta [Fri, 16 Aug 2013 07:17:06 +0000 (12:47 +0530)]
Add support for ARC Cores from Synopsys
Take #2 on mainlining strace support for ARC (last one was 4.6 based back
in March 2011), see
http://sourceforge.net/p/strace/mailman/message/27210168/
The syscall ABI is asm-generic/unistd.h based (so no legacy syscalls),
hence very similar to metag port.
test/* all seem to work well.
* linux/arc/ioctlent.h.in: New file.
* linux/arc/syscallent.h: Likewise.
* Makefile.am (EXTRA_DIST): Add linux/arc/ioctlent.h.in and
linux/arc/syscallent.h.
* configure.ac: Add ARC to the list of supported architectures.
* defs.h: Add ARC support.
* process.c (struct_user_offsets): Likewise.
* signal.c (sys_sigreturn): Likewise.
* syscall.c (print_pc, get_regset, get_regs, get_scno, get_syscall_args,
get_syscall_result, get_error): Likewise.
* util.c (change_syscall): Likewise.
Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Acked-by: Mike Frysinger <vapier@gentoo.org>
William Manley [Fri, 9 Aug 2013 17:04:11 +0000 (18:04 +0100)]
Add support for decoding sync_file_range
* file.c (sync_file_range_flags): New xlat structure.
(sys_sync_file_range, sys_sync_file_range2): New functions.
* linux/syscall.h (sys_sync_file_range, sys_sync_file_range2): New
prototypes.
* linux/dummy.h (sys_sync_file_range, sys_sync_file_range2): Remove.
* linux/mips/syscallent-o32.h: Set the number of sync_file_range
arguments to 7.
Mike Frysinger [Mon, 19 Aug 2013 05:00:39 +0000 (01:00 -0400)]
fanotify_mark: fix number of args for 32bit arches
The fanotify_mark func takes a 64bit mask, so 32bit arches have to split
it up into two fields. When the syscall was added, it was listed as only
having 5 fields total (since that's correct for 64bit systems).
* linux/arm/syscallent.h: Set the number of fanotify_mark arguments to 6.
* linux/bfin/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/metag/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent-o32.h: Likewise.
* linux/or1k/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent1.h: Likewise.
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Acked-by: Chris Metcalf <cmetcalf@tilera.com> [for tile]
In almost all cases, the parameter was 1 ("decode RT sigs too").
This change hardwires it to be 1.
The cases where it was 0 are, and why the change to "decode RT sigs too"
is fine:
IA64: 64-bit arch, all 64 signals fit in one word in any case.
S390[x]: sc.oldmask is a sigset_t on kernel side,
(sigset_t *)&sc.oldmask[0] does contain all 64 signals.
TILE: uc.uc_sigmask is a sigset_t on kernel side,
memcpy(&sigm, &uc.uc_sigmask, NSIG / 8) copies all 64 signals.
Replace print_sigset() with print_sigset_addr_len(),
which takes not only addr, but also len parameter.
This allows us to drop "do we need to print RT signals?" parameter,
and this fixes RT signals printing in many syscalls.
sys_sigprocmask: print_sigset -> print_sigset_addr_len(current_wordsize),
no change in functionality.
sys_sigpending: use print_sigset_addr_len(current_wordsize)
instead of open-coding it.
sys_rt_sigprocmask: use print_sigset_addr_len instead of open-coding it.
sys_rt_sigpending: ditto.
sys_rt_sigsuspend: ditto.
sys_rt_sigtimedwait: ditto.
do_signalfd: print_sigset -> print_sigset_addr_len. This fixes
RT signals printing (wasn't showing them before).
sys_ppoll: ditto.
copy_sigset_len() is folded into its only user, print_sigset_addr_len(),
and copy_sigset() is gone.
While at it, checked kernel sources and noted where kernel enforces
sigset_size == NSIG / 8 (== sizeof(kernel_sigset_t)),
and where it allows word-sized sigset_size ([rt_]sigpending).
In practice, we always copy as many bytes as syscall param says
(8, or 16 on mips). However, malicious program can call sigaction
with wrong sigset size. Such syscall will result in EINVAL,
but we (strace) end up copying 128 bytes (sizeof(sigset_t)),
which copyes some garbage from stack after struct sigaction.
Now we always copy NSIG / 8 bytes (which is 8 bytes, or 16 on mips).
ARM in fact has 64 signals (1..64), and NSIG should be 65
(as usual, rememebr that NSIG_libc == NSIG_kernel+1).
I carefully reviewed all usages of NSIG. In syscall.c,
the only usage is:
for (i = 0; i <= NSIG; i++)
if (strcasecmp(s, signame(i) + 3) == 0)...
which is safe even if NSIG is way too big - signame(i)
returns a well-formed string for any i.
In signal.c, memcpy(&sigset, &sc.sc_mask, NSIG / 8) is used by
IA64 and TILE code, so ARM change can't affect it. And final
usage is:
struct new_sigaction::unsigned long sa_mask[NSIG / sizeof(long)];
It will grow on ARM (and become correct in the process).
Its only use is
memcpy(&sigset, &sa.sa_mask, NSIG / 8);
printsigmask(&sigset, 1);
which used to copy garbage in high bits, now it will copy actual data.
PTRACE_SEIZE can set ptrace options immediately, use this feature
This eliminates some rare bugs, such as post-execve SIGTRAP
generation when we attach to a process, and it manages to finish
execve'ing before we set TRACEEXEC option to suppress that.