diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2019-10-22 10:33:11 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2019-10-22 10:33:11 +0100 |
commit | 419af24e7e492dd94a16a1691736ab48d0029a30 (patch) | |
tree | a0ce321a7b9e9c49bdec72c3948d933dbf4424e3 | |
parent | e9d42461920f6f40f4d847a5ba18e90d095ed0b9 (diff) | |
parent | 9a68960d8e7fdda16c2ea779a70f7f894ed2ce56 (diff) |
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-4.2-pull-request' into staging
sockaddr alignment fixes, strace update and fd-trans fix.
# gpg: Signature made Tue 22 Oct 2019 09:10:44 BST
# gpg: using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C
# gpg: issuer "laurent@vivier.eu"
# gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" [full]
# gpg: aka "Laurent Vivier <laurent@vivier.eu>" [full]
# gpg: aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" [full]
# Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F 5173 F30C 38BD 3F2F BE3C
* remotes/vivier2/tags/linux-user-for-4.2-pull-request:
linux-user/syscall: Align target_sockaddr fields using ABI types
linux-user/strace: Let print_sockaddr() have a 'last' argument
linux-user/strace: Improve bind() output
linux-user/strace: Add print_sockfd()
linux-user/strace: Dump AF_NETLINK sockaddr content
linux-user/syscall: Introduce target_sockaddr_nl
linux-user/strace: Improve settimeofday()
linux-user/strace: Add print_timezone()
linux-user/strace: Display invalid pointer in print_timeval()
Fix unsigned integer underflow in fd-trans.c
linux-user: add strace for dup3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r-- | linux-user/fd-trans.c | 51 | ||||
-rw-r--r-- | linux-user/strace.c | 120 | ||||
-rw-r--r-- | linux-user/strace.list | 7 | ||||
-rw-r--r-- | linux-user/syscall.c | 6 | ||||
-rw-r--r-- | linux-user/syscall_defs.h | 41 |
5 files changed, 180 insertions, 45 deletions
diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c index 60077ce531..9b92386abf 100644 --- a/linux-user/fd-trans.c +++ b/linux-user/fd-trans.c @@ -279,6 +279,7 @@ static abi_long host_to_target_for_each_nlmsg(struct nlmsghdr *nlh, (struct nlmsghdr *)) { uint32_t nlmsg_len; + uint32_t aligned_nlmsg_len; abi_long ret; while (len > sizeof(struct nlmsghdr)) { @@ -312,8 +313,13 @@ static abi_long host_to_target_for_each_nlmsg(struct nlmsghdr *nlh, break; } tswap_nlmsghdr(nlh); - len -= NLMSG_ALIGN(nlmsg_len); - nlh = (struct nlmsghdr *)(((char*)nlh) + NLMSG_ALIGN(nlmsg_len)); + + aligned_nlmsg_len = NLMSG_ALIGN(nlmsg_len); + if (aligned_nlmsg_len >= len) { + break; + } + len -= aligned_nlmsg_len; + nlh = (struct nlmsghdr *)(((char*)nlh) + aligned_nlmsg_len); } return 0; } @@ -323,6 +329,7 @@ static abi_long target_to_host_for_each_nlmsg(struct nlmsghdr *nlh, abi_long (*target_to_host_nlmsg) (struct nlmsghdr *)) { + uint32_t aligned_nlmsg_len; int ret; while (len > sizeof(struct nlmsghdr)) { @@ -349,8 +356,13 @@ static abi_long target_to_host_for_each_nlmsg(struct nlmsghdr *nlh, return ret; } } - len -= NLMSG_ALIGN(nlh->nlmsg_len); - nlh = (struct nlmsghdr *)(((char *)nlh) + NLMSG_ALIGN(nlh->nlmsg_len)); + + aligned_nlmsg_len = NLMSG_ALIGN(nlh->nlmsg_len); + if (aligned_nlmsg_len >= len) { + break; + } + len -= aligned_nlmsg_len; + nlh = (struct nlmsghdr *)(((char *)nlh) + aligned_nlmsg_len); } return 0; } @@ -363,6 +375,7 @@ static abi_long host_to_target_for_each_nlattr(struct nlattr *nlattr, void *context)) { unsigned short nla_len; + unsigned short aligned_nla_len; abi_long ret; while (len > sizeof(struct nlattr)) { @@ -377,8 +390,13 @@ static abi_long host_to_target_for_each_nlattr(struct nlattr *nlattr, if (ret < 0) { return ret; } - len -= NLA_ALIGN(nla_len); - nlattr = (struct nlattr *)(((char *)nlattr) + NLA_ALIGN(nla_len)); + + aligned_nla_len = NLA_ALIGN(nla_len); + if (aligned_nla_len >= len) { + break; + } + len -= aligned_nla_len; + nlattr = (struct nlattr *)(((char *)nlattr) + aligned_nla_len); } return 0; } @@ -389,6 +407,7 @@ static abi_long host_to_target_for_each_rtattr(struct rtattr *rtattr, (struct rtattr *)) { unsigned short rta_len; + unsigned short aligned_rta_len; abi_long ret; while (len > sizeof(struct rtattr)) { @@ -403,8 +422,13 @@ static abi_long host_to_target_for_each_rtattr(struct rtattr *rtattr, if (ret < 0) { return ret; } - len -= RTA_ALIGN(rta_len); - rtattr = (struct rtattr *)(((char *)rtattr) + RTA_ALIGN(rta_len)); + + aligned_rta_len = RTA_ALIGN(rta_len); + if (aligned_rta_len >= len) { + break; + } + len -= aligned_rta_len; + rtattr = (struct rtattr *)(((char *)rtattr) + aligned_rta_len); } return 0; } @@ -1058,6 +1082,7 @@ static abi_long target_to_host_for_each_rtattr(struct rtattr *rtattr, abi_long (*target_to_host_rtattr) (struct rtattr *)) { + unsigned short aligned_rta_len; abi_long ret; while (len >= sizeof(struct rtattr)) { @@ -1071,9 +1096,13 @@ static abi_long target_to_host_for_each_rtattr(struct rtattr *rtattr, if (ret < 0) { return ret; } - len -= RTA_ALIGN(rtattr->rta_len); - rtattr = (struct rtattr *)(((char *)rtattr) + - RTA_ALIGN(rtattr->rta_len)); + + aligned_rta_len = RTA_ALIGN(rtattr->rta_len); + if (aligned_rta_len >= len) { + break; + } + len -= aligned_rta_len; + rtattr = (struct rtattr *)(((char *)rtattr) + aligned_rta_len); } return 0; } diff --git a/linux-user/strace.c b/linux-user/strace.c index c80e93b5db..3d4d684450 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -8,6 +8,7 @@ #include <arpa/inet.h> #include <netinet/tcp.h> #include <linux/if_packet.h> +#include <linux/netlink.h> #include <sched.h> #include "qemu.h" @@ -63,9 +64,10 @@ UNUSED static void print_string(abi_long, int); UNUSED static void print_buf(abi_long addr, abi_long len, int last); UNUSED static void print_raw_param(const char *, abi_long, int); UNUSED static void print_timeval(abi_ulong, int); +UNUSED static void print_timezone(abi_ulong, int); UNUSED static void print_number(abi_long, int); UNUSED static void print_signal(abi_ulong, int); -UNUSED static void print_sockaddr(abi_ulong addr, abi_long addrlen); +UNUSED static void print_sockaddr(abi_ulong, abi_long, int); UNUSED static void print_socket_domain(int domain); UNUSED static void print_socket_type(int type); UNUSED static void print_socket_protocol(int domain, int type, int protocol); @@ -334,7 +336,7 @@ static void print_siginfo(const target_siginfo_t *tinfo) } static void -print_sockaddr(abi_ulong addr, abi_long addrlen) +print_sockaddr(abi_ulong addr, abi_long addrlen, int last) { struct target_sockaddr *sa; int i; @@ -397,6 +399,12 @@ print_sockaddr(abi_ulong addr, abi_long addrlen) gemu_log("}"); break; } + case AF_NETLINK: { + struct target_sockaddr_nl *nl = (struct target_sockaddr_nl *)sa; + gemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u}", + tswap32(nl->nl_pid), tswap32(nl->nl_groups)); + break; + } default: gemu_log("{sa_family=%d, sa_data={", sa->sa_family); for (i = 0; i < 13; i++) { @@ -410,7 +418,7 @@ print_sockaddr(abi_ulong addr, abi_long addrlen) } else { print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0); } - gemu_log(", "TARGET_ABI_FMT_ld, addrlen); + gemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last)); } static void @@ -423,6 +431,9 @@ print_socket_domain(int domain) case PF_INET: gemu_log("PF_INET"); break; + case PF_NETLINK: + gemu_log("PF_NETLINK"); + break; case PF_PACKET: gemu_log("PF_PACKET"); break; @@ -472,6 +483,33 @@ print_socket_protocol(int domain, int type, int protocol) return; } + if (domain == PF_NETLINK) { + switch (protocol) { + case NETLINK_ROUTE: + gemu_log("NETLINK_ROUTE"); + break; + case NETLINK_AUDIT: + gemu_log("NETLINK_AUDIT"); + break; + case NETLINK_NETFILTER: + gemu_log("NETLINK_NETFILTER"); + break; + case NETLINK_KOBJECT_UEVENT: + gemu_log("NETLINK_KOBJECT_UEVENT"); + break; + case NETLINK_RDMA: + gemu_log("NETLINK_RDMA"); + break; + case NETLINK_CRYPTO: + gemu_log("NETLINK_CRYPTO"); + break; + default: + gemu_log("%d", protocol); + break; + } + return; + } + switch (protocol) { case IPPROTO_IP: gemu_log("IPPROTO_IP"); @@ -1243,8 +1281,10 @@ print_timeval(abi_ulong tv_addr, int last) struct target_timeval *tv; tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1); - if (!tv) + if (!tv) { + print_pointer(tv_addr, last); return; + } gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s", tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last)); unlock_user(tv, tv_addr, 0); @@ -1252,6 +1292,25 @@ print_timeval(abi_ulong tv_addr, int last) gemu_log("NULL%s", get_comma(last)); } +static void +print_timezone(abi_ulong tz_addr, int last) +{ + if (tz_addr) { + struct target_timezone *tz; + + tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1); + if (!tz) { + print_pointer(tz_addr, last); + return; + } + gemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest), + tswap32(tz->tz_dsttime), get_comma(last)); + unlock_user(tz, tz_addr, 0); + } else { + gemu_log("NULL%s", get_comma(last)); + } +} + #undef UNUSED #ifdef TARGET_NR_accept @@ -1561,6 +1620,19 @@ print_futimesat(const struct syscallname *name, } #endif +#ifdef TARGET_NR_settimeofday +static void +print_settimeofday(const struct syscallname *name, + abi_long arg0, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + print_syscall_prologue(name); + print_timeval(arg0, 0); + print_timezone(arg1, 1); + print_syscall_epilogue(name); +} +#endif + #ifdef TARGET_NR_link static void print_link(const struct syscallname *name, @@ -1635,6 +1707,15 @@ print_socket(const struct syscallname *name, #endif +#if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind) + +static void print_sockfd(abi_long sockfd, int last) +{ + print_raw_param(TARGET_ABI_FMT_ld, sockfd, last); +} + +#endif + #if defined(TARGET_NR_socketcall) #define get_user_ualx(x, gaddr, idx) \ @@ -1669,8 +1750,8 @@ static void do_print_sockaddr(const char *name, abi_long arg1) get_user_ualx(addrlen, arg1, 2); gemu_log("%s(", name); - print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); - print_sockaddr(addr, addrlen); + print_sockfd(sockfd, 0); + print_sockaddr(addr, addrlen, 0); gemu_log(")"); } @@ -1682,7 +1763,7 @@ static void do_print_listen(const char *name, abi_long arg1) get_user_ualx(backlog, arg1, 1); gemu_log("%s(", name); - print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); + print_sockfd(sockfd, 0); print_raw_param(TARGET_ABI_FMT_ld, backlog, 1); gemu_log(")"); } @@ -1717,7 +1798,7 @@ static void do_print_sendrecv(const char *name, abi_long arg1) get_user_ualx(flags, arg1, 3); gemu_log("%s(", name); - print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); + print_sockfd(sockfd, 0); print_buf(msg, len, 0); print_raw_param(TARGET_ABI_FMT_ld, len, 0); print_flags(msg_flags, flags, 1); @@ -1736,11 +1817,11 @@ static void do_print_msgaddr(const char *name, abi_long arg1) get_user_ualx(addrlen, arg1, 5); gemu_log("%s(", name); - print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); + print_sockfd(sockfd, 0); print_buf(msg, len, 0); print_raw_param(TARGET_ABI_FMT_ld, len, 0); print_flags(msg_flags, flags, 0); - print_sockaddr(addr, addrlen); + print_sockaddr(addr, addrlen, 0); gemu_log(")"); } @@ -1752,7 +1833,7 @@ static void do_print_shutdown(const char *name, abi_long arg1) get_user_ualx(how, arg1, 1); gemu_log("shutdown("); - print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); + print_sockfd(sockfd, 0); switch (how) { case SHUT_RD: gemu_log("SHUT_RD"); @@ -1779,7 +1860,7 @@ static void do_print_msg(const char *name, abi_long arg1) get_user_ualx(flags, arg1, 2); gemu_log("%s(", name); - print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); + print_sockfd(sockfd, 0); print_pointer(msg, 0); print_flags(msg_flags, flags, 1); gemu_log(")"); @@ -1796,7 +1877,7 @@ static void do_print_sockopt(const char *name, abi_long arg1) get_user_ualx(optlen, arg1, 4); gemu_log("%s(", name); - print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0); + print_sockfd(sockfd, 0); switch (level) { case SOL_TCP: gemu_log("SOL_TCP,"); @@ -1973,6 +2054,19 @@ print_socketcall(const struct syscallname *name, } #endif +#if defined(TARGET_NR_bind) +static void +print_bind(const struct syscallname *name, + abi_long arg0, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + print_syscall_prologue(name); + print_sockfd(arg0, 0); + print_sockaddr(arg1, arg2, 1); + print_syscall_epilogue(name); +} +#endif + #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \ defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64) static void diff --git a/linux-user/strace.list b/linux-user/strace.list index 63a946642d..1de4319dcf 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -41,7 +41,7 @@ { TARGET_NR_bdflush, "bdflush" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_bind -{ TARGET_NR_bind, "bind" , NULL, NULL, NULL }, +{ TARGET_NR_bind, "bind" , NULL, print_bind, NULL }, #endif #ifdef TARGET_NR_bpf { TARGET_NR_bpf, "bpf" , NULL, NULL, NULL }, @@ -121,6 +121,9 @@ #ifdef TARGET_NR_dup2 { TARGET_NR_dup2, "dup2" , NULL, NULL, NULL }, #endif +#ifdef TARGET_NR_dup3 +{ TARGET_NR_dup3, "dup3" , NULL, NULL, NULL }, +#endif #ifdef TARGET_NR_epoll_create { TARGET_NR_epoll_create, "epoll_create" , NULL, NULL, NULL }, #endif @@ -1345,7 +1348,7 @@ { TARGET_NR_set_tid_address, "set_tid_address" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_settimeofday -{ TARGET_NR_settimeofday, "settimeofday" , NULL, NULL, NULL }, +{ TARGET_NR_settimeofday, "settimeofday" , NULL, print_settimeofday, NULL }, #endif #ifdef TARGET_NR_setuid { TARGET_NR_setuid, "setuid" , NULL, NULL, NULL }, diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e2af3c1494..f1ab81b917 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1496,8 +1496,10 @@ static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, sizeof(target_saddr->sa_family)) { target_saddr->sa_family = tswap16(addr->sa_family); } - if (addr->sa_family == AF_NETLINK && len >= sizeof(struct sockaddr_nl)) { - struct sockaddr_nl *target_nl = (struct sockaddr_nl *)target_saddr; + if (addr->sa_family == AF_NETLINK && + len >= sizeof(struct target_sockaddr_nl)) { + struct target_sockaddr_nl *target_nl = + (struct target_sockaddr_nl *)target_saddr; target_nl->nl_pid = tswap32(target_nl->nl_pid); target_nl->nl_groups = tswap32(target_nl->nl_groups); } else if (addr->sa_family == AF_PACKET) { diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index fa69c6ab8d..98c2119de9 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -134,44 +134,51 @@ #define TARGET_IOWRU(type,nr) TARGET_IOC(TARGET_IOC_READ|TARGET_IOC_WRITE,(type),(nr),TARGET_IOC_SIZEMASK) struct target_sockaddr { - uint16_t sa_family; + abi_ushort sa_family; uint8_t sa_data[14]; }; struct target_sockaddr_ll { - uint16_t sll_family; /* Always AF_PACKET */ - uint16_t sll_protocol; /* Physical layer protocol */ - int sll_ifindex; /* Interface number */ - uint16_t sll_hatype; /* ARP hardware type */ - uint8_t sll_pkttype; /* Packet type */ - uint8_t sll_halen; /* Length of address */ - uint8_t sll_addr[8]; /* Physical layer address */ + abi_ushort sll_family; /* Always AF_PACKET */ + abi_ushort sll_protocol; /* Physical layer protocol */ + abi_int sll_ifindex; /* Interface number */ + abi_ushort sll_hatype; /* ARP hardware type */ + uint8_t sll_pkttype; /* Packet type */ + uint8_t sll_halen; /* Length of address */ + uint8_t sll_addr[8]; /* Physical layer address */ }; struct target_sockaddr_un { - uint16_t su_family; + abi_ushort su_family; uint8_t sun_path[108]; }; +struct target_sockaddr_nl { + abi_ushort nl_family; /* AF_NETLINK */ + abi_ushort __pad; + abi_uint nl_pid; + abi_uint nl_groups; +}; + struct target_in_addr { - uint32_t s_addr; /* big endian */ + abi_uint s_addr; /* big endian */ }; struct target_sockaddr_in { - uint16_t sin_family; - int16_t sin_port; /* big endian */ + abi_ushort sin_family; + abi_short sin_port; /* big endian */ struct target_in_addr sin_addr; uint8_t __pad[sizeof(struct target_sockaddr) - - sizeof(uint16_t) - sizeof(int16_t) - + sizeof(abi_ushort) - sizeof(abi_short) - sizeof(struct target_in_addr)]; }; struct target_sockaddr_in6 { - uint16_t sin6_family; - uint16_t sin6_port; /* big endian */ - uint32_t sin6_flowinfo; /* big endian */ + abi_ushort sin6_family; + abi_ushort sin6_port; /* big endian */ + abi_uint sin6_flowinfo; /* big endian */ struct in6_addr sin6_addr; /* IPv6 address, big endian */ - uint32_t sin6_scope_id; + abi_uint sin6_scope_id; }; struct target_sock_filter { |