Commit Graph

2818 Commits

Author SHA1 Message Date
cff9f8aa94 xlat: extend syntax
* xlat/gen.sh (gen_header): If the name of constant is specified with a
value, generate a default definition for the constant using this value.
* xlat/timerfdflags.in: Use extended syntax.
2015-02-19 01:54:14 +00:00
2f0808b88e Move CAP_* definitions out to header files
* Makefile.am (strace_SOURCES): Add caps0.h and caps1.h.
* caps0.h: New file.
* caps1.h: New file.
* capability.c: Remove CAP_* definitions, include "caps0.h"
and "caps1.h" instead.
Include "xlat/cap_mask0.h" instead of "xlat/capabilities.h".
Include "xlat/cap_mask1.h" instead of "xlat/capabilities1.h".
(print_cap_bits): Update callers.
* xlat/capabilities.in: Rename to xlat/cap_mask0.in.
* xlat/capabilities1.in: Rename to xlat/cap_mask1.in.
2015-02-19 00:33:39 +00:00
f523f103cc Declare all format printers with printf format attribute
* defs.h (printllval, printnum_int, printnum_long): Mark with
format(printf) attribute.
* sock.c (sock_ioctl): Fix format string.
2015-02-18 02:44:43 +00:00
1c603a9e07 Rename printnum to printnum_long to avoid confusion
* defs.h (printnum): Rename to printnum_long.
* util.c (printnum): Likewise.
* process.c (sys_ptrace): Likewise.
* time.c (sys_time): Likewise.
2015-02-17 22:03:17 +00:00
f55cca729f Use printnum_int consistently
* sock.c (sock_ioctl): Use printnum_int instead of printnum to print
integer type.
* stream.c (sys_getpmsg): Likewise.
2015-02-17 22:00:45 +00:00
e96cb621fa print_pc: fix multiple personalities support
* syscall.c (print_pc): Choose instruction pointer format depending
on current_wordsize, not the size of long integer type.
* tests/pc.c: New file.
* tests/pc.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add pc.
(TESTS): Add pc.test.
* tests/.gitignore: Add pc.
2015-02-16 02:39:21 +00:00
4f2d1ae243 mips: use PTRACE_GETREGS to fetch all registers
* linux/mips/arch_regs.h (struct mips_regs): New structure.
(mips_REG_*): New macros.
* signal.c (sys_sigreturn) [MIPS]: Use mips_REG_SP.
* syscall.c [MIPS] (struct mips_regs): New variable.
[MIPS] (ARCH_REGS_FOR_GETREGS): New macro.
(mips_a3, mips_r2): Remove.
(print_pc) [MIPS]: Use mips_REG_EPC.
(get_scno) [MIPS]: Use mips_REG_V0 and mips_REG_A3.
(get_syscall_args) [MIPS]: Use mips_REG_A[0-5].
(get_syscall_result) [MIPS]: Remove.
(get_error) [MIPS]: Use mips_REG_A3 and mips_REG_V0.
2015-02-16 02:39:13 +00:00
047365efde mips: move ABI check to configure.ac
* configure.ac [MIPS]: Check for MIPS ABI.
* defs.h [MIPS]: Remove MIPS ABI check.
* ioctlsort.c: Likewise.
2015-02-16 02:35:58 +00:00
4a00fc4867 tests: support alternative names of select syscall
* tests/select.awk: Recognize "_newselect" as another name of "select".
* tests/select.test: Try alternative names of select syscall.
2015-02-16 02:35:58 +00:00
f97a4774d2 i386: fix compilation warning
Some gcc versions complain about assigning long* to uint32_t* on i386.

* syscall.c [I386] (i386_esp_ptr): Change type from uint32_t* to long*.
* linux/i386/arch_regs.h (i386_esp_ptr): Likewise.
* linux/x86_64/arch_regs.h: Do not include "i386/arch_regs.h".
(i386_esp_ptr): New prototype.
2015-02-15 00:08:11 +00:00
e9bfff6de6 Do not reset get_regs_error unnecessarily
As get_regs() is now guaranteed to set get_regs_error,
there is no need to reset get_regs_error before get_regs() call.

* strace.c (trace): Call clear_regs() iff !WIFSTOPPED.
2015-02-14 00:12:23 +00:00
5d09224f90 get_syscall_result: remove redundant ifdefs
As get_regs() is now guaranteed to fetch registers when either
ARCH_REGS_FOR_GETREGSET or ARCH_REGS_FOR_GETREGS is defined, we can
safely replace all checks for architectures where these macros are defined
with a single check for these macros.

* syscall.c (get_syscall_result): Check for [ARCH_REGS_FOR_GETREGSET ||
ARCH_REGS_FOR_GETREGS].  Remove all checks for architectures where
nothing has to be done after get_regs().
2015-02-14 00:12:21 +00:00
9a176c9290 get_regs: define for all architectures
* defs.h (get_regs_error): Remove.
(clear_regs): Update prototype, declare unconditionally.
(get_regs): Declare unconditionally.
* syscall.c (clear_regs): New function.
(get_regs): Define unconditionally.
(get_regs_error): Define unconditionally, change scope to static.
2015-02-14 00:12:18 +00:00
7abf2e8307 get_regs: unify code for architectures that use PTRACE_GETREGS
* syscall.c [I386, POWERPC, ARM, AVR32, SPARC, SPARC64, TILE]
(ARCH_REGS_FOR_GETREGS): New macro.
(get_regs): Unify code for ARCH_REGS_FOR_GETREGS architectures.
2015-02-14 00:12:03 +00:00
d6db1db2a4 get_regset: define iff PTRACE_GETREGSET is used
* syscall.c [AARCH64, X86_64, X32] (ARCH_REGS_FOR_GETREGSET,
ARCH_IOVEC_FOR_GETREGSET): New macros.
(get_regset): Define iff ARCH_REGS_FOR_GETREGSET is defined; change
return type to long, return ptrace() return code instead of assigning it
to get_regs_error; do not list individual architectures, implement
constant and variable iovec cases depending on ARCH_IOVEC_FOR_GETREGSET.
(get_regs): Assign get_regset() return code to get_regs_error.
2015-02-14 00:11:35 +00:00
82ae5b9e1b arm, i386: switch back to use PTRACE_GETREGS
PTRACE_GETREGSET and PTRACE_GETREGS methods are equally good on arm and
i386 architectures, but PTRACE_GETREGSET with fallback to PTRACE_GETREGS
is a bit more costly, so choose the method that costs less.
This partially reverts commit v4.7-149-gfaa177e.

* syscall.c [ARM, I386] (ARCH_REGS_FOR_GETREGSET): Remove.
(get_regset) [ARM || I386]: Remove.
(get_regs) [ARM || I386]: Use PTRACE_GETREGS unconditionally.
2015-02-14 00:11:32 +00:00
ebea3426bb syscall.c: remove obsolete ifdefs
* syscall.c (get_regset, get_regs): Do not check for availability
of PTRACE_GETREGSET and NT_PRSTATUS macros.
2015-02-14 00:11:28 +00:00
4c3f2ae2c8 syscall.c: ensure that NT_PRSTATUS is defined
* syscall.c: Do not include <elf.h>.
(NT_PRSTATUS): New macro.
2015-02-14 00:11:18 +00:00
5503dd28c6 Move regs-related macros and declarations from defs.h to regs.h
* regs.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* linux/arch_regs.h: New file.
* linux/alpha/arch_regs.h: Likewise.
* linux/arm/arch_regs.h: Likewise.
* linux/hppa/arch_regs.h: Likewise.
* linux/i386/arch_regs.h: Likewise.
* linux/ia64/arch_regs.h: Likewise.
* linux/mips/arch_regs.h: Likewise.
* linux/powerpc/arch_regs.h: Likewise.
* linux/sh64/arch_regs.h: Likewise.
* linux/sparc/arch_regs.h: Likewise.
* linux/sparc64/arch_regs.h: Likewise.
* linux/tile/arch_regs.h: Likewise.
* linux/x86_64/arch_regs.h: Likewise.
* Makefile.am (EXTRA_DIST): Add them.
* defs.h: Remove definitions of PTRACE_*, REG_*, PT_*, U_REG_*,
and ARM_* macros.
Remove declarations of struct pt_regs variables.
[SPARC]: Do not include <asm/psr.h>.
[SPARC64]: Do not include <asm/psrcompat.h>.
* bjm.c: Do not include <sys/user.h>.
* process.c: Include "regs.h".
Do not include <sys/user.h> and <sys/reg.h>.
[IA64]: Do not include <asm/ptrace_offsets.h> and <asm/rse.h>.
* util.c: Likewise.
* syscall.c: Likewise.
[AARCH64]: Define struct arm_pt_regs and ARM_* macros.
[SPARC]: Include <asm/psr.h>.
[SPARC64]: Include <asm/psrcompat.h>.
* signal.c: Include "regs.h".
Do not include <sys/user.h> and <sys/reg.h>.
[IA64]: Do not include <asm/ptrace_offsets.h>.
* strace.c [IA64]: Do not include <asm/ptrace_offsets.h>.
2015-02-13 18:28:08 +00:00
fadf379b8e Move all ptrace-related macros and declarations from defs.h to ptrace.h
* ptrace.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* configure.ac (AC_CHECK_HEADERS): Remove linux/ptrace.h and sys/ptrace.h.
* defs.h: Do not include <sys/ptrace.h> and <asm/ptrace.h>.
Remove definitions of PTRACE_* macros.
* process.c: Remove <linux/ptrace.h> workarounds, include "ptrace.h".
* signal.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.
* strace.c: Include "ptrace.h".
* wait.c: Likewise.
2015-02-13 18:27:58 +00:00
d8b3404555 Enhance wait status decoding
* xlat/ptrace_events.in: New file.
* wait.c: Include "xlat/ptrace_events.h".
(printstatus): In case of WIFSTOPPED, print 0x80 flag separately from
the stop signal name.
[WIFCONTINUED]: Add WIFCONTINUED support.
Decode PTRACE_EVENT_* events.
2015-02-12 23:24:46 +00:00
Bart Van Assche
67d0a8ecfa scsi: add bsg support
The Linux kernel supports two different versions of the SG_IO API,
namely v3 and v4. This patch adds support for version 4 of this API.
At least the sg3_utils package supports version 4 of this API.  Version
4 of this API is used if /dev/bsg/H:C:I:L is used as device name.

This patch has been tested by inspecting the output of the following
commands:

modprobe scsi_debug dev_size_mb=16 delay=0
dev=$(lsscsi | sed -n '/ scsi_debug /s,^[^/]*,,p')
./strace -eioctl -s256 sg_inq $dev
echo 'Test XDWRITEREAD(10)'
bsg=/dev/bsg/$(lsscsi | sed -n '/ scsi_debug /s,^\[\([^]]\+\)\].*,\1,p')
dd if=/dev/zero bs=512 count=1 |
  ./strace -eioctl -s256 sg_raw -s 512 -r 1024 $bsg 53 00 00 00 00 01 00 00 01 00

* configure.ac (AC_CHECK_HEADERS): Add linux/bsg.h.
* xlat/bsg_protocol.in: New file.
* xlat/bsg_subprotocol.in: Likewise.
* scsi.c: Include them and <linux/bsg.h>.
(print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res): New functions.
(print_sg_io_req, print_sg_io_res): Use them.
(scsi_ioctl): Update callers.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2015-02-08 02:07:22 +00:00
Bart Van Assche
791145ee6e scsi: Add iovec support
* scsi.c (print_sg_io_req, print_sg_io_res): Add support for decoding
iovecs passed via the SG I/O v3 interface.  Decode the "data in" and
"data out" buffers in hex instead of in ASCII.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2015-02-08 01:42:00 +00:00
Bart Van Assche
0014bb1b9d scsi: on exit, print only initialized part of the buffer
* scsi.c (print_sg_io_res): Only print that part of the data in buffer
that has been initialized by the SCSI LLD driver.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2015-02-08 01:42:00 +00:00
Bart Van Assche
ea6972c162 scsi: make print_sg_io_buffer() print square brackets instead of its callers
* scsi.c (print_sg_io_buffer): Print square brackets in this function.
(print_sg_io_req, print_sg_io_res): Update callers.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2015-02-08 01:42:00 +00:00
Bart Van Assche
c760251451 scsi: improve consistency with other decoding functions
Pass pointers to tracee's memory as integers instead of pointers.

* scsi.c (print_sg_io_buffer): Change second argument's type to
unsigned long.
(print_sg_io_req, print_sg_io_res): Update callers.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2015-02-08 01:42:00 +00:00
d07056f4d0 tests: extend getdents to support all filesystems regardless of file order
* tests/getdents.awk: Include all 6 possible permutations of 3
direntries to regexps.
2015-02-08 01:41:37 +00:00
3910d0f67c print_setsockopt: fix fall-through bug in SOL_IP switch case
This fixes the bug introduced by commit v4.9-250-ga0a4909.

* net.c (print_setsockopt): Separate SOL_IP case from SOL_PACKET.

Reported-by: Ben Noordhuis <info@bnoordhuis.nl>
2015-02-08 01:19:06 +00:00
85dc4a11c7 Do not watch for post-execve SIGTRAP if PTRACE_O_TRACEEXEC is enabled
If PTRACE_O_TRACEEXEC option is enabled, then post-execve SIGTRAPs are
suppressed and we can safely skip -ENOSYS heuristics.  This partially
reverts commits v4.9-258-g8e398b6 and v4.9-261-gd70c41d.

* syscall.c (syscall_fixup_on_sysenter): Skip if PTRACE_O_TRACEEXEC
flag is set in ptrace_setoptions.  Remove all SECCOMP_RET_ERRNO
workarounds as they are not needed when PTRACE_O_TRACEEXEC is not
supported by the kernel.
2015-02-07 23:38:25 +00:00
2cd488b259 When the process stared by strace exits/terminates, forget its pid
The process stared by strace can exit/terminate only once.  When this
happens, forget its pid, so that any other event or action related to a
process with the same pid as the pid of that first process would not be
confused with that first process.

* strace.c (print_signalled, print_exited): Clear strace_child when it
equals to the given pid.
2015-02-07 22:28:31 +00:00
aa80192e79 -b execve: avoid misleading warning about unknown pid
* strace.c (maybe_allocate_tcb): If detach_on_execve is set, do not warn
about !WIFSTOPPED process with pid == strace_child.
* tests/bexecve.test: New test.
* tests/Makefile.am (TESTS): Add it.
2015-02-07 22:28:27 +00:00
e69081359a -b execve: do not use struct tcb after detach
* strace.c (trace): Do not proceed after detach.
2015-02-07 17:47:53 +00:00
4b4ec12087 trace: split into several functions
This change moves the main loop back to main() and splits trace()
into several functions.  There are no algorithmic changes.

* strace.c (print_debug_info, maybe_allocate_tcb, maybe_switch_tcbs,
print_signalled, print_exited, print_stopped, startup_tcb): New
functions.
(trace) Use them.  Move the main loop ...
(main): ... here.
2015-02-07 17:31:54 +00:00
d8890b5c9d printsiginfo: constify the first argument
* signal.c (printsiginfo): Make the first argument a pointer to a const type.
* defs.h (printsiginfo): Likewise.
(printsiginfo, printsiginfo_at): Always define these prototypes.
* configure.ac (AC_CHECK_TYPES): Remove siginfo_t, as HAVE_SIGINFO_T
is no longer used.
2015-02-07 15:47:24 +00:00
35701997cf test: add a manual test for seccomp decoding
* test/.gitignore: Add seccomp.
* test/Makefile (PROGS): Likewise.
* test/seccomp.c: New file.
* test/README: Mention ../tests/.
2015-02-06 01:52:59 +00:00
2af6903f45 Implement seccomp decoding
* configure.ac (AC_CHECK_HEADERS): Add linux/filter.h
and linux/seccomp.h.
* defs.h (print_seccomp_filter): New prototype.
* linux/dummy.h (sys_seccomp): Remove.
* linux/syscall.h (sys_seccomp): New prototype.
* prctl.c: Include <linux/seccomp.h>.
(sys_prctl): Decode PR_SET_SECCOMP.
* seccomp.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* xlat/bpf_class.in: New file.
* xlat/bpf_miscop.in: Likewise.
* xlat/bpf_mode.in: Likewise.
* xlat/bpf_op_alu.in: Likewise.
* xlat/bpf_op_jmp.in: Likewise.
* xlat/bpf_rval.in: Likewise.
* xlat/bpf_size.in: Likewise.
* xlat/bpf_src.in: Likewise.
* xlat/seccomp_filter_flags.in: Likewise.
* xlat/seccomp_mode.in: Likewise.
* xlat/seccomp_ops.in: Likewise.
* xlat/seccomp_ret_action.in: Likewise.
2015-02-06 01:23:05 +00:00
0946052255 is_negated_errno: support large errno values
Thanks to SECCOMP_RET_DATA == 0xffff, abnormally large errno
values could be easily seen when a seccomp filter is used, e.g.
BPF_STMT(BPF_RET, SECCOMP_RET_ERRNO | SECCOMP_RET_DATA)

* syscall.c (is_negated_errno): Allow errno values as large as 0xffff.
2015-02-06 01:23:05 +00:00
d70c41ddad x86, x32, x86_64: print SECCOMP_RET_ERRNO filtered syscalls
This is required to process SECCOMP_RET_ERRNO filtered syscalls on
systems where linux kernel does not change the syscall number to -1.

* syscall.c (is_negated_errno): Move before syscall_fixup_on_sysenter.
(syscall_fixup_on_sysenter) [I386 || X32 || X86_64] : Use it to check
AX register.
2015-02-06 01:23:05 +00:00
f46ab5f169 is_negated_errno: merge x86_64 and x32 definitions
* syscall.c (kernel_long_t, kernel_ulong_t): New types.
(is_negated_errno): Merge [X32] and [!X32] definitions.
(get_error): Merge [X86_64] and [X32] code.
2015-02-06 01:23:05 +00:00
38b295569f x32: rename is_negated_errno_x32 to is_negated_errno
Use the same function name on all architectures.

* syscall.c [X32] (is_negated_errno_x32): Rename to is_negated_errno.
(get_error) [X32]: Update callers.
2015-02-06 01:23:05 +00:00
8e398b6c40 x86, x32, x86_64: do not skip syscall number -1
Syscall number -1 might be a side effect of SECCOMP_RET_ERRNO filtering.

* syscall.c (syscall_fixup_on_sysenter) [I386 || X32 || X86_64]:
Do not skip syscalls that have number -1.
2015-02-06 01:23:05 +00:00
c394832771 x86_64: do not interpet syscall number -1 as a x32 personality syscall
Syscall number -1 might be a side effect of SECCOMP_RET_ERRNO filtering.

* syscall.c (get_scno) [X86_64]: Handle the case of scno == -1.
2015-02-06 01:22:28 +00:00
fef09070d6 Implement getrandom syscall decoding
* getrandom.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* linux/dummy.h (sys_getrandom): Remove.
* linux/syscall.h (sys_getrandom): New prototype.
* xlat/getrandom_flags.in: New file.
* tests/getrandom.c: New file.
* tests/getrandom.awk: New file.
* tests/getrandom.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add getrandom.
(TESTS): Add getrandom.test.
(EXTRA_DIST): Add getrandom.awk.
* tests/.gitignore: Add getrandom.
2015-02-05 01:10:47 +00:00
e837b14a53 tests: add a test for select syscall decoding
Convert test/select.c into a regular test.

* test/Makefile (PROGS): Remove select.
* test/.gitignore: Likewise.
* test/select.c: Rewrite to ...
* tests/select.c: ... new file.
* tests/select.awk: New file.
* tests/select.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add select.
(TESTS): Add select.test.
(EXTRA_DIST): Add select.awk.
* tests/.gitignore: Add select.
2015-02-04 02:21:13 +00:00
495f525d68 tests: add a test for the latest dumpio fix
* tests/dumpio.expected: New file.
* tests/unix-pair-send-recv.c: New file.
* tests/dumpio.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add unix-pair-send-recv.
(TESTS): Add dumpio.test.
(EXTRA_DIST): Add dumpio.expected.
* tests/.gitignore: Add unix-pair-send-recv.
2015-02-01 01:33:20 +00:00
Aurelien Jacobs
dc52121cd0 Fix simultaneous -e read and -e write usage
This allows using both -e read=FD and -e write=FD at the same time
with the same FD.
Without this patch, the -e write=FD is ignored if -e read=FD is used
at the same time.

Signed-off-by: Aurelien Jacobs <aurel@gnuage.org>
2015-02-01 01:33:17 +00:00
f362a33660 net.c: remove unused HAVE_SIN6_SCOPE_ID_LINUX-based code
The AC_SIN6_SCOPE_ID autoconf macro that was able to define
HAVE_SIN6_SCOPE_ID_LINUX was removed by commit v4.4-98-g64f793a.

* net.c [HAVE_SIN6_SCOPE_ID_LINUX]: Remove.
2015-01-31 01:14:39 +00:00
d0dceaf0ff printsock: do not fetch sockaddr.sa_data twice
* net.c (printsock): Print addrbuf.sa.sa_data using print_quoted_string.
2015-01-30 13:36:49 +00:00
a0a4909988 setsockopt: add decoding of MCAST_JOIN_GROUP and MCAST_LEAVE_GROUP
* net.c (print_group_req): New function.
(print_setsockopt): Use it.
2015-01-30 01:55:20 +00:00
c9e2418827 tests: add a test for sockaddr_un.sun_path decoding
* tests/net-accept-connect.c: Allow long socket addresses.
* tests/sun_path.test: New test.
* tests/Makefile.am (TESTS): Add it.
2015-01-29 23:06:15 +00:00