Skip to contentSkip to conversation

linux-user: improve NETLINK strace

PATCH In review Philippe Mathieu-Daudé 3 participants 29 messages Jan 24, 2018 – Jun 28, 2018

lore
Share & tools
lore
#0 lore raw

cover linux-user: improve NETLINK strace

Few patches I'v been writting while trying to figure out this issue:
http://lists.nongnu.org/archive/html/qemu-arm/2018-01/msg00514.html

Regards,

Phil.

Philippe Mathieu-Daudé (11):
linux-user/strace: dump AF_NETLINK sockaddr content linux-user/strace: improve sendto() output
linux-user/strace: add print_sockaddr_ptr() to handle plain/pointer addrlen linux-user/strace: improve recvfrom() output
linux-user/strace: improve getsockname() output linux-user/strace: improve recvmsg() output
linux-user/strace: improve bind() output
linux-user/strace: improve gettimeofday() output linux-user/strace: improve capget()/capset() output linux-user/syscall: verify recvfrom(addr) is user-writable linux-user/syscall: simplify recvfrom()

 linux-user/syscall_defs.h |   7 +++
 linux-user/strace.c       | 122 +++++++++++++++++++++++++++++++++++++++++++++-
 linux-user/syscall.c      |  16 +++---
 linux-user/strace.list    |  16 +++---
 4 files changed, 144 insertions(+), 17 deletions(-)
Signature · 1 line
2.15.1
#1 lore raw

RFC PATCH 1/11 linux-user/strace: dump AF_NETLINK sockaddr content

---
please double check __pad and ntohl()

 linux-user/syscall_defs.h |  7 +++++++
 linux-user/strace.c       | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
linux-user/syscall_defs.h +7 -0
index bec3680b94..550e7d2939 100644
@@ -151,6 +151,13 @@ struct target_sockaddr_un {
     uint8_t sun_path[108];
 };
 
+struct target_sockaddr_nl {
+    uint16_t nl_family;     /* AF_NETLINK */
+    int16_t __pad;
+    uint32_t nl_pid;
+    uint32_t nl_groups;
+};
+
 struct target_in_addr {
     uint32_t s_addr; /* big endian */
 };
linux-user/strace.c +34 -0
index bd897a3f20..7eb5e2ab48 100644
@@ -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"
 
@@ -397,6 +398,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}",
+                     ntohl(nl->nl_pid), ntohl(nl->nl_groups));
+            break;
+        }
         default:
             gemu_log("{sa_family=%d, sa_data={", sa->sa_family);
             for (i = 0; i < 13; i++) {
@@ -423,6 +430,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 +482,30 @@ print_socket_protocol(int domain, int type, int protocol)
         return;
     }
 
+    if (domain == AF_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_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");
Signature · 1 line
2.15.1
#2 lore raw

Re: [Qemu-devel] [RFC PATCH 01/11] linux-user/strace: dump AF_NETLINK sockaddr content

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 13 lines

---
please double check __pad and ntohl()

 linux-user/syscall_defs.h |  7 +++++++
 linux-user/strace.c       | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
linux-user/syscall_defs.h +0 -0
index bec3680b94..550e7d2939 100644

linux-user/syscall_defs.h struct target_sockaddr_un { · line 156

Quoted 6 lines
linux-user/syscall_defs.h +3 -0
@@ -151,6 +151,13 @@ struct target_sockaddr_un {
     uint8_t sun_path[108];
 };
 
+struct target_sockaddr_nl {
+    uint16_t nl_family;     /* AF_NETLINK */
+    int16_t __pad;

netlink.h uses an unsigned type here.

Quoted 20 lines
linux-user/syscall_defs.h +4 -0
+    uint32_t nl_pid;
+    uint32_t nl_groups;
+};
+
 struct target_in_addr {
     uint32_t s_addr; /* big endian */
 };
linux-user/strace.c +1 -0
index bd897a3f20..7eb5e2ab48 100644
@@ -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"
 

linux-user/strace.c print_sockaddr(abi_ulong addr, abi_long addrlen) · line 404

Quoted 7 lines
linux-user/strace.c +4 -0
@@ -397,6 +398,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}",
+                     ntohl(nl->nl_pid), ntohl(nl->nl_groups));

Both sides of the netlink pipe are local and have the same endianness, so I don't think we need the ntohl() here. Moreover, I didn't find any endianness change in the kernel for them.

Thanks,
Laurent

#3 lore raw

Re: [Qemu-devel] [RFC PATCH 01/11] linux-user/strace: dump AF_NETLINK sockaddr content

Hi Laurent,

Quoted 17 lines · Laurent Vivier

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 16 lines

---
please double check __pad and ntohl()

 linux-user/syscall_defs.h |  7 +++++++
 linux-user/strace.c       | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
linux-user/syscall_defs.h +0 -0
index bec3680b94..550e7d2939 100644
@@ -151,6 +151,13 @@ struct target_sockaddr_un {
     uint8_t sun_path[108];
 };
 
Quoted 5 lines

linux-user/syscall_defs.h struct target_sockaddr_un { · line 156

Quoted 3 lines
linux-user/syscall_defs.h +3 -0
+struct target_sockaddr_nl {
+    uint16_t nl_family;     /* AF_NETLINK */
+    int16_t __pad;

netlink.h uses an unsigned type here.

This is padding, do you prefer char pad[2]?

Quoted 20 lines
Quoted 20 lines
linux-user/syscall_defs.h +4 -0
+    uint32_t nl_pid;
+    uint32_t nl_groups;
+};
+
 struct target_in_addr {
     uint32_t s_addr; /* big endian */
 };
linux-user/strace.c +1 -0
index bd897a3f20..7eb5e2ab48 100644
@@ -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"
 
Quoted 12 lines

linux-user/strace.c print_sockaddr(abi_ulong addr, abi_long addrlen) · line 404

Quoted 8 lines
linux-user/strace.c +4 -0
@@ -397,6 +398,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}",
+                     ntohl(nl->nl_pid), ntohl(nl->nl_groups));

Both sides of the netlink pipe are local and have the same endianness, so I don't think we need the ntohl() here. Moreover, I didn't find any endianness change in the kernel for them.

I had the same feeling but didn't check the kernel :\ since I was unsure I used ntohl(), I'll remove it and respin. Thanks to verify!

Regards,

Phil.

Quoted 4 lines

Thanks,
Laurent

#4 lore raw

Re: [Qemu-devel] [RFC PATCH 01/11] linux-user/strace: dump AF_NETLINK sockaddr content

Le 15/02/2018 à 16:28, Philippe Mathieu-Daudé a écrit :

Quoted 20 lines

Hi Laurent,

Quoted 17 lines · Laurent Vivier

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 16 lines

---
please double check __pad and ntohl()

 linux-user/syscall_defs.h |  7 +++++++
 linux-user/strace.c       | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
linux-user/syscall_defs.h +0 -0
index bec3680b94..550e7d2939 100644
@@ -151,6 +151,13 @@ struct target_sockaddr_un {
     uint8_t sun_path[108];
 };
 
Quoted 7 lines
Quoted 5 lines

linux-user/syscall_defs.h struct target_sockaddr_un { · line 156

Quoted 3 lines
linux-user/syscall_defs.h +3 -0
+struct target_sockaddr_nl {
+    uint16_t nl_family;     /* AF_NETLINK */
+    int16_t __pad;

netlink.h uses an unsigned type here.

This is padding, do you prefer char pad[2]?

kernel has:

struct sockaddr_nl {
__kernel_sa_family_t nl_family; /* AF_NETLINK */
unsigned short nl_pad; /* zero */
__u32 nl_pid; /* port ID */
__u32 nl_groups; /* multicast groups mask */
};

so I prefer "uint16_t", but as you say, it is padding, so sign is meaningless, if you prefer you can keep int16_t.

Now, it would be good to use target_sockaddr_nl in host_to_target_sockaddr() as we define it.

Thanks,
Laurent

#5 lore raw

PATCH 2/11 linux-user/strace: improve sendto() output

In reply to Philippe Mathieu-Daudé
---
 linux-user/strace.c    | 16 ++++++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)
linux-user/strace.c +16 -0
index 7eb5e2ab48..e7272f4ede 100644
@@ -1922,6 +1922,22 @@ print_socketcall(const struct syscallname *name,
 }
 #endif
 
+#if defined(TARGET_NR_sendto)
+static void
+print_sendto(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_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
+    print_buf(arg1, arg2, 0);
+    print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
+    print_flags(msg_flags, arg3, 0);
+    print_sockaddr(arg4, arg5);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
     defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
 static void
linux-user/strace.list +1 -1
index a91e33f7e5..47669a2f50 100644
@@ -1248,7 +1248,7 @@
 { TARGET_NR_sendmsg, "sendmsg" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_sendto
-{ TARGET_NR_sendto, "sendto" , NULL, NULL, NULL },
+{ TARGET_NR_sendto, "sendto" , NULL, print_sendto, NULL },
 #endif
 #ifdef TARGET_NR_setdomainname
 { TARGET_NR_setdomainname, "setdomainname" , NULL, NULL, NULL },
Signature · 1 line
2.15.1
#6 lore raw

Re: [Qemu-devel] [PATCH 02/11] linux-user/strace: improve sendto() output

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 12 lines
---
 linux-user/strace.c    | 16 ++++++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)
linux-user/strace.c +0 -0
index 7eb5e2ab48..e7272f4ede 100644
@@ -1922,6 +1922,22 @@ print_socketcall(const struct syscallname *name,
 }

linux-user/strace.c print_socketcall(const struct syscallname *name, · line 1932

Quoted 10 lines
linux-user/strace.c +8 -0
 #endif
 
+#if defined(TARGET_NR_sendto)
+static void
+print_sendto(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_raw_param(TARGET_ABI_FMT_ld, arg0, 0);

Other strace functions (accept(), fcntl(), ...) use "%d" for fd.

Thanks,
Laurent

#7 lore raw

PATCH 3/11 linux-user/strace: add print_sockaddr_ptr() to handle plain/pointer addrlen

In reply to Philippe Mathieu-Daudé

since this argument differs between sendto()/recvfrom()

---
 linux-user/strace.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
linux-user/strace.c +15 -2
index e7272f4ede..9726d9b378 100644
@@ -335,12 +335,15 @@ static void print_siginfo(const target_siginfo_t *tinfo)
 }
 
 static void
-print_sockaddr(abi_ulong addr, abi_long addrlen)
+print_sockaddr_ptr(abi_ulong addr, abi_long addrlen, bool addrlen_ptr)
 {
     struct target_sockaddr *sa;
     int i;
     int sa_family;
 
+    if (addrlen_ptr) {
+        get_user_ual(addrlen, addrlen);
+    }
     sa = lock_user(VERIFY_READ, addr, addrlen, 1);
     if (sa) {
         sa_family = tswap16(sa->sa_family);
@@ -417,7 +420,17 @@ 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);
+    if (addrlen_ptr) {
+        gemu_log(", ["TARGET_ABI_FMT_ld"]", addrlen);
+    } else {
+        gemu_log(", "TARGET_ABI_FMT_ld, addrlen);
+    }
+}
+
+static void
+print_sockaddr(abi_ulong addr, abi_long addrlen)
+{
+    print_sockaddr_ptr(addr, addrlen, false);
 }
 
 static void
Signature · 1 line
2.15.1
#8 lore raw

Re: [Qemu-devel] [PATCH 03/11] linux-user/strace: add print_sockaddr_ptr() to handle plain/pointer addrlen

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 38 lines

since this argument differs between sendto()/recvfrom()

---
 linux-user/strace.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
linux-user/strace.c +8 -2
index e7272f4ede..9726d9b378 100644
@@ -335,12 +335,15 @@ static void print_siginfo(const target_siginfo_t *tinfo)
 }
 
 static void
-print_sockaddr(abi_ulong addr, abi_long addrlen)
+print_sockaddr_ptr(abi_ulong addr, abi_long addrlen, bool addrlen_ptr)
 {
     struct target_sockaddr *sa;
     int i;
     int sa_family;
 
+    if (addrlen_ptr) {
+        get_user_ual(addrlen, addrlen);
+    }
     sa = lock_user(VERIFY_READ, addr, addrlen, 1);
     if (sa) {
         sa_family = tswap16(sa->sa_family);
@@ -417,7 +420,17 @@ 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);
+    if (addrlen_ptr) {
+        gemu_log(", ["TARGET_ABI_FMT_ld"]", addrlen);
+    } else {
+        gemu_log(", "TARGET_ABI_FMT_ld, addrlen);

linux-user/strace.c print_sockaddr(abi_ulong addr, abi_long addrlen) · line 436

Quoted 10 lines
linux-user/strace.c +7 -0
+    }
+}
+
+static void
+print_sockaddr(abi_ulong addr, abi_long addrlen)
+{
+    print_sockaddr_ptr(addr, addrlen, false);
 }
 
 static void

Why not only something like:

static void
print_sockaddr_ptr(abi_ulong addr, abi_long addrlen_ptr)

{
    abi_ulong addrlen;

    get_user_ual(addrlen, addrlen_ptr);
    print_sockaddr(addr, addrlen);
}

?

You should also check addrlen_ptr != NULL (it's allowed with recvfrom()).

Thanks,
Laurent

#9 lore raw

Re: [Qemu-devel] [PATCH 03/11] linux-user/strace: add print_sockaddr_ptr() to handle plain/pointer addrlen

Hi Laurent,

Quoted 54 lines · Laurent Vivier

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 38 lines

since this argument differs between sendto()/recvfrom()

---
 linux-user/strace.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
linux-user/strace.c +8 -2
index e7272f4ede..9726d9b378 100644
@@ -335,12 +335,15 @@ static void print_siginfo(const target_siginfo_t *tinfo)
 }
 
 static void
-print_sockaddr(abi_ulong addr, abi_long addrlen)
+print_sockaddr_ptr(abi_ulong addr, abi_long addrlen, bool addrlen_ptr)
 {
     struct target_sockaddr *sa;
     int i;
     int sa_family;
 
+    if (addrlen_ptr) {
+        get_user_ual(addrlen, addrlen);
+    }
     sa = lock_user(VERIFY_READ, addr, addrlen, 1);
     if (sa) {
         sa_family = tswap16(sa->sa_family);
@@ -417,7 +420,17 @@ 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);
+    if (addrlen_ptr) {
+        gemu_log(", ["TARGET_ABI_FMT_ld"]", addrlen);
+    } else {
+        gemu_log(", "TARGET_ABI_FMT_ld, addrlen);

linux-user/strace.c print_sockaddr(abi_ulong addr, abi_long addrlen) · line 436

Quoted 10 lines
linux-user/strace.c +7 -0
+    }
+}
+
+static void
+print_sockaddr(abi_ulong addr, abi_long addrlen)
+{
+    print_sockaddr_ptr(addr, addrlen, false);
 }
 
 static void

Why not only something like:

static void
print_sockaddr_ptr(abi_ulong addr, abi_long addrlen_ptr)

Quoted 8 lines
{
    abi_ulong addrlen;

    get_user_ual(addrlen, addrlen_ptr);
    print_sockaddr(addr, addrlen);
}

?

Because we loose the [] around addrlen.

Quoted 1 line

You should also check addrlen_ptr != NULL (it's allowed with recvfrom()).

OK.

Quoted 4 lines

Thanks,
Laurent

#10 lore raw

PATCH 4/11 linux-user/strace: improve recvfrom() output

In reply to Philippe Mathieu-Daudé
---
 linux-user/strace.c    | 16 ++++++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)
linux-user/strace.c +16 -0
index 9726d9b378..3537a3ae92 100644
@@ -1935,6 +1935,22 @@ print_socketcall(const struct syscallname *name,
 }
 #endif
 
+#if defined(TARGET_NR_recvfrom)
+static void
+print_recvfrom(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_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
+    print_buf(arg1, arg2, 0);
+    print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
+    print_flags(msg_flags, arg3, 0);
+    print_sockaddr_ptr(arg4, arg5, true);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #if defined(TARGET_NR_sendto)
 static void
 print_sendto(const struct syscallname *name,
linux-user/strace.list +1 -1
index 47669a2f50..bf4192fb47 100644
@@ -1101,7 +1101,7 @@
 { TARGET_NR_recv, "recv" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_recvfrom
-{ TARGET_NR_recvfrom, "recvfrom" , NULL, NULL, NULL },
+{ TARGET_NR_recvfrom, "recvfrom" , NULL, print_recvfrom, NULL },
 #endif
 #ifdef TARGET_NR_recvmmsg
 { TARGET_NR_recvmmsg, "recvmmsg" , NULL, NULL, NULL },
Signature · 1 line
2.15.1
#11 lore raw

PATCH 5/11 linux-user/strace: improve getsockname() output

In reply to Philippe Mathieu-Daudé
---
 linux-user/strace.c    | 13 +++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
linux-user/strace.c +13 -0
index 3537a3ae92..70ecb1fc98 100644
@@ -1935,6 +1935,19 @@ print_socketcall(const struct syscallname *name,
 }
 #endif
 
+#if defined(TARGET_NR_getsockname)
+static void
+print_getsockname(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_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
+    print_sockaddr_ptr(arg1, arg2, true);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #if defined(TARGET_NR_recvfrom)
 static void
 print_recvfrom(const struct syscallname *name,
linux-user/strace.list +1 -1
index bf4192fb47..947ff04eab 100644
@@ -371,7 +371,7 @@
 { TARGET_NR_getsid, "getsid" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_getsockname
-{ TARGET_NR_getsockname, "getsockname" , NULL, NULL, NULL },
+{ TARGET_NR_getsockname, "getsockname" , NULL, print_getsockname, NULL },
 #endif
 #ifdef TARGET_NR_getsockopt
 { TARGET_NR_getsockopt, "getsockopt" , NULL, NULL, NULL },
Signature · 1 line
2.15.1
#12 lore raw

PATCH 6/11 linux-user/strace: improve recvmsg() output

In reply to Philippe Mathieu-Daudé
---
 linux-user/strace.list | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/strace.list +1 -1
index 947ff04eab..ae6dc8fecf 100644
@@ -1107,7 +1107,7 @@
 { TARGET_NR_recvmmsg, "recvmmsg" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_recvmsg
-{ TARGET_NR_recvmsg, "recvmsg" , NULL, NULL, NULL },
+{ TARGET_NR_recvmsg, "recvmsg" , "%s(%d,%p,%#x)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_remap_file_pages
 { TARGET_NR_remap_file_pages, "remap_file_pages" , NULL, NULL, NULL },
Signature · 1 line
2.15.1
Reviewed-by on v1 6/11
#13 lore raw

Re: [Qemu-devel] [PATCH 06/11] linux-user/strace: improve recvmsg() output

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 11 lines
---
 linux-user/strace.list | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/strace.list +0 -0
index 947ff04eab..ae6dc8fecf 100644

linux-user/strace.list line 1113

Quoted 8 lines
linux-user/strace.list +1 -1
@@ -1107,7 +1107,7 @@
 { TARGET_NR_recvmmsg, "recvmmsg" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_recvmsg
-{ TARGET_NR_recvmsg, "recvmsg" , NULL, NULL, NULL },
+{ TARGET_NR_recvmsg, "recvmsg" , "%s(%d,%p,%#x)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_remap_file_pages
 { TARGET_NR_remap_file_pages, "remap_file_pages" , NULL, NULL, NULL },
#14 lore raw

PATCH 7/11 linux-user/strace: improve bind() output

In reply to Philippe Mathieu-Daudé
---
 linux-user/strace.c    | 13 +++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
linux-user/strace.c +13 -0
index 70ecb1fc98..4b8ab6bcfb 100644
@@ -1935,6 +1935,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_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
+    print_sockaddr(arg1, arg2);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #if defined(TARGET_NR_getsockname)
 static void
 print_getsockname(const struct syscallname *name,
linux-user/strace.list +1 -1
index ae6dc8fecf..958d10d48f 100644
@@ -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 },
Signature · 1 line
2.15.1
#15 lore raw

Re: [Qemu-devel] [PATCH 07/11] linux-user/strace: improve bind() output

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 12 lines
---
 linux-user/strace.c    | 13 +++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
linux-user/strace.c +0 -0
index 70ecb1fc98..4b8ab6bcfb 100644
@@ -1935,6 +1935,19 @@ print_socketcall(const struct syscallname *name,
 }

linux-user/strace.c print_socketcall(const struct syscallname *name, · line 1945

Quoted 10 lines
linux-user/strace.c +8 -0
 #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_raw_param(TARGET_ABI_FMT_ld, arg0, 0);

Other functions use "%d" for fd.

Thanks,
Laurent

#16 lore raw

PATCH 8/11 linux-user/strace: improve gettimeofday() output

In reply to Philippe Mathieu-Daudé
---
 linux-user/strace.c    | 13 +++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
linux-user/strace.c +13 -0
index 4b8ab6bcfb..b7c4cfae58 100644
@@ -1526,6 +1526,19 @@ print_futimesat(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_gettimeofday
+static void
+print_gettimeofday(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_pointer(arg0, 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_link
 static void
 print_link(const struct syscallname *name,
linux-user/strace.list +1 -1
index 958d10d48f..f90c0e8ee4 100644
@@ -384,7 +384,7 @@
 { TARGET_NR_gettid, "gettid" , "%s()", NULL, NULL },
 #endif
 #ifdef TARGET_NR_gettimeofday
-{ TARGET_NR_gettimeofday, "gettimeofday" , NULL, NULL, NULL },
+{ TARGET_NR_gettimeofday, "gettimeofday" , NULL, print_gettimeofday, NULL },
 #endif
 #ifdef TARGET_NR_getuid
 { TARGET_NR_getuid, "getuid" , "%s()", NULL, NULL },
Signature · 1 line
2.15.1
#17 lore raw

Re: [Qemu-devel] [PATCH 08/11] linux-user/strace: improve gettimeofday() output

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 36 lines
---
 linux-user/strace.c    | 13 +++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
linux-user/strace.c +13 -0
index 4b8ab6bcfb..b7c4cfae58 100644
@@ -1526,6 +1526,19 @@ print_futimesat(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_gettimeofday
+static void
+print_gettimeofday(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_pointer(arg0, 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_link
 static void
 print_link(const struct syscallname *name,
linux-user/strace.list +0 -0
index 958d10d48f..f90c0e8ee4 100644

linux-user/strace.list line 390

Quoted 8 lines
linux-user/strace.list +1 -1
@@ -384,7 +384,7 @@
 { TARGET_NR_gettid, "gettid" , "%s()", NULL, NULL },
 #endif
 #ifdef TARGET_NR_gettimeofday
-{ TARGET_NR_gettimeofday, "gettimeofday" , NULL, NULL, NULL },
+{ TARGET_NR_gettimeofday, "gettimeofday" , NULL, print_gettimeofday, NULL },
 #endif
 #ifdef TARGET_NR_getuid
 { TARGET_NR_getuid, "getuid" , "%s()", NULL, NULL },

There is a print_timeval(), and you could add a print_timezone(), and update the result() function pointer to call them.

And once it is done, you can also display them for settimeofday().

Thanks,
Laurent

#18 lore raw

Re: [Qemu-devel] [PATCH 08/11] linux-user/strace: improve gettimeofday() output

Hi Laurent,

Quoted 40 lines · Laurent Vivier

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 39 lines
---
 linux-user/strace.c    | 13 +++++++++++++
 linux-user/strace.list |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
linux-user/strace.c +13 -0
index 4b8ab6bcfb..b7c4cfae58 100644
@@ -1526,6 +1526,19 @@ print_futimesat(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_gettimeofday
+static void
+print_gettimeofday(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_pointer(arg0, 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_link
 static void
 print_link(const struct syscallname *name,
linux-user/strace.list +0 -1
index 958d10d48f..f90c0e8ee4 100644
@@ -384,7 +384,7 @@
 { TARGET_NR_gettid, "gettid" , "%s()", NULL, NULL },
 #endif
 #ifdef TARGET_NR_gettimeofday
-{ TARGET_NR_gettimeofday, "gettimeofday" , NULL, NULL, NULL },
Quoted 8 lines

linux-user/strace.list line 390

Quoted 5 lines
linux-user/strace.list +1 -0
+{ TARGET_NR_gettimeofday, "gettimeofday" , NULL, print_gettimeofday, NULL },
 #endif
 #ifdef TARGET_NR_getuid
 { TARGET_NR_getuid, "getuid" , "%s()", NULL, NULL },

There is a print_timeval(), and you could add a print_timezone(), and update the result() function pointer to call them.

The result prototype is:

  void (*result)(const struct syscallname *, abi_long);

So we don't have access to the address of the struct timeval argument as the call() function.

Quoted 2 lines

And once it is done, you can also display them for settimeofday().

OK.

#19 lore raw

PATCH 9/11 linux-user/strace: improve capget()/capset() output

In reply to Philippe Mathieu-Daudé
---
 linux-user/strace.list | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/strace.list +2 -2
index f90c0e8ee4..f09234345f 100644
@@ -59,10 +59,10 @@
 { TARGET_NR_cacheflush, "cacheflush" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_capget
-{ TARGET_NR_capget, "capget" , NULL, NULL, NULL },
+{ TARGET_NR_capget, "capget" , "%s(%p,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_capset
-{ TARGET_NR_capset, "capset" , NULL, NULL, NULL },
+{ TARGET_NR_capset, "capset" , "%s(%p,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_chdir
 { TARGET_NR_chdir, "chdir" , NULL, print_chdir, NULL },
Signature · 1 line
2.15.1
Reviewed-by on v1 9/11
#20 lore raw

Re: [Qemu-devel] [PATCH 09/11] linux-user/strace: improve capget()/capset() output

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 13 lines
---
 linux-user/strace.list | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/strace.list +0 -0
index f90c0e8ee4..f09234345f 100644
@@ -59,10 +59,10 @@
 { TARGET_NR_cacheflush, "cacheflush" , NULL, NULL, NULL },
 #endif

linux-user/strace.list line 68

Quoted 10 lines
linux-user/strace.list +2 -2
 #ifdef TARGET_NR_capget
-{ TARGET_NR_capget, "capget" , NULL, NULL, NULL },
+{ TARGET_NR_capget, "capget" , "%s(%p,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_capset
-{ TARGET_NR_capset, "capset" , NULL, NULL, NULL },
+{ TARGET_NR_capset, "capset" , "%s(%p,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_chdir
 { TARGET_NR_chdir, "chdir" , NULL, print_chdir, NULL },
#21 lore raw

PATCH 10/11 linux-user/syscall: verify recvfrom(addr) is user-writable

In reply to Philippe Mathieu-Daudé
---
 linux-user/syscall.c | 5 +++++
 1 file changed, 5 insertions(+)
linux-user/syscall.c +5 -0
index 11c9116c4a..b6b9beca5b 100644
@@ -4040,6 +4040,11 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags,
             ret = -TARGET_EINVAL;
             goto fail;
         }
+        if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) {
+            ret = -TARGET_EFAULT;
+            goto fail;
+        }
+
         addr = alloca(addrlen);
         ret = get_errno(safe_recvfrom(fd, host_msg, len, flags,
                                       addr, &addrlen));
Signature · 1 line
2.15.1
Reviewed-by on v1 10/11
#22 lore raw

Re: [Qemu-devel] [PATCH 10/11] linux-user/syscall: verify recvfrom(addr) is user-writable

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 12 lines
---
 linux-user/syscall.c | 5 +++++
 1 file changed, 5 insertions(+)
linux-user/syscall.c +0 -0
index 11c9116c4a..b6b9beca5b 100644
@@ -4040,6 +4040,11 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags,
             ret = -TARGET_EINVAL;

linux-user/syscall.c static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, · line 4050

Quoted 10 lines
linux-user/syscall.c +5 -0
             goto fail;
         }
+        if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) {
+            ret = -TARGET_EFAULT;
+            goto fail;
+        }
+
         addr = alloca(addrlen);
         ret = get_errno(safe_recvfrom(fd, host_msg, len, flags,
                                       addr, &addrlen));

Even if host_to_target_sockaddr() will do the check before copying data to the target, I think it is good to check this before reading the data, so:

Thanks,
Laurent

#23 lore raw

PATCH 11/11 linux-user/syscall: simplify recvfrom()

In reply to Philippe Mathieu-Daudé
---
 linux-user/syscall.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
linux-user/syscall.c +4 -7
index b6b9beca5b..e082af2911 100644
@@ -4023,8 +4023,8 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags,
                             abi_ulong target_addr,
                             abi_ulong target_addrlen)
 {
-    socklen_t addrlen;
-    void *addr;
+    socklen_t addrlen = 0;
+    void *addr = NULL;
     void *host_msg;
     abi_long ret;
 
@@ -4046,12 +4046,9 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags,
         }
 
         addr = alloca(addrlen);
-        ret = get_errno(safe_recvfrom(fd, host_msg, len, flags,
-                                      addr, &addrlen));
-    } else {
-        addr = NULL; /* To keep compiler quiet.  */
-        ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, NULL, 0));
     }
+    ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, addr, &addrlen));
+
     if (!is_error(ret)) {
         if (fd_trans_host_to_target_data(fd)) {
             ret = fd_trans_host_to_target_data(fd)(host_msg, ret);
Signature · 1 line
2.15.1
#24 lore raw

Re: [Qemu-devel] [PATCH 11/11] linux-user/syscall: simplify recvfrom()

Le 24/01/2018 à 14:01, Philippe Mathieu-Daudé a écrit :

Quoted 26 lines
---
 linux-user/syscall.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
linux-user/syscall.c +2 -3
index b6b9beca5b..e082af2911 100644
@@ -4023,8 +4023,8 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags,
                             abi_ulong target_addr,
                             abi_ulong target_addrlen)
 {
-    socklen_t addrlen;
-    void *addr;
+    socklen_t addrlen = 0;
+    void *addr = NULL;
     void *host_msg;
     abi_long ret;
 
@@ -4046,12 +4046,9 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags,
         }
 
         addr = alloca(addrlen);
-        ret = get_errno(safe_recvfrom(fd, host_msg, len, flags,

linux-user/syscall.c static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, · line 4054

Quoted 10 lines
linux-user/syscall.c +2 -4
-                                      addr, &addrlen));
-    } else {
-        addr = NULL; /* To keep compiler quiet.  */
-        ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, NULL, 0));
     }
+    ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, addr, &addrlen));
+
     if (!is_error(ret)) {
         if (fd_trans_host_to_target_data(fd)) {
             ret = fd_trans_host_to_target_data(fd)(host_msg, ret);

I think it would be better to pass a NULL pointer to the function for addrlen if addr is NULL.

In man page we have:

If the caller is not interested in the source address, src_addr and addrlen should be specified as NULL.

Something like:

...

-    socklen_t addrlen;
-    void *addr;
+    socklen_t *addrlen = NULL;
+    void *addr = NULL;
+    socklen_t target_len;

...
- addr = alloca(addrlen);
- ret = get_errno(safe_recvfrom(fd, host_msg, len, flags,
- addr, &addrlen));
- } else {

-        addr = NULL; /* To keep compiler quiet.  */
-        ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, NULL, 0));
+        addr = alloca(target_len);
+        addrlen = &target_len
     }

+ ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, addr,
addrlen));
...

Thanks,
Laurent

#25 lore raw
In reply to Philippe Mathieu-Daudé

Hi,

Quoted 2 lines · Philippe Mathieu-Daudé

Few patches I'v been writting while trying to figure out this issue:
http://lists.nongnu.org/archive/html/qemu-arm/2018-01/msg00514.html

I can't comment code wise but it makes the -strace output much more useful in this area.
-- Guido

Quoted 27 lines

Regards,

Phil.

Philippe Mathieu-Daudé (11):
linux-user/strace: dump AF_NETLINK sockaddr content linux-user/strace: improve sendto() output
linux-user/strace: add print_sockaddr_ptr() to handle plain/pointer addrlen linux-user/strace: improve recvfrom() output
linux-user/strace: improve getsockname() output linux-user/strace: improve recvmsg() output
linux-user/strace: improve bind() output
linux-user/strace: improve gettimeofday() output linux-user/strace: improve capget()/capset() output linux-user/syscall: verify recvfrom(addr) is user-writable linux-user/syscall: simplify recvfrom()

 linux-user/syscall_defs.h |   7 +++
 linux-user/strace.c       | 122 +++++++++++++++++++++++++++++++++++++++++++++-
 linux-user/syscall.c      |  16 +++---
 linux-user/strace.list    |  16 +++---
 4 files changed, 144 insertions(+), 17 deletions(-)
Signature · 1 line
2.15.1
Tested-by .....
#26 lore raw

Le 24/01/2018 à 19:50, Guido Günther a écrit :

Quoted 7 lines

Hi,

Quoted 2 lines · Philippe Mathieu-Daudé

Few patches I'v been writting while trying to figure out this issue:
http://lists.nongnu.org/archive/html/qemu-arm/2018-01/msg00514.html

I can't comment code wise but it makes the -strace output much more useful in this area.

If you have tested the patches and found they work well, you can add a:

Tested-by .....

Thanks,
Laurent

Tested-by on the v1 series
#27 lore raw
In reply to Philippe Mathieu-Daudé

Hi,

Quoted 2 lines · Philippe Mathieu-Daudé

Few patches I'v been writting while trying to figure out this issue:
http://lists.nongnu.org/archive/html/qemu-arm/2018-01/msg00514.html

Whole series

Quoted 27 lines

Regards,

Phil.

Philippe Mathieu-Daudé (11):
linux-user/strace: dump AF_NETLINK sockaddr content linux-user/strace: improve sendto() output
linux-user/strace: add print_sockaddr_ptr() to handle plain/pointer addrlen linux-user/strace: improve recvfrom() output
linux-user/strace: improve getsockname() output linux-user/strace: improve recvmsg() output
linux-user/strace: improve bind() output
linux-user/strace: improve gettimeofday() output linux-user/strace: improve capget()/capset() output linux-user/syscall: verify recvfrom(addr) is user-writable linux-user/syscall: simplify recvfrom()

 linux-user/syscall_defs.h |   7 +++
 linux-user/strace.c       | 122 +++++++++++++++++++++++++++++++++++++++++++++-
 linux-user/syscall.c      |  16 +++---
 linux-user/strace.list    |  16 +++---
 4 files changed, 144 insertions(+), 17 deletions(-)
Signature · 1 line
2.15.1