* [Qemu-devel] [PATCH v2 1/4] linux-user: fix recvmsg()/recvfrom() with netlink and MSG_TRUNC
2018-08-20 17:15 [Qemu-devel] [PATCH v2 0/4] linux-user: netlink fixes Laurent Vivier
@ 2018-08-20 17:15 ` Laurent Vivier
2018-08-20 17:15 ` [Qemu-devel] [PATCH v2 2/4] linux-user: introduce QEMU_RTA_* to use with rtattr_type_t Laurent Vivier
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2018-08-20 17:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier, Peter Maydell
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.
Bug: https://github.com/vivier/qemu-m68k/issues/33
Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
linux-user/syscall.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bb42a225eb..a62cd15dc7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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);
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v2 2/4] linux-user: introduce QEMU_RTA_* to use with rtattr_type_t
2018-08-20 17:15 [Qemu-devel] [PATCH v2 0/4] linux-user: netlink fixes Laurent Vivier
2018-08-20 17:15 ` [Qemu-devel] [PATCH v2 1/4] linux-user: fix recvmsg()/recvfrom() with netlink and MSG_TRUNC Laurent Vivier
@ 2018-08-20 17:15 ` Laurent Vivier
2018-08-20 17:31 ` Peter Maydell
2018-08-20 17:15 ` [Qemu-devel] [PATCH v2 3/4] linux-user: update netlink route types Laurent Vivier
2018-08-20 17:15 ` [Qemu-devel] [PATCH v2 4/4] linux-user: add QEMU_IFLA_INFO_KIND nested type for tun Laurent Vivier
3 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2018-08-20 17:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier, Peter Maydell
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)
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 53 +++++++++++++++++++++++++++++++++++---------
1 file changed, 42 insertions(+), 11 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a62cd15dc7..a2395eb1b6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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;
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v2 2/4] linux-user: introduce QEMU_RTA_* to use with rtattr_type_t
2018-08-20 17:15 ` [Qemu-devel] [PATCH v2 2/4] linux-user: introduce QEMU_RTA_* to use with rtattr_type_t Laurent Vivier
@ 2018-08-20 17:31 ` Peter Maydell
0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2018-08-20 17:31 UTC (permalink / raw)
To: Laurent Vivier; +Cc: QEMU Developers, Riku Voipio
On 20 August 2018 at 18:15, Laurent Vivier <laurent@vivier.eu> wrote:
> 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)
>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
> linux-user/syscall.c | 53 +++++++++++++++++++++++++++++++++++---------
> 1 file changed, 42 insertions(+), 11 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index a62cd15dc7..a2395eb1b6 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -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,
Upstream 4.18 kernel has also
RTA_IP_PROTO,
RTA_SPORT,
RTA_DPORT,
> + QEMU___RTA_MAX
> +};
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
with or without those 3 extras, as you prefer.
thanks
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v2 3/4] linux-user: update netlink route types
2018-08-20 17:15 [Qemu-devel] [PATCH v2 0/4] linux-user: netlink fixes Laurent Vivier
2018-08-20 17:15 ` [Qemu-devel] [PATCH v2 1/4] linux-user: fix recvmsg()/recvfrom() with netlink and MSG_TRUNC Laurent Vivier
2018-08-20 17:15 ` [Qemu-devel] [PATCH v2 2/4] linux-user: introduce QEMU_RTA_* to use with rtattr_type_t Laurent Vivier
@ 2018-08-20 17:15 ` Laurent Vivier
2018-08-20 17:33 ` Peter Maydell
2018-08-20 17:15 ` [Qemu-devel] [PATCH v2 4/4] linux-user: add QEMU_IFLA_INFO_KIND nested type for tun Laurent Vivier
3 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2018-08-20 17:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier, Peter Maydell
Add RTA_PREF and RTA_CACHEINFO.
Fix following errors when we start gedit:
Unknown host RTA type: 12
Unknown host RTA type: 20
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a2395eb1b6..197010945f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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;
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v2 4/4] linux-user: add QEMU_IFLA_INFO_KIND nested type for tun
2018-08-20 17:15 [Qemu-devel] [PATCH v2 0/4] linux-user: netlink fixes Laurent Vivier
` (2 preceding siblings ...)
2018-08-20 17:15 ` [Qemu-devel] [PATCH v2 3/4] linux-user: update netlink route types Laurent Vivier
@ 2018-08-20 17:15 ` Laurent Vivier
2018-08-20 17:34 ` Peter Maydell
3 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2018-08-20 17:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier, Peter Maydell
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 197010945f..f1e5d1bd79 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread