Skip to contentSkip to conversation

linux-user: netlink fixes

PATCH In review Laurent Vivier 2 participants 8 messages Aug 20, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover linux-user: netlink fixes

This series fixes some netlink errors while we start "gedit".

The first patch has already been sent alone.

v2:
- added Peter's R-b for the first patch
- added a patch to intoduce QEMU_RTA_* enum

Laurent Vivier (4):
linux-user: fix recvmsg()/recvfrom() with netlink and MSG_TRUNC
linux-user: introduce QEMU_RTA_* to use with rtattr_type_t
linux-user: update netlink route types
linux-user: add QEMU_IFLA_INFO_KIND nested type for tun

 linux-user/syscall.c | 129 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 116 insertions(+), 13 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/4 linux-user: fix recvmsg()/recvfrom() with netlink and MSG_TRUNC

If recvmsg()/recvfrom() are used with the MSG_TRUNC flag, they return the real length even if it was longer than the passed buffer.
So when we translate the buffer we must check we don't go beyond the end of the buffer.

---
 linux-user/syscall.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
linux-user/syscall.c +7 -2
index bb42a225eb..a62cd15dc7 100644
@@ -3892,7 +3892,7 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp,
             len = ret;
             if (fd_trans_host_to_target_data(fd)) {
                 ret = fd_trans_host_to_target_data(fd)(msg.msg_iov->iov_base,
-                                                       len);
+                                               MIN(msg.msg_iov->iov_len, len));
             } else {
                 ret = host_to_target_cmsg(msgp, &msg);
             }
@@ -4169,7 +4169,12 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags,
     }
     if (!is_error(ret)) {
         if (fd_trans_host_to_target_data(fd)) {
-            ret = fd_trans_host_to_target_data(fd)(host_msg, ret);
+            abi_long trans;
+            trans = fd_trans_host_to_target_data(fd)(host_msg, MIN(ret, len));
+            if (is_error(trans)) {
+                ret = trans;
+                goto fail;
+            }
         }
         if (target_addr) {
             host_to_target_sockaddr(target_addr, addr, addrlen);
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/4 linux-user: introduce QEMU_RTA_* to use with rtattr_type_t

In reply to Laurent Vivier

Following commit will introduce RTA_PREF that appears only with kernel v4.1. To avoid to manage a specific case for it, this patch introduces the full list of rtattr_type_t prefixed with QEMU_ (as we did for IFLA values)

---
 linux-user/syscall.c | 53 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 11 deletions(-)
linux-user/syscall.c +42 -11
index a62cd15dc7..a2395eb1b6 100644
@@ -539,6 +539,37 @@ enum {
     QEMU___IFLA_XDP_MAX,
 };
 
+enum {
+    QEMU_RTA_UNSPEC,
+    QEMU_RTA_DST,
+    QEMU_RTA_SRC,
+    QEMU_RTA_IIF,
+    QEMU_RTA_OIF,
+    QEMU_RTA_GATEWAY,
+    QEMU_RTA_PRIORITY,
+    QEMU_RTA_PREFSRC,
+    QEMU_RTA_METRICS,
+    QEMU_RTA_MULTIPATH,
+    QEMU_RTA_PROTOINFO, /* no longer used */
+    QEMU_RTA_FLOW,
+    QEMU_RTA_CACHEINFO,
+    QEMU_RTA_SESSION, /* no longer used */
+    QEMU_RTA_MP_ALGO, /* no longer used */
+    QEMU_RTA_TABLE,
+    QEMU_RTA_MARK,
+    QEMU_RTA_MFC_STATS,
+    QEMU_RTA_VIA,
+    QEMU_RTA_NEWDST,
+    QEMU_RTA_PREF,
+    QEMU_RTA_ENCAP_TYPE,
+    QEMU_RTA_ENCAP,
+    QEMU_RTA_EXPIRES,
+    QEMU_RTA_PAD,
+    QEMU_RTA_UID,
+    QEMU_RTA_TTL_PROPAGATE,
+    QEMU___RTA_MAX
+};
+
 typedef abi_long (*TargetFdDataFunc)(void *, size_t);
 typedef abi_long (*TargetFdAddrFunc)(void *, abi_ulong, socklen_t);
 typedef struct TargetFdTrans {
@@ -2661,14 +2692,14 @@ static abi_long host_to_target_data_route_rtattr(struct rtattr *rtattr)
     uint32_t *u32;
     switch (rtattr->rta_type) {
     /* binary: depends on family type */
-    case RTA_GATEWAY:
-    case RTA_DST:
-    case RTA_PREFSRC:
+    case QEMU_RTA_GATEWAY:
+    case QEMU_RTA_DST:
+    case QEMU_RTA_PREFSRC:
         break;
     /* u32 */
-    case RTA_PRIORITY:
-    case RTA_TABLE:
-    case RTA_OIF:
+    case QEMU_RTA_PRIORITY:
+    case QEMU_RTA_TABLE:
+    case QEMU_RTA_OIF:
         u32 = RTA_DATA(rtattr);
         *u32 = tswap32(*u32);
         break;
@@ -2808,13 +2839,13 @@ static abi_long target_to_host_data_route_rtattr(struct rtattr *rtattr)
     uint32_t *u32;
     switch (rtattr->rta_type) {
     /* binary: depends on family type */
-    case RTA_DST:
-    case RTA_SRC:
-    case RTA_GATEWAY:
+    case QEMU_RTA_DST:
+    case QEMU_RTA_SRC:
+    case QEMU_RTA_GATEWAY:
         break;
     /* u32 */
-    case RTA_PRIORITY:
-    case RTA_OIF:
+    case QEMU_RTA_PRIORITY:
+    case QEMU_RTA_OIF:
         u32 = RTA_DATA(rtattr);
         *u32 = tswap32(*u32);
         break;
Signature · 1 line
2.17.1
Reviewed-by on v2 2/4
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] linux-user: introduce QEMU_RTA_* to use with rtattr_type_t

Quoted 36 lines · Laurent Vivier

Following commit will introduce RTA_PREF that appears only with kernel v4.1. To avoid to manage a specific case for it, this patch introduces the full list of rtattr_type_t prefixed with QEMU_ (as we did for IFLA values)

---
 linux-user/syscall.c | 53 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 11 deletions(-)
linux-user/syscall.c +18 -0
index a62cd15dc7..a2395eb1b6 100644
@@ -539,6 +539,37 @@ enum {
     QEMU___IFLA_XDP_MAX,
 };
 
+enum {
+    QEMU_RTA_UNSPEC,
+    QEMU_RTA_DST,
+    QEMU_RTA_SRC,
+    QEMU_RTA_IIF,
+    QEMU_RTA_OIF,
+    QEMU_RTA_GATEWAY,
+    QEMU_RTA_PRIORITY,
+    QEMU_RTA_PREFSRC,
+    QEMU_RTA_METRICS,
+    QEMU_RTA_MULTIPATH,
+    QEMU_RTA_PROTOINFO, /* no longer used */
+    QEMU_RTA_FLOW,
+    QEMU_RTA_CACHEINFO,
+    QEMU_RTA_SESSION, /* no longer used */
+    QEMU_RTA_MP_ALGO, /* no longer used */
+    QEMU_RTA_TABLE,
+    QEMU_RTA_MARK,

linux-user/syscall.c enum { · line 569

Quoted 10 lines
linux-user/syscall.c +10 -0
+    QEMU_RTA_MFC_STATS,
+    QEMU_RTA_VIA,
+    QEMU_RTA_NEWDST,
+    QEMU_RTA_PREF,
+    QEMU_RTA_ENCAP_TYPE,
+    QEMU_RTA_ENCAP,
+    QEMU_RTA_EXPIRES,
+    QEMU_RTA_PAD,
+    QEMU_RTA_UID,
+    QEMU_RTA_TTL_PROPAGATE,

Upstream 4.18 kernel has also
RTA_IP_PROTO,
RTA_SPORT,
RTA_DPORT,

linux-user/syscall.c enum { · line 571

Quoted 2 lines
linux-user/syscall.c +2 -0
+    QEMU___RTA_MAX
+};

with or without those 3 extras, as you prefer.

thanks
-- PMM

#4 lore raw

PATCH v2 3/4 linux-user: update netlink route types

In reply to Laurent Vivier

Add RTA_PREF and RTA_CACHEINFO.

Fix following errors when we start gedit:

Unknown host RTA type: 12
Unknown host RTA type: 20

---
 linux-user/syscall.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
linux-user/syscall.c +19 -0
index a2395eb1b6..197010945f 100644
@@ -2690,12 +2690,17 @@ static abi_long host_to_target_data_addr_rtattr(struct rtattr *rtattr)
 static abi_long host_to_target_data_route_rtattr(struct rtattr *rtattr)
 {
     uint32_t *u32;
+    struct rta_cacheinfo *ci;
+
     switch (rtattr->rta_type) {
     /* binary: depends on family type */
     case QEMU_RTA_GATEWAY:
     case QEMU_RTA_DST:
     case QEMU_RTA_PREFSRC:
         break;
+    /* u8 */
+    case QEMU_RTA_PREF:
+        break;
     /* u32 */
     case QEMU_RTA_PRIORITY:
     case QEMU_RTA_TABLE:
@@ -2703,6 +2708,20 @@ static abi_long host_to_target_data_route_rtattr(struct rtattr *rtattr)
         u32 = RTA_DATA(rtattr);
         *u32 = tswap32(*u32);
         break;
+    /* struct rta_cacheinfo */
+    case QEMU_RTA_CACHEINFO:
+        ci = RTA_DATA(rtattr);
+        ci->rta_clntref = tswap32(ci->rta_clntref);
+        ci->rta_lastuse = tswap32(ci->rta_lastuse);
+        ci->rta_expires = tswap32(ci->rta_expires);
+        ci->rta_error = tswap32(ci->rta_error);
+        ci->rta_used = tswap32(ci->rta_used);
+#if defined(RTNETLINK_HAVE_PEERINFO)
+        ci->rta_id = tswap32(ci->rta_id);
+        ci->rta_ts = tswap32(ci->rta_ts);
+        ci->rta_tsage = tswap32(ci->rta_tsage);
+#endif
+        break;
     default:
         gemu_log("Unknown host RTA type: %d\n", rtattr->rta_type);
         break;
Signature · 1 line
2.17.1
Reviewed-by on v2 3/4
#5 lore raw

Re: [Qemu-devel] [PATCH v2 3/4] linux-user: update netlink route types

Quoted 4 lines · Laurent Vivier

Add RTA_PREF and RTA_CACHEINFO.

Fix following errors when we start gedit:

Quoted 8 lines

Unknown host RTA type: 12
Unknown host RTA type: 20

---
 linux-user/syscall.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

thanks
-- PMM

#6 lore raw

PATCH v2 4/4 linux-user: add QEMU_IFLA_INFO_KIND nested type for tun

In reply to Laurent Vivier
---
 linux-user/syscall.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
linux-user/syscall.c +48 -0
index 197010945f..f1e5d1bd79 100644
@@ -501,6 +501,20 @@ enum {
     QEMU___IFLA_BRPORT_MAX
 };
 
+enum {
+    QEMU_IFLA_TUN_UNSPEC,
+    QEMU_IFLA_TUN_OWNER,
+    QEMU_IFLA_TUN_GROUP,
+    QEMU_IFLA_TUN_TYPE,
+    QEMU_IFLA_TUN_PI,
+    QEMU_IFLA_TUN_VNET_HDR,
+    QEMU_IFLA_TUN_PERSIST,
+    QEMU_IFLA_TUN_MULTI_QUEUE,
+    QEMU_IFLA_TUN_NUM_QUEUES,
+    QEMU_IFLA_TUN_NUM_DISABLED_QUEUES,
+    QEMU___IFLA_TUN_MAX,
+};
+
 enum {
     QEMU_IFLA_INFO_UNSPEC,
     QEMU_IFLA_INFO_KIND,
@@ -2346,6 +2360,34 @@ static abi_long host_to_target_slave_data_bridge_nlattr(struct nlattr *nlattr,
     return 0;
 }
 
+static abi_long host_to_target_data_tun_nlattr(struct nlattr *nlattr,
+                                                  void *context)
+{
+    uint32_t *u32;
+
+    switch (nlattr->nla_type) {
+    /* uint8_t */
+    case QEMU_IFLA_TUN_TYPE:
+    case QEMU_IFLA_TUN_PI:
+    case QEMU_IFLA_TUN_VNET_HDR:
+    case QEMU_IFLA_TUN_PERSIST:
+    case QEMU_IFLA_TUN_MULTI_QUEUE:
+        break;
+    /* uint32_t */
+    case QEMU_IFLA_TUN_NUM_QUEUES:
+    case QEMU_IFLA_TUN_NUM_DISABLED_QUEUES:
+    case QEMU_IFLA_TUN_OWNER:
+    case QEMU_IFLA_TUN_GROUP:
+        u32 = NLA_DATA(nlattr);
+        *u32 = tswap32(*u32);
+        break;
+    default:
+        gemu_log("Unknown QEMU_IFLA_TUN type %d\n", nlattr->nla_type);
+        break;
+    }
+    return 0;
+}
+
 struct linkinfo_context {
     int len;
     char *name;
@@ -2380,6 +2422,12 @@ static abi_long host_to_target_data_linkinfo_nlattr(struct nlattr *nlattr,
                                                   nlattr->nla_len,
                                                   NULL,
                                              host_to_target_data_bridge_nlattr);
+        } else if (strncmp(li_context->name, "tun",
+                    li_context->len) == 0) {
+            return host_to_target_for_each_nlattr(NLA_DATA(nlattr),
+                                                  nlattr->nla_len,
+                                                  NULL,
+                                                host_to_target_data_tun_nlattr);
         } else {
             gemu_log("Unknown QEMU_IFLA_INFO_KIND %s\n", li_context->name);
         }
Signature · 1 line
2.17.1