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.
Dmitry V. Levin [Wed, 16 Nov 2016 17:26:58 +0000 (17:26 +0000)]
Implement syscall fault injection
Introduce new -e fault=EXPR syntax that can be used to specify a subset
of syscalls that are subject of syscall fault injection, an error code
that has to be injected, and a frequency of injection.
The expression specifying syscall fault injection has the following
format: SET[:error=ERRNO][:when=FIRST[+[STEP]]]
where only SET is a required part and all the rest is optional.
The method used to implement syscall fault injection is the following:
on entering syscall the syscall number is substituted by an invalid
syscall number -1, and on exiting syscall the error code returned by
the kernel is substituted with the error code specified in the fault
expression.
This implementaion is based on the prototype developed
by Nahim El Atmani as a part of his GSoC 2016 strace project.
* defs.h (struct fault_opts): New forward declaration.
(struct tcb): Add fault_vec field.
(TCB_FAULT_INJ, QUAL_FAULT): New macros.
* strace.1: Document -e fault expression syntax.
* strace.c (usage): Mention -e fault expression.
(droptcb): Deallocate fault_vec member.
* syscall.c (qual_fault, arch_set_scno, arch_set_error): New prototypes.
(qual_options): Add "fault" option.
(struct fault_opts): New structure.
(num_faults): New variable.
(fault_vec): New array.
(syscall_fault_injected, tcb_fault_opts, reallocate_fault,
find_errno_by_name, qual_syscall_ex, strip_prefix, parse_fault_token,
parse_fault_expression, qual_fault, inject_syscall_fault_entering,
update_syscall_fault_exiting): New functions.
(qual_syscall): Use qual_syscall_ex.
(qualify_one): Add argument: a pointer to struct fault_opts, all callers
changed. Copy struct fault_opts from the pointer to fault_vec.
Use reallocate_fault.
(qualify_scno, qualify_syscall_class, qualify_syscall_name): Add
argument: a pointer to struct fault_opts.
(qualify): Use reallocate_fault. Do not check "all" class for
QUAL_FAULT qualifier.
(lookup_class): Check for "all" class.
(trace_syscall_entering): Use inject_syscall_fault_entering.
(trace_syscall_exiting): Use update_syscall_fault_exiting. Clear
TCB_FAULT_INJ flag along with TCB_INSYSCALL. Print " (INJECTED)" suffix
when the syscall has been injected successfully.
[ARCH_REGS_FOR_GETREGSET && !HAVE_GETREGS_OLD]
(ptrace_setregset): New function.
(ptrace_setregset_or_setregs): Define to ptrace_setregset.
[ARCH_REGS_FOR_GETREGS && !HAVE_GETREGS_OLD]
(ptrace_setregs): New function.
(ptrace_setregset_or_setregs): Define to ptrace_setregs.
[ptrace_setregset_or_setregs] (set_regs): New function.
Include "set_scno.c" and "set_error.c"
* NEWS: Mention this enhancement.