btrfs: use umove_or_printaddr_ignore_syserror instead of u_error mangling
* btrfs.c (MPERS_PRINTER_DECL(btrfs_ioctl)) <case
BTRFS_IOC_TREE_SEARCH_V2>: Use umove_or_printaddr_ignore_syserror
instead of tcp->u_error mangling around umove_or_printaddr call.
* defs.h (umove_or_printaddr64_ignore_syserror): New macro, a thin
wrapper around umoven_or_printaddr64_ignore_syserror.
(umove_or_printaddr_ignore_syserror): New macro, a thin wrapper around
umoven_or_printaddr_ignore_syserror.
As there are some possible users for it, apparently.
* defs.h (XLAT_STYLE_FORMAT_MASK): Update the value in order to
accommodate XLAT_STYLE_FMT_D.
(enum xlat_style) <XLAT_STYLE_FMT_D>: New enumeration entity.
(printxval64_d, printxval_d): New function, a shorthand for
printxvals_ex with a single xlat and XLAT_STYLE_FMT_D xlat style.
* xlat.c (sprint_xlat_val): Handle XLAT_STYLE_FMT_D.
Since xlat printing routines now have a notion of "style" that should be
used for printing xlat values, we can also employ this argument for
passing information about number printing format (unsigned decimal
or hexadecimal, so far).
* defs.h (XLAT_STYLE_FORMAT_SHIFT, XLAT_STYLE_FORMAT_MASK): New macro
constant.
(enum xlat_style) <XLAT_STYLE_FMT_X, XLAT_STYLE_FMT_U>: New enumeration
entities.
* xlat.c (xlat_verbose, xlat_format): New macro for checking specific
aspect of style argument.
(get_xlat_style): Use xlat_verbose for checking xlat verbosity style.
(sprint_xlat_val, print_xlat_val): New function, for easing printing
raw constant number with respect to printing format style.
(printxvals_ex, sprintxval_ex, printxval_searchn_ex,
printxval_searchn_ex, sprintflags_ex, printflags_ex, print_xlat_ex):
Use xlat_verbose macro for xlat verbosity style checks. Use
print_xlat_val instead of direct raw xlat value printing.
* futex.c [!FUTEX_OP_OPARG_SHIFT] (FUTEX_OP_OPARG_SHIFT): New macro
constant.
(SYS_FUNC(futex)): Use print_xlat for printing FUTEX_OP_OPARG_SHIFT
named constant.
print_xlat_ex prints a named constant in accordance with xlat style
provided, print_xlat is a thin wrapper around print_xlat_ex that passes
stringified constant name as a string and XLAT_STYLE_DEFAULT as a style.
* defs.h (print_xlat_ex): New function prototype.
(print_xlat): New macro, a thin wrapper around print_xlat_ex.
* xlat.c (print_xlat_ex): New function.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
This will be needed later, with the introduction of user-configurable
xlat style setting (stored in xlat_verbosity variable).
* defs.h (XLAT_STYLE_VERBOSITY_MASK): New macro constant.
(enum xlat_style) <XLAT_STYLE_DEFAULT>: New enumeration entity.
(xlat_verbosity): New external declaration.
(printxvals, printxval_searchn, printxval_search_ex, sprintxval,
sprintflags, printflags64): Use XLAT_STYLE_DEFAULT instead of
XLAT_STYLE_ABBREV.
* strace.c (xlat_verbosity): New variable.
* xlat.c (get_xlat_style): New function.
(printxvals_ex, sprintxval_ex, printxval_searchn_ex, sprintflags_ex,
printflags_ex): Use it.
* defs.h (printxvals_ex): Rename from printxvals, add style argument.
(enum xlat_style): New enumeration.
(printxvals): New macro, a wrapper for printxvals_ex.
(printxval_searchn_ex): Rename from printxval_searchn, add style
argument.
(printxval_searchn): New macro, a wrapper for printxval_searchn_ex.
(printxval_search_ex): New macro, a wrapper for printxval_searchn_ex.
(sprintxval_ex): Rename from sprintxval, add style argument.
(sprintxval): New macro, a wrapper for sprintxval_ex.
(printflags_ex): Add style argument.
(sprintflags_ex): Rename from sprintflags, add style argument.
(sprintflags): New macro, a wrapper for sprintflags_ex.
(printflags64): Pass XLAT_STYLE_ABBREV as a style in printflags_ex call.
* netlink.c (decode_nlmsg_flags): Pass XLAT_STYLE_ABBREV as a style in
printflags_ex call.
* xlat.c (printxvals_ex): Rename from printxvals, add style argument,
handle it.
(sprintxval_ex): Rename from sprintxval, add style argument, handle it.
(printxval_searchn_ex): Rename from printxval_searchn, add style
argument, handle it.
(sprintflags_ex): Rename from sprintflags, add style argument,
handle it.
(printflags_ex): Add style argument, handle it.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
References: https://github.com/strace/strace/issues/27
tests: robustify signal delivery test against kernel bugs
Recent kernel siginfo changes, namely, v4.14-rc1~60^2^2~1,
v4.16-rc1~159^2~37, and v4.16-rc1~159^2~39, introduced ABI regressions
that render the whole siginfo interface unreliable.
Looks like the kernel side is not eager to fix the breakage,
so here is a workaround.
* tests/signal_receive.c (s_sig, s_code, s_pid, s_uid): New volatile
variables.
(handler): Add siginfo_t parameter, save siginfo_t fields.
(sig_print): Remove.
(main): Rewrite. Use variables saved by handler to print expected
siginfo output. Print diagnostics in case of siginfo mismatch.
* strace.spec.in (%check): Extract the diagnostics.
* tests/strace-k.test: When actual strace -k output doesn't match the
expected output because of limited architecture support, skip the test
on architectures that are not currently supported by libdw.
tests: check corner cases of udev_monitor_netlink_header decoding
* tests/netlink_kobject_uevent.c (test_nlmsg_type_kernel): Create
a tail-allocated udev_monitor_netlink_header object and pass it
to sys_send.
(test_nlmsg_type_udev): Likewise. Check decoding of
udev_monitor_netlink_header object that ends in unmapped memory region.
tests: check decoding of udev_monitor_netlink_header
* tests/netlink_kobject_uevent.c: Include <string.h>, <arpa/inet.h>,
and "netlink_kobject_uevent.h".
(test_nlmsg_type_udev, test_nlmsg_type_kernel): New functions.
(main): Use them.
BPF_PROG_QUERY was introduced in Linux commit v4.15-rc1~84^2~558^2~6.
* xlat/bpf_commands.in (BPF_PROG_QUERY): New constant.
* xlat/bpf_query_flags.in: New file.
* bpf.c: Include it.
(DECL_BPF_CMD_DECODER): Add priv argument for passing tcb private data.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): New function.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Add BPF_PROG_QUERY entry.
(SYS_FUNC(bpf)): Fetch buf on entering and exiting, pass buf on exiting,
retrieve private data on exiting, pass it to decoder as well, explicitly
rework rc handling logic for size argument printing.
* bpf_attr.h (struct BPF_PROG_QUERY_struct): New structure declaration.
(BPF_PROG_QUERY_struct_size, expected_BPF_PROG_QUERY_struct_size): New
macro.
* tests/bpf.c: Add checks for BPF_PROG_QUERY command.
Counterparts for umoven_or_printaddr/umoven_or_printaddr_ignore_syserror
that always print 64 bits of addr (as this is needed in bpf and btrfs
decoders).
* util.c (umoven_or_printaddr64): Rename from umoven_or_printaddr,
change addr argument type to uint64_t, call printaddr64 instead of
printaddr.
(umoven_or_printaddr64_ignore_syserror): Rename from
umoven_or_printaddr_ignore_syserror, change addr argument type to
uint64_t, call printaddr64 instead of printaddr.
* defs.h (umoven_or_printaddr64): Rename from umoven_or_printaddr,
change addr argument type to uint64_t.
(umoven_or_printaddr64_ignore_syserror): Rename from
umoven_or_printaddr_ignore_syserror, change addr argument type to
uint64_t.
(umove_or_printaddr64): New macro, a wrapper for umoven_or_printaddr64.
(umoven_or_printaddr): New function, a wrapper for
umoven_or_printaddr64.
(umoven_or_printaddr_ignore_syserror): New function, a wrapper for
umoven_or_printaddr64_ignore_syserror.
unwind: prepare configure subsystem for alternative unwinders
Introduce --enable-stacktrace configure option to control whether
-k option support is compiled in, --with-libunwind option remains
available to control whether libunwind can be used as an unwinder.
* m4/st_demangle.m4: New file.
* m4/st_libunwind.m4: Likewise.
* m4/st_stacktrace.m4: Likewise.
* configure.ac: Replace all libunwind and libiberty checks
with a single st_STACKTRACE invocation.
* Makefile.am: Conditionalize checks for USE_LIBUNWIND and USE_DEMANGLE
on ENABLE_STACKTRACE.
[ENABLE_STACKTRACE] (strace_SOURCES): Append unwind.c and unwind.h.
* strace.1.in: Replace libunwind with an unwinder-agnostic wording.
* defs.h: Replace USE_LIBUNWIND with ENABLE_STACKTRACE.
* strace.c: Likewise.
(print_version): Print stack-trace instead of stack-unwind.
* syscall.c: Replace USE_LIBUNWIND with ENABLE_STACKTRACE.
* tests/Makefile.am: Likewise. Replace LIBUNWIND_TESTS
with STACKTRACE_TESTS.
* tests/strace-V.test: Update expected output.
bpf: implement decoding of prog_name and prog_ifindex fields
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Add support for decoding
of prog_name (introduced in Linux commit v4.15-rc1~84^2~605^2~4) and
prog_ifindex (introduced as prog_target_ifindex in v4.15-rc1~84^2~127^2~13,
renamed in v4.15-rc1~15^2~5^2~3^2~7).
* bpf_attr.h [!BPF_OBJ_NAME_LEN] (BPF_OBJ_NAME_LEN): New macro constant.
[BPF_OBJ_NAME_LEN]: Check that BPF_OBJ_NAME_LEN is equal to 16.
(struct BPF_PROG_LOAD_struct): Add prog_name and prog_ifindex fields.
(BPF_PROG_LOAD_struct_size, expected_BPF_PROG_LOAD_struct_size): Update.
* tests/bpf.c (init_BPF_PROG_LOAD_attr): Rename
to init_BPF_PROG_LOAD_attr3.
(print_BPF_PROG_LOAD_attr): Rename to print_BPF_PROG_LOAD_attr3.
(init_BPF_PROG_LOAD_attr4, print_BPF_PROG_LOAD_attr4): New functions.
(BPF_PROG_LOAD_checks): Check new decoding features.
Masatake YAMATO [Tue, 13 Mar 2018 17:28:09 +0000 (02:28 +0900)]
unwind: rename public functions in an object-oriented fashion
This change renames functions exported to strace core part from unwind
subsystem.
The new names imply that unwind subsystem exports two types of
functions. One is for manipulating back-end itself, "unwind_" prefix
is used for this type. Another is for manipulating back-end private data
structure (unwind_ctx) attached to tcb, "unwind_tcb_" is used for this
type.
This naming should help people to understand unwind subsystem
and the relation between unwind subsystem and back-ends.
* defs.h (unwind_print_stacktrace): Rename to unwind_tcb_print.
(unwind_capture_stacktrace): Rename to unwind_tcb_capture.
* unwind.c: Ditto.
* syscall.c (syscall_entering_trace, syscall_exiting_trace): Use
new names.
Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Masatake YAMATO [Tue, 13 Mar 2018 17:28:07 +0000 (02:28 +0900)]
unwind: add unwind_ prefix to struct tcb.queue field and its type
The names given to struct tcb.queue field and its type are too common,
this may cause conflicts in the future if new fields are added
to struct tcb.
* defs.h (struct tcb): Rename queue field to unwind_queue,
rename its type queue_t to unwind_queue_t.
* unwind.c (struct unwind_queue_t): Rename to unwind_queue_t.
All users updated.
Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Masatake YAMATO [Tue, 13 Mar 2018 17:28:06 +0000 (02:28 +0900)]
unwind: make the field type of struct tcb independent from libunwind
Narrowing the area where the code refers to names associated with
libunwind is needed to utilize libdw of elfutils as an alternative
unwinder.
* defs.h (struct tcb): Rename libunwind_ui field to unwind_ctx, change
its type to "void *".
* unwind.c (unwind_tcb_init, unwind_tcb_fin, stracetrace_walk): Reflect
* the above field renaming.
Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
strace.c: add support for opening output file in append mode
* strace.c (open_append): New variable.
(init): Handle -A option.
(strace_fopen): Open file in "a" mode if open_append is set to true.
* strace.1.in: Document this.
* NEWS: Mention this.
Suggested-by: Philipp Marek <philipp.marek@emerion.com> Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528488
strace.c: support simultaneous usage of -r and -t options
* strace.c (init): Do not set tflag when rflag is set.
(printleader): Handle rflag and tflag separately.
* strace.1.in (.SH OPTIONS): Add a note about differences between
the monotonic clock time and the wall clock time.
* tests/options-syntax.test: Remove the check for
"-tt has no effect with -r" warning.
* NEWS: Mention this.
syscall.c: dump write I/O even if error is returned
It makes sense to try to dump the argument of write syscalls as they can
be readily available despite the fact that error has been returned.
* syscall.c (dumpio): Move check for syserror and check for fd in
read_set to the end of the function.
* tests/read-write.c: Add a check for this behaviour.
* tests/pread64-pwrite64.c: Update expected output.
* NEWS: Mention this.
Suggested-by: J. Bruce Fields <bfields@fieldses.org> Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=436284
These were introduced by Linux commit v4.15-rc1~84^2~384^2~4.
* bpf_attr.h (struct BPF_OBJ_PIN_struct): Add file_flags field.
(struct BPF_PROG_GET_NEXT_ID_struct, struct BPF_PROG_GET_FD_BY_ID_struct,
struct BPF_MAP_GET_FD_BY_ID_struct): Add open_flags field.
(BPF_OBJ_PIN_struct_size, expected_BPF_OBJ_PIN_struct_size,
expected_BPF_PROG_GET_NEXT_ID_struct_size,
expected_BPF_PROG_GET_FD_BY_ID_struct_size,
expected_BPF_MAP_GET_FD_BY_ID_struct_size): Update.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the bpf_fd field, print file_flags field otherwise.
(DEF_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
DEF_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
DEF_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the next_id field, print open_flags field otherwise.
* xlat/bpf_file_mode_flags.in: New file.
* tests/bpf.c (BPF_OBJ_PIN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks): Check it.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
The aim of this change is to introduce an ability to perform multiple
checks for a specific bpf command. In order to achieve so, all the
related data is stored in check descriptor, and test_bpf iterates over
it. There are also some provisions made in regard to future changes
(specifically, the way bpf_attr_data union is defined).
* tests/bpf.c (print_bpf_attr): New function, a wrapper around
struct bpf_check.printer.
(test_bpf_): Rename to...
(test_bpf): ...this. Replace arguments with struct bpf_check pointer.
Iterate over possible attribute variants. Account for changes in
attribute initialisation routine: provide a pointer to locally defined
union bpf_attr_data and perform memcpy afterwards. Initialise memory
from data each time before a bpf call.
(TEST_BPF, DEF_*, init_*, print_*): Remove.
(init_BPF_PROG_LOAD_attr, print_BPF_PROG_LOAD_attr,
init_BPF_OBJ_PIN_attr): New functions.
(license, pathname): New variables.
(BPF_MAP_CREATE_checks, BPF_MAP_LOOKUP_ELEM_checks,
BPF_MAP_UPDATE_ELEM_checks, BPF_MAP_DELETE_ELEM_checks,
BPF_MAP_GET_NEXT_KEY_checks, BPF_PROG_LOAD_checks, BPF_OBJ_PIN_checks,
BPF_PROG_ATTACH_checks, BPF_PROG_DETACH_checks,
BPF_PROG_TEST_RUN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks,
BPF_OBJ_GET_INFO_BY_FD_checks): New arrays.
(BPF_OBJ_GET_checks, BPF_MAP_GET_NEXT_ID_checks): New macros.
(CHK): New macro, a shorthand for initialising array of struct bpf_check.
(main): New static constant checks, iterate over checks and run test_bpf
with each element.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
* configure.ac (AC_CHECK_HEADERS([linux/bpf.h])): Check for
struct bpf_insn.
* tests/bpf.c: Remove the test guard, include "scno.h", "bpf_attr.h",
"xlat.h", and "xlat/bpf_commands.h". Conditionalize inclusion of
<linux/bpf.h> on HAVE_LINUX_BPF_H. Remove all HAVE_UNION_* checks.
(BPF_ATTR_DATA_FIELD): New macro.
(bpf_attr_data): New union. Note that it is larger than modern
union bpf_attr, this allows more checks to be implemented in the future.
(sizeof_attr, test_bpf_): Replace union bpf_attr with
union bpf_attr_data.
(DEF_BPF_INIT_FIRST): Replace union bpf_attr with the corresponding
structure.
(init_BPF_MAP_CREATE_attr): Replace union bpf_attr with
struct BPF_MAP_CREATE_struct.
(init_BPF_MAP_LOOKUP_ELEM_attr): Replace union bpf_attr with
struct BPF_MAP_LOOKUP_ELEM_struct.
(init_BPF_MAP_UPDATE_ELEM_attr): Replace union bpf_attr with
struct BPF_MAP_UPDATE_ELEM_struct.
(init_BPF_MAP_DELETE_ELEM_attr): Replace union bpf_attr with
struct BPF_MAP_DELETE_ELEM_struct.
(init_BPF_MAP_GET_NEXT_KEY_attr): Replace union bpf_attr with
struct BPF_MAP_GET_NEXT_KEY_struct.
(init_BPF_PROG_LOAD_attr): Replace union bpf_attr with
struct BPF_PROG_LOAD_struct.
(init_BPF_OBJ_PIN_attr): Replace union bpf_attr with
struct BPF_OBJ_PIN_struct.
(init_BPF_PROG_ATTACH_attr): Replace union bpf_attr with
struct BPF_PROG_ATTACH_struct.
(init_BPF_PROG_DETACH_attr): Replace union bpf_attr with
struct BPF_PROG_DETACH_struct.
(init_BPF_PROG_GET_NEXT_ID_attr): Replace union bpf_attr with
struct BPF_PROG_GET_NEXT_ID_struct.
(sample_BPF_PROG_TEST_RUN_attr): Change type from union bpf_attr to
struct BPF_PROG_TEST_RUN_struct, all users updated.
(sample_BPF_OBJ_GET_INFO_BY_FD_attr): Change type from union bpf_attr
to struct BPF_OBJ_GET_INFO_BY_FD_struct, all users updated.
Check that structures defined by bpf_attr.h match system union bpf_attr
* gen_bpf_attr_check.sh: New file.
* Makefile.am (EXTRA_DIST): Add it.
(strace_SOURCES_check): New variable.
(strace_SOURCES): Add $(strace_SOURCES_check).
(BUILT_SOURCES, CLEANFILES): Add bpf_attr_check.c.
(bpf_attr_check.c): New rule.
(sys_func_h_sources): New variable.
(sys_func.h): Use it instead of strace_SOURCES_c.
* .gitignore: Add /bpf_attr_check.c.
build: generate all union bpf_attr checks automatically
Rather than list by hand some members of union bpf_attr that we check
for availability, automatically list all members of union bpf_attr we
are aware of.
* m4/gen_bpf_attr_m4.sh: New file.
* bootstrap: Invoke it.
* configure.ac (AC_CHECK_HEADERS([linux/bpf.h])): Use st_BPF_ATTR.
* m4/.gitignore: New file.
bpf: move definitions of bpf_attr structures to separate header file
This also unifies decoders of bpf commands by moving common code
to new macros.
* bpf_attr.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* bpf.c: Include it.
(DEF_BPF_CMD_DECODER): Rename to BEGIN_BPF_CMD_DECODER, add code common
to all decoders. All users updated.
(END_BPF_CMD_DECODER): New macro, add its invocation to all users
of BEGIN_BPF_CMD_DECODER macro.
This is needed at least for bpf, btrfs, and sg_io, as 32-bit tracer
cannot figure out whether the kernel is 32-bit or 64-bit,
and its behaviour differs when it handles u64 as a pointer.
We are going to use static_assert provided by <assert.h> or,
if it doesn't work, our cheap imitation that doesn't display
the message specified as the second argument of static_assert.
* configure.ac (AC_CACHE_CHECK): Check for static_assert in <assert.h>,
define HAVE_STATIC_ASSERT if it is available.
* static_assert.h: New file.
* Makefile.am (strace_SOURCES): Add it.
tests: forward SIZEOF_KERNEL_LONG_T and SIZEOF_LONG to C preprocessor
* tests/Makefile.am (AM_CPPFLAGS): Forward SIZEOF_KERNEL_LONG_T
and SIZEOF_LONG as TESTS_SIZEOF_KERNEL_LONG_T and TESTS_SIZEOF_LONG.
* tests/tests.h [TESTS_SIZEOF_KERNEL_LONG_T] (SIZEOF_KERNEL_LONG_T):
Redefine to TESTS_SIZEOF_KERNEL_LONG_T.
[TESTS_SIZEOF_LONG] (SIZEOF_LONG): Redefine to TESTS_SIZEOF_LONG.
Complements: v4.21~5 ("Export SIZEOF_LONG and SIZEOF_KERNEL_LONG_T to tests")
Restore kvm ioctl definitions for aarch64 and mips architectures
* maint/ioctls_sym.sh: Add aarch64 and mips architectures to the list
of kvm-capable architectures.
* linux/aarch64/ioctls_arch0.h: Regenerate.
* linux/mips/ioctls_arch0.h: Regenerate.
Fixes: v4.15~92 ("Move KVM_* ioctl entries from ioctls_inc*.h to ioctls_arch*.h")
Let's make a step towards the growing strace userbase all around
the world and translate something to the language of their choice.
This change enables translation of error messages corresponding
to errno codes, making it consistent with error diagnostics of other
i18n-aware tools, e.g.
$ LANG=es_ES strace -qq -a38 -P /missing unlink /missing
unlink("/missing") = -1 ENOENT (No existe el fichero o el directorio)
unlink: no se puede deshacer el enlace '/missing': No existe el fichero o el directorio
* strace.c: Include <locale.h>.
(main): Invoke setlocale.
* tests/init.sh: Export LC_ALL=C.
* NEWS: Mention this enhancement.
Dmitry V. Levin [Thu, 29 Mar 2018 16:00:18 +0000 (16:00 +0000)]
Remove RVAL_PRINT_ERR_VAL
* defs.h (RVAL_PRINT_ERR_VAL): Remove.
* ldt.c (SYS_FUNC(modify_ldt)): Return 0.
* syscall.c (syscall_exiting_trace): When printing an error,
always print struct tcb.u_rval as if RVAL_PRINT_ERR_VAL was set.
Extend the range of injected return value to the maximum, print warnings
if negative injection value can be clipped in compat personality or can
inadvertently turn into a fault injection.
* defs.h (INJECT_F_ERROR): New macro.
* filter_qualify.c (parse_inject_token): Revert type of intval local
variable back to int, check INJECT_F_ERROR along with INJECT_F_RETVAL,
use strtoull to parse retval argument, print warnings in case of retval
clipping and inadvertent fault injection.
(qualify_inject_common): Set INJECT_F_ERROR instead of INJECT_F_RETVAL.
* syscall.c (tamper_with_syscall_exiting): Check inject_data.flags
to determine whether a fault injection or retval injection has to be
performed.
(syscall_exiting_trace) <case RVAL_DECIMAL>: Explicitly print
tcp->u_rval as int if current_klongsize < sizeof(tcp->u_rval).
* tests/inject-nf.c (main): Update.
* tests/inject-nf.test: Test injection of negative return values.
* tests/qual_inject-syntax.test: Remove retval=-1 check as it is now
allowed, add checks for invalid retval parameters.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Wed, 28 Mar 2018 04:29:22 +0000 (04:29 +0000)]
Turn struct inject_data.rval into an index
Add one level of indirection to decrease the size of struct inject_data
as hundreds of these structures are created for each process when
injection mechanism is activated.
* retval.h: New file.
* retval.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* defs.h (struct inject_data): Replace rval field with rval_idx.
* filter_qualify.c: Include "retval.h".
(parse_inject_token, qualify_inject_common): Initialize
struct inject_data.rval_idx using retval_new.
* syscall.c: Include "retval.h".
(tamper_with_syscall_exiting): Obtain the value that has to be injected
using retval_get.
* xlat/mmap_flags.in (_MAP_NEW): Remove SunOS-specific comment, add
a comment that this is a SPARC-specific constant (from
arch/sparc/include/uapi/asm/mman.h).
(MAP_GROWSUP): IA-64-specific constant (from
arch/ia64/include/uapi/asm/mman.h).
(MAP_INHERIT): Add a comment that this is a SPARC-specific constant
(from arch/sparc/include/uapi/asm/mman.h).
(_MAP_INHERIT): Add a comment that this is an Alpha-specific constant
(from arch/alpha/include/uapi/asm/mman.h).
(MAP_ANON): Remove, FreeBSD-specific constant.
(MAP_HASSEMAPHORE): Rename to...
(_MAP_HASSEMAPHORE): ...this, add a comment that this is an
Alpha-specific constant (from arch/alpha/include/uapi/asm/mman.h).
(MAP_NOSYNC, MAP_NOCORE): Remove.
(MAP_AUTOGROW, MAP_AUTORSRV, MAP_LOCAL): Add a comment that this is
an architecture-specific constant (from
arch/mips/include/uapi/asm/mman.h, arch/xtensa/include/uapi/asm/mman.h).
(_MAP_UNALIGNED): Add a comment that this is an Alpha-specific constant
(from arch/alpha/include/uapi/asm/mman.h).