2016-05-19 01:09:39 +03:00
/*
* Copyright ( c ) 2016 Jeff Mahoney < jeffm @ suse . com >
2018-06-14 14:00:00 +03:00
* Copyright ( c ) 2016 - 2018 The strace developers .
2016-05-19 01:09:39 +03:00
* All rights reserved .
*
2018-12-10 03:00:00 +03:00
* SPDX - License - Identifier : LGPL - 2.1 - or - later
2016-05-19 01:09:39 +03:00
*/
# include "defs.h"
2016-05-24 03:19:40 +03:00
# include <linux/ioctl.h>
2016-05-19 01:09:39 +03:00
# include <linux/fs.h>
2016-05-19 01:09:40 +03:00
2016-05-24 03:19:17 +03:00
# ifdef HAVE_LINUX_FIEMAP_H
# include <linux / fiemap.h>
# include "xlat / fiemap_flags.h"
# include "xlat / fiemap_extent_flags.h"
# endif
2016-05-19 01:09:40 +03:00
2016-05-19 01:09:39 +03:00
# ifndef FICLONE
2017-06-18 01:23:09 +03:00
# define FICLONE _IOW(0x94, 9, int)
2016-05-19 01:09:39 +03:00
# endif
# ifndef FICLONERANGE
2017-06-18 01:23:09 +03:00
# define FICLONERANGE _IOW(0x94, 13, struct file_clone_range)
2016-05-19 01:09:39 +03:00
struct file_clone_range {
int64_t src_fd ;
uint64_t src_offset ;
uint64_t src_length ;
uint64_t dest_offset ;
} ;
# endif
# ifndef FIDEDUPERANGE
2017-06-18 01:23:09 +03:00
# define FIDEDUPERANGE _IOWR(0x94, 54, struct file_dedupe_range)
2016-05-19 01:09:39 +03:00
struct file_dedupe_range_info {
int64_t dest_fd ; /* in - destination file */
uint64_t dest_offset ; /* in - start of extent in destination */
uint64_t bytes_deduped ; /* out - total # of bytes we were able
* to dedupe from this file . */
/* status of this dedupe operation:
* < 0 for error
* = = FILE_DEDUPE_RANGE_SAME if dedupe succeeds
* = = FILE_DEDUPE_RANGE_DIFFERS if data differs
*/
int32_t status ; /* out - see above description */
uint32_t reserved ; /* must be zero */
} ;
struct file_dedupe_range {
uint64_t src_offset ; /* in - start of extent in source */
uint64_t src_length ; /* in - length of extent */
uint16_t dest_count ; /* in - total elements in info array */
uint16_t reserved1 ; /* must be zero */
uint32_t reserved2 ; /* must be zero */
struct file_dedupe_range_info info [ 0 ] ;
} ;
# endif
2016-05-24 03:20:07 +03:00
static bool
print_file_dedupe_range_info ( struct tcb * tcp , void * elem_buf ,
size_t elem_size , void * data )
{
const struct file_dedupe_range_info * info = elem_buf ;
2016-05-27 23:07:22 +03:00
unsigned int * count = data ;
if ( count ) {
if ( * count = = 0 ) {
tprints ( " ... " ) ;
return false ;
}
- - * count ;
}
2016-05-24 03:20:07 +03:00
if ( entering ( tcp ) ) {
2016-05-25 10:59:13 +03:00
tprints ( " {dest_fd= " ) ;
printfd ( tcp , info - > dest_fd ) ;
tprintf ( " , dest_offset=% " PRIu64 " } " ,
2016-05-24 03:20:07 +03:00
( uint64_t ) info - > dest_offset ) ;
} else {
tprintf ( " {bytes_deduped=% " PRIu64 " , status=%d} " ,
( uint64_t ) info - > bytes_deduped , info - > status ) ;
}
return true ;
}
# ifdef HAVE_LINUX_FIEMAP_H
static bool
print_fiemap_extent ( struct tcb * tcp , void * elem_buf , size_t elem_size , void * data )
{
const struct fiemap_extent * fe = elem_buf ;
tprintf ( " {fe_logical=% " PRI__u64
" , fe_physical=% " PRI__u64
" , fe_length=% " PRI__u64 " , " ,
fe - > fe_logical , fe - > fe_physical , fe - > fe_length ) ;
printflags64 ( fiemap_extent_flags , fe - > fe_flags ,
" FIEMAP_EXTENT_??? " ) ;
tprints ( " } " ) ;
return true ;
}
# endif /* HAVE_LINUX_FIEMAP_H */
2016-05-19 01:09:39 +03:00
int
Change type of ioctl 3rd argument from long to kernel_ureg_t
* defs.h (DECL_IOCTL): Change arg type from long to kernel_ureg_t.
* dm.c (dm_known_ioctl, dm_ioctl): Likewise.
* file_ioctl.c (file_ioctl): Likewise.
* fs_x_ioctl.c (fs_x_ioctl): Likewise.
* ioctl.c (ioctl_decode): Likewise.
* loop.c (decode_loop_info, decode_loop_info64): Change addr type
from long to kernel_ureg_t.
(loop_ioctl): Change arg type from long to kernel_ureg_t.
* ptp.c (ptp_ioctl): Likewise.
* scsi.c (print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res, scsi_ioctl): Likewise.
* sock.c (print_ifreq, sock_ioctl): Likewise.
(decode_ifconf): Change addr type from long to kernel_ureg_t.
* term.c (decode_termios, decode_termio, decode_winsize, decode_ttysize,
decode_modem_flags): Likewise.
(term_ioctl): Change arg type from long to kernel_ureg_t.
* ubi.c (ubi_ioctl): Likewise.
* userfaultfd.c (uffdio_ioctl): Likewise.
2016-12-21 06:03:09 +03:00
file_ioctl ( struct tcb * const tcp , const unsigned int code ,
2016-12-26 13:26:03 +03:00
const kernel_ulong_t arg )
2016-05-19 01:09:39 +03:00
{
switch ( code ) {
case FICLONE : /* W */
2016-05-24 03:19:53 +03:00
tprintf ( " , %d " , ( int ) arg ) ;
2016-05-19 01:09:39 +03:00
break ;
case FICLONERANGE : { /* W */
struct file_clone_range args ;
tprints ( " , " ) ;
if ( umove_or_printaddr ( tcp , arg , & args ) )
break ;
2016-05-25 10:59:13 +03:00
tprints ( " {src_fd= " ) ;
printfd ( tcp , args . src_fd ) ;
tprintf ( " , src_offset=% " PRIu64
2016-05-24 03:19:53 +03:00
" , src_length=% " PRIu64
" , dest_offset=% " PRIu64 " } " ,
( uint64_t ) args . src_offset ,
( uint64_t ) args . src_length ,
( uint64_t ) args . dest_offset ) ;
2016-05-19 01:09:39 +03:00
break ;
}
case FIDEDUPERANGE : { /* RW */
struct file_dedupe_range args ;
2016-05-27 23:07:22 +03:00
struct file_dedupe_range_info info ;
unsigned int * limit = NULL ;
unsigned int count = 2 ;
bool rc ;
2016-05-19 01:09:39 +03:00
if ( entering ( tcp ) )
tprints ( " , " ) ;
else if ( syserror ( tcp ) )
break ;
else
tprints ( " => " ) ;
if ( umove_or_printaddr ( tcp , arg , & args ) )
break ;
2016-05-24 03:20:07 +03:00
tprints ( " { " ) ;
2016-05-19 01:09:39 +03:00
if ( entering ( tcp ) ) {
2016-05-24 03:20:07 +03:00
tprintf ( " src_offset=% " PRIu64
" , src_length=% " PRIu64
" , dest_count=%hu, " ,
( uint64_t ) args . src_offset ,
( uint64_t ) args . src_length ,
( uint16_t ) args . dest_count ) ;
}
2016-05-19 01:09:39 +03:00
2016-05-24 03:20:07 +03:00
tprints ( " info= " ) ;
2016-05-27 23:07:22 +03:00
/* Limit how many elements we print in abbrev mode. */
if ( abbrev ( tcp ) & & args . dest_count > count )
limit = & count ;
rc = print_array ( tcp , arg + offsetof ( typeof ( args ) , info ) ,
args . dest_count , & info , sizeof ( info ) ,
print_array: enhance printing of unfetchable object addresses
When umoven_func invocation fails to fetch data, it prints the faulty
address. If this happens to a subsequent umoven_func invocation,
the printed address may be undistinguishable from a valid data printed
by print_func, e.g. when the data is printed in a numeric form like
[0x1, 0x2, 0x3, 0xdefaced].
Fix this source of confusion by moving the printing of the faulty
address from umoven_func to print_array itself. This change renames
umoven_func to tfetch_mem_func and changes its semantics, so that
- tfetch_mem_func never prints anything;
- tfetch_mem_func returns true if the fetch succeeded,
and false otherwise.
* defs.h (print_array): Replace umoven_func argument with
tfetch_mem_func.
* util.c (print_array): Replace umoven_func argument with
tfetch_mem_func, document expected tfetch_mem_func return value
semantics. When tfetch_mem_func returns false, print either addr
or "... /* addr */" depending on the context (inside the array or not).
* bpf.c (print_ebpf_prog, print_bpf_prog_info,
BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): Replace umoven_or_printaddr
argument of print_array with tfetch_mem.
* bpf_filter.c (print_bpf_fprog): Likewise.
* btrfs.c (btrfs_print_logical_ino_container,
btrfs_print_ino_path_container, btrfs_print_qgroup_inherit,
btrfs_ioctl): Likewise.
* dm.c (dm_decode_dm_target_deps): Likewise.
* epoll.c (epoll_wait_common): Likewise.
* file_ioctl.c (file_ioctl): Likewise.
* ipc_sem.c (tprint_sembuf_array): Likewise.
* kexec.c (print_kexec_segments): Likewise.
* mem.c (SYS_FUNC(subpage_prot)): Likewise.
* net.c (print_getsockopt): Likewise.
* netlink.c (decode_nlmsgerr_attr_cookie): Likewise.
* netlink_netlink_diag.c (decode_netlink_diag_groups): Likewise.
* netlink_packet_diag.c (decode_packet_diag_mclist): Likewise.
* netlink_unix_diag.c (decode_unix_diag_inode): Likewise.
* nlattr.c (decode_nla_meminfo): Likewise.
* numa.c (print_nodemask, SYS_FUNC(move_pages),
* perf_ioctl.c (perf_ioctl_query_bpf): Likewise.
* poll.c (decode_poll_entering): Likewise.
* printsiginfo.c (print_siginfo_array): Likewise.
* rtnl_tc.c (decode_tca_stab_data): Likewise.
* sock.c (decode_ifconf): Likewise.
* uid.c (print_groups): Likewise.
* io.c (SYS_FUNC(io_submit), SYS_FUNC(io_getevents)): Replace
umoven_or_printaddr argument of print_array with tfetch_mem.
(tprint_iov_upto): Replace umoven_or_printaddr_ignore_syserror
with tfetch_mem_ignore_syserror.
* v4l2.c (print_v4l2_format_fmt): Replace umoven_or_printaddr argument
of print_array with tfetch_mem.
(print_v4l2_ext_controls): Replace umoven_or_printaddr_ignore_syserror
with tfetch_mem_ignore_syserror.
* mmsghdr.c (fetch_struct_mmsghdr_or_printaddr): Rename
to fetch_struct_mmsghdr_for_print, do not print address, return bool.
(decode_mmsgvec): Replace fetch_struct_mmsghdr_or_printaddr
with fetch_struct_mmsghdr_for_print.
* tests/aio.c (main): Update expected output.
* tests/bpf.c (print_BPF_PROG_QUERY_attr5): Likewise.
* tests/ioctl_perf-success.c (main): Likewise.
* tests/ioctl_v4l2.c (main): Update expected output.
* tests/kexec_load.c (main): Likewise.
* tests/mmsg_name.c (test_mmsg_name): Update expected output.
* tests/move_pages.c (print_page_array, print_node_array): Likewise.
* tests/poll.c (print_pollfd_array_entering): Likewise.
* tests/preadv-pwritev.c (main): Likewise.
* tests/preadv2-pwritev2.c (dumpio): Likewise.
* tests/process_vm_readv_writev.c (print_iov): Likewise.
* tests/pwritev.c (print_iovec): Likewise.
* tests/readv.c (main): Likewise.
* tests/seccomp-filter-v.c
* tests/semop.c (main): Likewise.
* tests/set_mempolicy.c (print_nodes): Likewise.
* tests/setgroups.c (main): Likewise.
* tests/test_nlattr.h (print_nlattr) Likewise.
Co-Authored-by: Eugene Syromyatnikov <evgsyr@gmail.com>
2018-05-29 04:15:19 +03:00
tfetch_mem ,
2016-05-27 23:07:22 +03:00
print_file_dedupe_range_info , limit ) ;
2016-05-24 03:20:07 +03:00
tprints ( " } " ) ;
if ( ! rc | | exiting ( tcp ) )
break ;
return 0 ;
2016-05-19 01:09:39 +03:00
}
2016-05-24 03:19:17 +03:00
# ifdef HAVE_LINUX_FIEMAP_H
2016-05-19 01:09:40 +03:00
case FS_IOC_FIEMAP : {
struct fiemap args ;
if ( entering ( tcp ) )
tprints ( " , " ) ;
else if ( syserror ( tcp ) )
break ;
else
tprints ( " => " ) ;
if ( umove_or_printaddr ( tcp , arg , & args ) )
break ;
if ( entering ( tcp ) ) {
tprintf ( " {fm_start=% " PRI__u64 " , "
" fm_length=% " PRI__u64 " , "
" fm_flags= " ,
args . fm_start , args . fm_length ) ;
printflags64 ( fiemap_flags , args . fm_flags ,
" FIEMAP_FLAG_??? " ) ;
tprintf ( " , fm_extent_count=%u} " , args . fm_extent_count ) ;
return 0 ;
}
tprints ( " {fm_flags= " ) ;
printflags64 ( fiemap_flags , args . fm_flags ,
" FIEMAP_FLAG_??? " ) ;
tprintf ( " , fm_mapped_extents=%u " ,
args . fm_mapped_extents ) ;
if ( abbrev ( tcp ) ) {
2018-03-19 07:24:16 +03:00
tprints ( " , ... " ) ;
2016-05-24 03:20:07 +03:00
} else {
struct fiemap_extent fe ;
2018-03-19 07:24:16 +03:00
tprints ( " , fm_extents= " ) ;
2016-05-24 03:20:07 +03:00
print_array ( tcp ,
arg + offsetof ( typeof ( args ) , fm_extents ) ,
args . fm_mapped_extents , & fe , sizeof ( fe ) ,
print_array: enhance printing of unfetchable object addresses
When umoven_func invocation fails to fetch data, it prints the faulty
address. If this happens to a subsequent umoven_func invocation,
the printed address may be undistinguishable from a valid data printed
by print_func, e.g. when the data is printed in a numeric form like
[0x1, 0x2, 0x3, 0xdefaced].
Fix this source of confusion by moving the printing of the faulty
address from umoven_func to print_array itself. This change renames
umoven_func to tfetch_mem_func and changes its semantics, so that
- tfetch_mem_func never prints anything;
- tfetch_mem_func returns true if the fetch succeeded,
and false otherwise.
* defs.h (print_array): Replace umoven_func argument with
tfetch_mem_func.
* util.c (print_array): Replace umoven_func argument with
tfetch_mem_func, document expected tfetch_mem_func return value
semantics. When tfetch_mem_func returns false, print either addr
or "... /* addr */" depending on the context (inside the array or not).
* bpf.c (print_ebpf_prog, print_bpf_prog_info,
BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): Replace umoven_or_printaddr
argument of print_array with tfetch_mem.
* bpf_filter.c (print_bpf_fprog): Likewise.
* btrfs.c (btrfs_print_logical_ino_container,
btrfs_print_ino_path_container, btrfs_print_qgroup_inherit,
btrfs_ioctl): Likewise.
* dm.c (dm_decode_dm_target_deps): Likewise.
* epoll.c (epoll_wait_common): Likewise.
* file_ioctl.c (file_ioctl): Likewise.
* ipc_sem.c (tprint_sembuf_array): Likewise.
* kexec.c (print_kexec_segments): Likewise.
* mem.c (SYS_FUNC(subpage_prot)): Likewise.
* net.c (print_getsockopt): Likewise.
* netlink.c (decode_nlmsgerr_attr_cookie): Likewise.
* netlink_netlink_diag.c (decode_netlink_diag_groups): Likewise.
* netlink_packet_diag.c (decode_packet_diag_mclist): Likewise.
* netlink_unix_diag.c (decode_unix_diag_inode): Likewise.
* nlattr.c (decode_nla_meminfo): Likewise.
* numa.c (print_nodemask, SYS_FUNC(move_pages),
* perf_ioctl.c (perf_ioctl_query_bpf): Likewise.
* poll.c (decode_poll_entering): Likewise.
* printsiginfo.c (print_siginfo_array): Likewise.
* rtnl_tc.c (decode_tca_stab_data): Likewise.
* sock.c (decode_ifconf): Likewise.
* uid.c (print_groups): Likewise.
* io.c (SYS_FUNC(io_submit), SYS_FUNC(io_getevents)): Replace
umoven_or_printaddr argument of print_array with tfetch_mem.
(tprint_iov_upto): Replace umoven_or_printaddr_ignore_syserror
with tfetch_mem_ignore_syserror.
* v4l2.c (print_v4l2_format_fmt): Replace umoven_or_printaddr argument
of print_array with tfetch_mem.
(print_v4l2_ext_controls): Replace umoven_or_printaddr_ignore_syserror
with tfetch_mem_ignore_syserror.
* mmsghdr.c (fetch_struct_mmsghdr_or_printaddr): Rename
to fetch_struct_mmsghdr_for_print, do not print address, return bool.
(decode_mmsgvec): Replace fetch_struct_mmsghdr_or_printaddr
with fetch_struct_mmsghdr_for_print.
* tests/aio.c (main): Update expected output.
* tests/bpf.c (print_BPF_PROG_QUERY_attr5): Likewise.
* tests/ioctl_perf-success.c (main): Likewise.
* tests/ioctl_v4l2.c (main): Update expected output.
* tests/kexec_load.c (main): Likewise.
* tests/mmsg_name.c (test_mmsg_name): Update expected output.
* tests/move_pages.c (print_page_array, print_node_array): Likewise.
* tests/poll.c (print_pollfd_array_entering): Likewise.
* tests/preadv-pwritev.c (main): Likewise.
* tests/preadv2-pwritev2.c (dumpio): Likewise.
* tests/process_vm_readv_writev.c (print_iov): Likewise.
* tests/pwritev.c (print_iovec): Likewise.
* tests/readv.c (main): Likewise.
* tests/seccomp-filter-v.c
* tests/semop.c (main): Likewise.
* tests/set_mempolicy.c (print_nodes): Likewise.
* tests/setgroups.c (main): Likewise.
* tests/test_nlattr.h (print_nlattr) Likewise.
Co-Authored-by: Eugene Syromyatnikov <evgsyr@gmail.com>
2018-05-29 04:15:19 +03:00
tfetch_mem ,
2016-05-24 03:20:07 +03:00
print_fiemap_extent , 0 ) ;
2016-05-19 01:09:40 +03:00
}
2016-05-24 03:20:07 +03:00
tprints ( " } " ) ;
2016-05-19 01:09:40 +03:00
break ;
}
2016-05-24 03:19:17 +03:00
# endif /* HAVE_LINUX_FIEMAP_H */
2016-05-19 01:09:40 +03:00
2016-05-19 01:09:39 +03:00
default :
return RVAL_DECODED ;
} ;
2017-08-28 03:39:15 +03:00
return RVAL_IOCTL_DECODED ;
2016-05-19 01:09:39 +03:00
}