Module Name:    src
Committed By:   ozaki-r
Date:           Thu Jun 28 06:20:36 UTC 2018

Modified Files:
        src/lib/librumphijack: hijack.c

Log Message:
rumphijack: don't modify a cmsg on just validating it

Pointed out by k-goda@IIJ


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/lib/librumphijack/hijack.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumphijack/hijack.c
diff -u src/lib/librumphijack/hijack.c:1.124 src/lib/librumphijack/hijack.c:1.125
--- src/lib/librumphijack/hijack.c:1.124	Mon Oct 23 06:52:17 2017
+++ src/lib/librumphijack/hijack.c	Thu Jun 28 06:20:36 2018
@@ -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 @@ write(int fd, const void *buf, size_t bl
  */
 
 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 @@ msg_convert(struct msghdr *msg, int (*fu
 				if (newval < 0) {
 					return ENOTSUP;
 				}
-				*fdp = newval;
+				if (!dryrun)
+					*fdp = newval;
 				fdp++;
 			}
 		}
@@ -1615,6 +1616,20 @@ msg_convert(struct msghdr *msg, int (*fu
 	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 @@ recvmsg(int fd, struct msghdr *msg, int 
 	 * 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 @@ sendmsg(int fd, const struct msghdr *msg
 	/*
 	 * 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 @@ sendmsg(int fd, const struct msghdr *msg
 		 *
 		 * 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);

Reply via email to