Dmitry V. Levin [Tue, 6 Dec 2016 01:54:13 +0000 (01:54 +0000)]
tests: robustify attach-f-p.test against race conditions
Introduce a synchronization mechanism between attach-f-p and strace.
* tests/attach-f-p-cmd.c: New file.
* tests/Makefile.am (check_PROGRAMS): Add attach-f-p-cmd.
* tests/attach-f-p.c: Include <sys/stat.h>.
(main): Write to stdout instead of descriptor 3. Wait for the peer
writing to stdout.
* tests/attach-f-p.test: Assume that ./attach-f-p-cmd works.
Use $OUT for expected output. Use attach-f-p-cmd for unlocking $OUT.
Dmitry V. Levin [Tue, 6 Dec 2016 00:32:06 +0000 (00:32 +0000)]
tests: robustify attach-p-cmd.test against race conditions
Introduce a synchronization mechanism between attach-p-cmd-p
and attach-p-cmd-cmd processes.
* tests/attach-p-cmd-cmd.c: Include <errno.h> and <sys/stat.h>.
(main): Wait for the lock directory creation by attach-p-cmd-p.
* tests/attach-p-cmd-p.c: Include <errno.h> and <sys/stat.h>.
(main): Create a lock directory and wait for its removal
by attach-p-cmd-cmd.
* tests/attach-p-cmd.test: Assume that test programs work.
Dmitry V. Levin [Sat, 3 Dec 2016 22:37:19 +0000 (22:37 +0000)]
Rewrite qual_signal using bit sets
* defs.h (signal_set): New variable prototypes.
(qualify_signals): New function prototypes.
(QUAL_SIGNAL): Change to a value greater than 0xff.
(QUAL_FAULT): Change to a lower value.
* qualify.c (signal_set): New variable.
(sigstr_to_uint, qualify_signals): New functions.
* syscall.c (qual_signal): Remove.
(qual_options): Replace qual_signal with NULL.
(qualify): Use qualify_signals.
* strace.c (print_signalled, print_stopped): Use is_number_in_set
with signal_set argument.
Dmitry V. Levin [Fri, 2 Dec 2016 22:16:40 +0000 (22:16 +0000)]
Rewrite qual_desc using bit sets
As a side effect, this also fixes support of negated sets
of descriptors.
* defs.h (struct number_set): New forward declaration.
(read_set, write_set): New variable prototypes.
(is_number_in_set, qualify_read, qualify_write): New function
prototypes.
(QUAL_READ, QUAL_WRITE): Change to values greater than 0xff.
* qualify.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* syscall.c (qual_desc): Remove.
(qual_options): Replace qual_desc with NULL.
(qualify): Use qualify_read and qualify_write.
(dumpio): Use is_number_in_set.
* tests/options-syntax.test: Check invalid sets of descriptors.
* tests/readv.test: Check dumping of negated sets of descriptors.
Dmitry V. Levin [Mon, 5 Dec 2016 10:34:33 +0000 (10:34 +0000)]
tests: skip redirect-fds.test when strace is wrapped with valgrind
valgrind is not as transparent as strace wrt standard descriptors,
so if strace is wrapped with valgrind, the test would check valgrind
transparency properties and fail imminently.
* tests/redirect-fds.test: Skip the test when $STRACE shows a presence
of valgrind.
Dmitry V. Levin [Mon, 5 Dec 2016 00:58:36 +0000 (00:58 +0000)]
tests: make options-syntax.test tolerant of strace wrappers
Change the test to allow wrappers like STRACE="valgrind ./strace".
* tests/options-syntax.test: Strip all words but last from $STRACE
variable in all contexts where the name of strace executable is expected
in its output.
* uid.c (setfsuid, get_print_uid, print_gid): Use printuid.
* tests/setfsugid.c (printuid): New function.
(main): Use it to print UID/GID values.
* tests/setgroups.c: Likewise.
* tests/setugid.c (ugid2int): Remove.
(printuid): New function.
(main): Use it to print UID/GID values.
The string literal "__NR_syscall_4294967295" is semantically incorrect
as there is no such constant defined.
* syscall.c (syscall_name): Return NULL if there is no syscall
corresponding to the given number.
* defs.h (syscall_name): Document this behaviour.
* printsiginfo.c (print_si_info): Print syscall name with "__NR_" prefix
only if there is a syscall corresponding to si_syscall number; print
a plain syscall number otherwise.
* tests/ptrace.c (main): Update expected output.
* print_statfs.c: Print f_fsid as a structure containing field "val"
which, in turn, is an array of two elements that used to be printed
as members of f_fsid structure.
* tests/statfs.expected: Update expected output.
* tests/xstatfsx.c (print_statfs): Likewise.
* swapon.c (SYS_FUNC(swapon)): Do not check for non-zero the value
of the prio variable in order to print it.
* tests/swap.c (main): Update expected output.
Dmitry V. Levin [Tue, 29 Nov 2016 22:56:49 +0000 (22:56 +0000)]
Fix dumping of io syscalls when descriptor argument has unused bits set
* syscall.c (dumpio): Explicitly cast the first argument of syscall
to "int", the same way as the kernel does.
* tests/read-write.c: Include <asm/unistd.h> and "kernel_types.h".
(k_read, k_write): New functions.
(test_dump, main): Use them.
Dmitry V. Levin [Tue, 29 Nov 2016 19:51:15 +0000 (19:51 +0000)]
x32: fix preadv2-pwritev2.test
* tests/preadv2-pwritev2.c: Include "kernel_types.h".
(main): Use kernel_ulong_t instead of unsigned long as types
of arguments of preadv2 and pwritev2 syscalls.
Elvira Khabirova [Sat, 13 Aug 2016 17:27:38 +0000 (20:27 +0300)]
Make date output format conform to ISO 8601
* util.c (sprinttime): Make date output conform to ISO 8601.
* tests/utime.c (print_tm): Update expected output.
* tests/xstatx.c (print_time): Likewise.
Dmitry V. Levin [Tue, 29 Nov 2016 02:11:48 +0000 (02:11 +0000)]
Fix meaning of negated sets in fault expressions
Change the parser of fault expression to follow the POLA:
-e fault=!SET
means that all syscalls except those from SET are subject to fault
injection;
-e fault=!SET1:error=ERRNO1, -e fault=!SET2:error=ERRNO2
means that all syscalls except those from SET2 are subject to fault
injection with error code ERRNO2, and all syscalls from SET2 that are
not in SET1 are subject to fault injection with error code ERRNO1.
* syscall.c (qualify_scno, qualify_syscall_class, qualify_syscall_name):
Handle negated QUAL_FAULT case differently.
* tests/fault_syntax.test: Add checks of negated sets.
utime: fix omission of field names in utimbuf structure printing
* utime.c (SYS_FUNC(utime)): Print struct utimbuf as a structure,
not as an array (use curly brackets instead of square ones).
Add field names to the output.
* tests/utime.c (main): Update expected output.
util: provide information whether xlat value has been found
This is necessary for the upcoming change in the output format
of the val3 argument of the FUTEX_WAKE_OP futex command.
* defs.h (printxvals, printxval_searchn): Change return type to int.
(printxval64, printxval, printxval_long): Likewise. Forward the value
returned by printxvals call.
* util.c (printxvals, printxval_searchn): Change return type to int,
return 1 if xlat value has been found, 0 otherwise.
Dmitry V. Levin [Mon, 28 Nov 2016 19:46:50 +0000 (19:46 +0000)]
aarch64, arm, sparc: add comments on fault injection support in kernel
* linux/aarch64/set_scno.c: Note the kernel commit that introduced
NT_ARM_SYSTEM_CALL support.
* linux/arm/set_scno.c: Note the kernel commit that introduced
PTRACE_SET_SYSCALL support.
* linux/sparc/set_scno.c: Note the kernel commit that introduced
reloading from the syscall number register.
Dmitry V. Levin [Mon, 28 Nov 2016 15:03:08 +0000 (15:03 +0000)]
Fix -r option syntax
While -r option implies -t, it should not literally have the effect
of -t option, e.g. -rr should not increment tflag twice.
* strace.c (init): In the getopt loop, do not increment tflag for each
occurrence of -r option. After the getopt loop, if rflag is set, set
tflag to 1. Issue a warning that -tt has no effect with -r.
* print_timeval.c (print_timeval_item): New function.
(print_timeval_pair): Use it as a print_function in print_array call.
* tests/futimesat.c (main): Update to test new behaviour.
* tests/utimes.c (main): Likewise.
Dmitry V. Levin [Mon, 28 Nov 2016 04:21:11 +0000 (04:21 +0000)]
alpha: print struct timeval32 consistently
* defs.h [ALPHA] (timeval32_t): New type.
[ALPHA] (print_timeval32_t): New prototype.
* print_timeval.c [ALPHA] (timeval32_t): Remove.
[ALPHA] (print_timeval32_t): Remove static keyword.
* printrusage.c [ALPHA] (printrusage32): Use timeval32_t instead
of local definition of struct timeval32. Use print_timeval32_t.
Dmitry V. Levin [Mon, 28 Nov 2016 02:45:13 +0000 (02:45 +0000)]
Split print_time.c
After commit v4.14-136-g151d1d1 that removed the last object common
for timespec and timeval parsers there is no need to keep them all
in a single file.
* print_timespec.c: New file.
* print_timeval.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* print_time.c: Move all timespec related code to print_timespec.c.
Move all timeval related code to print_timeval.c.
Dmitry V. Levin [Sat, 26 Nov 2016 23:45:05 +0000 (23:45 +0000)]
Set PTRACE_O_TRACEEXIT option and handle PTRACE_EVENT_EXIT events
Do not assume that some syscalls do not generate syscall-exit-stops.
When syscalls fail for any reason they may generate syscall-exit-stops.
The solution is to wait for an actual exit reported by PTRACE_EVENT_EXIT
and print the end of unfinished exiting syscall properly.
* exit.c: Remove.
* Makefile.am (strace_SOURCES): Remove exit.c.
* linux/dummy.h (sys_exit): Alias to printargs_d.
* strace.c (ptrace_setoptions): Add PTRACE_O_TRACEEXIT bit.
(print_event_exit): New function.
(trace): Use it in case of PTRACE_EVENT_EXIT.
* syscall.c (trace_syscall_entering): Remove special handling
of SEN_exit.
Dmitry V. Levin [Sun, 27 Nov 2016 14:19:09 +0000 (14:19 +0000)]
Change printargs to return RVAL_DECODED
As printargs is invoked as a generic syscall decoder only and
it is not supposed to print anything on exiting, change printargs
to return RVAL_DECODED so it would not be called on exiting at all.
Dmitry V. Levin [Sat, 26 Nov 2016 18:08:01 +0000 (18:08 +0000)]
Move two global flags to tracee scope
A simultaneous use of -p option and tracing of a command available
since commit v4.11-183-gfa8c286 introduces a race condition because
the flags whether the first exec has happened are global.
Fix the race by moving hide_log_until_execve and hide_log_until_execve
global variables to TCB_HIDE_LOG and TCB_SKIP_DETACH_ON_FIRST_EXEC bits
in struct tcb.flags, correspondingly.
* defs.h (TCB_HIDE_LOG, TCB_SKIP_DETACH_ON_FIRST_EXEC, hide_log):
New macros.
(hide_log_until_execve): Remove prototype.
* strace.c (skip_one_b_execve, hide_log_until_execve): Remove.
(startup_child): Set TCB_HIDE_LOG and TCB_SKIP_DETACH_ON_FIRST_EXEC bits
in the allocated tcb structure.
(init): Remove initialization of hide_log_until_execve and
skip_one_b_execve.
(print_stopped): Use hide_log() instead of hide_log_until_execve.
(trace): Check and clear TCB_SKIP_DETACH_ON_FIRST_EXEC flag instead
of skip_one_b_execve.
* syscall.c (trace_syscall_entering): Clear TCB_HIDE_LOG flag instead of
hide_log_until_execve.
(trace_syscall_entering, trace_syscall_exiting): Check hide_log()
instead of hide_log_until_execve.
Dmitry V. Levin [Fri, 25 Nov 2016 23:47:32 +0000 (23:47 +0000)]
Change parser of fault expressions to conform the documentation
Make expressions like fault=SYSCALL1,SYSCALL2:error=EPERM work
as documented, i.e. fail both SYSCALL1 and SYSCALL2 with EPERM.
* syscall.c (parse_fault_expression): Remove const qualifier from
"name" and "token: variables, as well as from the return value.
(qual_fault): Remove const qualifier from "name" variables.
Split "name" into comma delimited tokens and pass each token
to individual qual_syscall_ex call.
(qualify): For QUAL_FAULT options, pass the whole option value
to their qualify methods without prior splitting into comma
delimited tokens.
* tests/fault_injection.test: Check it.
* tests/fault_syntax.test: Check empty syscall sets.
Dmitry V. Levin [Tue, 22 Nov 2016 00:20:49 +0000 (00:20 +0000)]
maint: add more workarounds for alpha and powerpc
* maint/ioctls_sym.sh: Skip asm/core_*.h. Filter out from
asm-generic/ioctls.h those macros that are defined using unavailable
struct termios2 on alpha and powerpc.
Dmitry V. Levin [Mon, 21 Nov 2016 16:08:08 +0000 (16:08 +0000)]
maint: rework workarounds for linux/kvm.h
* maint/ioctls_sym.sh: Remove pre-include linux/kvm.h workarounds.
Skip linux/kvm.h on those architectures that have no asm/kvm.h file.
Introduce post-process workarounds, add post-process workarounds
for linux/kvm.h.
The prctl syscall does not use compat on x32/n32, so argument types
are in fact kernel_ulong_t.
* prctl.c (print_prctl_args): Use getarg_ull, print as "%#llx" instead
of "%#lx".
(SYS_FUNC(prctl)): Use getarg_ull to store call arguments in arg2, arg3,
arg4, arg5 variables of type unsigned long long. Use them in printing
routines.
(SYS_FUNC(arch_prctl)): Use getarg_ull to store call argument in addr
variable of type unsigned long long. Print it as "%#llx" instead of
"%#lx".
This is done in order to fix build error on old distributions where
struct blkpg_ioctl_arg declaration is broken:
In file included from block.c:35:
/usr/include/linux/blkpg.h:36: error: expected ':', ',', ';', '}' or '__attribute__' before '*' token
block.c: In function 'print_blkpg_req':
block.c:113: error: 'struct_blkpg_ioctl_arg' has no member named 'data'
(from SLE10)
* block.c: Include <linux/ioctl.h> instead of <linux/blkpg.h>.
(BLKPG, BLKPG_DEVNAMELTH, BLKPG_VOLNAMELTH): New macros.
(struct_blkpg_ioctl_arg, struct_blkpg_partition): New definitions,
copied from blkpg_ioctl_arg and blkpg_partition structures defined
in <linux/blkpg.h>.
Dmitry V. Levin [Sun, 20 Nov 2016 00:38:34 +0000 (00:38 +0000)]
prctl: fix printing of PR_SET_NAME's argument
* prctl.c (SYS_FUNC(prctl)): Use printstr_ex with QUOTE_0_TERMINATED
instead of printstr to print the argument of PR_SET_NAME and PR_GET_NAME
operations.
Dmitry V. Levin [Sun, 20 Nov 2016 00:29:46 +0000 (00:29 +0000)]
printstr_ex: fix handling of last byte when QUOTE_0_TERMINATED bit set
* util.c (printstr_ex): Simplify handling of size == 0 case.
Do not artificially decrement size when QUOTE_0_TERMINATED bit is set.
Ensure that str[size] byte is non-zero if it hasn't been fetched.
Dmitry V. Levin [Sat, 19 Nov 2016 21:01:03 +0000 (21:01 +0000)]
printstr_ex: handle QUOTE_0_TERMINATED bit consistently
When user_style has QUOTE_0_TERMINATED bit set, printstr_ex prints
the fetched string as a NUL-terminated.
After this change, the string is being fetched as a NUL-terminated, too.
* util.c (printstr_ex): Use umovestr instead of umoven
if QUOTE_0_TERMINATED bit is set.
Dmitry V. Levin [Fri, 18 Nov 2016 13:23:03 +0000 (13:23 +0000)]
Update V4L2_* constants
* xlat/v4l2_device_capabilities_flags.in: Add V4L2_CAP_TOUCH introduced
by linux kernel commit v4.9-rc4~7^2~422.
* xlat/v4l2_input_types.in: Add V4L2_CAP_TOUCH introduced
by linux kernel commit v4.9-rc4~7^2~422.
Dmitry V. Levin [Fri, 18 Nov 2016 00:51:37 +0000 (00:51 +0000)]
tests: fix btrfs build error on some old systems
Fix the following build error on SLE 11 SP4:
btrfs.c: In function 'btrfs_test_dev_replace_ioctl':
btrfs.c:1570: error: unknown field 'start' specified in initializer
* tests/btrfs.c (btrfs_test_dev_replace_ioctl): Move initialization
of struct btrfs_ioctl_dev_replace_args.start.srcdevid out of the
designated initializer.
Dmitry V. Levin [Thu, 17 Nov 2016 15:44:21 +0000 (15:44 +0000)]
Make -e fault= expressions cumulative
Change the way how subsequent -e fault= expressions are interpreted
to implement a cumulative behavior. For example,
-e fault=file:when=3+ -e fault=chdir
now specifies that all chdir syscalls and 3+ file related syscalls
except chdir are subject for fault injection.
* syscall.c (qualify): Do not reset qual_vec for QUAL_FAULT.
* tests/fault_injection.test: Check it.