6355 Commits

Author SHA1 Message Date
Eugene Syromyatnikov
a4886a7f99 syscall.c: add sanity check for the target personality number
We can never be cautious enough.

* defs.h (set_personality): Change argument type to unsigned int.
* syscall.c (set_personality): Change argument type to unsigned int,
check whether requested personality is sane, die otherwise.
2018-01-16 22:54:38 +00:00
Eugene Syromyatnikov
1fd3b7e30a syscall.c: move current_personality check to set_personality
As all the personality-dependent entries are initially in sync, we can
move the check whether we are setting the same personality as we
currently are inside set_personality out of update_personality.

* syscall.c (current_wordsize, current_klongsize): Initialise to 0'th
personality value in order to make the statement about "all the
personality-dependent entries are initially in sync" true.
(set_personality): Check whether requested personality differs from
current_personality.
(update_personality): Call set_personality unconditionally.
2018-01-16 22:54:38 +00:00
Eugene Syromyatnikov
7d9a21fcba syscall.c: always update tcp->currpers in update_personality
Sometimes (for example, switching from a process with one personality
to a process that previously had different personality but returning
from execve to that same personality into) it is possible that
current_personality is not changed, but tcp->currpers is different.
So, let's not return from update_personality and always update
tcp->currpers if it differs from the target personality.

* syscall.c (update_personality): Do not exit early if personality ==
current_personality.
2018-01-16 22:54:38 +00:00
Eugene Syromyatnikov
396961b1b4 Update current_personality on tcb switch
* strace.c (set_current_tcp): New function.
(printleader, droptcb, print_event_exit, next_event, dispatch_event):
Call set_current_tcp instead of setting current_tcp manually.
2018-01-16 22:54:38 +00:00
Eugene Syromyatnikov
558ece68c8 Add support for specifying compiler options for mpers builds
Because some architectures are very, very special.

* configure.ac (cc_flags_m32, cc_flags_mx32): New variables. AC_SUBST
them.
* m4/mpers.m4 (MPERS_CFLAGS): Use instead of CFLAG, pushdef as
$cc_flags_$1.
Use mpers_name instead of CFLAG in AC_CACHE_CHECK messages.
Pass MPERS_CFLAGS as the second argument to mpers_test.sh
* mpers.sh: Add CC_ARCH_FLAGS as the second argument (PARSER_FILE
is moved to the third one). Do not expect leading dash in ARCH_FLAG
anymore.
* mpers_test.sh (mpers_cc_flags): New variable, initialise to the second
command line argument.
Pass $mpers_name without leading dash to mpers.sh.
Pass $mpers_cc_flags as the second argument to mpers.sh ($sample is
the third argument now).
* Makefile.am (mpers-m%.stamp:): Pass $(mpers_CC_FLAGS) as the second
argument to mpers.sh ($$f is now the third argument).
($(mpers_m32_targets)): Define target variable mpers_CC_FLAGS with the
value of @cc_flags_m32@
($(mpers_mx32_targets)): Define target variable mpers_CC_FLAGS with the
value of @cc_flags_mx32@
* tests/Makefile.am (MERS_CC_FLAGS): New variable.
* bootstrap: Append @cc_flags_$1@ to MPERS_CC_FLAGS. Append
$(MPERS_CC_FLAGS) to ARCH_MFLAGS.
2018-01-16 23:02:35 +01:00
114c7d3e80 tests: improve syscall set syntax testing
* tests/filtering_syscall-syntax.test: New file.
* tests/options-syntax.test: Move syscall set syntax testing
to filtering_syscall-syntax.test.
* tests/qual_fault-syntax.test: Likewise.
* tests/qual_inject-syntax.test: Likewise.
* tests/Makefile.am (MISC_TESTS): Add filtering_syscall-syntax.test.

Co-authored-by: Nikolay Marchuk <marchuk.nikolay.a@gmail.com>
2018-01-16 04:34:25 +00:00
69bd90eb80 Enhance error diagnostics about invalid syscalls in fault injection syntax
Validate syscall set before the whole fault injection syntax.

* filter_qualify.c (parse_inject_expression): Add const qualifier to
return type.  Return an empty string when no syscall set is specified.
(qualify_inject_common): Add const qualifier to "name".  Move
qualify_syscall_tokens invocation right after parse_inject_expression.
* tests/qual_fault-syntax.test: Update expected output.
* tests/qual_inject-syntax.test: Likewise.
2018-01-16 04:34:25 +00:00
e6d3c79d60 basic_filters: use loop initial declarations
* basic_filters.c (qualify_syscall_number, qualify_syscall_regex,
lookup_class, qualify_syscall_class, qualify_syscall_tokens,
qualify_tokens): Use "for" loop initial declarations.
2018-01-16 01:09:14 +00:00
f31ef8f967 filter_qualify: use loop initial declarations
* filter_qualify.c (sigstr_to_uint, find_errno_by_name,
parse_inject_expression, qualify_inject_common, qualify): Use "for" loop
initial declarations.
2018-01-16 01:09:14 +00:00
376cf85efe configure: try to set the C compiler mode to accept ISO Standard C
* configure.ac: Use AC_PROG_CC_STDC.
* NEWS: Mention this.
2018-01-16 01:09:14 +00:00
4ab21ae0b8 pathtrace: update the list of unrelated syscalls
* pathtrace.c (pathtrace_match_set) <SEN_accept4, SEN_accept,
SEN_signalfd4, SEN_signalfd>: Skip matching.
2018-01-15 23:33:18 +00:00
3782831620 basic_filters: move legacy tracing class names to the end of table
* basic_filters.c (lookup_class) <syscall_class>: Move names that do not
start with % to the end of table.
2018-01-15 22:58:48 +00:00
8672a7189d Enhance decoding of mq_* syscalls
* mq.c (SYS_FUNC(mq_open)): Add RVAL_FD to return value.
(SYS_FUNC(mq_timedsend), SYS_FUNC(mq_timedreceive), SYS_FUNC(mq_notify),
SYS_FUNC(mq_getsetattr)): Print the first argument using printfd.
* NEWS: Mention this change.
* pathtrace.c (pathtrace_match_set) <SEN_mq_getsetattr, SEN_mq_notify,
SEN_mq_open, SEN_mq_timedreceive, SEN_mq_timedsend>: Skip matching.
* linux/32/syscallent.h (mq_getsetattr, mq_notify, mq_open,
mq_timedreceive, mq_timedsend): Add TD flag.
* linux/64/syscallent.h: Likewise.
* linux/alpha/syscallent.h: Likewise.
* linux/arm/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/crisv10/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent-n32.h: Likewise.
* linux/mips/syscallent-n64.h: Likewise.
* linux/mips/syscallent-o32.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/powerpc64/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/sparc64/syscallent.h: Likewise.
* linux/x32/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.
* linux/xtensa/syscallent.h: Likewise.
2018-01-15 22:47:38 +00:00
24d48dde06 Enhance error diagnostics about invalid syscalls in fault injection syntax
* basic_filters.c (qualify_syscall_tokens): Remove "name" argument,
assume its value is "system call".
* filter.h (qualify_syscall_tokens): Remove "name" argument.
All callers updated.
* tests/qual_fault-syntax.test: Update expected output.
2018-01-15 18:16:31 +00:00
7ef06058e2 basic_filters: handle "all" in a more readable way
* basic_filters.c (qualify_syscall_tokens, qualify_tokens): Remove
handle_inversion label, handle "all" by invoking invert_number_set_array
directly.
2018-01-15 16:23:54 +00:00
5f2597ef21 filter: remove redundant braces around single line expressions
* basic_filters.c (qualify_syscall_class, qualify_syscall_name):
Rearrange the inner loop body.
(qualify_syscall_number, lookup_class, qualify_syscall_tokens,
qualify_tokens): Remove redundant braces around single line expressions.
* filter_qualify.c (qualify_inject_common): Likewise.
2018-01-15 16:23:54 +00:00
79a08404d8 filter_qualify: move memory allocation from parse_inject_expression
* filter_qualify.c (parse_inject_expression): Replace "s" and "buf"
arguments with "str" argument, use it instead of "s" and "*buf".
(qualify_inject_common): Rename "buf" to "copy", initialize it to a copy
of "str", pass "copy" to parse_inject_expression instead of "str" and
"buf".
2018-01-15 16:23:54 +00:00
Eugene Syromyatnikov
4e5033c8d2 xlat: update NT_* constants
Update NT_* descriptor types with the values borrowed from
kernel's include/uapi/linux/elf.h and glibc's elf.h.

* xlat/nt_descriptor_types.in (NT_PRSTATUS, NT_FPREGSET, NT_PRPSINFO,
NT_PRXREG, NT_TASKSTRUCT, NT_PLATFORM, NT_AUXV, NT_GWINDOWS, NT_ASRS,
NT_PSTATUS, NT_PSINFO, NT_PRCRED, NT_UTSNAME, NT_LWPSTATUS,
NT_LWPSINFO, NT_PRFPXREG, NT_PRXFPREG, NT_PPC_VMX, NT_PPC_SPE,
NT_PPC_VSX, NT_386_TLS, NT_386_IOPERM, NT_X86_XSTATE): Add fallback
definitions.
(NT_SIGINFO, NT_FILE, NT_PPC_*, NT_S390_*, NT_ARM_*, NT_METAG_*,
NT_ARC_V2): New constants.
* NEWS: Mention this.
2018-01-14 23:08:10 +00:00
752e6b4792 configure: use AC_MSG_ERROR and AC_MSG_FAILURE consistently
* configure.ac [$arch = mips]: Use AC_MSG_FAILURE instead of
AC_MSG_ERROR when _MIPS_SIM cannot be determined.  Use AC_MSG_ERROR
instead of AC_MSG_FAILURE when syscallent stubs cannot be generated.
2018-01-13 13:46:45 +00:00
Eugene Syromyatnikov
3eb199a29d configure: add --disable-mpers and --enable-mpers=check options
On architectures supporting multiple personalities, multiple
personalities support in strace is required for proper decoding of
structures used by tracees with personalities that differ from the
personality of strace.

New configure options control whether multiple personalities support
in strace is mandatory, optional, or disabled.

The default is changed from what is now equivalent of
--enable-mpers=check (automatically detect whether required mpers
support could be enabled) to --enable-mpers (terminate the build
if required mpers support could not be enabled).

* configure.ac (AC_ARG_ENABLE([mpers])): New option.
* m4/mpers.m4 (st_MPERS): Use enable_mpers.  Terminate the build
if mpers could not be enabled and enable_mpers==yes.
* strace.spec.in: Specify --enable-mpers=check to %configure.
* debian/rules (build/Makefile, build64/Makefile): Specify
--enable-mpers=check to configure.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Suggested-by: DJ Delorie <dj@redhat.com>
2018-01-11 23:09:56 +00:00
Gleb Fotengauer-Malinovskiy
649dd83545 Update ioctl entries from linux v4.15-rc7
* linux/32/ioctls_inc_align16.h: Update from linux v4.15-rc7 using ioctls_gen.sh.
* linux/32/ioctls_inc_align32.h: Likewise.
* linux/32/ioctls_inc_align64.h: Likewise.
* linux/64/ioctls_inc.h: Likewise.
* linux/x32/ioctls_inc0.h: Likewise.
* NEWS: Mention this.
2018-01-11 19:24:15 +00:00
Eugene Syromyatnikov
88fa069e35 Issue a warning when strace lacks tracee personality support
* defs.h (HAVE_PERSONALITY_1_MPERS, HAVE_PERSONALITY_2_MPERS): New
macros.
* syscall.c (update_personality): Add need_mpers_warning array
initialized with mpers support data.  Use it for printing the mpers
unavailability warning once per personality.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
671f2ffcdc tests: add more checks of reboot syscall decoding
In particular, check for the recent fixes in reboot syscall decoder.

* tests/gen_tests.in (reboot): Provide -s 256 option.
* tests/reboot.c (STR32, STR128): New macros.
(main): Add more checks.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
ce98c7b297 tests: use sprintrc in reboot.test
* test/reboot.c (main): Use sprintrc instead of old-style manual
printing of return code.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
395c90f71c reboot.c: limit printing of the fourth argument to 255 bytes
The size of kernel buffer is 256 bytes and the last byte is always zero.

* reboot.c (SYS_FUNC(reboot)): Replace printstr call with printstr_ex
with size of 255 and style flag QUOTE_0_TERMINATED.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
92eb77e8c3 reboot.c: use printxval instead of printflags
Numeric arguments of reboot syscall are not flags but magic values.

* reboot.c (SYS_FUNC(reboot)): Replace printflags with printxval.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
843369ebe1 Search for <libiberty/demangle.h> in addition to <demangle.h>
This is the location where this header is installed on Debian-based
systems.

* configure.ac: Check for libiberty/demangle.h in addition to
demangle.h.
* unwind.c [USE_DEMANGLE]: Include either <demangle.h> or
<libiberty_demangle.h> based on the presence of HAVE_DEMANGLE_H and
HAVE_LIBIBERTY_DEMANGLE_H macros.
2018-01-11 15:54:33 +00:00
459b13e1b8 strace.1: fix typo
* strace.1.in (.SH NOTES): Replace prlimit with prlimit64.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
b172dbf27a Document multiple personalities support
* strace.1.in (.SH "MULTIPLE PERSONALITY SUPPORT"): New section.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
7dbc3780a6 Add indication of mpers support to strace -V output
* strace.c (print_version): Append information about m32 and mx32
decoding support.
* tests/strace-V.test: Update expected output.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
5c3d4b631d Provide strace's native arch to the test framework
* configure.ac (arch_native): New variable, set to arch.
* tests/Makefile.am (NATIVE_ARCH): New variable, set to @arch_native@.
(AM_TEST_LOG_FLAGS): Pass NATIVE_ARCH as STRACE_NATIVE_ARCH environment
variable.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
8cea0b917a Add indication of optional demangle feature strace -V output
* strace.c (print_version) [USE_DEMANGLE]: Append " stack-demangle"
to the features string.
* tests/strace-V.test: Update expected output.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
54402590c3 configure.ac: check for mpers support on RISC-V
* confgure.ac (st_MPERS([m32])): Add riscv.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
0b803f8edd Use xappendstr instead of xsnprintf where suitable
Replace occurrences of

    outptr += xsnprintf(outptr, sizeof(outstr) - (outptr - outstr), ...)

with much more sleek

    outptr = xappendstr(outstr, outptr, ...)

* desc.c (decode_select): Replace xsnprintf with xappendstr.
* open.c (sprint_open_modes): Likewise.
* poll.c (decode_poll_exiting): Likewise.
* signal.c (sprintsigmask_n): Likewise.
* xlat.c (sprintflags): Likewise.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
fdec47f63f xstring.h: add xappendstr
Introduce a macro for handling common case of partial writes
to a character array.

* xstring.h (get_pos_diff_): New function.
(xappendstr): New macro.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
3b871d948f Update perf-related flags
- PERF_SAMPLE_BRANCH_TYPE_SAVE, added in v4.14-rc1~173^2~33^2~6
 - PERF_SAMPLE_PHYS_ADDR, added in v4.14-rc1~173^2~2

* xlat/perf_branch_sample_type.in (PERF_SAMPLE_BRANCH_TYPE_SAVE): New
flag.
* xlat/perf_event_sample_format.in (PERF_SAMPLE_PHYS_ADDR): Likewise.
* tests/perf_event_open.c: Update expected output.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
7527de8263 perf.c: add support for struct perf_event_attr.namespaces
This field was introduced by linux kernel commit v4.12-rc1~152^2~42^2~10.

* configure.ac (AC_CHECK_MEMBERS): Add  perf_event_attr.namespaces.
* perf_event_struct.h (struct perf_event_attr): Add namespaces field.
* perf.c (print_perf_event_attr): Print namespaces field.
Update comment for __reserved_1 field.
* tests/perf_event_open.c (struct pea_flags): Add namespaces field.
(print_event_attr): Update expected output.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
fd334b39b0 tests: check decoding of [gs]et_thread_area syscalls on x86
* tests/xet_thread_area_x86.c: New file.
* tests/xet_thread_area_x86.test: New test.
* tests/Makefile.am (DECODER_TESTS): Add it.
* tests/.gitignore: Add xet_thread_area_x86.
* tests/pure_executables.list: Likewise.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
692d8a6e54 tests: check decoding of modify_ldt with for 4-byte-available user_desc
Since there is possibility now that strace read only entry_number field
of the user_desc struct, let's check that it doesn't do it with
modify_ldt syscall.

* tests/modify_ldt.c (main): Add 4-byte-sized tail_alloc'ed variable.
Try to provide it as an argument to modify_ldt.
2018-01-10 01:57:53 +00:00
Eugene Syromyatnikov
0c7e458044 Allow separate printing of struct user_desc.entry_number
Kernel reads only entry_number field in the beginning of the
get_thread_area syscall handler.  Let's replicate this behaviour.

* defs.h (enum user_desc_print_filter): New enumeration.
(print_user_desc): Add an argument for signalling which part of the
structure should be printed.
* clone.c (print_tls_arg): Update print_user_desc call.
* ldt.c (print_user_desc): Add filter argument.  Print entry_number on
entering and the rest on exiting. Store entering value of the
entry_number field in order to print the updated value in the impossible
case of changed entry_number value.
(SYS_FUNC(modify_ldt), SYS_FUNC(set_thread_area)): Update
print_user_desc call.
(SYS_FUNC(get_thread_area)): Call print_user_desc with
USER_DESC_ENTERING format argument on entering and with
USER_DESC_EXITING on exiting.
2018-01-10 01:57:53 +00:00
Eugene Syromyatnikov
1e23e9aab8 tests: move struct user_desc printing function into a separate file
As part of preparation for the introduction of [gs]et_thread_area test.

* tests/modify_ldt.c (print_user_desc): Move it ...
* tests/print_user_desc.c: ... to new file.
* tests/Makefile.am (EXTRA_DIST): Add print_user_desc.c.
2018-01-10 01:57:53 +00:00
Eugene Syromyatnikov
ede97886b8 tests: check decoding of modify_ldt syscall
* tests/modify_ldt.c: New file.
* tests/gen_tests.in: Add modify_ldt test.
* tests/pure_executables.list: Add modify_ldt.
* tests/.gitignore: Likewise.
2018-01-08 00:40:22 +00:00
Eugene Syromyatnikov
8830aa8fca ldt.c: manually set modify_ldt's error code
* ldt.c (modify_ldt): Move parsing under entering(tcp). Check whether
return code is erroneous and set tcp->u_error appropriately along with
RVAL_PRINT_ERR_VAL flag.
2018-01-08 00:40:22 +00:00
Eugene Syromyatnikov
03cb7092d3 syscall.c: add support for printing return value and error code
Some weird syscalls (like modify_ldt) return value that doesn't indicate
an error (less than -4096), but it is, in fact, erroneous (because they
decide to clip the return value to 32-bit, for example).

Add a flag to print decoded error code along with syscall return value.

* defs.h (RVAL_PRINT_ERR_VAL): New rval flag.
* syscall.c (syscall_exiting_trace): Handle it.
2018-01-08 00:40:22 +00:00
Eugene Syromyatnikov
b65f452393 ldt.c: print the first argument of modify_ldt as int
* ldt.c (SYS_FUNC(modify_ldt)): Print the first argument as %d.
2018-01-08 00:40:22 +00:00
Eugene Syromyatnikov
916cb4ec13 ldt.c: print lm field for 64-bit tracees
* configure.ac (AC_CHECK_MEMBERS): Add struct user_desc.lm.
* ldt.c (print_user_desc) [HAVE_STRUCT_USER_DESC_LM]: Print lm field
for non-compat tracees (it is ignored for compat ones).
2018-01-08 00:40:22 +00:00
Eugene Syromyatnikov
3d51a91276 ldt.c: make struct user_desc output more structured
Also, while we are here, let's fix print qualifiers (which should be %u
and not %d).

* ldt.c (print_user_desc): Use PRINT_FIELD_* macros for printing
structure.
(SYS_FUNC(set_thread_area)): Change field key-value separator from ":"
to "=", change print format qualifier from %d to %u.
2018-01-08 00:40:22 +00:00
Eugene Syromyatnikov
03a7b946e2 print_fields.h: add PRINT_FIELD_U_CAST
Add a macro for printing fields explicitly casted to specific type.
This is useful for bit fields, as otherwise the magic of *_extend_to_*
macros breaks.

* print_field.h (PRINT_FIELD_U_CAST): New macro.
2018-01-08 00:40:22 +00:00
Eugene Syromyatnikov
45532079c6 print_fields.h: rename PRINT_FIELD_UID to PRINT_FIELD_ID
As uid is not the only thing that has a special treatment of the -1
value (and, as a result, needs special care), let's rename
PRINT_FIELD_UID to PRINT_FIELD_ID and make PRINT_FIELD_UID its alias.

* print_fields.h (PRINT_FIELD_ID): Rename from PRINT_FIELD_UID.
(PRINT_FIELD_UID): Define to PRINT_FIELD_ID.
2018-01-08 00:40:22 +00:00
a35f7f1fa1 Fix build on systems without linux/genetlink.h
* socketutils.c [!HAVE_LINUX_GENETLINK_H] (genl_families_xlat): Add
tcp argument.

Fixes: v4.20-134-gc46fefc ("Add tcp arguments to netlink calls")
2018-01-07 23:23:01 +00:00