Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/librumphijack rumphijack: don't modify a cmsg on just va...
details: https://anonhg.NetBSD.org/src/rev/2b012bf9b4ae
branches: trunk
changeset: 991122:2b012bf9b4ae
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Thu Jun 28 06:20:36 2018 +0000
description:
rumphijack: don't modify a cmsg on just validating it
Pointed out by k-goda@IIJ
diffstat:
lib/librumphijack/hijack.c | 31 +++++++++++++++++++++++--------
1 files changed, 23 insertions(+), 8 deletions(-)
diffs (88 lines):
diff -r 085492d9aa9a -r 2b012bf9b4ae lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c Thu Jun 28 06:02:24 2018 +0000
+++ b/lib/librumphijack/hijack.c Thu Jun 28 06:20:36 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hijack.c,v 1.124 2017/10/23 06:52:17 ozaki-r Exp $ */
+/* $NetBSD: hijack.c,v 1.125 2018/06/28 06:20:36 ozaki-r Exp $ */
/*-
* Copyright (c) 2011 Antti Kantee. All Rights Reserved.
@@ -34,7 +34,7 @@
#include <rump/rumpuser_port.h>
#if !defined(lint)
-__RCSID("$NetBSD: hijack.c,v 1.124 2017/10/23 06:52:17 ozaki-r Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.125 2018/06/28 06:20:36 ozaki-r Exp $");
#endif
#include <sys/param.h>
@@ -1587,7 +1587,7 @@
*/
static int
-msg_convert(struct msghdr *msg, int (*func)(int))
+_msg_convert_fds(struct msghdr *msg, int (*func)(int), bool dryrun)
{
struct cmsghdr *cmsg;
@@ -1607,7 +1607,8 @@
if (newval < 0) {
return ENOTSUP;
}
- *fdp = newval;
+ if (!dryrun)
+ *fdp = newval;
fdp++;
}
}
@@ -1615,6 +1616,20 @@
return 0;
}
+static int
+msg_convert_fds(struct msghdr *msg, int (*func)(int))
+{
+
+ return _msg_convert_fds(msg, func, false);
+}
+
+static int
+msg_check_fds(struct msghdr *msg, int (*func)(int))
+{
+
+ return _msg_convert_fds(msg, func, true);
+}
+
ssize_t
recvmsg(int fd, struct msghdr *msg, int flags)
{
@@ -1636,9 +1651,9 @@
* convert descriptors in the message.
*/
if (isrump) {
- msg_convert(msg, fd_rump2host);
+ msg_convert_fds(msg, fd_rump2host);
} else {
- msg_convert(msg, fd_host2host);
+ msg_convert_fds(msg, fd_host2host);
}
return ret;
}
@@ -1681,7 +1696,7 @@
/*
* reject descriptors from a different kernel.
*/
- error = msg_convert(__UNCONST(msg),
+ error = msg_check_fds(__UNCONST(msg),
isrump ? fd_check_rump: fd_check_host);
if (error != 0) {
errno = error;
@@ -1700,7 +1715,7 @@
*
* it's safer to copy and modify instead.
*/
- msg_convert(__UNCONST(msg), fd_host2rump);
+ msg_convert_fds(__UNCONST(msg), fd_host2rump);
op_sendmsg = GETSYSCALL(rump, SENDMSG);
} else {
op_sendmsg = GETSYSCALL(host, SENDMSG);
Home |
Main Index |
Thread Index |
Old Index