Andre McCurdy [Fri, 5 Feb 2016 22:00:00 +0000 (14:00 -0800)]
mips: use <asm/sgidefs.h>
Build fix for MIPS with musl libc.
The MIPS specific header <sgidefs.h> is provided by glibc and uclibc
but not by musl. Regardless of the libc, the kernel headers provide
<asm/sgidefs.h> which provides the same definitions, so use that
instead.
* configure.ac: Replace <sgidefs.h> with <asm/sgidefs.h>.
Signed-off-by: Andre McCurdy <armccurdy@gmail.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
JingPiao Chen [Thu, 19 Jan 2017 06:59:51 +0000 (14:59 +0800)]
Makefile.am: allow indented DEF_MPERS_TYPE includes
* Makefile.am (m%_type_defs.h): Change sed regular expression to allow
arbitrary number of whitespace characters between "#" symbol
and "include" directive.
Dmitry V. Levin [Fri, 13 Jan 2017 20:07:09 +0000 (20:07 +0000)]
tests: drop non-USE_ASM_STAT case support
With the switch of fstatat family tests to USE_ASM_STAT variant,
there are no non-USE_ASM_STAT users left. Remove support of unused
non-USE_ASM_STAT case.
Dmitry V. Levin [Fri, 13 Jan 2017 19:54:57 +0000 (19:54 +0000)]
tests: call newfstatat and fstatat64 syscalls directly
Do not use glibc wrappers to call newfstatat and fstatat64.
These wrappers have various problems, e.g. they segfault on sparc64
and mips64 if BOGUS_STRUCT_STAT is not disabled, and they do wrong
conversion of timestamps on mips64.
Dmitry V. Levin [Fri, 13 Jan 2017 19:31:30 +0000 (19:31 +0000)]
tests: change SAMPLE_SIZE type to libc_off_t
As ftruncate libc function and our create_sample function that calls
ftruncate both take size argument of type libc_off_t, change the type
of SAMPLE_SIZE constant to libc_off_t.
Alexey Neyman [Thu, 12 Jan 2017 21:15:59 +0000 (13:15 -0800)]
ioctlsort: get ioctl definitions from host, not build
When cross-compiling, ioctlsort must obtain _IOC_* values from the
host, build's values may be incompatible.
* ioctl_iocdef.c: New file.
* Makefile.am (EXTRA_DIST): Add it.
(ioctl_iocdef.i, ioctl_iocdef.h): New rules.
(ioctlsort%.o): Depend on ioctl_iocdef.h.
(CLEANFILES): Add ioctl_iocdef.h and ioctl_iocdef.i.
* ioctlsort.c: Include "ioctl_iocdef.h" instead of <linux/ioctl.h>.
Signed-off-by: Alexey Neyman <stilor@att.net> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Fri, 13 Jan 2017 01:14:51 +0000 (01:14 +0000)]
tests: treat struct stat mismatch as an error
If the test detects struct stat mismatch, this is likely an error
in definitions of a stat structure that might affect strace as well.
Fail the test instead of skipping it to attract more attention.
* tests/xstatx.c (main): Return 1 instead of 77
in case of struct stat mismatch.
Dmitry V. Levin [Mon, 9 Jan 2017 16:01:08 +0000 (16:01 +0000)]
scsi: implement decoding of all SG_* ioctl commands
* print_sg_req_info.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* xlat/sg_scsi_reset.in: New file.
* scsi.c: Include "xlat/sg_scsi_reset.h".
(scsi_ioctl): Implement decoding of all SG_* ioctl commands.
Dmitry V. Levin [Sun, 8 Jan 2017 18:31:51 +0000 (18:31 +0000)]
sg_io: cleanup printing of sg_io buffers
Turn print_sg_io_buffer into a universal sg_io buffer printer.
* sg_io_v3.c (print_sg_io_buffer): Add iovec_count argument.
Call tprint_iov_upto when iovec_count is non-zero.
(decode_request, decode_response): Do not call tprint_iov_upto directly,
use print_sg_io_buffer instead.
* sg_io_v4.c: Likewise.
Dmitry V. Levin [Sun, 8 Jan 2017 17:43:21 +0000 (17:43 +0000)]
sg_io: decode structures on exiting syscall in case of syserror
The SCSI driver, starting with kernel commit v2.6.25-rc1~1230^2~78,
translates its "struct request.errors" to ioctl errors after
filling in all the output members of the SG_IO header structure.
As there is no easy way to tell SCSI layer errors from other syscall
errors, decode the structure on exiting syscall in case of syserror,
too.
* scsi.c (scsi_ioctl): Do not call set_tcb_priv_ulong, use
get_tcb_priv_data instead of get_tcb_priv_ulong, call decode_sg_io
unconditionally.
* sg_io_v3.c (decode_request): Save a copy of struct_sg_io_hdr using
set_tcb_priv_data.
(decode_response): Restore it using get_tcb_priv_data. Print its i/o
fields when umove call fails. Pass IOV_DECODE_STR to tprint_iov_upto
unconditionally.
* sg_io_v4.c (decode_request): Save a copy of struct sg_io_v4 using
set_tcb_priv_data.
(decode_response): Restore it using get_tcb_priv_data. Print its i/o
fields when umove call fails. Pass IOV_DECODE_STR to tprint_iov_upto
unconditionally.
Dmitry V. Levin [Sun, 8 Jan 2017 15:43:40 +0000 (15:43 +0000)]
sg_io_v3: print status fields using %#x format specifier
The formerly used format string %02x led to misleading output as there
was no clear indication sometimes whether the printed integer was
decimal or hexadecimal.
* sg_io_v3.c (decode_response): Print status and masked_status fields
using %#x format specifier instead of %02x.
Dmitry V. Levin [Sun, 8 Jan 2017 15:36:42 +0000 (15:36 +0000)]
sg_io_v4: print request_tag and generated_tag fields in hex
The tradition is to print scsi tags in a hexadecimal form.
* sg_io_v4.c (decode_request): Print request_tag field
using ("%#" PRI__x64) format string.
(decode_response): Print generated_tag field using ("%#" PRI__x64)
format string.
Dmitry V. Levin [Sun, 8 Jan 2017 01:20:59 +0000 (01:20 +0000)]
sg_io: decode struct sg_io_hdr.flags and struct sg_io_v4.flags
Print struct sg_io_hdr.flags and struct sg_io_v4.flags using printflags.
* xlat/sg_io_flags.in: New file.
* sg_io_v3.c: Include "xlat/sg_io_flags.h".
(decode_request): Print struct_sg_io_hdr.flags using printflags.
* xlat/bsg_flags.in: New file.
* sg_io_v4.c: Include "xlat/bsg_flags.h".
(decode_request): Print struct sg_io_v4.flags using printflags.
Dmitry V. Levin [Sat, 7 Jan 2017 19:09:37 +0000 (19:09 +0000)]
scsi: detect and print changes of interface id
* scsi.c (print_sg_io_v3_res): Detect and print changes
of struct sg_io_hdr.interface_id field between entering and exiting
syscall.
(print_sg_io_v4_res): Detect and print changes of struct sg_io_v4.guard
field between entering and exiting syscall.
Dmitry V. Levin [Sat, 7 Jan 2017 19:01:27 +0000 (22:01 +0300)]
scsi: print field names of all fields being printed
* scsi.c (print_sg_io_v3_req): Always print the name
of struct sg_io_hdr.interface_id field.
(print_sg_io_v4_req): Always print the name of struct sg_io_v4.guard
field.
(print_sg_io_req): Print unknown interface id as an integer.
(scsi_ioctl): Save interface id on entering syscall and use it
on exiting syscall.
Dmitry V. Levin [Sat, 7 Jan 2017 16:44:44 +0000 (16:44 +0000)]
Print hexadecimal integer in error diagnostics using %#x
The formerly used format string %x led to misleading output as there was
no clear indication sometimes whether the printed integer was decimal or
hexadecimal.
* aio.c (startup_child, test_ptrace_seize): Print status
using %#x format specifier instead of %x.
Dmitry V. Levin [Sat, 7 Jan 2017 16:44:44 +0000 (16:44 +0000)]
aio: print hexadecimal integer using %#x
The formerly used format string %x led to misleading output as there was
no clear indication sometimes whether the printed integer was decimal or
hexadecimal.
* aio.c (print_common_flags): Print struct iocb.aio_flags using %#x
format specifier instead of %x.
* tests/aio.c (main): Likewise.
Since there is no reason to interpret the value returned by getrandom as
ASCII string, it makes sense to always print it as a hex-escaped string.
* getrandom.c (SYS_FUNC(getrandom)): Use printstr_ex instead
of printstrn, set QUOTE_FORCE_HEX in user_style parameter in order
to force hex-escaped string formatting.
* tests/getrandom.test: Remove no longer needed -xx flag as the string
is always printed in hexadecimal format now.
term: do not abort decoding in case of non-verbose output
The case of unset verbose is handled by umoven_or_printaddr, moreover,
exiting at this point is plain wrong and leads to last argument not
being printed while it should be.
* term.c (decode_termios, decode_termio, decode_winsize, decode_ttysize,
decode_modem_flags): Do not check verbose flags explicitly and do not
exit early if it is not set.
Dmitry V. Levin [Thu, 5 Jan 2017 01:34:24 +0000 (01:34 +0000)]
tests: rewrite ioctl_v4l2 test without reliance on init_magic
* tests/ioctl_v4l2.c (cc0, cc1, cc2, cc3, fourcc): New macros.
(main): Use them. Rewrite expected output without assumptions
on any particular magic data.
Dmitry V. Levin [Wed, 4 Jan 2017 22:08:32 +0000 (22:08 +0000)]
tests: change the type of fill_memory{,_ex} first argument to void *
As these functions behave like memset, it's more convenient to have
the first argument of type void * like memset.
* tests/fill_memory.c (fill_memory, fill_memory_ex): Change the type
of first argument from "char *" to "void *".
* tests/tests.h (fill_memory, fill_memory_ex): Likewise.
Dmitry V. Levin [Wed, 4 Jan 2017 13:22:19 +0000 (13:22 +0000)]
Drop vsprintf.c
Drop custom vfprintf implementation that was disabled by default.
Apparently nobody tests strace with this vfprintf enabled, otherwise
multiple uses of format specifiers not supported by this custom vfprintf
would not left unnoticed.
The GNU C library is not the only libc available, so those who want
faster implementations of libc functions are encouraged to try building
strace with other libc implementations.
The verbose flag is responsible for dereferencing of addresses, and it
is perfectly handled by umove_or_printaddr; moreover, this early exit
leads to incorrect formatting of last argument.
* loop.c (loop_ioctl): Do not check verbose flag explicitly and do not
exit early if it is not set.
tests: add more checks of unknown ioctl command formatting
* tests/ioctl.c (main): Additional check for unknown ioctl command
decoding.
* tests/ioctl_evdev.c (main): Likewise.
* tests/ioctl_dm.c: Include <linux/ioctl.h> for _IOC_SIZE and _IOC_NR.
(main) <dummy_dm_ioctl1, dummy_dm_ioctl2, dummy_dm_arg>: New constants.
Add more checks for unknown command formatting.
ioctl: do not print explicit 0x prefix and do not specify minimum width
Specifying output width for size argument is rather misleading - it can
be up to 14 bits in size. The use of explicit "0x" prefix is
discouraged because 0x0 looks ugly. Usage of width specification along
with alternate form flag leads to inconsistent output for 0.
Let's use just plain %#x qualifiers instead.
* ioctl.c (ioctl_print_code): Change printf qualifiers for ioctl command
type, number and size to "%#x".
* tests/ioctl.c (main): Update expected test output.
* tests/ioctl_dm.c (main): Likewise.
* tests/ioctl_evdev.c (main): Likewise.
loop: fix printing of the reserved field array items
They are of char type, so "hh" length modifier should be used (otherwise
they are printed incorrectly as they are sign extended implicitly when
passed as printf arguments in case char is a signed type which is true
for most compilers).
* loop.c (decode_loop_info): Change "%#x" printf qualifier to "%#hhx"
in printing routine for array elements of the "reserved" field of
loop_info structure.
Dmitry V. Levin [Tue, 3 Jan 2017 13:46:26 +0000 (13:46 +0000)]
Remove checks of __NR_* availability from strace source code
* strace.c: Remove __NR_tkill checks, assume it is always defined.
* util.c: Remove __NR_process_vm_readv checks and fallback definitions,
assume it is always defined.
Dmitry V. Levin [Sun, 1 Jan 2017 11:33:40 +0000 (11:33 +0000)]
Update all publicly shown copyright year number ranges
* COPYING: Update copyright year number range.
* configure.ac: Likewise.
* strace.c: Likewise.
* tests/strace-V.test: Use the current year for the check.
Dmitry V. Levin [Fri, 30 Dec 2016 09:43:12 +0000 (09:43 +0000)]
tests: do not use defs.h and syscall.h
* tests/generate_scno.c: Include "tests.h", "sysent.h", <stdio.h>,
<string.h>, and <asm/unistd.h> instead of "defs.h" and "syscall.h".
* tests/ksysent.c: Likewise.
* tests/nsyscalls.c: Include "tests.h", "sysent.h", <errno.h>,
<stdio.h>, and <unistd.h> instead of "defs.h" and "syscall.h".
loop: add fallback definitions for LOOP_* ioctl command constants
Since these are architecture-independent and have been added over the
kernel's lifetime, it makes sense to have these definitions in strace
itself.
* xlat/loop_cmds.in: New file.
* loop.c: Include "xlat/loop_cmds.h".
(loop_ioctl): Eliminate conditional compilation based on availability
of LOOP_* constant definitions.
Dmitry V. Levin [Thu, 29 Dec 2016 00:30:26 +0000 (00:30 +0000)]
xlat: extend syntax
* xlat/gen.sh: Implement #stop directive that stops preprocessor
at the line it has been encountered during the first pass. This could
be used, for example, to provide fallback definitions for constants
without defining xlat tables.
loop: mpersify struct loop_info and loop_ioctl function
struct loop_info contains fields of type long, so it definitely should
have been mpersified.
* defs.h (loop_ioctl): Remove prototype.
* loop.c (struct_loop_info): New typedef.
Include DEF_MPERS_TYPE(struct_loop_info) and MPERS_DEFS.
(decode_loop_info): Replace struct loop_info with struct_loop_info.
Cast lo_inode, lo_init[0], and lo_init[1] to kernel_ulong_t and print
them using appropriate format specifiers.
(loop_ioctl): Wrap into MPERS_PRINTER_DECL.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Move device number printing code into a separate routine
* print_dev_t.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (print_dev_t): New prototype.
* dm.c: Do not include <sys/sysmacros.h>.
(dm_decode_device, dm_print_dev, dm_decode_dm_name_list): Use
print_dev_t function for printing device numbers.
* mknod.c: Do not include <sys/sysmacros.h>.
(decode_mknod): Use print_dev_t function for printing device number.
* print_struct_stat.c: Do not include <sys/sysmacros.h>.
(print_struct_stat): Use print_dev_t function for printing device
numbers.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Wed, 28 Dec 2016 22:33:38 +0000 (22:33 +0000)]
tests: enhance invalid address decoding check in seccomp-strict.test
* tests/seccomp-strict.c (main): Change the type of addr variable
containg the invalid address from unsigned long to kernel_ulong_t,
print it using %#llx format.
This extends the fault injection capability with :signal=SIG option
which injects a signal on entering each syscall from the specified set.
:signal and :error options are complementary, if they are both specified
the syscall will be fault injected as usual and the specified signal
will be delivered to the tracee.
* defs.h (struct fault_opts): Change the type of err field to int16_t,
add signo field.
(trace_syscall): Add a pointer argument.
* qualify.c: Include "nsig.h".
(parse_fault_token): Handle signal= option.
(qualify_fault): Update default fault_opts.
* strace.c (trace): Forward signal number from trace_syscall
to ptrace_restart(PTRACE_SYSCALL).
* syscall.c (inject_syscall_fault_entering): Add pointer argument,
save there the signal number specified by fault options. Do not inject
a syscall fault unless instructed by fault options.
(update_syscall_fault_exiting): Update the error code injection check.
(trace_syscall_entering): Add pointer argument, forward it to
inject_syscall_fault_entering.
(trace_syscall): Add pointer argument, forward it to
trace_syscall_entering.
Signed-off-by: Seraphime Kirkovski <kirkseraph@gmail.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>