Commit Graph

5790 Commits

Author SHA1 Message Date
JingPiao Chen
00e48349a9 netlink: add a basic rtnetlink parser of neightbl messages
* rtnl_neightbl.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_ndtmsg): New prototype.
* netlink_route.c (route_decoders): Add RTM_GETNEIGHTBL,
RTM_NEWNEIGHTBL, and RTM_SETNEIGHTBL.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-14 01:07:59 +00:00
JingPiao Chen
9f22c62767 tests: check decoding of rtnetlink neigh messages
* tests/netlink_route.c: Include <linux/neighbour.h>.
(test_rtnl_neigh): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-14 01:07:59 +00:00
JingPiao Chen
8f3b3e6578 netlink: add a basic rtnetlink parser of neigh messages
* rtnl_neigh.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_ndmsg, decode_rtm_getneigh): New prototypes.
* configure.ac (AC_CHECK_HEADERS): Add linux/neighbour.h.
* netlink_route.c (route_decoders): Add RTM_DELNEIGH, RTM_DELNEIGH,
and RTM_NEWNEIGH.
* xlat/nda_types.in: New file.
* xlat/neighbor_cache_entry_flags.in: Likewise.
* xlat/neighbor_cache_entry_states.in: Likewise.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-14 01:07:07 +00:00
JingPiao Chen
50b2249877 tests: check decoding of rtnetlink rule messages
* tests/netlink_route.c: Include <linux/fib_rules.h>.
(test_rtnl_rule): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-14 01:07:07 +00:00
JingPiao Chen
a0d3f258d0 netlink: add a basic rtnetlink parser of rule messages
* defs.h (routing_table_ids): New xlat prototype.
* rtnl_rule.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (ip_type_of_services, routing_table_ids): New xlat prototypes.
* netlink_route.h (decode_fib_rule_hdr): New prototype.
* configure.ac (AC_CHECK_HEADERS): Add linux/fib_rules.h.
* netlink_route.c (route_decoders): Add RTM_DELRULE, RTM_GETRULE,
and RTM_NEWRULE.
* xlat/fib_rule_actions.in: New file.
* xlat/fib_rule_flags.in: Likewise.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-14 01:06:59 +00:00
JingPiao Chen
a114dd92fe tests: check decoding of rtnetlink route messages
* tests/netlink_route.c: Include <linux/ip.h>.
(test_rtnl_route): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-14 01:06:59 +00:00
JingPiao Chen
0ca787b5ba netlink: add a basic rtnetlink parser of route messages
* defs.h (routing_scopes): New xlat prototype.
* rtnl_route.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_rtmsg): New prototype.
* netlink_route.c (route_decoders): Add RTM_DELROUTE, RTM_GETROUTE,
and RTM_NEWROUTE.
* xlat/ip_type_of_services.in: New file.
* xlat/routing_flags.in: Likewise.
* xlat/routing_protocols.in: Likewise.
* xlat/routing_table_ids.in: Likewise.
* xlat/routing_types.in: Likewise.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-14 01:06:38 +00:00
JingPiao Chen
0a3ebb0443 tests: check decoding of rtnetlink addr messages
* tests/netlink_route.c: Include <linux/if_addr.h>.
(test_rtnl_addr): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-14 01:06:38 +00:00
JingPiao Chen
3226d22ffc netlink: add a basic rtnetlink parser of addr messages
* rtnl_addr.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* configure.ac (AC_CHECK_HEADERS): Add linux/if_addr.h.
* netlink_route.h (decode_ifaddrmsg): New prototype.
* netlink_route.c (route_decoders): Add RTM_DELADDR,
RTM_GETADDR, RTM_GETANYCAST, RTM_GETMULTICAST, and RTM_NEWADDR.
* xlat/ifaddrflags.in: New file.
* xlat/routing_scopes.in: Likewise.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-13 23:01:46 +00:00
Eugene Syromyatnikov
d720877b1f Make description of discrepancies between libc and kernel APIs more relevant
Looks like this part was untouched since the days strace supported OSes
other than Linux. Well, it's time to make it more contemporary.

* strace.1.in (.SH NOTES): Use faccessat(2) and setrlimit(2)/prlimit(2)
instead of time(2) and stat(2)/xstat(2) as examples of libc/kernel API
discrepancies.
2017-08-14 00:29:15 +02:00
JingPiao Chen
7d216d508e tests: check decoding of NLMSG_DONE messages of NETLINK_ROUTE
* tests/netlink_route.c (test_nlmsg_done): New function.
(main): Use it.
2017-08-11 15:50:14 +00:00
Nikolay Marchuk
86259ebb47 Add TF flag to inotify_add_watch syscall entries
The second argument of the inotify_add_watch syscall is a file name,
but inotify_add_watch has no TF flag set.

* linux/32/syscallent.h (inotify_add_watch): Add TF 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.
2017-08-11 10:48:38 +00:00
Nikolay Marchuk
71712fea8b pathtrace: fix matching of execveat syscall
* pathtrace.c (pathtrace_match_set): Add testing of SEN_execveat.
2017-08-11 10:48:38 +00:00
Eugene Syromyatnikov
87fd823df9 strace.1: add indentation to examples
* strace.1 (.de CW): Add .in +4n.
(.de CE): Add .in.
2017-08-10 21:36:01 +02:00
Eugene Syromyatnikov
23bd66bfee Generate date for the man page
* Makefile.am (dist-hook): Add .strace.1.in.date generation.
* strace.spec.in (%setup): Likewise.
* configure.ac (manpage_date): New m4 define.
(MANPAGE_DATE): New define/subst.
* strace.1 (.TH): Add manpage date and strace's version.
2017-08-10 21:36:01 +02:00
Eugene Syromyatnikov
189320c6c7 Add script for generating date of the last commit for specific file
* file-date-gen: New auxiliary script.
2017-08-10 21:36:01 +02:00
Eugene Syromyatnikov
4f9270f0c5 Make strace.1 generated
* .gitignore (/strace.1): New entry.
* configure.ac (AC_CONFIG_FILES): Add strace.1.
* strace.1.in: Rename from strace.1.
2017-08-10 21:36:01 +02:00
Eugene Syromyatnikov
e552b7b765 strace.1: format synopsis using .SY/.OP macros
Also, add .OM and .OR macros and use { ... | ... } syntax for indicating
possible options regarding mandatory arguments.

* strace.1 (.OM, .OR): New macro definitions, based on .OP
(.SH SYNOPSYS): Format using .SY/.OP/.OM/.OR. Put -p/command inside
{ ... | ... } block.
2017-08-10 21:36:01 +02:00
Eugene Syromyatnikov
718804ae95 strace.1: remove date from .TH, as it is no longer relevant
* strace.1 (.TH): Remove date.
2017-08-10 21:33:33 +02:00
Eugene Syromyatnikov
59bbc6507b strace.1: remove .IX definition
It is present in groff macros nowadays.

* strace.1 (.de IX): Remove.
2017-08-10 21:33:27 +02:00
Eugene Syromyatnikov
edd2189a05 strace.1: replace .TP with .TQ between command-line option variants
In order to eliminate unneeded space between them.

* strace.1 (Filtering): Replace .TP with .TQ between different variants
of the same option.
2017-08-10 20:51:22 +02:00
c81ad544ae rtnl_link: include "netlink.h" before <linux/rtnetlink.h>
<sys/socket.h> has to be included before <linux/netlink.h> because
the latter used to be incomplete in older kernel headers.

As a local wrapper file called netlink.h was introduced earlier
to workaround this and related portability issues, include it before
<linux/rtnetlink.h> that in turn includes <linux/netlink.h>.

This fixes build on systems with older kernel headers.

* rtnl_link.c: Include "netlink.h" before <linux/rtnetlink.h>.
2017-08-09 13:24:13 +00:00
JingPiao Chen
fc15305b9f tests: check decoding of rtnetlink link messages
* tests/netlink_route.c: Include <linux/if_arp.h>.
(TEST_NL_ROUTE): New macro.
(test_rtnl_link): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-09 00:43:49 +00:00
JingPiao Chen
b955f683f4 netlink: add a basic rtnetlink parser of link messages
* netlink_route.h: New file.
* rtnl_link.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* defs.h (arp_hardware_types, iffflags): New xlat prototypes.
* netlink_route.c: Include "netlink_route.h"
and <linux/rtnetlink.h>.
(netlink_route_decoder_t): New typedef.
(route_decoders): New array.
(decode_netlink_route): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-09 00:43:49 +00:00
JingPiao Chen
4c437e1856 Move nl_route_types definition from netlink.c to netlink_route.c
The side effect of #include "xlat/nl_route_types.h" is
RTM_* constants properly defined in that header file.
While netlink.c does not use these constants itself,
netlink_route.c is going to need them soon.

* defs.h (nl_route_types): New xlat prototype.
* netlink.c: Move inclusion of "xlat/nl_route_types.h" ...
* netlink_route.c: ... here.
2017-08-09 08:43:49 +08:00
JingPiao Chen
7f95ee6017 tests: check netlink family specific decoder of NETLINK_ROUTE
* tests/netlink_route.c: Include <stdint.h>,
include "test_netlink.h" instead of "netlink.h".
(test_rtnl_unspec): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-09 08:43:34 +08:00
JingPiao Chen
670390ac71 netlink: introduce family specific decoder of NETLINK_ROUTE
* netlink_route.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (decode_netlink_route): New prototype.
* netlink.c (netlink_decoders): Add NETLINK_ROUTE.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-08-09 08:18:43 +08:00
JingPiao Chen
474031e41b tests: check decoding of NETLINK_KOBJECT_UEVENT messages
* tests/netlink_kobject_uevent.c: New file.
* tests/gen_tests.in (netlink_kobject_uevent): New entry.
* tests/pure_executables.list: Add netlink_kobject_uevent.
* tests/.gitignore: Likewise.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2017-08-08 16:36:59 +00:00
JingPiao Chen
6555267d92 netlink: add decoding of NETLINK_KOBJECT_UEVENT messages
* netlink.c (decode_netlink): Print NETLINK_KOBJECT_UEVENT messages
as a string using printstrn.
2017-08-08 16:36:59 +00:00
JingPiao Chen
338f0592ae netlink: call get_fd_nl_family before nlmsghdr decoding
Prepare for decoding of NETLINK_KOBJECT_UEVENT.  Messages of the latter,
unlike traditional netlink families, don't contain a header at all.

* netlink.c (NL_FAMILY_*): Remove enum.
(get_fd_nl_family): Replace NL_FAMILY_ERROR with -1.
(decode_nlmsg_type): Update the comment.
Skip family specific type decoders for type < NLMSG_MIN_TYPE.
(decode_nlmsghdr_with_payload): Skip family specific decoders
for type < NLMSG_MIN_TYPE && type != NLMSG_DONE.
(print_nlmsghdr): Move get_fd_nl_family invocation ...
(decode_nlmsghdr_with_payload): ... here.
2017-08-08 16:36:59 +00:00
15cc2f5364 Make sysent_shorthand_defs.h suitable for tests
* sysent_shorthand_defs.h [STRACE_TESTS_H]: Add shorthand notations from
tests/ksysent.c and tests/nsyscalls.c.
* tests/ksysent.c: Remove shorthand notations.
* tests/nsyscalls.c: Likewise.
2017-08-07 12:49:44 +00:00
Edgar Kaziakhmedov
3d565ef25a Move sysent shorthand notations to separate files
Avoid proliferation of exactly the same definitions of shorthand
notations for macros defined in sysent.h by moving definitions
and undefs of these shorthand notations to separate files.

* sysent_shorthand_defs.h: New file.
* sysent_shorthand_undefs.h: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* syscall.c: Use them.

Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2017-08-07 12:49:44 +00:00
JingPiao Chen
f9638667ee netlink.c: fix indentation
* netlink.c (print_cookie): Fix indentation.
2017-08-07 12:48:20 +00:00
Edgar Kaziakhmedov
b4f16886e7 Move err/mem subroutines to separate files
In order to allow usage of utility functions by other binaries
included in the strace package (like the upcoming asinfo utility),
these functions should be moved to separate files.

* error_prints.h: New file.
* xmalloc.h: Likewise.
* defs.h: Include "xmalloc.h" and "error_prints.h".
(error_msg, error_msg_and_die, error_msg_and_help, perror_msg,
perror_msg_and_die): Move to error_prints.h.
(xcalloc, xmalloc, xreallocarray, xstrdup, xstrndup): Move to xmalloc.h.
* strace.c (die): Remove static quialifier to make visible
by error_prints.c.
(error_msg, error_msg_and_die, error_msg_and_help, perror_msg,
perror_msg_and_die, verror_msg): Move ...
* error_prints.c: ... to the new file.
* xmalloc.c: Include "config.h", <stdlib.h>, <string.h>,
"error_prints.h", and "xmalloc.h" instead of "defs.h".
Use int instead of bool.  Fix codestyle.
* Makefile.am (strace_SOURCES): Add error_prints.c, error_prints.h,
and xmalloc.h.

Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2017-08-07 10:59:22 +00:00
Nikolay Marchuk
35c006d93c tests: move check_* functions from options-syntax.test to separate file
* tests/options-syntax.test: Move check_* functions to ...
* tests/syntax.sh: ... new file.
* tests/Makefile.am (EXTRA_DIST): Add syntax.sh.
2017-08-07 03:22:26 +00:00
Nikolay Marchuk
b75c5b14e7 Split qualify.c into basic_filters.c and filter_qualify.c
This change also exports add_number_to_set, qualify_tokens,
and qualify_syscall_tokens.

* basic_filters.c: New file, part of qualify.c.
* filter_qualify.c: Likewise.
* filter.h: New file.
* qualify.c: Remove.
* Makefile.am (strace_SOURCES): Add new files, remove qualify.c.
2017-08-07 03:01:30 +00:00
330f4633d5 Simplify handling of unexpected tracees
* strace.c (maybe_allocate_tcb) <WIFSTOPPED(status) && !followfork>:
Remove the dance around possible re-injection of WSTOPSIG(status)
as the only observable stop here is the initial ptrace-stop.
2017-08-06 15:10:56 +00:00
7a35b711df Fix handling of unexpected tracees when PTRACE_SEIZE is not in use
* strace.c (maybe_allocate_tcb) <WIFSTOPPED(status) && !followfork>:
The expected ptrace stop signal in case of !use seize is not
syscall_trap_sig but SIGSTOP.  An idea of using PTRACE_GETSIGINFO to
distinguish signal stops that should be re-injected from other kinds
of stops didn't work out due to kernel implementation peculiarities
of initial ptrace-stop.
2017-08-06 13:27:07 +00:00
10360644ca pathtrace: fix matching of symlinkat syscall
* pathtrace.c (pathtrace_match_set) <SEN_symlinkat>: The first argument
of symlinkat syscall is not a path but an arbitrary string, ignore it.
2017-08-06 12:39:56 +00:00
Nikolay Marchuk
f027d33049 pathtrace: fix missing syscalls
* pathtrace.c (pathtrace_match_set): Fix symlink decoding,
disable pathtracing for inotify_init.
2017-08-06 12:39:56 +00:00
255bc6fded Enhance fflush error diagnostics
* strace.c (flush_tcp_output): New function.
(line_ended, droptcb, print_event_exit): Use it to flush tcp->outf.
* tests/fflush.c: New file.
* tests/fflush.test: New test.
* tests/Makefile.am (MISC_TESTS): Add it.
* tests/.gitignore: Add fflush.
* tests/pure_executables.list: Likewise.
2017-08-06 11:26:52 +00:00
a93e2de99e tests: check handling of CLONE_PARENT'ed and CLONE_PTRACE'ed processes
* tests/clone_parent.c: New file.
* tests/clone_ptrace.c: Likewise.
* tests/clone_parent.test: New test.
* tests/clone_ptrace.test: Likewise.
* tests/.gitignore: Add clone_parent and clone_ptrace.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(MISC_TESTS): Add clone_parent.test and clone_ptrace.test.
2017-08-06 00:23:20 +00:00
d874bbf61e tests: export a path to the trace executable to check_PROGRAMS
* tests/init.sh (STRACE_EXE): Initialize from $STRACE and export.
2017-08-06 00:23:20 +00:00
Eugene Syromyatnikov
7d56c3d808 Makefile.am: build top directory first
This solves potential issues when tests run first and strace is rebuilt
only after they have finished.  As noted in [1], providing the current
directory explicitly should help.

[1] https://www.gnu.org/software/automake/manual/html_node/Subdirectories.html

* Makefile.am (SUBDIRS): Prepend the current directory.
2017-08-05 21:26:35 +00:00
Eugene Syromyatnikov
1b93f4032a Improve handling of unexpected tracees
When receiving a ptrace stop of an unexpected child, handle it
in the most transparent way possible:
- detach it instead of PTRACE_CONT'ing;
- send it the signal with which it has been stopped.
This should hopefully help to deal with processes that have been created
with misused CLONE_PTRACE flag set.

* strace.c (maybe_allocate_tcb) <WIFSTOPPED(status) && !followfork>:
Calculate the signal similarly to the way next_event does,
forward it to the unexpected tracee, and detach the tracee.
2017-08-05 21:26:35 +00:00
17f095a945 tests: fix unaligned access in nlattr.test
* tests/nlattr.c (test_nlattr): Use SET_STRUCT
to initialize potentially unaligned struct nlattr.
2017-08-04 19:08:27 +00:00
8bf63c5ec7 tests: fix unaligned access in nlattr_packet_diag_msg.test
* tests/nlattr_packet_diag_msg.c (init_packet_diag_msg): Use SET_STRUCT
to initialize potentially unaligned struct packet_diag_msg.
2017-08-04 19:06:49 +00:00
9284ce55f0 sparc64: do not bail out in get_scno if PTRACE_PEEKTEXT fails
If the kernel contains commit 84d77d3f06e7e8dea057d10e8ec77ad71f721be3,
PTRACE_PEEKTEXT becames unavailable when the process dumpable flag is
cleared.  As this is not a fatal condition for get_scno, do not bail out
if PTRACE_PEEKTEXT fails.

This condition is triggered and therefore tested by prctl-dumpable test.

* linux/sparc64/get_scno.c (arch_get_scno): Do not bail out
if PTRACE_PEEKTEXT fails.
2017-08-04 18:47:59 +00:00
92ac75f6f4 tests: enhance test coverage of printstrn and umoven
* tests/printstrn-umoven.c: New file.
* tests/printstrn-umoven-peekdata.c: Likewise.
* tests/printstrn-umoven-undumpable.c: Likewise.
* tests/printstrn-umoven-legacy.test: New test.
* tests/Makefile.am (MISC_TESTS): Add printstrn-umoven-legacy.test.
* tests/gen_tests.in (printstrn-umoven, printstrn-umoven-peekdata,
printstrn-umoven-undumpable): New entries.
* tests/pure_executables.list: Add printstrn-umoven,
printstrn-umoven-peekdata, and printstrn-umoven-undumpable.
* tests/.gitignore: Likewise.
2017-08-02 00:45:47 +00:00
4341074ee1 tests: add test_printstrn function to libtests
* tests/test_ucopy.h (test_printstrn): New prototype.
* tests/test_printstrn.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
2017-08-02 00:44:28 +00:00