summaryrefslogtreecommitdiffstats
path: root/sys/compat/linux/linux_socket.c
diff options
context:
space:
mode:
authorpirofti <pirofti@openbsd.org>2012-06-26 10:18:08 +0000
committerpirofti <pirofti@openbsd.org>2012-06-26 10:18:08 +0000
commit09d40082a8114991c377f87660af6fbf45047262 (patch)
treed79e1d1d5819f16fb257bb307861aa9954b4a26e /sys/compat/linux/linux_socket.c
parentuse /var/www/tmp/ for the temp directories even if not chrooted (diff)
downloadwireguard-openbsd-09d40082a8114991c377f87660af6fbf45047262.tar.xz
wireguard-openbsd-09d40082a8114991c377f87660af6fbf45047262.zip
Don't ignore SOCK_CLOEXEC and SOCK_NONBLOCK.
CAVEATS: Assumes that a new socket can't have any of the FCNTLFLAGS set on it, which _is_ true, currently... (guenther@) Okay guenther@, deraadt@.
Diffstat (limited to 'sys/compat/linux/linux_socket.c')
-rw-r--r--sys/compat/linux/linux_socket.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index 4f1ab4ea55b..297125da01e 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_socket.c,v 1.45 2012/06/19 11:28:20 pirofti Exp $ */
+/* $OpenBSD: linux_socket.c,v 1.46 2012/06/26 10:18:08 pirofti Exp $ */
/* $NetBSD: linux_socket.c,v 1.14 1996/04/05 00:01:50 christos Exp $ */
/*
@@ -239,17 +239,50 @@ linux_socket(p, v, retval)
} */ *uap = v;
struct linux_socket_args lsa;
struct sys_socket_args bsa;
- int error;
+ struct sys_fcntl_args bfa;
+ struct sys_close_args bca;
+ int error, type_flags, fd;
if ((error = copyin((caddr_t) uap, (caddr_t) &lsa, sizeof lsa)))
return error;
+ type_flags = lsa.type & ~LINUX_SOCKET_TYPE_MASK;
+ if (type_flags & ~(LINUX_SOCK_CLOEXEC | LINUX_SOCK_NONBLOCK))
+ return EINVAL;
+
SCARG(&bsa, protocol) = lsa.protocol;
SCARG(&bsa, type) = lsa.type & LINUX_SOCKET_TYPE_MASK;
SCARG(&bsa, domain) = linux_to_bsd_domain(lsa.domain);
if (SCARG(&bsa, domain) == -1)
return EINVAL;
- return sys_socket(p, &bsa, retval);
+ error = sys_socket(p, &bsa, retval);
+ if (error)
+ return error;
+
+ fd = SCARG(&bfa, fd) = retval[0];
+ if (type_flags & LINUX_SOCK_NONBLOCK) {
+ SCARG(&bfa, cmd) = F_SETFL;
+ SCARG(&bfa, arg) = (void *)O_NONBLOCK;
+ error = sys_fcntl(p, &bfa, retval);
+ if (error)
+ goto err;
+ }
+
+ if (type_flags & LINUX_SOCK_CLOEXEC) {
+ SCARG(&bfa, cmd) = F_SETFD;
+ SCARG(&bfa, arg) = (void *)FD_CLOEXEC;
+ error = sys_fcntl(p, &bfa, retval);
+ if (error)
+ goto err;
+ }
+ retval[0] = fd;
+ return error;
+
+err:
+ SCARG(&bca, fd) = fd;
+ sys_close(p, &bca, retval);
+ retval[0] = -1;
+ return error;
}
int