* m4/ax_code_coverage.m4: Update to serial 24. In particular,
this version has no lcov version check.
* Makefile.am (strace_LDADD): Rename CODE_COVERAGE_LDFLAGS
to CODE_COVERAGE_LIBS.
* netlink.c: Include "nlattr.h" and "xlat/nlmsgerr_attrs.h".
(print_cookie, decode_nlmsgerr_attr_cookie): New functions.
(nlmsgerr_nla_decoders): New array.
(decode_nlmsgerr): Use it.
* xlat/nlmsgerr_attrs.in: New file.
* NEWS: Mention this.
* netlink.c: Include "xlat/netlink_ack_flags.h".
(decode_nlmsg_flags): Decode ack flags when type == NLMSG_ERROR.
* xlat/netlink_ack_flags.in: New file.
* NEWS: Mention this.
* tests/netlink_protocol.c (test_ack_flags): New function, check this.
(main): Use it.
* tests/init.sh (dump_log_and_fail_with): Dump $LOG to stderr instead
of stdout as the latter is more likely to be redirected to a temporary
file in the context where this function is called.
* tests/init.sh: Trap SIGXCPU.
* tests/run.sh: Send SIGXCPU instead of SIGKILL in case of timeout, send
SIGKILL if the command is still running 5 seconds after SIGXCPU.
userfaultfd: decode struct uffdio_api.features as flags
* xlat/uffd_api_features.in: New file.
* userfaultfd.c: Include "xlat/uffd_api_features.h".
(uffdio_ioctl): Print struct uffdio_api.features using
PRINT_FIELD_FLAGS64 and uffd_api_features.
* NEWS: Mention this.
* tests/ioctl_uffdio.c: Include "xlat.h" and "xlat/uffd_api_features.h".
(main): Update expected output.
userfaultfd: enhance decoding of struct uffdio_api.features
As struct uffdio_api.features has read-write semantics,
print the value returned by the kernel only when it differs
from the value passed to the kernel.
* userfaultfd.c (uffdio_ioctl) <UFFDIO_API>: On entering syscall,
save the value of struct uffdio_api.features. On exiting syscall, do
not print struct uffdio_api.features when it's the same as on entering.
* tests/ioctl_uffdio.c (main): Update expected output.
This also fixes output correctness for struct uffdio_api.features.
* userfaultfd.c: Include "print_fields.h".
(tprintf_uffdio_range): Use PRINT_FIELD_X.
(PRINT_FIELD_UFFDIO_RANGE): New macro.
(uffdio_ioctl): Use it, PRINT_FIELD_FLAGS64, and PRINT_FIELD_X.
* tests/ioctl_uffdio.c (main): Update expected output.
* xlat/bpf_commands.in: Add BPF_PROG_TEST_RUN, BPF_PROG_GET_NEXT_ID,
BPF_MAP_GET_NEXT_ID, BPF_PROG_GET_FD_BY_ID, BPF_MAP_GET_FD_BY_ID,
and BPF_OBJ_GET_INFO_BY_FD introduced by linux kernel commits
v4.12-rc1~64^3~287^2~5, v4.13-rc1~157^2~271^2~5,
v4.13-rc1~157^2~271^2~4, v4.13-rc1~157^2~271^2~3, and
v4.13-rc1~157^2~271^2~1, respectively.
* xlat/bpf_attach_type.in: Add BPF_CGROUP_SOCK_OPS introduced
by linux kernel commit v4.13-rc1~157^2~37^2~15.
* xlat/bpf_prog_types.in: Add BPF_PROG_TYPE_SOCK_OPS introduced
by the same commit.
* test_netlink.h (TEST_NETLINK_OBJECT): New macro.
* tests/netlink_selinux.c: Include "test_netlink.h"
instead of "netlink.h".
(test_selnl_msg_unspec, test_selnl_msg_setenforce,
test_selnl_msg_policyload): New functions.
(main): Use them.
* sg_io_v3.c: Include "print_fields.h".
(PRINT_FIELD_SG_IO_BUFFER): New macro.
(decode_request, decode_response): Use it, PRINT_FIELD_D, PRINT_FIELD_U,
PRINT_FIELD_X, PRINT_FIELD_PTR, PRINT_FIELD_FLAGS, and PRINT_FIELD_XVAL.
Move is_negated_errno() to new header negated_errno.h
Move is_negated_errno() to a separate new header file negated_errno.h
and include it just for architectures which require it.
is_negated_errno() is not used on those architectures
that have a dedicated register to signal a syscall error.
The issue was raised when compiling with clang, which is more
strict regarding semantics of unused static inline functions
defined in C files and will issue a -Wunused-function warrning
if they are not used anywhere.
* sg_io_v4.c: Include "print_fields.h".
(PRINT_FIELD_SG_IO_BUFFER): New macro.
(decode_request, decode_response): Use it, PRINT_FIELD_D, PRINT_FIELD_U,
PRINT_FIELD_X, PRINT_FIELD_FLAGS, and PRINT_FIELD_XVAL.
mips64: fix PRI__64 macro definition when compiled for Android
By default for MIPS64 in Android __u64 type is exported
as unsigned long long. This caused compilation -Wformat warnings
and would break the build if -Werror is used.
* defs.h [SIZEOF_LONG != 4 && MIPS && __ANDROID__] (PRI__64): Change
from "l" to "ll".
netlink_sock_diag: enhance decoding of long meminfo arrays
Print trailing dots instead of silent truncation if the array
is too long.
* netlink_sock_diag.c (decode_meminfo): Do not apply SK_MEMINFO_VARS
limit to nmemb, specify element count to print_array instead.
(print_meminfo): Check element count and terminate printing
if the element count exceeds SK_MEMINFO_VARS.
* tests/nlattr_inet_diag_msg.c (main): Check it.
tests: introduce TEST_NETLINK and TEST_NETLINK_ macros
* tests/test_netlink.h: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
* tests/netlink_sock_diag.c: Include "test_netlink.h"
instead of "netlink.h".
(TEST_SOCK_DIAG): New macro.
(test_unix_diag_req, test_unix_diag_msg,
test_netlink_diag_req, test_netlink_diag_msg,
test_packet_diag_req, test_packet_diag_msg,
test_inet_diag_req, test_inet_diag_req_v2,
test_inet_diag_msg, test_smc_diag_req,
test_smc_diag_msg): Use it.
(test_odd_family_req, test_odd_family_msg,
test_inet_diag_sockid): Use TEST_NETLINK macro.
* linux/inet_diag.h (inet_diag_bc_op, inet_diag_hostcond,
inet_diag_markcond): New structures.
(INET_DIAG_BC_*): New enum.
* netlink_sock_diag.c: Include "xlat/inet_diag_bytecodes.h".
(decode_inet_addr, decode_inet_diag_hostcond,
print_inet_diag_bc_op, decode_inet_diag_markcond,
decode_bytecode_data, decode_inet_diag_bc_op): New functions.
(inet_diag_req_nla_decoders): New array.
(decode_inet_diag_req_compat, decode_inet_diag_req_v2): Use it.
* xlat/inet_diag_bytecodes.in: New file.
* print_fields.h (PRINT_FIELD_0X): New macro.
* sockaddr.c (print_sockaddr_data_ipx, print_sockaddr_data_nl): Use it
instead of manual tprintf statements.
* netlink_sock_diag.c (PRINT_FIELD_SMC_DIAG_CONNINFO_FLAGS): Remove.
(decode_smc_diag_conninfo): Replace it with PRINT_FIELD_0X.
JingPiao Chen [Sun, 21 May 2017 11:49:43 +0000 (19:49 +0800)]
netlink: decode AF_SMC smc_diag_msg attributes
* linux/smc_diag.h (smc_diag_cursor, smc_diag_conninfo
smc_diag_linkinfo, smc_diag_lgrinfo): New structures.
* netlink_sock_diag.c: Include "xlat/smc_link_group_roles.h".
(decode_smc_diag_conninfo, decode_smc_diag_lgrinfo): New functions.
(smc_diag_msg_nla_decoders): New array.
(decode_smc_diag_msg): Use it.
* xlat/smc_link_group_roles.in: New file.
Nikolay Marchuk [Sat, 8 Jul 2017 08:28:56 +0000 (15:28 +0700)]
pathtrace.c: introduce user-provided sets of paths
* defs.h (struct path_set): New structure.
(global_path_set): New variable prototype.
(tracing_paths): Change macro body to use global_path_set variable.
(pathtrace_select_set): Add "struct path_set *" argument.
(pathtrace_match_set): Likewise. Change return type to bool.
(pathtrace_select, pathtrace_match): Change into thin macro wrappers
around pathtrace_select_set and pathtrace_match_set, repsectively.
* pathtrace.c (global_path_set): New variable.
(storepath, pathtrace_select_set): Add "struct path_set *" argument.
(pathmatch, upathmatch, fdmatch, pathtrace_match_set): Likewise.
Change return type to bool.
The size of struct group_req depends on alignment of long and therefore
has to be mpersified.
* print_group_req.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* net.c (print_group_req): Move to print_group_req.c, wrap into
MPERS_PRINTER_DECL.
net: enhance decoding of MCAST_JOIN_GROUP/MCAST_LEAVE_GROUP
* net.c (print_group_req): Allow option length greater than
sizeof(struct group_req) to match the kernel behaviour.
When the option length is invalid, print the address.
* NEWS: Mention this.
net: enhance decoding of IP_ADD_MEMBERSHIP et al socket options
* net.c (print_mreq, print_mreq6): Treat negative option length
as invalid to match the kernel behaviour. When the option length
is invalid, print the address.
* NEWS: Mention it.
* tests/ip_mreq.c (main): Check it. Update expected output.
* msghdr.c (print_scm_creds): Use PRINT_FIELD_U and PRINT_FIELD_UID.
(print_cmsg_ip_recverr): Use PRINT_FIELD_U.
(print_struct_msghdr): Use PRINT_FIELD_U and PRINT_FIELD_FLAGS.
* print_fields.h (PRINT_FIELD_SOCKADDR): New macro.
* msghdr.c (print_cmsg_ip_recverr): Use it instead of print_sockaddr.
* net.c (print_group_req): Likewise.
* sock.c (PRINT_IFREQ_ADDR): Remove.
(print_ifreq, print_ifconf_ifreq): Use PRINT_FIELD_SOCKADDR
instead of PRINT_IFREQ_ADDR.
* net.c (print_tpacket_stats, print_tpacket_req): Use PRINT_FIELD_U.
(print_group_req): Use PRINT_FIELD_IFINDEX.
(print_packet_mreq): Use PRINT_FIELD_IFINDEX, PRINT_FIELD_U,
and PRINT_FIELD_XVAL.
* netlink_sock_diag.c (PRINT_FIELD_INET_DIAG_SOCKID): New macro.
(decode_inet_diag_req_compat, decode_inet_diag_req_v2,
decode_inet_diag_msg, decode_smc_diag_req, decode_smc_diag_msg): Use it
instead of print_inet_diag_sockid.
* print_fields.h (PRINT_FIELD_NET_PORT): New macro.
* netlink_sock_diag.c (print_inet_diag_sockid): Use it
instead of a manual tprintf statement.
* sockaddr.c (print_sockaddr_data_in, print_sockaddr_data_in6,
print_sockaddr_data_ipx): Likewise.
* linux/packet_diag.h (packet_diag_info, packet_diag_mclist,
packet_diag_ring): New structures.
(PDI_*): New macros.
* netlink_sock_diag.c: Include <linux/filter.h>
and "xlat/packet_diag_info_flags.h".
(decode_packet_diag_info, decode_packet_diag_mclist,
decode_packet_diag_ring, decode_packet_diag_filter): New functions.
(packet_diag_msg_nla_decoders): New array.
(decode_packet_diag_msg): Use it.
* print_fields.h (PRINT_FIELD_QUOTED_STRING): New macro.
* xlat/packet_diag_info_flags.in: New file.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
tests: fix TEST_NLATTR_OBJECT and TEST_NLATTR_ARRAY for large objects
commit v4.17-161-gdbd0605 that adjusted TEST_NLATTR_OBJECT and
TEST_NLATTR_ARRAY for large objects, only changed the pattern
print length, large length still can be specified as nla_data_len,
resulting to output mismatch.
* tests/test_nlattr.h (TEST_NLATTR_OBJECT): Pass "plen"
both as nla_data_len and slen arguments of TEST_NLATTR_
in len < sizeof(object) case.
(TEST_NLATTR_ARRAY): Likewise, Pass "plen" both as nla_data_len
and slen arguments of TEST_NLATTR_ in len < sizeof(object[0]) case.
Implement decoding of linux socket filter programs
* bpf_sock_filter.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* xlat/skf_ad.in: New file.
* defs.h (decode_sock_fprog, print_sock_fprog): New prototypes.
* fetch_bpf_fprog.c (get_bpf_fprog_size): New mpers printer.
* net.c (print_getsockopt): Use decode_sock_fprog to print
socket filter programs for SO_GET_FILTER socket option.
(print_setsockopt): Use decode_sock_fprog and get_bpf_fprog_size
to print socket filter programs for SO_ATTACH_FILTER
and SO_ATTACH_REUSEPORT_CBPF socket options.
* NEWS: Mention this.
tests: fix print_quoted_hex output of bytes with high bit set
* tests/tests.h (print_quoted_memory, print_quoted_hex): Change the type
of first argument from "const char *" to "const void *".
* tests/print_quoted_string.c: Likewise.
(print_quoted_hex): Print bytes as unsigned char objects to avoid
unwanted sign extension.
* tests/netlink_protocol.c (send_query): Remove the cast of print_quoted_hex
first argument which is now redundant.
net: accept arbitrary option length for getsockopt's SO_LINGER
* net.c (print_linger): Rename to print_set_linger.
(print_setsockopt): Replace print_linger with print_set_linger.
(print_get_linger): New function that accepts arbitrary option length
to match the kernel behaviour.
(print_getsockopt): Replace print_linger with print_get_linger.
* NEWS: Mention this.
net: enhance decoding of getsockopt's optlen argument
As the last argument of getsockopt syscall has read-write semantics,
print both user and kernel values when they differ.
* net.c (SYS_FUNC(getsockopt)): On entering syscall, fetch and save
the length specified to the kernel. On error, print the length saved
on entering. When the saved length and the length returned by the
kernel differ, print both values.
* NEWS: Mention this.
* tests/net-icmp_filter.c (main): Update expected output.
Linux socket filter uses almost the same classic BPF as seccomp filter,
The only difference noticeable from strace PoV is the meaning of generic
multiuse field.
Transform the parser of seccomp filters to a more generic parser
of classic BPF, parametrized with a method of parsing the generic
multiuse field in BPF_STMT.
* bpf_filter.c: New file.
* bpf_filter.h: Likewise.
* bpf_fprog.h: Likewise.
* bpf_seccomp_filter.c: Likewise.
* fetch_bpf_fprog.c: Likewise.
* fetch_seccomp_fprog.c: Remove.
* seccomp_fprog.h: Likewise.
* Makefile.am (strace_SOURCES): Add bpf_filter.c, bpf_filter.h,
bpf_fprog.h, bpf_seccomp_filter.c, and fetch_bpf_fprog.c.
Remove fetch_seccomp_fprog.c and seccomp_fprog.h.
* seccomp.c: Do not include linux/filter.h and xlat header files.
Do not define SECCOMP_RET_ACTION.
(bpf_filter, decode_bpf_code, decode_bpf_stmt, decode_bpf_jump,
print_bpf_filter, print_seccomp_fprog, print_seccomp_filter): Remove.
* defs.h (print_seccomp_filter): Rename to decode_seccomp_fprog.
(SYS_FUNC(seccomp)): Replace print_seccomp_filter
with decode_seccomp_fprog.
* prctl.c (SYS_FUNC(prctl)): Likewise.
* nlattr.c (decode_nlattr_with_data): Replace printstrn
with printstr_ex and set QUOTE_FORCE_HEX flag.
* tests/tests.h (print_quoted_hex): New prototype.
* tests/print_quoted_string.c (print_quoted_hex): New function.
* tests/test_nlattr.h (TEST_NLATTR_OBJECT, TEST_NLATTR_ARRAY): Use it
for updated expected output. Change the type of "plen" variable
to unsigned int.
* tests/nlattr.c (test_nlattr): Update expected output.
tests: print quotation marks in print_quoted_memory
* tests/print_quoted_string.c (print_quoted_memory): Print opening
and closing quotation marks.
* tests/getcwd.c (main): Do not print quotation marks around
print_quoted_string.
* tests/uname.c (main): Likewise.
* tests/keyctl.c (print_quoted_string_limit): Do not print quotation
marks around print_quoted_memory.
* tests/netlink_protocol.c (send_query): Likewise.
* tests/xattr.c (main): Likewise.
tests: robustify create_nl_socket based tests against the race condition
There is a race condition between the moment a netlink socket is created
and the moment it is reported via SOCK_DIAG_BY_FAMILY interface.
Add one more operation on the socket created by create_nl_socket
to increase chances of winning the race.
* tests/create_nl_socket.c (create_nl_socket_ext): Add a getsockopt call
with the created socket.