]> granicus.if.org Git - strace/log
strace
7 years agotests/ip_mreq: use ifindex_lo and IFINDEX_LO_STR
Dmitry V. Levin [Fri, 11 Aug 2017 18:26:02 +0000 (18:26 +0000)]
tests/ip_mreq: use ifindex_lo and IFINDEX_LO_STR

* tests/ip_mreq.c: Do not check for HAVE_IF_INDEXTONAME.
(main): Use ifindex_lo instead of if_nametoindex, use IFINDEX_LO_STR
instead of hardcoded string.

7 years agotests/group_req: use ifindex_lo and IFINDEX_LO_STR
Dmitry V. Levin [Thu, 10 Aug 2017 18:47:28 +0000 (18:47 +0000)]
tests/group_req: use ifindex_lo and IFINDEX_LO_STR

* tests/group_req.c: Do not check for HAVE_IF_INDEXTONAME.
(main): Use ifindex_lo instead of if_nametoindex, use IFINDEX_LO_STR
instead of hardcoded string.

7 years agotests: add ifindex_lo function and IFINDEX_LO_STR macro to libtests
Dmitry V. Levin [Tue, 8 Aug 2017 20:40:57 +0000 (20:40 +0000)]
tests: add ifindex_lo function and IFINDEX_LO_STR macro to libtests

* tests/ifindex.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
* tests/tests.h (ifindex_lo): New prototype.
(IFINDEX_LO_STR): New macro.

7 years agoconfigure.ac: remove redundant linux/dcbnl.h header check
JingPiao Chen [Tue, 15 Aug 2017 04:41:09 +0000 (12:41 +0800)]
configure.ac: remove redundant linux/dcbnl.h header check

* configure.ac (AC_CHECK_HEADERS): Remove linux/dcbnl.h.
* rtnl_dcb.c: Replace HAVE_LINUX_DCBNL_H with HAVE_STRUCT_DCBMSG.
* tests/netlink_route.c: Likewise.

7 years agopathtrace: fix typo in comment
Eugene Syromyatnikov [Fri, 21 Jul 2017 18:14:58 +0000 (20:14 +0200)]
pathtrace: fix typo in comment

7 years agopathtrace: limit amount of checked poll fds similarly to select limit
Eugene Syromyatnikov [Fri, 21 Jul 2017 18:15:24 +0000 (20:15 +0200)]
pathtrace: limit amount of checked poll fds similarly to select limit

* pathtrace.c (pathtrace_match_set): Limit the maximum descriptor number
checked for fd match in poll family syscalls to 1024 * 1024.

7 years agopathtrace: fail poll path match on first failed umove
Eugene Syromyatnikov [Thu, 20 Jul 2017 19:14:42 +0000 (21:14 +0200)]
pathtrace: fail poll path match on first failed umove

* pathtrace.c (pathtrace_match_set): When checking descriptors of poll
family syscalls for fd match, break the loop on first failed umove call.

7 years agoUpdate NEWS
JingPiao Chen [Sun, 13 Aug 2017 02:30:36 +0000 (10:30 +0800)]
Update NEWS

7 years agotests: check decoding of rtnetlink nsid messages
JingPiao Chen [Sun, 13 Aug 2017 02:29:03 +0000 (10:29 +0800)]
tests: check decoding of rtnetlink nsid messages

* tests/netlink_route.c (test_rtnl_nsid): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink: add a basic rtnetlink parser of nsid messages
JingPiao Chen [Sun, 13 Aug 2017 02:29:02 +0000 (10:29 +0800)]
netlink: add a basic rtnetlink parser of nsid messages

* rtnl_nsid.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_rtgenmsg): New prototype.
* netlink_route.c (route_decoders): Add RTM_DELNSID, RTM_GETNSID,
and RTM_NEWNSID.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agotests: check decoding of rtnetlink mdb messages
JingPiao Chen [Sun, 13 Aug 2017 02:27:31 +0000 (10:27 +0800)]
tests: check decoding of rtnetlink mdb messages

* tests/netlink_route.c: Include <netinet/in.h>
and <linux/if_bridge.h>.
(test_rtnl_mdb): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink: add a basic rtnetlink parser of mdb messages
JingPiao Chen [Sun, 13 Aug 2017 02:27:30 +0000 (10:27 +0800)]
netlink: add a basic rtnetlink parser of mdb messages

* rtnl_mdb.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_br_port_msg): New prototype.
* configure.ac (AC_CHECK_TYPES): Check for struct br_port_msg
in <linux/if_bridge.h>.
* netlink_route.c (route_decoders): Add RTM_DELMDB, RTM_GETMDB,
and RTM_NEWMDB.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agotests: check decoding of rtnetlink netconf messages
JingPiao Chen [Sun, 13 Aug 2017 02:27:29 +0000 (10:27 +0800)]
tests: check decoding of rtnetlink netconf messages

* tests/netlink_route.c: Include <linux/netconf.h>.
(test_rtnl_netconf): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink: add a basic rtnetlink parser of netconf messages
JingPiao Chen [Sun, 13 Aug 2017 02:27:28 +0000 (10:27 +0800)]
netlink: add a basic rtnetlink parser of netconf messages

* rtnl_netconf.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_netconfmsg): New prototype.
* configure.ac (AC_CHECK_TYPES): Check for struct netconfmsg
in <linux/netconf.h>.
* netlink_route.c (route_decoders): Add RTM_GETNETCONF
and RTM_NEWNETCONF.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agotests: check decoding of rtnetlink dcb messages
JingPiao Chen [Sun, 13 Aug 2017 02:27:27 +0000 (10:27 +0800)]
tests: check decoding of rtnetlink dcb messages

* tests/netlink_route.c: Include <linux/dcbnl.h>.
(test_rtnl_dcb): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink: add a basic rtnetlink parser of dcb messages
JingPiao Chen [Sun, 13 Aug 2017 02:27:26 +0000 (10:27 +0800)]
netlink: add a basic rtnetlink parser of dcb messages

* rtnl_dcb.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_dcbmsg): New prototype.
* configure.ac (AC_CHECK_HEADERS): Add linux/dcbnl.h.
(AC_CHECK_TYPES): Check for struct dcbmsg in <linux/dcbnl.h>.
* netlink_route.c (route_decoders): Add RTM_GETDCB and RTM_SETDCB.
* xlat/dcb_commands.in: New file.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agotests: check decoding of rtnetlink addrlabel messages
JingPiao Chen [Sun, 13 Aug 2017 02:27:25 +0000 (10:27 +0800)]
tests: check decoding of rtnetlink addrlabel messages

* tests/netlink_route.c: Include <linux/if_addrlabel.h>.
(test_rtnl_addrlabel): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink: add a basic rtnetlink parser of addrlabel messages
JingPiao Chen [Sun, 13 Aug 2017 02:27:24 +0000 (10:27 +0800)]
netlink: add a basic rtnetlink parser of addrlabel messages

* rtnl_addrlabel.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_ifaddrlblmsg): New prototype.
* configure.ac (AC_CHECK_TYPES): Check for struct ifaddrlblmsg
in <linux/if_addrlabel.h>.
* netlink_route.c (route_decoders): Add RTM_DELADDRLABEL,
RTM_GETADDRLABEL, and RTM_NEWADDRLABEL.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agotests: check decoding of rtnetlink tc action messages
JingPiao Chen [Sun, 13 Aug 2017 02:26:38 +0000 (10:26 +0800)]
tests: check decoding of rtnetlink tc action messages

* tests/netlink_route.c (test_rtnl_tca): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink: add a basic rtnetlink parser of tc action messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:31 +0000 (10:22 +0800)]
netlink: add a basic rtnetlink parser of tc action messages

* rtnl_tc_action.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_tcamsg): New prototype.
* netlink_route.c (route_decoders): Add RTM_DELACTION, RTM_GETACTION,
and RTM_NEWACTION.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agotests: check decoding of rtnetlink tc messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:30 +0000 (10:22 +0800)]
tests: check decoding of rtnetlink tc messages

* tests/netlink_route.c (test_rtnl_tc): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink: add a basic rtnetlink parser of tc messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:29 +0000 (10:22 +0800)]
netlink: add a basic rtnetlink parser of tc messages

* rtnl_tc.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_tcmsg): New prototype.
* netlink_route.c (route_decoders): Add RTM_DELQDISC,
RTM_GETQDISC, RTM_NEWQDISC, RTM_DELTCLASS, RTM_GETTCLASS,
RTM_NEWTCLASS, RTM_DELTFILTER, RTM_GETTFILTER, and RTM_NEWTFILTER.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agotests: check decoding of rtnetlink neightbl messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:28 +0000 (10:22 +0800)]
tests: check decoding of rtnetlink neightbl messages

* tests/netlink_route.c (test_rtnl_neightbl): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink: add a basic rtnetlink parser of neightbl messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:27 +0000 (10:22 +0800)]
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>
7 years agotests: check decoding of rtnetlink neigh messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:26 +0000 (10:22 +0800)]
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>
7 years agonetlink: add a basic rtnetlink parser of neigh messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:25 +0000 (10:22 +0800)]
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>
7 years agotests: check decoding of rtnetlink rule messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:24 +0000 (10:22 +0800)]
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>
7 years agonetlink: add a basic rtnetlink parser of rule messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:23 +0000 (10:22 +0800)]
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>
7 years agotests: check decoding of rtnetlink route messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:22 +0000 (10:22 +0800)]
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>
7 years agonetlink: add a basic rtnetlink parser of route messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:21 +0000 (10:22 +0800)]
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>
7 years agotests: check decoding of rtnetlink addr messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:20 +0000 (10:22 +0800)]
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>
7 years agonetlink: add a basic rtnetlink parser of addr messages
JingPiao Chen [Sun, 13 Aug 2017 02:22:19 +0000 (10:22 +0800)]
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>
7 years agoMake description of discrepancies between libc and kernel APIs more relevant
Eugene Syromyatnikov [Sun, 13 Aug 2017 17:33:58 +0000 (19:33 +0200)]
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.

7 years agotests: check decoding of NLMSG_DONE messages of NETLINK_ROUTE
JingPiao Chen [Thu, 10 Aug 2017 01:03:23 +0000 (09:03 +0800)]
tests: check decoding of NLMSG_DONE messages of NETLINK_ROUTE

* tests/netlink_route.c (test_nlmsg_done): New function.
(main): Use it.

7 years agoAdd TF flag to inotify_add_watch syscall entries
Nikolay Marchuk [Fri, 11 Aug 2017 05:43:58 +0000 (12:43 +0700)]
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.

7 years agopathtrace: fix matching of execveat syscall
Nikolay Marchuk [Fri, 11 Aug 2017 05:43:57 +0000 (12:43 +0700)]
pathtrace: fix matching of execveat syscall

* pathtrace.c (pathtrace_match_set): Add testing of SEN_execveat.

7 years agostrace.1: add indentation to examples
Eugene Syromyatnikov [Thu, 10 Aug 2017 19:32:15 +0000 (21:32 +0200)]
strace.1: add indentation to examples

* strace.1 (.de CW): Add .in +4n.
(.de CE): Add .in.

7 years agoGenerate date for the man page
Eugene Syromyatnikov [Thu, 10 Aug 2017 18:40:29 +0000 (20:40 +0200)]
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.

7 years agoAdd script for generating date of the last commit for specific file
Eugene Syromyatnikov [Thu, 10 Aug 2017 18:39:29 +0000 (20:39 +0200)]
Add script for generating date of the last commit for specific file

* file-date-gen: New auxiliary script.

7 years agoMake strace.1 generated
Eugene Syromyatnikov [Thu, 10 Aug 2017 18:38:10 +0000 (20:38 +0200)]
Make strace.1 generated

* .gitignore (/strace.1): New entry.
* configure.ac (AC_CONFIG_FILES): Add strace.1.
* strace.1.in: Rename from strace.1.

7 years agostrace.1: format synopsis using .SY/.OP macros
Eugene Syromyatnikov [Thu, 10 Aug 2017 17:58:15 +0000 (19:58 +0200)]
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.

7 years agostrace.1: remove date from .TH, as it is no longer relevant
Eugene Syromyatnikov [Thu, 10 Aug 2017 17:58:01 +0000 (19:58 +0200)]
strace.1: remove date from .TH, as it is no longer relevant

* strace.1 (.TH): Remove date.

7 years agostrace.1: remove .IX definition
Eugene Syromyatnikov [Thu, 10 Aug 2017 17:45:56 +0000 (19:45 +0200)]
strace.1: remove .IX definition

It is present in groff macros nowadays.

* strace.1 (.de IX): Remove.

7 years agostrace.1: replace .TP with .TQ between command-line option variants
Eugene Syromyatnikov [Thu, 10 Aug 2017 16:14:56 +0000 (18:14 +0200)]
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.

7 years agortnl_link: include "netlink.h" before <linux/rtnetlink.h>
Dmitry V. Levin [Wed, 9 Aug 2017 13:24:13 +0000 (13:24 +0000)]
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>.

7 years agotests: check decoding of rtnetlink link messages
JingPiao Chen [Mon, 19 Jun 2017 07:02:59 +0000 (15:02 +0800)]
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>
7 years agonetlink: add a basic rtnetlink parser of link messages
JingPiao Chen [Fri, 16 Jun 2017 13:11:23 +0000 (21:11 +0800)]
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>
7 years agoMove nl_route_types definition from netlink.c to netlink_route.c
JingPiao Chen [Fri, 16 Jun 2017 12:58:38 +0000 (20:58 +0800)]
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.

7 years agotests: check netlink family specific decoder of NETLINK_ROUTE
JingPiao Chen [Mon, 19 Jun 2017 07:02:59 +0000 (15:02 +0800)]
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>
7 years agonetlink: introduce family specific decoder of NETLINK_ROUTE
JingPiao Chen [Fri, 16 Jun 2017 12:49:15 +0000 (20:49 +0800)]
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>
7 years agotests: check decoding of NETLINK_KOBJECT_UEVENT messages
JingPiao Chen [Tue, 8 Aug 2017 14:39:22 +0000 (22:39 +0800)]
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>
7 years agonetlink: add decoding of NETLINK_KOBJECT_UEVENT messages
JingPiao Chen [Tue, 8 Aug 2017 14:39:21 +0000 (22:39 +0800)]
netlink: add decoding of NETLINK_KOBJECT_UEVENT messages

* netlink.c (decode_netlink): Print NETLINK_KOBJECT_UEVENT messages
as a string using printstrn.

7 years agonetlink: call get_fd_nl_family before nlmsghdr decoding
JingPiao Chen [Tue, 8 Aug 2017 14:37:37 +0000 (22:37 +0800)]
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.

7 years agoMake sysent_shorthand_defs.h suitable for tests
Dmitry V. Levin [Mon, 7 Aug 2017 12:49:44 +0000 (12:49 +0000)]
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.

7 years agoMove sysent shorthand notations to separate files
Edgar Kaziakhmedov [Sat, 5 Aug 2017 01:57:35 +0000 (04:57 +0300)]
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>
7 years agonetlink.c: fix indentation
JingPiao Chen [Mon, 7 Aug 2017 12:44:55 +0000 (20:44 +0800)]
netlink.c: fix indentation

* netlink.c (print_cookie): Fix indentation.

7 years agoMove err/mem subroutines to separate files
Edgar Kaziakhmedov [Sat, 5 Aug 2017 01:57:34 +0000 (04:57 +0300)]
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>
7 years agotests: move check_* functions from options-syntax.test to separate file
Nikolay Marchuk [Mon, 17 Jul 2017 03:44:51 +0000 (10:44 +0700)]
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.

7 years agoSplit qualify.c into basic_filters.c and filter_qualify.c
Nikolay Marchuk [Tue, 27 Jun 2017 04:33:29 +0000 (11:33 +0700)]
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.

7 years agoSimplify handling of unexpected tracees
Dmitry V. Levin [Sun, 6 Aug 2017 15:10:56 +0000 (15:10 +0000)]
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.

7 years agoFix handling of unexpected tracees when PTRACE_SEIZE is not in use
Dmitry V. Levin [Sun, 6 Aug 2017 13:27:07 +0000 (13:27 +0000)]
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.

7 years agopathtrace: fix matching of symlinkat syscall
Dmitry V. Levin [Sun, 6 Aug 2017 12:39:56 +0000 (12:39 +0000)]
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.

7 years agopathtrace: fix missing syscalls
Nikolay Marchuk [Sun, 6 Aug 2017 12:22:06 +0000 (19:22 +0700)]
pathtrace: fix missing syscalls

* pathtrace.c (pathtrace_match_set): Fix symlink decoding,
disable pathtracing for inotify_init.

7 years agoEnhance fflush error diagnostics
Dmitry V. Levin [Sun, 6 Aug 2017 11:26:52 +0000 (11:26 +0000)]
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.

7 years agotests: check handling of CLONE_PARENT'ed and CLONE_PTRACE'ed processes
Dmitry V. Levin [Sun, 6 Aug 2017 00:23:20 +0000 (00:23 +0000)]
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.

7 years agotests: export a path to the trace executable to check_PROGRAMS
Dmitry V. Levin [Sat, 5 Aug 2017 23:05:54 +0000 (23:05 +0000)]
tests: export a path to the trace executable to check_PROGRAMS

* tests/init.sh (STRACE_EXE): Initialize from $STRACE and export.

7 years agoMakefile.am: build top directory first
Eugene Syromyatnikov [Sat, 5 Aug 2017 18:03:38 +0000 (20:03 +0200)]
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.

7 years agoImprove handling of unexpected tracees
Eugene Syromyatnikov [Fri, 4 Aug 2017 09:33:04 +0000 (11:33 +0200)]
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.

7 years agotests: fix unaligned access in nlattr.test
Dmitry V. Levin [Fri, 4 Aug 2017 19:08:27 +0000 (19:08 +0000)]
tests: fix unaligned access in nlattr.test

* tests/nlattr.c (test_nlattr): Use SET_STRUCT
to initialize potentially unaligned struct nlattr.

7 years agotests: fix unaligned access in nlattr_packet_diag_msg.test
Dmitry V. Levin [Fri, 4 Aug 2017 19:06:49 +0000 (19:06 +0000)]
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.

7 years agosparc64: do not bail out in get_scno if PTRACE_PEEKTEXT fails
Dmitry V. Levin [Fri, 4 Aug 2017 18:47:59 +0000 (18:47 +0000)]
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.

7 years agotests: enhance test coverage of printstrn and umoven
Dmitry V. Levin [Wed, 2 Aug 2017 00:45:47 +0000 (00:45 +0000)]
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.

7 years agotests: add test_printstrn function to libtests
Dmitry V. Levin [Wed, 2 Aug 2017 00:44:28 +0000 (00:44 +0000)]
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.

7 years agotests: enhance test coverage of printpath and umovestr
Dmitry V. Levin [Tue, 1 Aug 2017 20:59:48 +0000 (20:59 +0000)]
tests: enhance test coverage of printpath and umovestr

* tests/init.sh (TIMEOUT_DURATION): Raise from 300 to 600.
* tests/printpath-umovestr.c: New file.
* tests/printpath-umovestr-peekdata.c: Likewise.
* tests/printpath-umovestr-undumpable.c: Likewise.
* tests/printpath-umovestr-legacy.test: New test.
* tests/Makefile.am (MISC_TESTS): Add printpath-umovestr-legacy.test.
* tests/gen_tests.in (printpath-umovestr, printpath-umovestr-peekdata,
printpath-umovestr-undumpable): New entries.
* tests/pure_executables.list: Add printpath-umovestr,
printpath-umovestr-peekdata, and printpath-umovestr-undumpable.
* tests/.gitignore: Likewise.

7 years agotests: add test_printpath function to libtests
Dmitry V. Levin [Tue, 1 Aug 2017 20:59:48 +0000 (20:59 +0000)]
tests: add test_printpath function to libtests

* tests/test_ucopy.h (test_printpath): New prototype.
* tests/test_printpath.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.

7 years agotests: add test_process_vm_readv and test_ptrace_peekdata to libtests
Dmitry V. Levin [Tue, 1 Aug 2017 20:59:48 +0000 (20:59 +0000)]
tests: add test_process_vm_readv and test_ptrace_peekdata to libtests

* tests/test_ucopy.c: New file.
* tests/test_ucopy.h: Likewise.
* tests/Makefile.am (libtests_a_SOURCES): Add them.

7 years agoprintpath: do not fetch more than PATH_MAX bytes from tracee's memory
Dmitry V. Levin [Tue, 1 Aug 2017 20:59:48 +0000 (20:59 +0000)]
printpath: do not fetch more than PATH_MAX bytes from tracee's memory

The kernel does not copy more than PATH_MAX bytes from userspace
pathnames, treating non-NUL-terminated pathnames as ENAMETOOLONG.

* util.c (printpathn): Decrease buffer size to PATH_MAX.
(printpath): Specify PATH_MAX - 1 as the maximum pathname length
to match the kernel behaviour.  The underlying umovestr call will fetch
up to PATH_MAX bytes from tracee's memory, but no more than first
PATH_MAX - 1 bytes will be printed.

7 years agoucopy: cleanup umoven_peekdata and umovestr_peekdata
Dmitry V. Levin [Mon, 31 Jul 2017 18:25:00 +0000 (18:25 +0000)]
ucopy: cleanup umoven_peekdata and umovestr_peekdata

* ucopy.c (umoven_peekdata, umovestr_peekdata): Merge aligned
and unaligned tracee address cases.

7 years agoucopy: move legacy fallbacks of umoven and umovestr to separate functions
Dmitry V. Levin [Mon, 31 Jul 2017 18:25:00 +0000 (18:25 +0000)]
ucopy: move legacy fallbacks of umoven and umovestr to separate functions

Move legacy PTRACE_PEEKDATA-based support to separate functions.

* ucopy.c (umoven_peekdata, umovestr_peekdata): New functions.
(umoven, umovestr): Use them.

7 years agoucopy: move process_vm_readv ENOSYS check to vm_read_mem
Dmitry V. Levin [Mon, 31 Jul 2017 18:21:56 +0000 (18:21 +0000)]
ucopy: move process_vm_readv ENOSYS check to vm_read_mem

* ucopy.c (vm_read_mem): Set process_vm_readv_not_supported in case
of ENOSYS.
* ucopy.c (umoven, umovestr): Do not set process_vm_readv_not_supported.

7 years agoPrint enabled optional features in strace version output
Eugene Syromyatnikov [Mon, 31 Jul 2017 16:52:01 +0000 (18:52 +0200)]
Print enabled optional features in strace version output

In order to provide information to user what optionally built features
are available.

* strace.c (print_version): New variable "features".  Print features string
after non-liability disclaimer (or "(none)" in case it is empty).
(print_version) [USE_LIBUNWIND]: Concatenate "stack-unwind" into features
string.
* tests/strace-V.tests (getoption): New function.
Update check in accordance with updated output.

7 years agotests/strace-V.test: rename getval to getstr
Eugene Syromyatnikov [Mon, 31 Jul 2017 17:21:39 +0000 (19:21 +0200)]
tests/strace-V.test: rename getval to getstr

As this name is more suitable.

* tests/strace-V (getval): Rename to getstr, update all call sites.

7 years agoucopy: refactor the check for invalid tracee addresses
Dmitry V. Levin [Sun, 30 Jul 2017 23:40:24 +0000 (23:40 +0000)]
ucopy: refactor the check for invalid tracee addresses

* ucopy.c (tracee_addr_is_invalid): New function.
* ucopy.c (umoven, umovestr): Use it.

7 years agoucopy: enhance vm_read_mem error diagnostics
Dmitry V. Levin [Sun, 30 Jul 2017 23:28:12 +0000 (23:28 +0000)]
ucopy: enhance vm_read_mem error diagnostics

* ucopy.c (umoven, umovestr): Enhance vm_read_mem error diagnostics
to match PTRACE_PEEKDATA case.

7 years agoucopy: skip redundant tracee address truncation check
Dmitry V. Levin [Sat, 29 Jul 2017 23:27:52 +0000 (23:27 +0000)]
ucopy: skip redundant tracee address truncation check

* ucopy.c (vm_read_mem): Skip raddr != truncated_raddr check
if these variables have the same data size.

7 years agoutil: move umoven and umovestr to a separate file
Dmitry V. Levin [Fri, 28 Jul 2017 10:24:35 +0000 (10:24 +0000)]
util: move umoven and umovestr to a separate file

These functions are more kernel-specific compared to all other functions
defined in util.c.

* ucopy.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* util.c (umoven, umovestr): Move to ucopy.c.

7 years agobpf: enhance decoding of BPF_MAP_LOOKUP_ELEM and BPF_MAP_GET_NEXT_KEY
Dmitry V. Levin [Thu, 27 Jul 2017 20:11:33 +0000 (20:11 +0000)]
bpf: enhance decoding of BPF_MAP_LOOKUP_ELEM and BPF_MAP_GET_NEXT_KEY

Print union bpf_attr.value field of BPF_MAP_LOOKUP_ELEM command
and union bpf_attr.next_key field of BPF_MAP_GET_NEXT_KEY command
on entering syscall.  These fields are addresses specified to the
kernel from userspace.  The amount of data written by the kernel
to these addresses is specified at the map creation time
by BPF_MAP_CREATE command and is not available at this point.

* bpf.c (decode_BPF_MAP_LOOKUP_ELEM): Print union bpf_attr.value
on entering syscall.
(decode_BPF_MAP_GET_NEXT_KEY): Print union bpf_attr.next_key
on entering syscall.
(bpf_map_io): Remove.
* tests/bpf.c (print_BPF_MAP_DELETE_ELEM_first,
print_BPF_MAP_DELETE_ELEM_attr, print_BPF_MAP_GET_NEXT_KEY_first,
print_BPF_MAP_GET_NEXT_KEY_attr): Replace macro redirects with
new functions.
(print_BPF_MAP_LOOKUP_ELEM_first, print_BPF_MAP_LOOKUP_ELEM_attr,

7 years agobpf: update BPF_MAP_CREATE decoding
Dmitry V. Levin [Thu, 27 Jul 2017 00:44:31 +0000 (00:44 +0000)]
bpf: update BPF_MAP_CREATE decoding

Implement decoding of map_flags and inner_map_fd fields of union bpf_attr
for BPF_MAP_CREATE command introduced by linux kernel commits
v4.6-rc1~91^2~108^2~6 and v4.12-rc1~64^3~373^2~2, respectively.

* configure.ac: Check for inner_map_fd member of union bpf_attr
instead of max_entries.
* xlat/bpf_map_flags.in: New file.
* bpf.c: Include "xlat/bpf_map_flags.h".
(decode_BPF_MAP_CREATE): Add map_flags and inner_map_fd fields
to the structure, print them.
* tests/bpf.c: Update macro guards of BPF_MAP_CREATE decoder test.
(init_BPF_MAP_CREATE_first, print_BPF_MAP_CREATE_attr): Update expected
output.
(init_BPF_MAP_CREATE_attr): Initialize map_flags and inner_map_fd
fields, update offset.

7 years agobpf: update BPF_PROG_LOAD decoding
Dmitry V. Levin [Thu, 27 Jul 2017 00:44:31 +0000 (00:44 +0000)]
bpf: update BPF_PROG_LOAD decoding

Implement decoding of union bpf_attr.prog_flags field for BPF_PROG_LOAD
command introduced by linux kernel commit v4.12-rc2~34^2~29^2~2.

* configure.ac: Check for prog_flags member of union bpf_attr
instead of kern_version.
* xlat/bpf_prog_flags.in: New file.
* bpf.c: Include "xlat/bpf_prog_flags.h".
(decode_BPF_PROG_LOAD): Add prog_flags field to the structure, print it.
* tests/bpf.c: Update macro guards of BPF_PROG_LOAD decoder test.
(init_BPF_PROG_LOAD_first, print_BPF_PROG_LOAD_attr): Update expected
output.
(init_BPF_PROG_LOAD_attr): Initialize prog_flags field, update offset.

7 years agotests: enhance test coverage of bpf syscall parser
Dmitry V. Levin [Wed, 26 Jul 2017 10:28:25 +0000 (10:28 +0000)]
tests: enhance test coverage of bpf syscall parser

* configure.ac: Update union bpf_attr member checks.
* tests/bpf.c: Rewrite.
* tests/bpf-v.c: New file.
* tests/gen_tests.in (bpf-v): New entry.
* tests/pure_executables.list: Add bpf-v.
* tests/.gitignore: Likewise.

7 years agom4: macroize union bpf_attr field checks
Dmitry V. Levin [Wed, 26 Jul 2017 10:28:25 +0000 (10:28 +0000)]
m4: macroize union bpf_attr field checks

* m4/st_bpf.m4: New file.
* configure.ac: Use st_CHECK_UNION_BPF_ATTR.

7 years agoMove offsetofend from defs.h to macros.h
Dmitry V. Levin [Wed, 26 Jul 2017 10:28:25 +0000 (10:28 +0000)]
Move offsetofend from defs.h to macros.h

* defs.h (offsetofend): Move ...
* macros.h: ... here.

7 years agobpf: print unused fields of union bpf_attr if one of them is non-zero
Dmitry V. Levin [Wed, 26 Jul 2017 10:28:25 +0000 (10:28 +0000)]
bpf: print unused fields of union bpf_attr if one of them is non-zero

When the size argument specifies more data than necessary for the given
command, kernel checks that all unused fields of union bpf_attr are
zero.  Print this extra data when it contains non-zero bytes to enhance
debugging experience.

* bpf.c (decode_attr_extra_data): New function.
(decode_BPF_MAP_CREATE, decode_BPF_MAP_UPDATE_ELEM,
decode_BPF_MAP_DELETE_ELEM, bpf_map_io, decode_BPF_PROG_LOAD,
decode_BPF_OBJ_PIN, decode_BPF_OBJ_GET, decode_BPF_PROG_ATTACH,
decode_BPF_PROG_DETACH): Use it to print extra data passed
via bpf_attr pointer.
(bpf_obj_manage, bpf_prog_attach_detach): Remove.
* tests/bpf.c (map_delete_elem): New function.
(main): Use it.

7 years agobpf: change handling of big and unaccessible data to match the kernel
Dmitry V. Levin [Wed, 26 Jul 2017 10:28:25 +0000 (10:28 +0000)]
bpf: change handling of big and unaccessible data to match the kernel

When the size argument exceeds PAGE_SIZE, the kernel fails with E2BIG
without parsing union bpf_attr.
When the whole chunk of memory specified by addr and size arguments is
not readable, the kernel fails with EFAULT.

* bpf.c (DECL_BPF_CMD_DECODER) <bpf_cmd_decoder>: Add const qualifier
to size argument, add data argument.
(decode_BPF_MAP_CREATE, decode_BPF_MAP_UPDATE_ELEM,
decode_BPF_MAP_DELETE_ELEM, bpf_map_io, decode_BPF_PROG_LOAD,
bpf_obj_manage, bpf_prog_attach_detach): Move size argument check and
memory fetching ...
(SYS_FUNC(bpf)) ... here, add PAGE_SIZE check, pass fetched memory
to command-specific parsers.

7 years agobpf: replace big switch statement with a dispatch table
Dmitry V. Levin [Tue, 25 Jul 2017 12:47:19 +0000 (12:47 +0000)]
bpf: replace big switch statement with a dispatch table

* bpf.c (DECL_BPF_CMD_DECODER, DEF_BPF_CMD_DECODER, BPF_CMD_ENTRY):
New macros.
(bpf_cmd_decoder_t): New typedef.
Rename static parser functions using DEF_BPF_CMD_DECODER.
(decode_BPF_MAP_LOOKUP_ELEM, decode_BPF_MAP_GET_NEXT_KEY): New proxy
functions.
(SYS_FUNC(bpf)): Replace big switch statement with a dispatch table.

7 years agobpf: use PRINT_FIELD_* macros
Dmitry V. Levin [Tue, 25 Jul 2017 12:47:19 +0000 (12:47 +0000)]
bpf: use PRINT_FIELD_* macros

* print_fields.h (PRINT_FIELD_STR, PRINT_FIELD_PATH): New macros.
* bpf.c: Include "print_fields.h".
(bpf_map_create): Use PRINT_FIELD_U and PRINT_FIELD_XVAL.
(bpf_map_update_elem): Use PRINT_FIELD_FD, PRINT_FIELD_X, and
PRINT_FIELD_XVAL.
(bpf_map_delete_elem, bpf_map_io): Use PRINT_FIELD_FD and PRINT_FIELD_X.
(bpf_prog_load): Use PRINT_FIELD_STR, PRINT_FIELD_U, PRINT_FIELD_X,
and PRINT_FIELD_XVAL.
(bpf_obj_manage): Use PRINT_FIELD_FD and PRINT_FIELD_PATH.
(bpf_prog_attach_detach): Use PRINT_FIELD_FD, PRINT_FIELD_FLAGS,
and PRINT_FIELD_XVAL.

7 years agoAdd terminating comment after each DECL_* macro definition
Eugene Syromyatnikov [Tue, 25 Jul 2017 10:57:11 +0000 (12:57 +0200)]
Add terminating comment after each DECL_* macro definition

In an attempt to improve readability.

* defs.h (DECL_IOCTL, DECL_NETLINK, DECL_PRINTNUM, DECL_PRINTNUM_ADDR,
ATTRIBUTE_FORMAT): Add comment that marks end of macro definition.
* netlink_sock_diag (DECL_NETLINK_DIAG_DECODER): Likewise.
* nlattr.h (DECL_NLA): Likewise.

7 years agoIntroduce print_quoted_cstring
Dmitry V. Levin [Mon, 24 Jul 2017 12:10:54 +0000 (12:10 +0000)]
Introduce print_quoted_cstring

In many places where kernel expects a NUL-terminated string of length
up to a known fixed limit, e.g. when a NUL-terminated string is
a fixed-size field of a structure, strace does not print the last byte
assuming it is NUL, which is not always the case.

Change output format for such strings to distinguish NUL-terminated
strings from non-NUL-terminated ones: append ellipsis to the output
when the string is not NUL-terminated.

* defs.h (print_quoted_cstring): New prototype.
* util.c (print_quoted_cstring): New function.
(printpathn): Use it instead of print_quoted_string with
QUOTE_0_TERMINATED argument.
* print_fields.h (PRINT_FIELD_CSTRING): Likewise.
* btrfs.c (btrfs_ioctl): Likewise.
* dirent.c (SYS_FUNC(getdents)): Likewise.
* dirent64.c (SYS_FUNC(getdents64)): Likewise.
* print_ifindex.c (print_ifindex): Likewise.
* sysmips.c (SYS_FUNC(sysmips)): Likewise.
* ubi.c (ubi_ioctl): Likewise.
* tests/tests.h (print_quoted_cstring): New prototype.
* tests/print_quoted_string.c (print_quoted_cstring): New function.
* tests/ioctl_block.c (main): Update expected output.
* tests/ioctl_dm.c (main): Likewise.
* tests/ioctl_loop.c (print_loop_info, print_loop_info64): Likewise.
* tests/netlink_crypto.c (test_crypto_msg_newalg): Likewise.

7 years agotests: check decoding of NETLINK_CRYPTO crypto_user_alg attributes
JingPiao Chen [Sat, 22 Jul 2017 23:56:04 +0000 (07:56 +0800)]
tests: check decoding of NETLINK_CRYPTO crypto_user_alg attributes

* tests/nlattr_crypto_user_alg.c: New file.
* tests/gen_tests.in (nlattr_crypto_user_alg): New entry.
* tests/pure_executables.list: Add nlattr_crypto_user_alg.
* tests/.gitignore: Likewise.

7 years agotests: extend TEST_NLATTR_OBJECT macro
JingPiao Chen [Thu, 20 Jul 2017 08:45:58 +0000 (16:45 +0800)]
tests: extend TEST_NLATTR_OBJECT macro

* tests/test_nlattr.h (TEST_NLATTR_OBJECT_EX_,
TEST_NLATTR_OBJECT_EX): New macros.
(TEST_NLATTR_OBJECT): Use TEST_NLATTR_OBJECT_EX_.