Dmitry V. Levin [Mon, 23 Feb 2015 21:35:20 +0000 (21:35 +0000)]
Fix compilation warnings about incompatible print formats
On some platforms printing of __s64 types with "%lld" format,
or __u64 types with "%llu" or "%llx" formats causes a warning
that __s64/__u64 type is not compatible with long long format.
From my PoV, this is nonsense, but the workaround costs nothing.
* scsi.c (print_sg_io_v4_req, print_sg_io_v4_res): Cast __u64 types
to (unsigned long long).
* v4l2.c (v4l2_ioctl): Likewise. Cast __s64 type to (long long).
Dmitry V. Levin [Sat, 21 Feb 2015 23:50:33 +0000 (02:50 +0300)]
evdev: fix build with old kernel headers
* configure.ac: Check whether struct input_absinfo.resolution is defined
in <linux/input.h>.
* evdev.c (SYN_MAX): Add fallback definition.
(abs_ioctl): Wrap use of struct input_absinfo.resolution in #ifdef check.
(keycode_V2_ioctl, mtslots_ioctl, repeat_ioctl): Wrap in #ifdef checks.
(evdev_read_ioctl): Wrap in #ifdef checks the code that uses EV_SW,
EVIOCGREP, EVIOCGKEYCODE_V2, EVIOCGMTSLOTS, EVIOCGPROP, and EVIOCGSW.
(evdev_write_ioctl): Wrap in #ifdef checks the code that uses EVIOCSREP,
EVIOCSKEYCODE_V2, EVIOCSCLOCKID, and EVIOCREVOKE.
Etienne Gemsa [Fri, 20 Feb 2015 16:14:10 +0000 (17:14 +0100)]
Add decoding for evdev ioctls
This patch introduces decoding for evdev ioctls. For EVIOCSFF the five
first members are decoded, the union is not. The code was compiled and
tested on x86_64 with Linux 3.13.
* evdev.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (evdev_ioctl): New prototype.
* ioctl.c (ioctl_decode): Call evdev_ioctl for 'E' ioctl commands.
* xlat/evdev_autorepeat.in: New file.
* xlat/evdev_ff_status.in: New file.
* xlat/evdev_ff_types.in: New file.
* xlat/evdev_keycode.in: New file.
* xlat/evdev_leds.in: New file.
* xlat/evdev_misc.in: New file.
* xlat/evdev_mtslots.in: New file.
* xlat/evdev_prop.in: New file.
* xlat/evdev_relative_axes.in: New file.
* xlat/evdev_snd.in: New file.
* xlat/evdev_switch.in: New file.
* xlat/evdev_sync.in: New file.
Signed-off-by: Etienne Gemsa <etienne.gemsa@lse.epita.fr> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Sun, 22 Feb 2015 02:13:04 +0000 (02:13 +0000)]
Fix build with old kernel headers
* strace.c (print_debug_info, maybe_allocate_tcb, print_signalled,
print_exited): Remove "const" qualifier from status variable to
workaround some old implementations of WIFSIGNALED/WIFSTOPPED/WIFEXITED
macros.
* v4l2.c: Include <linux/types.h>.
(v4l2_ioctl): Check that V4L2_CTRL_FLAG_NEXT_CTRL and VIDIOC_S_EXT_CTRLS
macros are defined.
* tests/Makefile.am (AM_CPPFLAGS): Define.
Dmitry V. Levin [Thu, 19 Feb 2015 21:00:41 +0000 (21:00 +0000)]
Remove linux/inotify.h
* linux/inotify.h: Remove.
* Makefile.am (EXTRA_DIST): Remove it.
* inotify.c: Do not include <linux/inotify.h>.
* xlat/inotify_flags.in: Add default values.
Dmitry V. Levin [Sat, 14 Feb 2015 01:51:03 +0000 (01:51 +0000)]
Improve prctl decoding
* configure.ac (AC_CHECK_HEADERS): Add linux/securebits.h.
* prctl.c (sys_prctl): Implement full decoding of all PR_* constants
as defined in linux v3.19.
(sys_arch_prctl): Fix decoding of unknown commands.
* xlat/cap.in: New file.
* xlat/pr_mce_kill.in: New file.
* xlat/pr_mce_kill_policy.in: New file.
* xlat/pr_set_mm.in: New file.
* xlat/pr_tsc.in: New file.
* xlat/pr_unalign_flags.in: New file.
* xlat/secbits.in: New file.
* xlat/prctl_options.in: Remove non-linux constants, add fallback
definitions.
* xlat/seccomp_mode.in: Add fallback definitions.
Dmitry V. Levin [Wed, 18 Feb 2015 03:47:17 +0000 (03:47 +0000)]
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.
Dmitry V. Levin [Wed, 18 Feb 2015 23:59:50 +0000 (23:59 +0000)]
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.
Dmitry V. Levin [Sun, 15 Feb 2015 15:52:02 +0000 (15:52 +0000)]
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.
Dmitry V. Levin [Sun, 15 Feb 2015 03:27:13 +0000 (03:27 +0000)]
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.
Dmitry V. Levin [Sun, 15 Feb 2015 00:08:11 +0000 (00:08 +0000)]
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.
Dmitry V. Levin [Fri, 13 Feb 2015 23:06:36 +0000 (23:06 +0000)]
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().
Dmitry V. Levin [Fri, 13 Feb 2015 23:41:04 +0000 (23:41 +0000)]
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.
Dmitry V. Levin [Fri, 13 Feb 2015 23:22:56 +0000 (23:22 +0000)]
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.
Dmitry V. Levin [Fri, 13 Feb 2015 02:12:14 +0000 (02:12 +0000)]
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>.
Dmitry V. Levin [Thu, 12 Feb 2015 22:43:02 +0000 (22:43 +0000)]
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.
Bart Van Assche [Fri, 6 Feb 2015 12:37:03 +0000 (13:37 +0100)]
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:
Bart Van Assche [Fri, 6 Feb 2015 12:36:26 +0000 (13:36 +0100)]
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>
Dmitry V. Levin [Sat, 7 Feb 2015 23:26:44 +0000 (23:26 +0000)]
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.
Dmitry V. Levin [Sat, 7 Feb 2015 19:41:48 +0000 (19:41 +0000)]
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.
Dmitry V. Levin [Sat, 7 Feb 2015 18:48:55 +0000 (18:48 +0000)]
-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.
Dmitry V. Levin [Sat, 7 Feb 2015 15:47:24 +0000 (15:47 +0000)]
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.
Dmitry V. Levin [Thu, 5 Feb 2015 23:47:36 +0000 (23:47 +0000)]
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.
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.
Aurelien Jacobs [Sat, 31 Jan 2015 22:57:00 +0000 (23:57 +0100)]
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.
Dmitry V. Levin [Thu, 29 Jan 2015 04:42:37 +0000 (04:42 +0000)]
net: define all SOL_* constants
Ensure that all known SOL_* constants are defined.
Sync the list of known SOL_* constants with linux/socket.h.
* net.c: Provide definitions for all SOL_* constants.
Remove all SOL_* preprocessor conditionals.
(socketlayers): Disconnect from inet_protocols.
* xlat/socketlayers.in: Remove SOL_ICMP, add SOL_ALG and SOL_NFC.
Dmitry V. Levin [Thu, 29 Jan 2015 03:11:41 +0000 (03:11 +0000)]
getsockopt, setsockopt: do not decode structures in non-verbose mode
Move the code that is common between getsockopt and setsockopt parsers
to a separate function.
Move printers specific to getsockopt and setsockopt to separate
functions, choose appropriate parsers depending on verbose mode.
Move parsers of specific socket options to separate functions.
* net.c (printicmpfilter): Rename to print_icmp_filter.
(printsockopt): Remove.
(print_sockopt_fd_level_name, print_linger, print_ucred,
print_tpacket_stats, print_getsockopt, print_tpacket_req,
print_packet_mreq, print_setsockopt): New functions.
(sys_getsockopt, sys_setsockopt): Use them.
Dmitry V. Levin [Sun, 25 Jan 2015 01:04:01 +0000 (01:04 +0000)]
block_ioctl: quote strings
* block.c (print_blkpg_req): Print blkpg_partition.devname and
blkpg_partition.volname using print_quoted_string.
(block_ioctl): Print blk_user_trace_setup.name using print_quoted_string.
Dmitry V. Levin [Mon, 26 Jan 2015 01:17:08 +0000 (01:17 +0000)]
Rework string_quote API
string_quote() has proven to be too hard to use, replace it with
print_quoted_string() that does memory allocation and prints the result.
* defs.h (string_quote): Remove.
(QUOTE_0_TERMINATED, QUOTE_OMIT_LEADING_TRAILING_QUOTES): New macros.
(print_quoted_string): New prototype.
* util.c (string_quote): Make static; take "style" flags instead
of "len", treat QUOTE_0_TERMINATED style flag as former (len == -1);
add QUOTE_OMIT_LEADING_TRAILING_QUOTES style flag support.
(ALLOCA_CUTOFF, use_alloca): New macros.
(print_quoted_string): New function.
(printpathn, printstr): Update to new API.
* loop.c (loop_ioctl): Likewise.
* mtd.c (ubi_ioctl): Likewise.
* net.c (print_scm_security): Likewise.
* socketutils.c (unix_parse_response): Likewise.
Dmitry V. Levin [Sat, 24 Jan 2015 15:20:31 +0000 (15:20 +0000)]
Impove struct cmsghdr decoding
Print all cmsghdr structures in msg_control array,
not just the first one.
Change output format to be consistent with other parts of strace
where structures and arrays are printed.
Implement decoder for SCM_SECURITY message type.
* net.c (print_scm_rights, print_scm_creds, print_scm_security):
New functions.
(printcmsghdr): Use them. Iterate over all members of the array.
* xlat/scmvals.in: Add SCM_SECURITY.
* tests/scm_rights.c (main): Pass one more descriptor to the receiver.
Set SO_PASSCRED on the receiver part. Reserve enough space to receive
SCM_CREDENTIALS and SCM_RIGHTS.
* tests/scm_rights-fd.test: Update.
Dmitry V. Levin [Sat, 24 Jan 2015 01:08:57 +0000 (01:08 +0000)]
Fix ILP32 personality struct cmsghdr decoding on LP64 architectures
* net.c (union_cmsghdr): New union.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (cmsghdr32): New structure.
(printcmsghdr): Properly handle the case of current_wordsize < sizeof(long).