James Cowgill [Thu, 11 Aug 2016 16:33:01 +0000 (16:33 +0000)]
tests/xstatx.c: fix stat syscall tests on mips64
For historical reasons the kernel struct stat represents times as unsigned
32-bit integers on mips64. Therefore, while it's possible to give a file a
timestamp before 1970 with futimens, reading the same timestamp through
struct stat will give a positive time (around 2106).
Workaround by using positive timestamps for testing on mips64.
* tests/xstatx.c (create_sample): Use positive timestamps on mips64.
Dmitry V. Levin [Tue, 9 Aug 2016 00:07:53 +0000 (00:07 +0000)]
Fix decoding of invalid syscalls mapped to indirect subcalls
When the syscall number returned by arch_get_scno is a mapped indirect
subcall (i.e. mapped subcall of socketcall or ipc syscall), do not
mistakenly treat it as a valid indirect subcall.
* defs.h (SCNO_IS_VALID): Treat scno with TRACE_INDIRECT_SUBCALL flag
as invalid.
* syscall.c (syscall_name): Do no shuffle scno.
(trace_syscall_entering, trace_syscall_exiting): Use
tcp->s_ent->sys_name instead of syscall_name.
(get_scno): In case of invalid syscall, allocate a dynamic struct sysent
containing an appropriate .sys_name.
* tests/nsyscalls.c (main) [SYS_socket_subcall]: Check decoding
of direct syscall number SYS_socket_subcall+1.
(main) [SYS_ipc_subcall]: Check decoding of direct syscall number
SYS_ipc_subcall+1.
Dmitry V. Levin [Mon, 8 Aug 2016 21:29:58 +0000 (21:29 +0000)]
sparc64: swap personality numbers
Fix inconsistency between syscall and ioctl entries on sparc64.
Make layout of personalities on sparc64 the same as on other
architectures that support two personalities.
* defs.h [SPARC64] (PERSONALITY0_WORDSIZE): Change to 8.
[SPARC64] (PERSONALITY1_WORDSIZE): Change to 4.
* linux/sparc64/get_scno.c (arch_get_scno): Swap personality numbers.
* linux/sparc64/ioctls_arch1.h: Rename to ioctls_arch0.h.
* linux/sparc64/ioctls_arch0.h: Rename to ioctls_arch1.h.
* linux/sparc64/ioctls_inc0.h: Rename to ioctls_inc1.h.
* linux/sparc64/ioctls_inc1.h: Rename to ioctls_inc0.h.
Dmitry V. Levin [Mon, 8 Aug 2016 21:11:47 +0000 (21:11 +0000)]
defs.h: cleanup personality specific macro definitions
Move the code that defines PERSONALITY[12]_INCLUDE_FUNCS,
PERSONALITY[12]_INCLUDE_PRINTERS_DECLS,
PERSONALITY[12]_INCLUDE_PRINTERS_DEFS, and MPERS_{m,mx}32_IOCTL_MACROS
macros outside arch specific ifdefs.
This commit is an attempt to unify usage of include guards (in top-level
headers, at least). As a side note, different files with *.h extension
have different semantics: for example, printargs.h is included multiple
times in order to generate slightly varying code depending on values of
macro definitions - maybe it's better to change extension of such files
to something like *.inc.
* defs.h: Add #include guard.
* flock.h: Likewise.
* ipc_defs.h: Likewise.
* mpers_type.h: Likewise.
* printsiginfo.h: Likewise.
* ptrace.h: Likewise.
* regs.h: Likewise.
* seccomp_fprog.h: Likewise.
* gcc_compat.h: Rename the macro used for #include guard.
* msghdr.h: Likewise.
* sigevent.h: Likewise.
* kernel_types.h: Comment the trailing part of #include guard.
* xlat.h: Add missing macro definition for #include guard.
Dmitry V. Levin [Thu, 4 Aug 2016 00:40:33 +0000 (00:40 +0000)]
travis: use a suitable musl revision
There seems to be no readily available binary packages of musl that are
sufficiently up to date to be used to build and test strace, so prepare
a suitable musl from source.
* travis-install.sh (musl-gcc): Do not add an extra repository,
do not install musl-tools and linux-musl-dev packages.
Download, build, and install a suitable musl revision instead.
Dmitry V. Levin [Wed, 3 Aug 2016 14:05:39 +0000 (14:05 +0000)]
Fix printing of mode_t, umode_t, and umask types
Print numeric umode_t type using %#03ho format.
Print return value of umask syscall using %#03lo format.
When printing symbolic mode_t type, always print lower 9 bits,
and print the numeric part using %#03o format.
* defs.h (sprintmode): Remove.
(print_symbolic_mode_t, print_numeric_umode_t,
print_numeric_long_umask): New prototypes.
* printmode.c (sprintmode): Remove.
(print_symbolic_mode_t, print_numeric_umode_t,
print_numeric_long_umask): New functions.
* chmod.c (decode_chmod): Use print_numeric_umode_t.
* ipc_msg.c (SYS_FUNC(msgget)): Likewise.
* ipc_msgctl.c (print_msqid_ds): Likewise.
* ipc_sem.c (SYS_FUNC(semget)): Likewise.
* ipc_shm.c (SYS_FUNC(shmget)): Likewise.
* ipc_shmctl.c (print_shmid_ds): Likewise.
* mq.c (SYS_FUNC(mq_open)): Likewise.
* open.c (decode_open, SYS_FUNC(creat)): Likewise.
* umask.c (SYS_FUNC(umask)): Likewise.
* mknod.c (decode_mknod): Use print_symbolic_mode_t.
* printstat.h (DO_PRINTSTAT): Likewise.
* syscall.c (trace_syscall_exiting): Use print_numeric_long_umask.
* tests/umode_t.c: New file.
* tests/Makefile.am (EXTRA_DIST): Add it.
* tests/creat.c: Rewrite as a thin wrapper around umode_t.c
* tests/mkdir.c: Likewise.
* tests/mkdirat.c: Likewise.
* tests/mknod.c: Extend test coverage of mknod syscall.
* tests/mknodat.c: Extend test coverage of mknodat syscall.
* tests/umask.c: Extend test coverage of umask syscall.
* tests/creat.test: Update the value specified for strace -a parameter.
* tests/mkdir.test: Likewise.
* tests/mkdirat.test: Likewise.
* tests/mknodat.test: Likewise.
Dmitry V. Levin [Tue, 2 Aug 2016 16:47:34 +0000 (16:47 +0000)]
tests: simplify attach-f-p.test
* tests/attach-f-p.c Simplify communications between threads
by replacing per-thread timers with pipes.
* tests/attach-f-p.test: Do not ignore signals.
signalfd4.test: rewrite from match_grep to match_diff
* tests/signalfd4.c (get_sigset_size): New function.
(main): Use it. Print expected output.
* tests/signalfd4.test: Use run_strace_match_diff.
* tests/signalfd4.expected: Remove.
* tests/Makefile.am (EXTRA_DIST): Remove it.
Report the name of ptrace command when ptrace_attach_or_seize fails.
* strace.c (ptrace_attach_cmd): New variable.
(ptrace_attach_or_seize): Save last ptrace command's name
to ptrace_attach_cmd.
(attach_tcb, startup_child): Use it in error diagnostics.
This script has been created by commit v4.8-180-g0ed617b
for the one-shot job of automatic convertion of xlat structures
from *.c files to xlat/*.in files.
Consistently use extended regular expressions where appropriate
When grep or sed is used with basic regular expressions containing
'(', ')', '{', '}', '|', '?', and '+' special characters, convert them
to extended regular expressions for better portability and readability.
* xlat/ipccalls.in: New file.
* ipc.c: New file.
* Makefile.am (libstrace_a_SOURCES): Add it.
* linux/dummy.h (sys_ipc): Remove stub alias.
* syscall.c (decode_ipc_subcall): Treat 1st argument of ipc syscall
as "unsigned int".
[S390 || S390X]: Skip ipc cubcalls that have non-zero version.
[SPARC64]: Likewise, for the native personality.
Save ipc cubcall version for later use by specific ipc parsers.
* ipc_msg.c (SYS_FUNC(msgrcv)): Handle non-zero ipc subcall version.
[SPARC64]: Handle non-ipc_kludge case for the native personality.
* linux/subcall.h (msgrcv): Change nargs from 4 to 5.
* linux/s390/syscallent.h (ipc): Change nargs from 6 to 5.
* linux/s390x/syscallent.h (ipc): Likewise.
* tests/netlink_protocol.c: Check that HAVE_SYS_XATTR_H is defined.
Include <stdlib.h> and <sys/xattr.h>.
(main): Check that system.sockprotoname attribute is supported.
x32, mips n32: make printargs print full 64-bit syscall arguments
As most of x32 syscalls are regular x86_64 syscalls, they should be
printed by default as 64-bit syscalls, and syscall parsers at their
discretion might print syscalls differently. This is already
implemented in 64-bit strace tracing x32 personality processes,
and now x32 strace will also behave this way.
Similar reasoning applies to mips n32.
* util.c (printargs) [HAVE_STRUCT_TCB_EXT_ARG]: Print syscall arguments
from ext_arg array using %llx format.
* xlat/socketcalls.in: New file.
* socketcall.c: New file.
* Makefile.am (libstrace_a_SOURCES): Add it.
* linux/dummy.h (sys_socketcall): Remove stub alias.
* syscall.c (decode_socket_subcall): Treat 1st argument of socketcall
as "int". Do not substitute syscall until all socketcall arguments
have been fetched successfully.
* mmsghdr.c (decode_mmsgvec): Clear syserror for the time of printing
struct mmsghdr array in !use_msg_len case.
(SYS_FUNC(sendmmsg)): As failed sendmmsg syscall does not
set msg_len fields, tell this to decode_mmsgvec.
* tests/mmsg_name.c (test_mmsg_name): Check it.
* defs.h (decode_mmsgvec): Add int argument.
* mmsghdr.c (print_struct_mmsghdr_config): Add msg_len_vlen field.
(print_struct_mmsghdr): Print struct mmsghdr.msg_len only for
msg_len_vlen first elements of struct mmsghdr array.
(decode_mmsgvec): Add msg_len_vlen argument.
(SYS_FUNC(sendmmsg), SYS_FUNC(recvmmsg)): Pass to decode_mmsgvec
the number of elements of struct mmsghdr array that contain meaningful
struct mmsghdr.msg_len.
* tests/mmsg_name.c (test_mmsg_name): Check it.
Fix decoding of msg_name* fields of recvmmsg syscall's msghdr array argument
As msg_namelen fields of recvmmsg syscall's struct msghdr array have
the same read-write semantics as struct msghdr argument of recvmsg
syscall, parser of recvmmsg syscall needs a similar fix.
* mmsghdr.c (print_struct_mmsghdr): Increment p_user_msg_namelen field.
(mmsgvec_data): New structure.
(free_mmsgvec_data, save_mmsgvec_namelen): New functions.
(decode_mmsgvec): Take into account the data saved
by save_mmsgvec_namelen function.
(SYS_FUNC(recvmmsg)): Use save_mmsgvec_namelen.
mmsghdr.c: rewrite decode_mmsgvec using print_array
* fetch_struct_mmsghdr.c (sizeof_struct_mmsghdr): New mpers printer.
* mmsghdr.c: Include <limits.h>.
(print_struct_mmsghdr_config): New structure.
(fetch_struct_mmsghdr_or_printaddr, print_struct_mmsghdr): New functions.
(decode_mmsgvec): Rewrite using them and print_array.
tests: add recv_mmsg and send_mmsg functions to libtests
* tests/tests.h (recv_mmsg, send_mmsg): New prototype.
* tests/libmmsg.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
* tests/mmsg.c Do not check for __NR_sendmmsg, __NR_recvmmsg,
HAVE_SENDMMSG, and HAVE_RECVMMSG. Do not include unused headers.
(recv_mmsg, send_mmsg): Remove.
As we've got a proper mechanism that parsers can use for storing private
data between entering and exiting stages, all cases of struct tcb.auxstr
abuse should go.
* btrfs.c (btrfs_ioctl): Use set_tcb_priv_ulong and get_tcb_priv_ulong
instead of abusing tcp->auxstr.
* file_handle.c (SYS_FUNC(name_to_handle_at)): Likewise.
* msghdr.c (SYS_FUNC(recvmsg)): Likewise.
* net.c (decode_sockname, SYS_FUNC(recvfrom)): Likewise.
* v4l2.c (print_v4l2_queryctrl): Likewise.
Fix race condition in decoding timeout argument of recvmmsg syscall
As the value returned by sprint_timespec points to a static area and may
be overwritten by subsequent calls to sprint_timespec, it is not safe to
save this value on entering syscall and use it later on exiting.
* mmsghdr.c (SYS_FUNC(recvmmsg)): On entering syscall, copy the value
returned by sprint_timespec to a dynamically allocated memory, and save
the pointer using set_tcb_priv_data. On exiting, restore it using
get_tcb_priv_data.
Fix race condition in decoding rt_sigtimedwait's timeout argument
As the value returned by sprint_timespec points to a static area and may
be overwritten by subsequent calls to sprint_timespec, it is not safe to
save this value on entering syscall and use it later on exiting.
* signal.c (SYS_FUNC(rt_sigtimedwait)): On entering syscall, copy the
value returned by sprint_timespec to a dynamically allocated memory,
and save the pointer using set_tcb_priv_data. On exiting, restore it
using get_tcb_priv_data.
Patrik Jakobsson [Mon, 24 Aug 2015 12:42:47 +0000 (14:42 +0200)]
Add private data field to struct tcb
We need to be able to store private data in the struct tcb across it's
lifetime. To ensure proper deallocation of this stored data a callback
must be provided along with the data. The callback is executed
automatically on exiting syscall, and when the life of the tcb ends.
* defs.h (struct tcb): Add _priv_data and _free_priv_data fields.
(get_tcb_priv_data, set_tcb_priv_data, free_tcb_priv_data):
New prototypes.
(get_tcb_priv_ulong, set_tcb_priv_ulong): New static inline functions.
* strace.c (get_tcb_priv_data, set_tcb_priv_data, free_tcb_priv_data):
New functions.
(droptcb): Call free_tcb_priv_data.
* syscall.c (trace_syscall_exiting): Call free_tcb_priv_data
when clearing TCB_INSYSCALL flag.
Signed-off-by: Patrik Jakobsson <patrik.jakobsson@linux.intel.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Fix decoding of struct msghdr.msg_name* arguments of recvmsg syscall
As the msghdr.msg_namelen argument of recvmsg syscall has the same
read-write semantics as the address length argument of recvfrom syscall,
parser of recvmsg syscall needs a similar fix.
* defs.h (fetch_msghdr_namelen): New prototype.
(decode_msghdr): Add "int *" argument.
* msghdr.c (print_msghdr): Likewise. Treat it as a pointer to struct
msghdr.msg_namelen passed to the kernel. Pass to decode_sockaddr
the size of socket address actually returned by the kernel.
Print both user and kernel address lengths when the value changes.
(decode_msghdr, decode_mmsghdr): Add "int *" argument,
forward it to print_msghdr.
(decode_mmsgvec): Update decode_mmsghdr invocation.
(fetch_msghdr_namelen): New function.
* net.c (SYS_FUNC(sendmsg)): Update decode_msghdr invocation.
(SYS_FUNC(recvmsg)): Use fetch_msghdr_namelen on entering to save
struct msghdr.msg_namelen. On exiting, pass the saved value
to decode_msghdr.
* linux/64/ioctls_inc.h: Update from linux v4.7 using ioctls_gen.sh.
* linux/32/ioctls_inc_align32.h: Likewise.
* linux/32/ioctls_inc_align64.h: Likewise.
Fix decoding of sockaddr related arguments of recvfrom syscall
* net.c (SYS_FUNC(recvfrom)): Use fetch_socklen. Save the address
length passed to the kernel and print it on error. Do not print more
bytes of the socket address than actually returned by the kernel.
Print both user and kernel address lengths when the returned address
is truncated.
Print both values of changing address length in sockname family syscalls
* net.c (decode_sockname): Print both user and kernel address lengths
when the value changes.
* tests/net-y-unix.c (main): Update expected output.
* tests/net-yy-unix.c (main): Likewise.
* tests/net.expected: Likewise.