Commit Graph

2795 Commits

Author SHA1 Message Date
Masatake YAMATO
120e5dbcac Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.

For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.

An example of a server side communication using netcat:

	$ ./strace -yy -e network nc -l -U /tmp/example.sock
	socket(PF_LOCAL, SOCK_STREAM, 0)        = 3
	setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
	bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
	listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
	accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
	recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
	INPUT

An example of a client side communication using netcat:

	$ ./strace -yy -e network nc -U /tmp/example.sock
	socket(PF_LOCAL, SOCK_STREAM, 0)        = 3
	connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
	getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
	INPUT
	...
	sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6

* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-25 01:00:48 +00:00
Masatake YAMATO
f605e92365 Use the protocol name of a socket as a hint for peer address resolution
To resolve the peer address of socket, all combinations of families
(AF_INET, AF_INET6) and protocols(IPPROTO_TCP, IPPROTO_UDP) were tried.
This change utilizes the protocol name obtained via getxattr to specify
the right combination.

* socketutils.c (inet_print): New helper function.
(print_sockaddr_by_inode): Use it.  Utilize the protocol name
associated with the given inode for resolving the peer socket
address.  If the protocol name is NULL, resolve the address
by trying combinations of families and protocols as before.
* defs.h (print_sockaddr_by_inode): Update prototype.
* util.c (printfd): Pass the protocol name associated with
the given path to print_sockaddr_by_inode as the 2nd argument.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-16 04:08:20 +00:00
530bed0ca8 Fix decoding of getgroups, getgroups32, setgroups, and setgroups32 syscalls
Convert parsers of these syscalls to the same scheme as were applied to
parsers of other uid/gid related syscalls.
That is, define two sets of parsers on architectures that support
(either directly or via multiarch) 16-bit and 32-bit gid getgroups
and setgroups syscalls simultaneously, and reuse essentially the same
code by parametrizing uid_t and names of parser functions.

* groups.c: Remove.
(sys_getgroups, sys_setgroups): Move ...
* uid.c: ... here and parametrize their names.
* Makefile.am (strace_SOURCES): Remove groups.c.
* linux/syscall.h (sys_getgroups32, sys_setgroups32): Remove.
[NEED_UID16_PARSERS] (sys_getgroups16, sys_setgroups16): New prototypes.
* linux/arm/syscallent.h: Rename sys_[gs]etgroups to sys_[gs]etgroups16,
rename sys_[gs]etgroups32 to sys_[gs]etgroups.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* tests/uid.c: Test for getgroups.
* tests/uid16.c: Likewise.
* tests/uid32.c: Test for getgroups32.
* tests/uid.awk: Test for getgroups/getgroups32 decoding.
* tests/uid.test: Trace getgroups/getgroups32 syscalls.
2014-12-16 01:09:23 +00:00
80f7db1fed Fix decoding of 16-bit *chown and [gs]et*[gu]id syscalls
Define two sets of parsers on architectures that support (either
directly or via multiarch) 16-bit and 32-bit uid/gid syscalls
simultaneously.  Since the code in these two sets is essentially
the same and the key difference between them is the size of uid_t,
implement it by parametrizing uid_t and names of parser functions.

* defs.h (NEED_UID16_PARSERS): New macro.
* linux/syscall.h [NEED_UID16_PARSERS] (sys_chown16, sys_fchown16,
sys_getresuid16, sys_getuid16, sys_setfsuid16, sys_setresuid16,
sys_setreuid16, sys_setuid16): New prototypes.
* linux/dummy.h (sys_geteuid16): Alias to sys_getuid16.
(sys_getegid16, sys_getgid16, sys_getresgid16, sys_setfsgid16,
sys_setgid16, sys_setregid16, sys_setresgid16): Alias to corresponding
sys_*uid16 functions.
* uid.c: Stop including <asm/posix_types.h>.
Parametrize uid_t and names of all exported functions.
(get_print_uid): New function.
(sys_getresuid): Use it.
(printuid): Check for (uid_t) -1.
* uid16.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* linux/arm/syscallent.h: Use sys_chown16, sys_fchown16, sys_getegid16,
sys_geteuid16, sys_getgid16, sys_getresgid16, sys_getresuid16,
sys_getuid16, sys_setfsgid16, sys_setfsuid16, sys_setgid16,
sys_setregid16, sys_setresgid16, sys_setresuid16, sys_setreuid16,
and sys_setuid16 parsers for *chown and [gs]et*[gu]id syscall entries.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* tests/uid16.c: New file.
* tests/uid16.test: New test.
* tests/Makefile.am (CHECK_PROGRAMS): Add uid16.
(TESTS): Add uid16.test.
* tests/.gitignore: Add uid16.
2014-12-16 01:07:12 +00:00
d535b8bd51 sh, sh64: fix uid/gid syscall entries
* linux/sh/syscallent.h: Replace printargs with real syscall
parsers in *chown32 and [gs]et*[gu]id32 syscall entries.
* linux/sh64/syscallent.h: Likewise.
2014-12-16 00:58:37 +00:00
641bb428dd s390: fix uid/gid syscall entries
* linux/s390/syscallent.h: Add "32" suffix to names of *chown32
and [gs]et*[gu]id32 syscalls #198..216.
2014-12-16 00:58:22 +00:00
37b20b3fd4 sparc: fix uid/gid syscall entries
* linux/sparc/syscallent.h: Add "32" suffix to names
of [gs]etres[gu]id32 syscalls #108..112.
Fix entry for syscall #112 from setresgid32 to setregid32.
2014-12-16 00:44:40 +00:00
2f7d020e22 chown.c: split into separate files
This will make further uid/gid fixes simpler.

* fchownat.c: New file.
* chown.c (sys_fchownat: Move to fchownat.c.
(sys_chown, sys_fchown): Move to uid.c.
* Makefile.am (strace_SOURCES): Remove chown.c, add fchownat.c.
2014-12-15 23:54:37 +00:00
25ebe46ce2 util.c: move printuid to uid.c
This will make further uid/gid fixes simpler.

* util.c (printuid): Move
* uid.c: ... here.
2014-12-15 23:54:37 +00:00
c55bfb0045 tests/uid.awk: rewrite in a more maintainable style
Since the test is virtually a FSM, rewrite it as a FSM.
2014-12-15 23:50:14 +00:00
1da7c95b62 printuid: fix uid_t decoding on 64-bit architectures
It was not a good idea to treat uid_t as a long int type because
the latter is twice larger than uid_t on 64-bit architectures.

* defs.h (printuid): Change uid argument type from "unsigned long"
to "unsigned int".
* util.c (printuid): Likewise.  When uid equals to -1, print "-1".
* tests/uid.awk: New file.
* tests/uid.c: New file.
* tests/uid32.c: Likewise.
* tests/uid.test: New test.
* tests/uid32.test: Likewise.
* tests/Makefile.am (CHECK_PROGRAMS): Add uid and uid32.
(TESTS): Add uid.test and uid32.test.
(EXTRA_DIST): Add uid.awk.
* tests/.gitignore: Add uid and uid32.
2014-12-14 03:54:04 +00:00
79fb4d6a9a Update PTRACE_* constants
* xlat/ptrace_cmds.in: Add PTRACE_PEEKSIGINFO, PTRACE_GETSIGMASK,
and PTRACE_SETSIGMASK.
2014-12-13 01:56:56 +00:00
825b524c8c Update SWAP_FLAG_* constants
* swapon.c: Ensure that SWAP_FLAG_DISCARD_ONCE and
SWAP_FLAG_DISCARD_PAGES are defined.
* xlat/swap_flags.in: Add SWAP_FLAG_DISCARD_ONCE and
SWAP_FLAG_DISCARD_PAGES.
2014-12-13 01:34:47 +00:00
719554d5eb Update SCHED_* constants
* xlat/schedulers.in: Add SCHED_BATCH, SCHED_ISO, SCHED_IDLE, and
SCHED_DEADLINE.
2014-12-11 23:33:02 +00:00
4bcce0ae6f Update prctl PR_* constants
* xlat/prctl_options.in: Add PR_SET_THP_DISABLE, PR_GET_THP_DISABLE,
PR_MPX_ENABLE_MANAGEMENT, and PR_MPX_DISABLE_MANAGEMENT.
2014-12-11 23:33:01 +00:00
8224758b33 Always compile sys_prctl parser
Since sys_prctl is referenced by syscallent files unconditionally,
conditional compilation of sys_prctl depending on prctl availability is
pointless.

* prctl.c (unalignctl_string, sys_prctl): Compile unconditionally.
2014-12-11 23:32:59 +00:00
fced7b0930 process.c: split struct_user_offsets into architecture-specific include files
* Makefile.am (EXTRA_DIST): Add linux/alpha/userent.h,
linux/arm/userent.h, linux/avr32/userent.h, linux/bfin/userent.h,
linux/crisv10/userent.h, linux/crisv32/userent.h,
linux/i386/userent.h, linux/i386/userent0.h, linux/ia64/userent.h,
linux/m68k/userent.h, linux/microblaze/userent.h,
linux/mips/userent.h, linux/or1k/userent.h, linux/powerpc/userent.h,
linux/s390/userent.h, linux/s390/userent0.h, linux/s390/userent1.h,
linux/s390x/userent.h, linux/sh/userent.h, linux/sh/userent0.h,
linux/sh64/userent.h, linux/sparc/userent.h, linux/sparc64/userent.h,
linux/tile/userent.h, linux/userent.h, linux/userent0.h,
linux/x32/userent.h, linux/x86_64/userent.h, and
linux/xtensa/userent.h.
* process.c (struct_user_offsets): Split into architecture-specific
include files, inculde userent.h.
2014-12-11 19:25:02 +00:00
6eee4e044c process.c: include less headers
* process.c: Do not include <fcntl.h> and <sys/stat.h>.
Reorder inclusion of xlat header files.
2014-12-11 19:25:02 +00:00
8c0ef9468c Unexport struct_user_offsets
* defs.h (struct_user_offsets): Remove.
* process.c (struct_user_offsets): Make static.
2014-12-11 19:25:02 +00:00
c6ce4fdafc process.c: introduce XLAT_UOFF macro
Introduce XLAT_UOFF macro and use it to automatically transform
struct_user_offsets array into a more readable and compact form.

for n in $(sed -n 's/^[[:space:]]*{[[:space:]]*uoff(\([a-z_0-9]\+\)),.*/\1/p' process.c |sort -u); do
	sed -i 's/^\([[:space:]]*\){[[:space:]]*uoff('"$n"'),[[:space:]]*"offsetof(struct user,[[:space:]]*'"$n"')"[[:space:]]*},$/\1XLAT_UOFF('"$n"'),/' process.c
done

* process.c (XLAT_UOFF): New macro.
(struct_user_offsets): Use it.
2014-12-11 19:25:02 +00:00
03c06ea592 process.c: move sethostname and gethostname parsers to a separate file
* hostname.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c (sys_sethostname, sys_gethostname): Move to hostname.c.
2014-12-11 22:52:03 +00:00
9175909acc process.c: move exit parser to a separate file
* exit.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c (sys_exit): Move to exit.c.
2014-12-11 22:52:03 +00:00
265903a416 process.c: move clone, setns, unshare, and fork parsers to a separate file
* clone.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c: Move sys_clone, sys_setns, sys_unshare, sys_fork, and
related code to clone.c.
2014-12-11 22:52:03 +00:00
e93ef1eb9d process.c: move get*uid and set*uid parsers to a separate file
* uid.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c (sys_getuid, sys_setfsuid, sys_setuid, sys_getresuid,
sys_setreuid, sys_setresuid): Move to uid.c.
2014-12-11 22:52:03 +00:00
7211480fee process.c: move getgroups* and setgroups* parsers to a separate file
* groups.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c: Move sys_setgroups, sys_getgroups, sys_setgroups32,
sys_getgroups32, and related code to groups.c.
2014-12-11 22:52:03 +00:00
7be2318ad2 process.c: move execve and execv parsers to a separate file
* execve.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c: Move sys_execve, sys_execv, and related code to execve.c.
2014-12-11 22:52:03 +00:00
7ccc144fdd process.c: move waitpid, wait4, osf_wait4, and waitid parsers to a separate file
* wait.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c: Move sys_waitpid, sys_wait4, sys_osf_wait4, sys_waitid and
related code to wait.c.
2014-12-11 22:51:45 +00:00
58dd2cf352 process.c: move uname parser to a separate file
* uname.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c (sys_uname): Move to uname.c.
2014-12-11 22:04:01 +00:00
e314f808bf process.c: move futex parser to a separate file
* futex.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c: Move sys_futex and related code to futex.c.
2014-12-11 19:25:02 +00:00
8357638568 process.c: move get_robust_list parser to a separate file
* get_robust_list.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c (sys_get_robust_list): Move to get_robust_list.c.
2014-12-11 19:25:02 +00:00
fff2f319f9 process.c: move sched_* parsers to a separate file
* sched.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c: Move sys_sched_getscheduler, sys_sched_setscheduler,
sys_sched_getparam, sys_sched_setparam, sys_sched_get_priority_min,
sys_sched_rr_get_interval, and related code to sched.c.
2014-12-11 21:44:56 +00:00
b94b9834fd process.c: move sched_setaffinity and sched_getaffinity parsers to a separate file
* affinity.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c (sys_sched_setaffinity, sys_sched_getaffinity): Move
to affinity.c.
2014-12-11 19:25:02 +00:00
53c993d9c1 process.c: move prctl and arch_prctl parsers to a separate file
* prctl.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c: Move sys_prctl, sys_arch_prctl, and related code to prctl.c.
2014-12-11 21:40:44 +00:00
665f10c9a4 process.c: move getcpu parser to a separate file
* getcpu.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c (sys_getcpu): Move to getcpu.c.
2014-12-11 21:40:40 +00:00
db16c52668 process.c: move process_vm_readv and process_vm_writev parsers to a separate file
* process_vm.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* process.c (sys_process_vm_readv, sys_process_vm_writev): Move
to process_vm.c.
2014-12-11 21:40:23 +00:00
52572b6fdd Implement decoding of fallocate FALLOC_FL_* flags
* xlat/falloc_flags.in: New file.
* configure.ac (AC_CHECK_HEADERS): Add linux/falloc.h.
* fallocate.c [HAVE_LINUX_FALLOC_H]: Include <linux/falloc.h>.
Include xlat/falloc_flags.h.
(sys_fallocate): Decode flags.
2014-12-11 21:40:23 +00:00
19b50da101 Fix decoding of renameat2 RENAME_* flags
* renameat.c: Include <linux/fs.h> where RENAME_NOREPLACE,
RENAME_EXCHANGE, and RENAME_WHITEOUT are usually defined.
2014-12-11 21:40:23 +00:00
964d80a0f7 file.c: move open, openat, and creat parsers to a separate file
* open.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c: Move sys_open, sys_openat, sys_creat, and related code
to open.c.
2014-12-11 21:40:20 +00:00
304cd81e46 file.c: move access and faccessat parsers to a separate file
* access.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c: Move sys_access, sys_faccessat and related code to access.c.
2014-12-11 21:40:17 +00:00
d590f3cdd8 file.c: move umask parser to a separate file
* umask.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c (sys_umask): Move to umask.c.
2014-12-11 21:40:15 +00:00
b5d25ec2f9 file.c: move lseek and llseek parsers to a separate file
* lseek.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c: Move sys_lseek, sys_llseek, and related code to lseek.c.
2014-12-11 21:40:11 +00:00
9e9ceab3b1 file.c: move readahead parser to a separate file
* readahead.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c (sys_readahead): Move to readahead.c.
2014-12-11 21:40:08 +00:00
6934182f16 file.c: move truncate, truncate64, ftruncate, and ftruncate64 parsers to a separate file
* truncate.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c (sys_truncate, sys_truncate64, sys_ftruncate, sys_ftruncate64):
Move to truncate.c.
2014-12-11 21:40:04 +00:00
9b2f674adb file.c: move chdir parser to a separate file
* chdir.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c (sys_chdir): Move to chdir.c.
2014-12-11 21:39:59 +00:00
231b19fca0 file.c: move link, linkat, unlinkat, and symlinkat parsers to a separate file
* link.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c: Move sys_link, sys_linkat, sys_unlinkat, sys_symlinkat, and
related code to link.c.
2014-12-11 21:39:44 +00:00
46245b3541 file.c: move readlink and readlinkat parsers to a separate file
* readlink.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c (decode_readlink, sys_readlink, sys_readlinkat): Move
to readlink.c.
2014-12-11 21:39:35 +00:00
6d20a0b9a3 file.c: move renameat and renameat2 parsers to a separate file
* renameat.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c: Move sys_renameat, sys_renameat2, and related code
to renameat.c.
2014-12-11 21:39:30 +00:00
2b7a53bff5 file.c: move chown, fchown, and fchownat parsers to a separate file
* chown.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c (sys_chown, sys_fchownat, sys_fchown): Move to chown.c.
2014-12-11 21:39:28 +00:00
43b110b7d1 Export at_flags
* defs.h (at_flags): New prototype.
2014-12-11 21:39:27 +00:00
ad5cf1e5ae file.c: move chmod, fchmod, and fchmodat parsers to a separate file
* chmod.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c (sys_chmod, sys_fchmodat, sys_fchmod): Move to chmod.c.
2014-12-11 21:39:25 +00:00