Fix decoding of struct msghdr.msg_name* arguments of recvmsg syscall
As the msghdr.msg_namelen argument of recvmsg syscall has the same
read-write semantics as the address length argument of recvfrom syscall,
parser of recvmsg syscall needs a similar fix.
* defs.h (fetch_msghdr_namelen): New prototype.
(decode_msghdr): Add "int *" argument.
* msghdr.c (print_msghdr): Likewise. Treat it as a pointer to struct
msghdr.msg_namelen passed to the kernel. Pass to decode_sockaddr
the size of socket address actually returned by the kernel.
Print both user and kernel address lengths when the value changes.
(decode_msghdr, decode_mmsghdr): Add "int *" argument,
forward it to print_msghdr.
(decode_mmsgvec): Update decode_mmsghdr invocation.
(fetch_msghdr_namelen): New function.
* net.c (SYS_FUNC(sendmsg)): Update decode_msghdr invocation.
(SYS_FUNC(recvmsg)): Use fetch_msghdr_namelen on entering to save
struct msghdr.msg_namelen. On exiting, pass the saved value
to decode_msghdr.
* linux/64/ioctls_inc.h: Update from linux v4.7 using ioctls_gen.sh.
* linux/32/ioctls_inc_align32.h: Likewise.
* linux/32/ioctls_inc_align64.h: Likewise.
Fix decoding of sockaddr related arguments of recvfrom syscall
* net.c (SYS_FUNC(recvfrom)): Use fetch_socklen. Save the address
length passed to the kernel and print it on error. Do not print more
bytes of the socket address than actually returned by the kernel.
Print both user and kernel address lengths when the returned address
is truncated.
Print both values of changing address length in sockname family syscalls
* net.c (decode_sockname): Print both user and kernel address lengths
when the value changes.
* tests/net-y-unix.c (main): Update expected output.
* tests/net-yy-unix.c (main): Likewise.
* tests/net.expected: Likewise.
Enhance diagnostics of address truncation in sockname family syscalls
* net.c (decode_sockname): Print both user and kernel address lengths
when the returned address is truncated.
* tests/sun_path.expected: Update expected output.
Fix decoding of getsockname, getpeername, accept, and accept4 syscalls
* net.c (fetch_socklen): New function.
(decode_sockname): Use it. On entering syscall, decode early
and return RVAL_DECODED when possible. On error, print the address
length passed to the kernel. Do not print more bytes of the socket
address than actually returned by the kernel.
Prepare parsers of sockname family syscalls for the upcoming fix
* net.c (do_sockname): Rename to decode_sockname, drop second argument,
do not print sock_type_flags, return RVAL_DECODED on exiting.
(SYS_FUNC(accept), SYS_FUNC(getsockname)): Use decode_sockname instead
of do_sockname, take its return code into account.
(SYS_FUNC(accept4)): Likewise. Print sock_type_flags when
decode_sockname returns RVAL_DECODED.
* tests/netlink_protocol.c (send_query): Check that no part
of netlink message is fetched beyond the end of message.
Check decoding of zero address and zero length messages.
Check decoding of messages with nlmsg_len exceeding message length.
Introduce a general socket netlink parser which prints the header and
a string for the remaining part of the buffer. It doesn't handle all
the netlink flags and types yet because the parser needs more
information, this will be implemented later.
* net.c (decode_sockbuf): New function.
(SYS_FUNC(send), SYS_FUNC(sendto), SYS_FUNC(recv), SYS_FUNC(recvfrom)):
Use it instead of printstr.
* msghdr.c (print_msghdr): Pass IOV_DECODE_NETLINK to tprint_iov_upto()
for netlink sockets.
* netlink.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (decode_netlink, getfdproto): New prototypes.
(iov_decode): Add IOV_DECODER_NETLINK.
* io.c (print_iovec): Use decode_netlink().
* util.c (getfdproto): Remove static keyword.
* xlat/netlink_flags.in: New file.
* xlat/netlink_types.in: New file.
* xlat/fsmagic.in: Add NSFS_MAGIC, TRACEFS_MAGIC, BPF_FS_MAGIC,
and UDF_SUPER_MAGIC introduced by linux kernel commits
v3.19-rc1~53^2~7^2~1, v4.1-rc1~147^2~4, v4.4-rc1~141^2~17^2~1,
and v4.7-rc1~161^2, respectively.
msghdr.c: limit output when printing excessively large messages
Limit output of struct msghdr.msg_control when
struct msghdr.msg_controllen is greater than the maximum ancillary
buffer size specified in /proc/sys/net/core/optmem_max file.
* configure.ac (AC_CHECK_FUNCS): Add open64.
* defs.h (read_int_from_file): New prototype.
* util.c (read_int_from_file): New function.
* msghdr.c (get_optmem_max): New function based on read_int_from_file.
(decode_msg_control): Use it to check control_len argument.
* tests/msg_control.c (test_big_len): New function.
(main): Use it to test printing of excessively large messages.
msghdr.c: limit IP_RECVOPTS/IP_RETOPTS output in abbrev mode
* msghdr.c (print_cmsg_ip_opts): Do not print more than max_strlen
bytes of ip options in abbrev mode.
* tests/msg_control.c (print_ip_opts): Use DEFAULT_STRLEN.
(test_sol_ip): Test IP_RETOPTS output in abbrev mode.
* msghdr.c (print_scm_rights): Do not print more than max_strlen
descriptors in abbrev mode.
* tests/msg_control.c (DEFAULT_STRLEN): New macro.
(print_fds): Use it.
(test_scm_rights3): New function.
(main): Use it to test SCM_RIGHTS output in abbrev mode.
* tests/msg_control-v.c: New file.
* tests/msg_control-v.test: New test.
* tests/.gitignore: Add msg_control-v.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add msg_control-v.test.
Dmitry V. Levin [Thu, 30 Jun 2016 22:39:02 +0000 (22:39 +0000)]
msghdr.c: merge print_cmsg_ip_ttl and print_cmsg_ip_checksum
* msghdr.c (print_cmsg_ip_ttl): Rename to print_cmsg_uint.
(print_cmsg_ip_checksum): Remove.
(print_cmsg_type_data): Replace print_cmsg_ip_ttl
and print_cmsg_ip_checksum with print_cmsg_uint.
Dmitry V. Levin [Mon, 27 Jun 2016 00:02:55 +0000 (00:02 +0000)]
net.c: move all msghdr and mmsghdr parsers to a separate file
* defs.h (msg_flags, socketlayers, decode_msghdr, decode_mmsg):
New prototypes.
* msghdr.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* net.c: Move all msghdr and mmsghdr parsers to msghdr.c.
Dmitry V. Levin [Mon, 27 Jun 2016 00:02:50 +0000 (00:02 +0000)]
Mpersify fetchers of struct msghdr and struct mmsghdr
* fetch_struct_msghdr.c: New file.
* fetch_struct_mmsghdr.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* net.c (struct msghdr32, struct mmsghdr32, copy_from_msghdr32,
fetch_msghdr, fetch_mmsghdr): Remove.
(decode_msghdr, dumpiov_in_msghdr): Use fetch_struct_msghdr instead
of fetch_msghdr.
(decode_mmsghdr): Change msg_len argument to use_msg_len.
Use fetch_struct_mmsghdr instead of fetch_mmsghdr.
Return fetch_struct_mmsghdr's return code.
(decode_mmsg): Rename to decode_mmsgvec. Take addr and len arguments.
Do not print vlen and flags. Check decode_mmsghdr's return code.
Print mmsghdr array using square brackets.
(dumpiov_in_mmsghdr): Use fetch_struct_mmsghdr instead of fetch_mmsghdr.
(SYS_FUNC(sendmmsg), SYS_FUNC(recvmmsg)): Use decode_mmsgvec instead
of decode_mmsg. Print vlen and flags.
* tests/mmsg.c (main): Update expected output.
Dmitry V. Levin [Mon, 27 Jun 2016 00:02:41 +0000 (00:02 +0000)]
net.c: move fallback definition of struct mmsghdr to a separate file.
* msghdr.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* net.c: Include it. Move fallback definition of struct mmsghdr there.
* tests/mmsg.c: Include "msghdr.h". Remove fallback definition
of struct mmsghdr.
Dmitry V. Levin [Sun, 26 Jun 2016 23:57:29 +0000 (23:57 +0000)]
net.c: rename some internal functions for consistency and readability
* net.c (printcmsghdr): Rename to decode_msg_control.
(do_msghdr): Rename to print_msghdr.
(extractmsghdr): Rename to fetch_msghdr.
(extractmmsghdr): Rename to fetch_mmsghdr.
(printmsghdr): Rename to decode_msghdr.
(printmmsghdr): Rename to decode_mmsghdr.
All callers updated.
Dmitry V. Levin [Sun, 26 Jun 2016 23:57:18 +0000 (23:57 +0000)]
net.c: when printing struct msghdr.msg_control, also print its name
* net.c (printcmsghdr): Skip control messages of zero length.
Always print "msg_control=" before the control message.
(do_msghdr): Print control message before its length, not after.
* tests/inet-cmsg.c (main): Update expected output.
* tests/scm_rights-fd.test: Likewise.
Dmitry V. Levin [Thu, 23 Jun 2016 15:15:22 +0000 (15:15 +0000)]
net.c: skip details of too short socket addresses, part 2
* net.c (sa_printers): Add minimal address length for each socket family.
(print_sockaddr): Call socket family specific sockaddr printer
only when socket address length is greater or equal
the minimal address length for the socket family.
Dmitry V. Levin [Thu, 23 Jun 2016 21:06:54 +0000 (21:06 +0000)]
net.c: fix printing AF_BLUETOOTH socket addresses
* xlat/hci_channels.in: New file.
* net.c (print_sockaddr_data_raw): New function.
(print_sockaddr): Use it.
[HAVE_BLUETOOTH_BLUETOOTH_H]: Include "xlat/hci_channels.h".
[HAVE_BLUETOOTH_BLUETOOTH_H] (print_sockaddr_data_bt): Fix printing
sockaddr_hci, sockaddr_sco, sockaddr_rc, and sockaddr_l2 structures.
Dmitry V. Levin [Fri, 24 Jun 2016 11:15:51 +0000 (11:15 +0000)]
net.c: fix printing AF_IPX sockets addresses, part 2
* net.c (print_sockaddr_data_ipx): Print sockaddr_ipx.sipx_network
using %#08x format. Print elements of sockaddr_ipx.sipx_node array
and sockaddr_ipx.sipx_type using %#02x format.
AF_UNIX abstract socket address specified by sockaddr_un.sun_path
is not a NUL-terminated string.
* net.c (SIZEOF_SA_FAMILY): New macro.
(print_sockaddr_data_un): Use it. Specify actual address length
in print_quoted_string calls. Do not set QUOTE_0_TERMINATED flag
when printing an abstract socket address.
Dmitry V. Levin [Thu, 23 Jun 2016 09:32:24 +0000 (09:32 +0000)]
net.c: do not print sockaddr_in6.sin6_scope_id unnecessarily
Prior to RFC2553, struct sockaddr_in6 had no sin6_scope_id field.
As the kernel still accepts RFC2133 editions of struct sockaddr_in6,
print sockaddr_in6.sin6_scope_id only when it is specified.
* net.c (SIN6_MIN_LEN): New macro.
(print_sockaddr_data_in6): Print sockaddr_in6.sin6_scope_id only when
socket address length exceeds SIN6_MIN_LEN.
Dmitry V. Levin [Wed, 22 Jun 2016 15:58:00 +0000 (15:58 +0000)]
Split print_sockaddr
* net.c (sockaddr_buf_t): Remove.
(sockaddr_printer): New type.
(sa_printers): New array of sockaddr_printer.
(print_sockaddr): Use it. Move printers of family specific
sockaddr data to separate funcions.
Fabien Siron [Wed, 22 Jun 2016 13:27:03 +0000 (13:27 +0000)]
Add a enum for decoding to tprint_iov() and tprint_iov_upto()
Introduce a new type iov_decode which will be used instead of the integer
"decode" as a parameter.
* defs.h (iov_decode): New enum.
(tprint_iov, tprint_iov_upto): Change type of "decode_iov" to enum iov_decode.
* aio.c (print_iocb): Change type of "decode_iov" to enum iov_decode in
tprint_iov() call.
* keyctl.c (keyctl_instantiate_key_iov): Likewise.
* process.c (ptrace): Likewise.
* process_vm.c (process_vm_readv, process_vm_writev): Likewise.
* io.c (writev, do_pwritev, vmsplice): Likewise.
(print_iovec): Replace the condition with a switch.
(tprint_iov_upto): Change type of "decode_iov" to enum iov_decode.
(readv, do_preadv): Change type of "decode_iov" to enum iov_decode in
tprint_iov_upto() call.
* scsi.c (print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res): Likewise.
* net.c (do_msghdr): Adapt call of tprint_iov_upto().
Dmitry V. Levin [Wed, 22 Jun 2016 00:21:47 +0000 (00:21 +0000)]
printsock: fix zero padding of sockaddr buffer
Before this change printsock used to erroneously clear the last byte
of sockaddr buffer.
* net.c (printsock): Use struct sockaddr_storage as a sockaddr buffer.
Reserve additional byte after the sockaddr buffer for zero padding.
Do not clear memory that is going to be overwritten by umoven.
Clear the tail of sockaddr buffer that was not overwritten by umoven.
Fabien Siron [Fri, 17 Jun 2016 16:29:53 +0000 (16:29 +0000)]
Make getfdproto return enum instead of string
Introduce a new enum type sock_proto and use it instead of strings for socket
protocols identification.
* defs.h (sock_proto): New enum.
(get_proto_by_name): New function.
* socketutils.c (protocols): New static table.
(print_sockaddr_by_inode): Use it. Change type of "proto" argument
to sock_proto.
(get_proto_by_name): New function.
* util.c (getfdproto): Use it. Change return type to sock_proto.
(printfd): Update.
Dmitry V. Levin [Sat, 18 Jun 2016 22:53:25 +0000 (22:53 +0000)]
Split travis-ci.sh
* travis-ci.sh: Split into travis-build.sh, travis-install.sh,
and travis-success.sh files.
* .travis.yml (before_install, after_success, git): New mappings.
(script): Change to travis-build.sh.
(addons, install): Remove.
(env): Remove matrix.
(matrix): Replace exclude list with include list.
Dmitry V. Levin [Fri, 17 Jun 2016 00:44:44 +0000 (00:44 +0000)]
btrfs: fix build with fresh linux/btrfs.h
Fix build with fresh <linux/btrfs.h> that provides a slightly different
definition of struct btrfs_ioctl_defrag_range_args.
* btrfs.c (btrfs_ioctl): Cast "len" member of
struct btrfs_ioctl_defrag_range_args to uint64_t.
* tests/btrfs.c (btrfs_print_defrag_range_args): Cast "start" and "len"
members of struct btrfs_ioctl_defrag_range_args to uint64_t.
Dmitry V. Levin [Fri, 17 Jun 2016 00:02:46 +0000 (03:02 +0300)]
btrfs: provide fallback definitions for BTRFS_IOC_QUOTA_RESCAN*
<linux/btrfs.h> was introduced in linux v3.9-rc1 while some
of btrfs ioctls were added later, e.g. BTRFS_IOC_QUOTA_RESCAN
and BTRFS_IOC_QUOTA_RESCAN_STATUS in v3.10-rc2,
or BTRFS_IOC_QUOTA_RESCAN_WAIT in v3.11-rc1.
* btrfs.c [!BTRFS_IOC_QUOTA_RESCAN]
(struct btrfs_ioctl_quota_rescan_args): New structure.
(BTRFS_IOC_QUOTA_RESCAN, BTRFS_IOC_QUOTA_RESCAN_STATUS): New macros.
[!BTRFS_IOC_QUOTA_RESCAN_WAIT] (BTRFS_IOC_QUOTA_RESCAN_WAIT): New macro.
* tests/btrfs.c: Likewise.
Dmitry V. Levin [Thu, 16 Jun 2016 23:21:57 +0000 (23:21 +0000)]
configure.ac: fix checks for btrfs specific structures
* configure.ac (AC_CHECK_MEMBERS): Fix typo in the check for
struct btrfs_ioctl_defrag_range_args.start and
struct btrfs_ioctl_search_args_v2.buf_size.
Dmitry V. Levin [Wed, 15 Jun 2016 21:27:41 +0000 (21:27 +0000)]
net.c: include <linux/icmp.h> unconditionally
* configure.ac (AC_CHECK_HEADERS): Remove linux/icmp.h.
* net.c: Follow the example of tests/net-icmp_filter.c and include
<linux/icmp.h> unconditionally.