CVS commit: src/lib/librumphijack
Module Name:src Committed By: christos Date: Wed May 27 18:55:36 UTC 2020 Modified Files: src/lib/librumphijack: hijack.c Log Message: Add pathconf and lpathconf (fixes lib/librumphijack/nfs test which uses ls which now uses lpathconf) To generate a diff of this commit: cvs rdiff -u -r1.130 -r1.131 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.130 src/lib/librumphijack/hijack.c:1.131 --- src/lib/librumphijack/hijack.c:1.130 Mon Feb 10 18:21:42 2020 +++ src/lib/librumphijack/hijack.c Wed May 27 14:55:36 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.130 2020/02/10 23:21:42 kamil Exp $ */ +/* $NetBSD: hijack.c,v 1.131 2020/05/27 18:55:36 christos Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.130 2020/02/10 23:21:42 kamil Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.131 2020/05/27 18:55:36 christos Exp $"); #endif #include @@ -170,6 +170,9 @@ enum dualcall { #ifdef __NetBSD__ DUALCALL_LINKAT, #endif + DUALCALL_PATHCONF, + DUALCALL_LPATHCONF, + DUALCALL__NUM }; @@ -405,6 +408,8 @@ struct sysnames { #ifdef __NetBSD__ { DUALCALL_LINKAT, "linkat", RSYS_NAME(LINKAT) }, #endif + { DUALCALL_PATHCONF, "pathconf", RSYS_NAME(PATHCONF) }, + { DUALCALL_LPATHCONF, "lpathconf", RSYS_NAME(LPATHCONF) }, }; #undef S @@ -1335,6 +1340,39 @@ linkat(int fromfd, const char *from, int } #endif +static long +do_pathconf(const char *path, int name, int link) +{ + long (*op_pathconf)(const char *, int); + enum pathtype pt; + + if ((pt = path_isrump(path)) != PATH_HOST) { + op_pathconf = link ? + GETSYSCALL(rump, LPATHCONF) : + GETSYSCALL(rump, PATHCONF); + if (pt == PATH_RUMP) + path = path_host2rump(path); + } else { + op_pathconf = link ? + GETSYSCALL(host, LPATHCONF) : + GETSYSCALL(host, PATHCONF); + } + + return op_pathconf(path, name); +} + +long +lpathconf(const char *path, int name) +{ + return do_pathconf(path, name, 1); +} + +long +pathconf(const char *path, int name) +{ + return do_pathconf(path, name, 0); +} + int link(const char *from, const char *to) {
CVS commit: src/lib/librumphijack
Module Name:src Committed By: kamil Date: Mon Feb 10 23:21:42 UTC 2020 Modified Files: src/lib/librumphijack: hijack.c Log Message: Change types of DUP2ALIAS and DUP2FDMASK bit masks to unsigned This is for consistency with the DUP2BIT change. To generate a diff of this commit: cvs rdiff -u -r1.129 -r1.130 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.129 src/lib/librumphijack/hijack.c:1.130 --- src/lib/librumphijack/hijack.c:1.129 Mon Feb 10 09:10:58 2020 +++ src/lib/librumphijack/hijack.c Mon Feb 10 23:21:42 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.129 2020/02/10 09:10:58 kamil Exp $ */ +/* $NetBSD: hijack.c,v 1.130 2020/02/10 23:21:42 kamil Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.129 2020/02/10 09:10:58 kamil Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.130 2020/02/10 23:21:42 kamil Exp $"); #endif #include @@ -441,8 +441,8 @@ static int hijack_fdoff = FD_SETSIZE/2; #define DUP2HIGH 2 static uint32_t dup2vec[DUP2HIGH+1]; #define DUP2BIT (1U<<31) -#define DUP2ALIAS (1<<30) -#define DUP2FDMASK ((1<<30)-1) +#define DUP2ALIAS (1U<<30) +#define DUP2FDMASK ((1U<<30)-1) static bool isdup2d(int fd)
CVS commit: src/lib/librumphijack
Module Name:src Committed By: kamil Date: Mon Feb 10 09:10:58 UTC 2020 Modified Files: src/lib/librumphijack: hijack.c Log Message: Avoid unportable bit shift semantics hijack.c:451:52, left shift of 1 by 31 places cannot be represented in type 'int To generate a diff of this commit: cvs rdiff -u -r1.128 -r1.129 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.128 src/lib/librumphijack/hijack.c:1.129 --- src/lib/librumphijack/hijack.c:1.128 Wed Sep 25 20:19:59 2019 +++ src/lib/librumphijack/hijack.c Mon Feb 10 09:10:58 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.128 2019/09/25 20:19:59 christos Exp $ */ +/* $NetBSD: hijack.c,v 1.129 2020/02/10 09:10:58 kamil Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.128 2019/09/25 20:19:59 christos Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.129 2020/02/10 09:10:58 kamil Exp $"); #endif #include @@ -440,7 +440,7 @@ static int hijack_fdoff = FD_SETSIZE/2; /* note: you cannot change this without editing the env-passing code */ #define DUP2HIGH 2 static uint32_t dup2vec[DUP2HIGH+1]; -#define DUP2BIT (1<<31) +#define DUP2BIT (1U<<31) #define DUP2ALIAS (1<<30) #define DUP2FDMASK ((1<<30)-1)
CVS commit: src/lib/librumphijack
Module Name:src Committed By: bad Date: Sun Feb 17 23:35:50 UTC 2019 Modified Files: src/lib/librumphijack: hijack.c Log Message: Linux doesn't have paccept(). To generate a diff of this commit: cvs rdiff -u -r1.126 -r1.127 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.126 src/lib/librumphijack/hijack.c:1.127 --- src/lib/librumphijack/hijack.c:1.126 Sun Dec 16 14:03:37 2018 +++ src/lib/librumphijack/hijack.c Sun Feb 17 23:35:50 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.126 2018/12/16 14:03:37 hannken Exp $ */ +/* $NetBSD: hijack.c,v 1.127 2019/02/17 23:35:50 bad Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.126 2018/12/16 14:03:37 hannken Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.127 2019/02/17 23:35:50 bad Exp $"); #endif #include @@ -89,7 +89,10 @@ __RCSID("$NetBSD: hijack.c,v 1.126 2018/ enum dualcall { DUALCALL_WRITE, DUALCALL_WRITEV, DUALCALL_PWRITE, DUALCALL_PWRITEV, DUALCALL_IOCTL, DUALCALL_FCNTL, - DUALCALL_SOCKET, DUALCALL_ACCEPT, DUALCALL_PACCEPT, + DUALCALL_SOCKET, DUALCALL_ACCEPT, +#ifndef __linux__ + DUALCALL_PACCEPT, +#endif DUALCALL_BIND, DUALCALL_CONNECT, DUALCALL_GETPEERNAME, DUALCALL_GETSOCKNAME, DUALCALL_LISTEN, DUALCALL_RECVFROM, DUALCALL_RECVMSG, @@ -272,7 +275,9 @@ struct sysnames { } syscnames[] = { { DUALCALL_SOCKET, S(REALSOCKET), RSYS_NAME(SOCKET) }, { DUALCALL_ACCEPT, "accept", RSYS_NAME(ACCEPT) }, +#ifndef __linux__ { DUALCALL_PACCEPT, "paccept", RSYS_NAME(PACCEPT) }, +#endif { DUALCALL_BIND, "bind", RSYS_NAME(BIND) }, { DUALCALL_CONNECT, "connect", RSYS_NAME(CONNECT) }, { DUALCALL_GETPEERNAME, "getpeername", RSYS_NAME(GETPEERNAME) }, @@ -1382,6 +1387,7 @@ accept(int s, struct sockaddr *addr, soc return fd; } +#ifndef __linux__ int paccept(int s, struct sockaddr *addr, socklen_t *addrlen, const sigset_t * restrict sigmask, int flags) @@ -1410,6 +1416,7 @@ paccept(int s, struct sockaddr *addr, so return fd; } +#endif /* * ioctl() and fcntl() are varargs calls and need special treatment.
CVS commit: src/lib/librumphijack
Module Name:src Committed By: bad Date: Sun Feb 17 23:33:20 UTC 2019 Modified Files: src/lib/librumphijack: Makefile Log Message: compile hijack.c with -D_INCOMPLETE_XOPEN_C063 so that AT_FDCWD is alwasy defined for rumpkernels. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/librumphijack/Makefile 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/Makefile diff -u src/lib/librumphijack/Makefile:1.20 src/lib/librumphijack/Makefile:1.21 --- src/lib/librumphijack/Makefile:1.20 Thu May 11 04:33:14 2017 +++ src/lib/librumphijack/Makefile Sun Feb 17 23:33:20 2019 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.20 2017/05/11 04:33:14 sevan Exp $ +# $NetBSD: Makefile,v 1.21 2019/02/17 23:33:20 bad Exp $ # LIB= rumphijack @@ -11,6 +11,7 @@ MAN= rumphijack.3 SRCS= hijack.c hijackdlsym.c CPPFLAGS+= -D_DIAGNOSTIC -D_REENTRANT +CPPFLAGS.hijack.c+= -D_INCOMPLETE_XOPEN_C063 WARNS?= 5
CVS commit: src/lib/librumphijack
Module Name:src Committed By: hannken Date: Sun Dec 16 14:03:37 UTC 2018 Modified Files: src/lib/librumphijack: hijack.c rumphijack.3 Log Message: Add an option "modctl" to capture modctl(). To generate a diff of this commit: cvs rdiff -u -r1.125 -r1.126 src/lib/librumphijack/hijack.c cvs rdiff -u -r1.12 -r1.13 src/lib/librumphijack/rumphijack.3 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.125 src/lib/librumphijack/hijack.c:1.126 --- src/lib/librumphijack/hijack.c:1.125 Thu Jun 28 06:20:36 2018 +++ src/lib/librumphijack/hijack.c Sun Dec 16 14:03:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.125 2018/06/28 06:20:36 ozaki-r Exp $ */ +/* $NetBSD: hijack.c,v 1.126 2018/12/16 14:03:37 hannken Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.125 2018/06/28 06:20:36 ozaki-r Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.126 2018/12/16 14:03:37 hannken Exp $"); #endif #include @@ -138,6 +138,7 @@ enum dualcall { #ifdef __NetBSD__ DUALCALL___SYSCTL, + DUALCALL_MODCTL, #endif #ifdef __NetBSD__ @@ -351,6 +352,7 @@ struct sysnames { #ifdef __NetBSD__ { DUALCALL___SYSCTL, "__sysctl", RSYS_NAME(__SYSCTL) }, + { DUALCALL_MODCTL, "modctl", RSYS_NAME(MODCTL) }, #endif #ifdef __NetBSD__ @@ -814,6 +816,30 @@ sysctlparser(char *buf) errx(1, "sysctl value should be y(es)/n(o), gave: %s", buf); } +static bool rumpmodctl = false; + +static void +modctlparser(char *buf) +{ + + if (buf == NULL) { + rumpmodctl = true; + return; + } + + if (strcasecmp(buf, "y") == 0 || strcasecmp(buf, "yes") == 0 || + strcasecmp(buf, "yep") == 0 || strcasecmp(buf, "tottakai") == 0) { + rumpmodctl = true; + return; + } + if (strcasecmp(buf, "n") == 0 || strcasecmp(buf, "no") == 0) { + rumpmodctl = false; + return; + } + + errx(1, "modctl value should be y(es)/n(o), gave: %s", buf); +} + static void fdoffparser(char *buf) { @@ -841,6 +867,7 @@ static struct { { blanketparser, "blanket", true }, { vfsparser, "vfs", true }, { sysctlparser, "sysctl", false }, + { modctlparser, "modctl", false }, { fdoffparser, "fdoff", true }, { NULL, NULL, false }, }; @@ -2334,6 +2361,20 @@ __sysctl(const int *name, unsigned int n return op___sysctl(name, namelen, old, oldlenp, new, newlen); } +int modctl(int, void *); +int +modctl(int operation, void *argp) +{ + int (*op_modctl)(int operation, void *argp); + + if (rumpmodctl) { + op_modctl = GETSYSCALL(rump, MODCTL); + } else { + op_modctl = GETSYSCALL(host, MODCTL); + } + + return op_modctl(operation, argp); +} #endif /* Index: src/lib/librumphijack/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.12 src/lib/librumphijack/rumphijack.3:1.13 --- src/lib/librumphijack/rumphijack.3:1.12 Mon Mar 14 15:21:22 2011 +++ src/lib/librumphijack/rumphijack.3 Sun Dec 16 14:03:37 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.12 2011/03/14 15:21:22 pooka Exp $ +.\" $NetBSD: rumphijack.3,v 1.13 2018/12/16 14:03:37 hannken Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 14, 2011 +.Dd December 16, 2018 .Dt RUMPHIJACK 3 .Os .Sh NAME @@ -173,6 +173,15 @@ Acceptable values are and .Dq no , meaning to call the rump or the host kernel, respectively. +.It Dq modctl +Direct the +.Fn modctl +call to the rump kernel. +Acceptable values are +.Dq yes +and +.Dq no , +meaning to call the rump or the host kernel, respectively. .It Dq fdoff Adjust the library's fd offset to the specified value. All rump kernel descriptors have the offset added to them
CVS commit: src/lib/librumphijack
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 #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 @@ -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);
CVS commit: src/lib/librumphijack
Module Name:src Committed By: ozaki-r Date: Mon Oct 23 06:52:17 UTC 2017 Modified Files: src/lib/librumphijack: hijack.c Log Message: Provide better debug messages for ioctl To generate a diff of this commit: cvs rdiff -u -r1.123 -r1.124 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.123 src/lib/librumphijack/hijack.c:1.124 --- src/lib/librumphijack/hijack.c:1.123 Tue Jun 6 19:48:42 2017 +++ src/lib/librumphijack/hijack.c Mon Oct 23 06:52:17 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.123 2017/06/06 19:48:42 christos Exp $ */ +/* $NetBSD: hijack.c,v 1.124 2017/10/23 06:52:17 ozaki-r Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.123 2017/06/06 19:48:42 christos Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.124 2017/10/23 06:52:17 ozaki-r Exp $"); #endif #include @@ -1406,7 +1406,7 @@ ioctl(int fd, unsigned long cmd, ...) va_list ap; int rv; - DPRINTF(("ioctl -> %d\n", fd)); + DPRINTF(("ioctl -> %d (%s)\n", fd, whichfd(fd))); if (fd_isrump(fd)) { fd = fd_host2rump(fd); op_ioctl = GETSYSCALL(rump, IOCTL); @@ -1417,6 +1417,7 @@ ioctl(int fd, unsigned long cmd, ...) va_start(ap, cmd); rv = op_ioctl(fd, cmd, va_arg(ap, void *)); va_end(ap); + DPRINTF(("ioctl <- %d\n", rv)); return rv; }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: christos Date: Tue Jun 6 19:48:42 UTC 2017 Modified Files: src/lib/librumphijack: hijack.c Log Message: since ln(1) now uses linkat(2) provide a dumb wrapper. To generate a diff of this commit: cvs rdiff -u -r1.122 -r1.123 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.122 src/lib/librumphijack/hijack.c:1.123 --- src/lib/librumphijack/hijack.c:1.122 Thu Feb 16 03:08:01 2017 +++ src/lib/librumphijack/hijack.c Tue Jun 6 15:48:42 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.122 2017/02/16 08:08:01 ozaki-r Exp $ */ +/* $NetBSD: hijack.c,v 1.123 2017/06/06 19:48:42 christos Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.122 2017/02/16 08:08:01 ozaki-r Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.123 2017/06/06 19:48:42 christos Exp $"); #endif #include @@ -163,6 +163,9 @@ enum dualcall { #ifdef HAVE___QUOTACTL DUALCALL_QUOTACTL, #endif +#ifdef __NetBSD__ + DUALCALL_LINKAT, +#endif DUALCALL__NUM }; @@ -379,6 +382,9 @@ struct sysnames { { DUALCALL_QUOTACTL, "__quotactl", RSYS_NAME(__QUOTACTL) }, #endif /* HAVE___QUOTACTL */ +#ifdef __NetBSD__ + { DUALCALL_LINKAT, "linkat", RSYS_NAME(LINKAT) }, +#endif }; #undef S @@ -1271,6 +1277,19 @@ moveish(const char *from, const char *to return op(from, to); } +#ifdef __NetBSD__ +int +linkat(int fromfd, const char *from, int tofd, const char *to, int flags) +{ + if (fromfd != AT_FDCWD || tofd != AT_FDCWD + || flags != AT_SYMLINK_FOLLOW) + return ENOSYS; + + return moveish(from, to, + GETSYSCALL(rump, LINK), GETSYSCALL(host, LINK)); +} +#endif + int link(const char *from, const char *to) {
CVS commit: src/lib/librumphijack
Module Name:src Committed By: ozaki-r Date: Thu Feb 16 08:08:01 UTC 2017 Modified Files: src/lib/librumphijack: hijack.c Log Message: Support paccept for nc To generate a diff of this commit: cvs rdiff -u -r1.121 -r1.122 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.121 src/lib/librumphijack/hijack.c:1.122 --- src/lib/librumphijack/hijack.c:1.121 Fri Dec 2 20:53:36 2016 +++ src/lib/librumphijack/hijack.c Thu Feb 16 08:08:01 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.121 2016/12/02 20:53:36 christos Exp $ */ +/* $NetBSD: hijack.c,v 1.122 2017/02/16 08:08:01 ozaki-r Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.121 2016/12/02 20:53:36 christos Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.122 2017/02/16 08:08:01 ozaki-r Exp $"); #endif #include @@ -89,7 +89,8 @@ __RCSID("$NetBSD: hijack.c,v 1.121 2016/ enum dualcall { DUALCALL_WRITE, DUALCALL_WRITEV, DUALCALL_PWRITE, DUALCALL_PWRITEV, DUALCALL_IOCTL, DUALCALL_FCNTL, - DUALCALL_SOCKET, DUALCALL_ACCEPT, DUALCALL_BIND, DUALCALL_CONNECT, + DUALCALL_SOCKET, DUALCALL_ACCEPT, DUALCALL_PACCEPT, + DUALCALL_BIND, DUALCALL_CONNECT, DUALCALL_GETPEERNAME, DUALCALL_GETSOCKNAME, DUALCALL_LISTEN, DUALCALL_RECVFROM, DUALCALL_RECVMSG, DUALCALL_SENDTO, DUALCALL_SENDMSG, @@ -267,6 +268,7 @@ struct sysnames { } syscnames[] = { { DUALCALL_SOCKET, S(REALSOCKET), RSYS_NAME(SOCKET) }, { DUALCALL_ACCEPT, "accept", RSYS_NAME(ACCEPT) }, + { DUALCALL_PACCEPT, "paccept", RSYS_NAME(PACCEPT) }, { DUALCALL_BIND, "bind", RSYS_NAME(BIND) }, { DUALCALL_CONNECT, "connect", RSYS_NAME(CONNECT) }, { DUALCALL_GETPEERNAME, "getpeername", RSYS_NAME(GETPEERNAME) }, @@ -1334,6 +1336,35 @@ accept(int s, struct sockaddr *addr, soc return fd; } +int +paccept(int s, struct sockaddr *addr, socklen_t *addrlen, +const sigset_t * restrict sigmask, int flags) +{ + int (*op_paccept)(int, struct sockaddr *, socklen_t *, + const sigset_t * restrict, int); + int fd; + bool isrump; + + isrump = fd_isrump(s); + + DPRINTF(("paccept -> %d", s)); + if (isrump) { + op_paccept = GETSYSCALL(rump, PACCEPT); + s = fd_host2rump(s); + } else { + op_paccept = GETSYSCALL(host, PACCEPT); + } + fd = op_paccept(s, addr, addrlen, sigmask, flags); + if (fd != -1 && isrump) + fd = fd_rump2host(fd); + else + fd = fd_host2host(fd); + + DPRINTF((" <- %d\n", fd)); + + return fd; +} + /* * ioctl() and fcntl() are varargs calls and need special treatment. */
CVS commit: src/lib/librumphijack
Module Name:src Committed By: christos Date: Fri Dec 2 20:53:37 UTC 2016 Modified Files: src/lib/librumphijack: hijack.c Log Message: fix test lib/librumphijack/t_sh/runscript (handle F_DUPFD_CLOEXEC that the shell is now using) To generate a diff of this commit: cvs rdiff -u -r1.120 -r1.121 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.120 src/lib/librumphijack/hijack.c:1.121 --- src/lib/librumphijack/hijack.c:1.120 Thu Aug 11 05:48:57 2016 +++ src/lib/librumphijack/hijack.c Fri Dec 2 15:53:36 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.120 2016/08/11 09:48:57 kre Exp $ */ +/* $NetBSD: hijack.c,v 1.121 2016/12/02 20:53:36 christos Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.120 2016/08/11 09:48:57 kre Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.121 2016/12/02 20:53:36 christos Exp $"); #endif #include @@ -987,7 +987,6 @@ fd_rump2host_withdup(int fd) static int fd_host2rump(int fd) { - if (!isdup2d(fd)) return fd - hijack_fdoff; else @@ -1381,6 +1380,7 @@ fcntl(int fd, int cmd, ...) DPRINTF(("fcntl -> %d (cmd %d)\n", fd, cmd)); switch (cmd) { + case F_DUPFD_CLOEXEC: /* Ignore CLOEXEC bit for now */ case F_DUPFD: va_start(ap, cmd); minfd = va_arg(ap, int);
CVS commit: src/lib/librumphijack
Module Name:src Committed By: kre Date: Thu Aug 11 09:48:57 UTC 2016 Modified Files: src/lib/librumphijack: hijack.c Log Message: Object to dup2() if target fd is in the range of fd's that librumphijack reserves for rump to use. This is not normally a problem, as most applications don't attempt to use very high fds - but /bin/sh does. This fix is something of a kludge - really the apparent fd resource limit ought to be lowered as well, but this is sufficient to allow the shell to work (when its dup2() gets rejected, it just tries again with a smaller target fd until it eventually succeeds.) This fixes the librumphijack shell ATF tests. A better, more comprehensive, fix would be good... To generate a diff of this commit: cvs rdiff -u -r1.119 -r1.120 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.119 src/lib/librumphijack/hijack.c:1.120 --- src/lib/librumphijack/hijack.c:1.119 Tue Aug 25 13:50:19 2015 +++ src/lib/librumphijack/hijack.c Thu Aug 11 09:48:57 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.119 2015/08/25 13:50:19 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.120 2016/08/11 09:48:57 kre Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.119 2015/08/25 13:50:19 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.120 2016/08/11 09:48:57 kre Exp $"); #endif #include @@ -1064,6 +1064,10 @@ dodup(int oldd, int minfd) minfd -= hijack_fdoff; isrump = 1; } else { + if (minfd >= hijack_fdoff) { + errno = EINVAL; + return -1; + } op_fcntl = GETSYSCALL(host, FCNTL); isrump = 0; }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Aug 25 13:50:19 UTC 2015 Modified Files: src/lib/librumphijack: hijack.c Log Message: Remember that dlsym() tends to fail on PowerPC during init (or at least tended), so call rumphijack_dlsym() instead to be safe. To generate a diff of this commit: cvs rdiff -u -r1.118 -r1.119 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.118 src/lib/librumphijack/hijack.c:1.119 --- src/lib/librumphijack/hijack.c:1.118 Tue Aug 25 13:45:00 2015 +++ src/lib/librumphijack/hijack.c Tue Aug 25 13:50:19 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.118 2015/08/25 13:45:00 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.119 2015/08/25 13:50:19 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.118 2015/08/25 13:45:00 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.119 2015/08/25 13:50:19 pooka Exp $"); #endif #include @@ -2235,7 +2235,7 @@ mmap(void *addr, size_t len, int prot, i return MAP_FAILED; } if (__predict_false(host_mmap == NULL)) { - host_mmap = dlsym(RTLD_NEXT, "mmap"); + host_mmap = rumphijack_dlsym(RTLD_NEXT, "mmap"); } return host_mmap(addr, len, prot, flags, fd, offset); }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Aug 25 13:45:00 UTC 2015 Modified Files: src/lib/librumphijack: hijack.c Log Message: allow mmap() to be called before init runs To generate a diff of this commit: cvs rdiff -u -r1.117 -r1.118 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.117 src/lib/librumphijack/hijack.c:1.118 --- src/lib/librumphijack/hijack.c:1.117 Sat Apr 11 12:54:41 2015 +++ src/lib/librumphijack/hijack.c Tue Aug 25 13:45:00 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.117 2015/04/11 12:54:41 riastradh Exp $ */ +/* $NetBSD: hijack.c,v 1.118 2015/08/25 13:45:00 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.117 2015/04/11 12:54:41 riastradh Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.118 2015/08/25 13:45:00 pooka Exp $"); #endif #include @@ -885,7 +885,8 @@ rcinit(void) host_fork = dlsym(RTLD_NEXT, "fork"); host_daemon = dlsym(RTLD_NEXT, "daemon"); - host_mmap = dlsym(RTLD_NEXT, "mmap"); + if (host_mmap == NULL) + host_mmap = dlsym(RTLD_NEXT, "mmap"); /* * In theory cannot print anything during lookups because @@ -2233,6 +2234,9 @@ mmap(void *addr, size_t len, int prot, i errno = ENOSYS; return MAP_FAILED; } + if (__predict_false(host_mmap == NULL)) { + host_mmap = dlsym(RTLD_NEXT, "mmap"); + } return host_mmap(addr, len, prot, flags, fd, offset); }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: riastradh Date: Sat Apr 11 12:54:41 UTC 2015 Modified Files: src/lib/librumphijack: hijack.c Log Message: Define the expansion of the VFORK macro, not the symbol `VFORK'. Fixes hijacking processes that vfork and exec. Symptom was the child would spin with read/EAGAIN <-> kevent/EBADF because the inheritance mechanism relied on setting the holyfd to -1 on fork...which didn't happen if we didn't hijack vfork. ok pooka@ To generate a diff of this commit: cvs rdiff -u -r1.116 -r1.117 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.116 src/lib/librumphijack/hijack.c:1.117 --- src/lib/librumphijack/hijack.c:1.116 Thu Mar 5 00:26:17 2015 +++ src/lib/librumphijack/hijack.c Sat Apr 11 12:54:41 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.116 2015/03/05 00:26:17 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.117 2015/04/11 12:54:41 riastradh Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.116 2015/03/05 00:26:17 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.117 2015/04/11 12:54:41 riastradh Exp $"); #endif #include @@ -1721,7 +1721,8 @@ fork(void) } #ifdef VFORK /* we do not have the luxury of not requiring a stackframe */ -__strong_alias(VFORK,fork); +#define __strong_alias_macro(m, f) __strong_alias(m, f) +__strong_alias_macro(VFORK,fork); #endif int
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Thu Mar 5 00:26:17 UTC 2015 Modified Files: src/lib/librumphijack: hijack.c Log Message: Wrap utimensat() only if present on host fixes buildrump.sh on NetBSD 6.1.5 To generate a diff of this commit: cvs rdiff -u -r1.115 -r1.116 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.115 src/lib/librumphijack/hijack.c:1.116 --- src/lib/librumphijack/hijack.c:1.115 Wed Mar 4 23:42:26 2015 +++ src/lib/librumphijack/hijack.c Thu Mar 5 00:26:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.115 2015/03/04 23:42:26 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.116 2015/03/05 00:26:17 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.115 2015/03/04 23:42:26 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.116 2015/03/05 00:26:17 pooka Exp $"); #endif #include @@ -2265,10 +2265,12 @@ __sysctl(const int *name, unsigned int n * Rest are std type calls. */ +#ifdef HAVE_UTIMENSAT ATCALL(int, utimensat, DUALCALL_UTIMENSAT,\ (int fd, const char *path, const struct timespec t[2], int f), \ (int, const char *, const struct timespec [2], int), (fd, path, t, f)) +#endif FDCALL(int, bind, DUALCALL_BIND, \ (int fd, const struct sockaddr *name, socklen_t namelen), \
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Mar 4 23:42:26 UTC 2015 Modified Files: src/lib/librumphijack: hijack.c Log Message: Make ATCALL() behave for absolute paths too. To generate a diff of this commit: cvs rdiff -u -r1.114 -r1.115 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.114 src/lib/librumphijack/hijack.c:1.115 --- src/lib/librumphijack/hijack.c:1.114 Wed Mar 4 23:31:49 2015 +++ src/lib/librumphijack/hijack.c Wed Mar 4 23:42:26 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.114 2015/03/04 23:31:49 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.115 2015/03/04 23:42:26 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.114 2015/03/04 23:31:49 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.115 2015/03/04 23:42:26 pooka Exp $"); #endif #include @@ -531,7 +531,7 @@ type name args\ type (*fun) proto; \ int isrump = -1; \ \ - if (fd == AT_FDCWD) { \ + if (fd == AT_FDCWD || *path == '/') {\ isrump = path_isrump(path);\ } else { \ isrump = fd_isrump(fd); \
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Mar 4 23:31:49 UTC 2015 Modified Files: src/lib/librumphijack: hijack.c Log Message: Define a generic ATCALL() and use it to implement utimensat() To generate a diff of this commit: cvs rdiff -u -r1.113 -r1.114 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.113 src/lib/librumphijack/hijack.c:1.114 --- src/lib/librumphijack/hijack.c:1.113 Tue Mar 3 01:24:39 2015 +++ src/lib/librumphijack/hijack.c Wed Mar 4 23:31:49 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.113 2015/03/03 01:24:39 enami Exp $ */ +/* $NetBSD: hijack.c,v 1.114 2015/03/04 23:31:49 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.113 2015/03/03 01:24:39 enami Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.114 2015/03/04 23:31:49 pooka Exp $"); #endif #include @@ -525,6 +525,33 @@ whichpath(const char *path) #define DPRINTF(x) #endif +#define ATCALL(type, name, rcname, args, proto, vars) \ +type name args\ +{ \ + type (*fun) proto; \ + int isrump = -1; \ + \ + if (fd == AT_FDCWD) { \ + isrump = path_isrump(path);\ + } else { \ + isrump = fd_isrump(fd); \ + }\ + \ + DPRINTF(("%s -> %d:%s (%s)\n", __STRING(name), \ + fd, path, isrump ? "rump" : "host")); \ + \ + assert(isrump != -1); \ + if (isrump) { \ + fun = syscalls[rcname].bs_rump;\ + if (fd != AT_FDCWD) \ + fd = fd_host2rump(fd);\ + path = path_host2rump(path);\ + } else { \ + fun = syscalls[rcname].bs_host;\ + }\ + return fun vars; \ +} + #define FDCALL(type, name, rcname, args, proto, vars) \ type name args\ { \ @@ -2238,6 +2265,11 @@ __sysctl(const int *name, unsigned int n * Rest are std type calls. */ +ATCALL(int, utimensat, DUALCALL_UTIMENSAT,\ + (int fd, const char *path, const struct timespec t[2], int f), \ + (int, const char *, const struct timespec [2], int), + (fd, path, t, f)) + FDCALL(int, bind, DUALCALL_BIND, \ (int fd, const struct sockaddr *name, socklen_t namelen), \ (int, const struct sockaddr *, socklen_t), \ @@ -2504,11 +2536,6 @@ PATHCALL(int, lutimes, DUALCALL_LUTIMES, (const char *, const struct timeval *),\ (path, tv)) -PATHCALL(int, utimensat, DUALCALL_UTIMENSAT,\ - (int fd, const char *path, const struct timespec *ts, int flags), \ - (int, const char *, const struct timespec *, int), \ - (fd, path, ts, flags)) - #ifdef HAVE_CHFLAGS PATHCALL(int, chflags, DUALCALL_CHFLAGS,\ (const char *path, u_long flags),\
CVS commit: src/lib/librumphijack
Module Name:src Committed By: enami Date: Tue Mar 3 01:24:39 UTC 2015 Modified Files: src/lib/librumphijack: hijack.c Log Message: Also hijack futimens(2) so that t_sh test passes. To generate a diff of this commit: cvs rdiff -u -r1.112 -r1.113 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.112 src/lib/librumphijack/hijack.c:1.113 --- src/lib/librumphijack/hijack.c:1.112 Tue Mar 3 00:19:07 2015 +++ src/lib/librumphijack/hijack.c Tue Mar 3 01:24:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.112 2015/03/03 00:19:07 enami Exp $ */ +/* $NetBSD: hijack.c,v 1.113 2015/03/03 01:24:39 enami Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.112 2015/03/03 00:19:07 enami Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.113 2015/03/03 01:24:39 enami Exp $"); #endif #include @@ -113,7 +113,7 @@ enum dualcall { DUALCALL_LINK, DUALCALL_RENAME, DUALCALL_MKDIR, DUALCALL_RMDIR, DUALCALL_UTIMES, DUALCALL_LUTIMES, DUALCALL_FUTIMES, - DUALCALL_UTIMENSAT, + DUALCALL_UTIMENSAT, DUALCALL_FUTIMENS, DUALCALL_TRUNCATE, DUALCALL_FTRUNCATE, DUALCALL_FSYNC, DUALCALL_ACCESS, @@ -307,6 +307,7 @@ struct sysnames { { DUALCALL_LUTIMES, S(REALLUTIMES), RSYS_NAME(LUTIMES) }, { DUALCALL_FUTIMES, S(REALFUTIMES), RSYS_NAME(FUTIMES) }, { DUALCALL_UTIMENSAT, "utimensat", RSYS_NAME(UTIMENSAT) }, + { DUALCALL_FUTIMENS, "futimens", RSYS_NAME(FUTIMENS) }, { DUALCALL_OPEN, "open", RSYS_NAME(OPEN) }, { DUALCALL_CHDIR, "chdir", RSYS_NAME(CHDIR) }, { DUALCALL_FCHDIR, "fchdir", RSYS_NAME(FCHDIR) }, @@ -2392,6 +2393,11 @@ FDCALL(int, futimes, DUALCALL_FUTIMES, (int, const struct timeval *), \ (fd, tv)) +FDCALL(int, futimens, DUALCALL_FUTIMENS,\ + (int fd, const struct timespec *ts),\ + (int, const struct timespec *), \ + (fd, ts)) + #ifdef HAVE_CHFLAGS FDCALL(int, fchflags, DUALCALL_FCHFLAGS,\ (int fd, u_long flags), \
CVS commit: src/lib/librumphijack
Module Name:src Committed By: enami Date: Tue Mar 3 00:19:07 UTC 2015 Modified Files: src/lib/librumphijack: hijack.c Log Message: Hijack utimensat(2) so that t_vfs test passes after cp(1)/mv(1) are changed to use the system call. Linux also has this system call, but not tested this on linux. To generate a diff of this commit: cvs rdiff -u -r1.111 -r1.112 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.111 src/lib/librumphijack/hijack.c:1.112 --- src/lib/librumphijack/hijack.c:1.111 Tue Nov 4 19:05:17 2014 +++ src/lib/librumphijack/hijack.c Tue Mar 3 00:19:07 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.111 2014/11/04 19:05:17 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.112 2015/03/03 00:19:07 enami Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.111 2014/11/04 19:05:17 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.112 2015/03/03 00:19:07 enami Exp $"); #endif #include @@ -113,6 +113,7 @@ enum dualcall { DUALCALL_LINK, DUALCALL_RENAME, DUALCALL_MKDIR, DUALCALL_RMDIR, DUALCALL_UTIMES, DUALCALL_LUTIMES, DUALCALL_FUTIMES, + DUALCALL_UTIMENSAT, DUALCALL_TRUNCATE, DUALCALL_FTRUNCATE, DUALCALL_FSYNC, DUALCALL_ACCESS, @@ -305,6 +306,7 @@ struct sysnames { { DUALCALL_UTIMES, S(REALUTIMES), RSYS_NAME(UTIMES) }, { DUALCALL_LUTIMES, S(REALLUTIMES), RSYS_NAME(LUTIMES) }, { DUALCALL_FUTIMES, S(REALFUTIMES), RSYS_NAME(FUTIMES) }, + { DUALCALL_UTIMENSAT, "utimensat", RSYS_NAME(UTIMENSAT) }, { DUALCALL_OPEN, "open", RSYS_NAME(OPEN) }, { DUALCALL_CHDIR, "chdir", RSYS_NAME(CHDIR) }, { DUALCALL_FCHDIR, "fchdir", RSYS_NAME(FCHDIR) }, @@ -2496,6 +2498,11 @@ PATHCALL(int, lutimes, DUALCALL_LUTIMES, (const char *, const struct timeval *),\ (path, tv)) +PATHCALL(int, utimensat, DUALCALL_UTIMENSAT,\ + (int fd, const char *path, const struct timespec *ts, int flags), \ + (int, const char *, const struct timespec *, int), \ + (fd, path, ts, flags)) + #ifdef HAVE_CHFLAGS PATHCALL(int, chflags, DUALCALL_CHFLAGS,\ (const char *path, u_long flags),\
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Aug 12 23:47:09 UTC 2014 Modified Files: src/lib/librumphijack: hijack.c Log Message: In case of no dup2'd fd's, make sure that F_CLOSEM for the rump kernel starts from 0. Fixes rumphijack fdoff test (notably, this bug had nothing to do with fdoff, and was exposed >3 years after writing the test when rump kernels started providing fd's 0/1/2) To generate a diff of this commit: cvs rdiff -u -r1.109 -r1.110 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.109 src/lib/librumphijack/hijack.c:1.110 --- src/lib/librumphijack/hijack.c:1.109 Mon Jul 21 14:23:43 2014 +++ src/lib/librumphijack/hijack.c Tue Aug 12 23:47:09 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.109 2014/07/21 14:23:43 gson Exp $ */ +/* $NetBSD: hijack.c,v 1.110 2014/08/12 23:47:09 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.109 2014/07/21 14:23:43 gson Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.110 2014/08/12 23:47:09 pooka Exp $"); #endif #include @@ -1380,7 +1380,7 @@ fcntl(int fd, int cmd, ...) * for the file descriptors not dup2'd. */ - for (i = 0, maxdup2 = 0; i <= DUP2HIGH; i++) { + for (i = 0, maxdup2 = -1; i <= DUP2HIGH; i++) { if (dup2vec[i] & DUP2BIT) { int val;
CVS commit: src/lib/librumphijack
Module Name:src Committed By: gson Date: Mon Jul 21 14:23:43 UTC 2014 Modified Files: src/lib/librumphijack: hijack.c Log Message: Ignore the contents of revents when poll() returns failure. This is one more part to the fix for PR kern/46464. Patch from pooka. To generate a diff of this commit: cvs rdiff -u -r1.108 -r1.109 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.108 src/lib/librumphijack/hijack.c:1.109 --- src/lib/librumphijack/hijack.c:1.108 Sat Jul 19 14:14:21 2014 +++ src/lib/librumphijack/hijack.c Mon Jul 21 14:23:43 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.108 2014/07/19 14:14:21 gson Exp $ */ +/* $NetBSD: hijack.c,v 1.109 2014/07/21 14:23:43 gson Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.108 2014/07/19 14:14:21 gson Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.109 2014/07/21 14:23:43 gson Exp $"); #endif #include @@ -2069,12 +2069,10 @@ REALPOLLTS(struct pollfd *fds, nfds_t nf errno_host = parg.errnum; /* strip cross-thread notification from real results */ - if (pfd_host[nfds].revents & POLLIN) { - assert(rv_host > 0); + if (rv_host > 0 && pfd_host[nfds].revents & POLLIN) { rv_host--; } - if (pfd_rump[nfds].revents & POLLIN) { - assert(rv_rump > 0); + if (rv_rump > 0 && pfd_rump[nfds].revents & POLLIN) { rv_rump--; }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: gson Date: Sat Jul 19 14:14:21 UTC 2014 Modified Files: src/lib/librumphijack: hijack.c Log Message: Do not assert that the two threads do not simultanously notify each other, because sometimes they do. Should fix PR kern/46464. OK pooka. To generate a diff of this commit: cvs rdiff -u -r1.107 -r1.108 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.107 src/lib/librumphijack/hijack.c:1.108 --- src/lib/librumphijack/hijack.c:1.107 Wed Apr 2 17:09:23 2014 +++ src/lib/librumphijack/hijack.c Sat Jul 19 14:14:21 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.107 2014/04/02 17:09:23 justin Exp $ */ +/* $NetBSD: hijack.c,v 1.108 2014/07/19 14:14:21 gson Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.107 2014/04/02 17:09:23 justin Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.108 2014/07/19 14:14:21 gson Exp $"); #endif #include @@ -2070,12 +2070,10 @@ REALPOLLTS(struct pollfd *fds, nfds_t nf /* strip cross-thread notification from real results */ if (pfd_host[nfds].revents & POLLIN) { - assert((pfd_rump[nfds].revents & POLLIN) == 0); assert(rv_host > 0); rv_host--; } if (pfd_rump[nfds].revents & POLLIN) { - assert((pfd_host[nfds].revents & POLLIN) == 0); assert(rv_rump > 0); rv_rump--; }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: tron Date: Sat Jan 18 18:37:30 UTC 2014 Modified Files: src/lib/librumphijack: Makefile Log Message: Make sure that "_FORTIFY_SOURCE" really gets undefined even if "USE_SSP" is set to "yes" to fix build problems caused by the recent change to this makefile. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/librumphijack/Makefile 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/Makefile diff -u src/lib/librumphijack/Makefile:1.15 src/lib/librumphijack/Makefile:1.16 --- src/lib/librumphijack/Makefile:1.15 Fri Jan 10 15:54:29 2014 +++ src/lib/librumphijack/Makefile Sat Jan 18 18:37:30 2014 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.15 2014/01/10 15:54:29 christos Exp $ +# $NetBSD: Makefile,v 1.16 2014/01/18 18:37:30 tron Exp $ # LIB= rumphijack @@ -18,6 +18,6 @@ WARNS?= 5 # a stack frame COPTS.hijackdlsym.c+= -O0 -CPPFLAGS+= -U_FORTIFY_SOURCE - .include + +CPPFLAGS+= -U_FORTIFY_SOURCE
CVS commit: src/lib/librumphijack
Module Name:src Committed By: christos Date: Fri Jan 10 15:54:29 UTC 2014 Modified Files: src/lib/librumphijack: Makefile Log Message: don't need to include anything before bsd.lib.mk since we don't use any variables To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/lib/librumphijack/Makefile 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/Makefile diff -u src/lib/librumphijack/Makefile:1.14 src/lib/librumphijack/Makefile:1.15 --- src/lib/librumphijack/Makefile:1.14 Fri Jan 10 10:00:16 2014 +++ src/lib/librumphijack/Makefile Fri Jan 10 10:54:29 2014 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.14 2014/01/10 15:00:16 martin Exp $ +# $NetBSD: Makefile,v 1.15 2014/01/10 15:54:29 christos Exp $ # LIB= rumphijack @@ -18,9 +18,6 @@ WARNS?= 5 # a stack frame COPTS.hijackdlsym.c+= -O0 -.include # prerequisite for bsd.sys.mk -.include - CPPFLAGS+= -U_FORTIFY_SOURCE .include
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Jul 31 12:23:25 UTC 2013 Modified Files: src/lib/librumphijack: hijack.c Log Message: remove unnecessary -- musl whines when it's included To generate a diff of this commit: cvs rdiff -u -r1.104 -r1.105 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.104 src/lib/librumphijack/hijack.c:1.105 --- src/lib/librumphijack/hijack.c:1.104 Sat Jul 27 17:37:29 2013 +++ src/lib/librumphijack/hijack.c Wed Jul 31 12:23:25 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.104 2013/07/27 17:37:29 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.105 2013/07/31 12:23:25 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.104 2013/07/27 17:37:29 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.105 2013/07/31 12:23:25 pooka Exp $"); #endif #include @@ -36,7 +36,6 @@ __RCSID("$NetBSD: hijack.c,v 1.104 2013/ #include #include #include -#include #include #include #include
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Jul 29 10:13:21 UTC 2013 Modified Files: src/lib/librumphijack: Makefile Log Message: Override ssp also in case where it doesn't come intrinsically from the compiler. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/lib/librumphijack/Makefile 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/Makefile diff -u src/lib/librumphijack/Makefile:1.11 src/lib/librumphijack/Makefile:1.12 --- src/lib/librumphijack/Makefile:1.11 Sat Jul 27 17:37:29 2013 +++ src/lib/librumphijack/Makefile Mon Jul 29 10:13:21 2013 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.11 2013/07/27 17:37:29 pooka Exp $ +# $NetBSD: Makefile,v 1.12 2013/07/29 10:13:21 pooka Exp $ # LIB= rumphijack @@ -11,7 +11,6 @@ MAN= rumphijack.3 SRCS= hijack.c hijackdlsym.c CPPFLAGS+= -D_DIAGNOSTIC -D_REENTRANT -I${.CURDIR}/../librumpuser -CPPFLAGS+= -U_FORTIFY_SOURCE WARNS?= 5 @@ -19,4 +18,8 @@ WARNS?= 5 # a stack frame COPTS.hijackdlsym.c+= -O0 +.include + +CPPFLAGS+= -U_FORTIFY_SOURCE + .include
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Sat Jul 27 17:37:29 UTC 2013 Modified Files: src/lib/librumphijack: Makefile hijack.c Log Message: Extend #undef _FORTIFY_SOURCE to both files to avoid compiler warning for -O0 and fortify combination. from Alessio Sergi via github To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/lib/librumphijack/Makefile cvs rdiff -u -r1.103 -r1.104 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/Makefile diff -u src/lib/librumphijack/Makefile:1.10 src/lib/librumphijack/Makefile:1.11 --- src/lib/librumphijack/Makefile:1.10 Sat Aug 25 18:00:06 2012 +++ src/lib/librumphijack/Makefile Sat Jul 27 17:37:29 2013 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.10 2012/08/25 18:00:06 pooka Exp $ +# $NetBSD: Makefile,v 1.11 2013/07/27 17:37:29 pooka Exp $ # LIB= rumphijack @@ -11,6 +11,7 @@ MAN= rumphijack.3 SRCS= hijack.c hijackdlsym.c CPPFLAGS+= -D_DIAGNOSTIC -D_REENTRANT -I${.CURDIR}/../librumpuser +CPPFLAGS+= -U_FORTIFY_SOURCE WARNS?= 5 Index: src/lib/librumphijack/hijack.c diff -u src/lib/librumphijack/hijack.c:1.103 src/lib/librumphijack/hijack.c:1.104 --- src/lib/librumphijack/hijack.c:1.103 Mon Jul 22 12:11:03 2013 +++ src/lib/librumphijack/hijack.c Sat Jul 27 17:37:29 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.103 2013/07/22 12:11:03 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.104 2013/07/27 17:37:29 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -25,13 +25,10 @@ * SUCH DAMAGE. */ -/* Disable namespace mangling, Fortification is useless here anyway. */ -#undef _FORTIFY_SOURCE - #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.103 2013/07/22 12:11:03 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.104 2013/07/27 17:37:29 pooka Exp $"); #endif #include
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Jul 22 12:11:03 UTC 2013 Modified Files: src/lib/librumphijack: hijack.c Log Message: Support Linuxen where libc ioctl has cmd as int unstead of unsigned long. To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 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.102 src/lib/librumphijack/hijack.c:1.103 --- src/lib/librumphijack/hijack.c:1.102 Sat Jul 20 18:46:15 2013 +++ src/lib/librumphijack/hijack.c Mon Jul 22 12:11:03 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.102 2013/07/20 18:46:15 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.103 2013/07/22 12:11:03 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -31,7 +31,7 @@ #include "rumpuser_port.h" #if !defined(lint) -__RCSID("$NetBSD: hijack.c,v 1.102 2013/07/20 18:46:15 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.103 2013/07/22 12:11:03 pooka Exp $"); #endif #include @@ -1305,12 +1305,24 @@ accept(int s, struct sockaddr *addr, soc } /* - * ioctl and fcntl are varargs calls and need special treatment + * ioctl() and fcntl() are varargs calls and need special treatment. + */ + +/* + * Various [Linux] libc's have various signatures for ioctl so we + * need to handle the discrepancies. On NetBSD, we use the + * one with unsigned long cmd. */ int +#ifdef HAVE_IOCTL_CMD_INT +ioctl(int fd, int cmd, ...) +{ + int (*op_ioctl)(int, int cmd, ...); +#else ioctl(int fd, unsigned long cmd, ...) { int (*op_ioctl)(int, unsigned long cmd, ...); +#endif va_list ap; int rv;
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Thu Jul 18 22:58:35 UTC 2013 Modified Files: src/lib/librumphijack: hijack.c hijackdlsym.c Log Message: sys/cdefs.h should come from rumpuser_port.h Noticed by Justin Cormack while building against musl libc. To generate a diff of this commit: cvs rdiff -u -r1.100 -r1.101 src/lib/librumphijack/hijack.c cvs rdiff -u -r1.3 -r1.4 src/lib/librumphijack/hijackdlsym.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.100 src/lib/librumphijack/hijack.c:1.101 --- src/lib/librumphijack/hijack.c:1.100 Tue Oct 16 12:56:10 2012 +++ src/lib/librumphijack/hijack.c Thu Jul 18 22:58:35 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.100 2012/10/16 12:56:10 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.101 2013/07/18 22:58:35 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -30,8 +30,9 @@ #include "rumpuser_port.h" -#include -__RCSID("$NetBSD: hijack.c,v 1.100 2012/10/16 12:56:10 pooka Exp $"); +#if !defined(lint) +__RCSID("$NetBSD: hijack.c,v 1.101 2013/07/18 22:58:35 pooka Exp $"); +#endif #include #include Index: src/lib/librumphijack/hijackdlsym.c diff -u src/lib/librumphijack/hijackdlsym.c:1.3 src/lib/librumphijack/hijackdlsym.c:1.4 --- src/lib/librumphijack/hijackdlsym.c:1.3 Sat Aug 25 18:00:06 2012 +++ src/lib/librumphijack/hijackdlsym.c Thu Jul 18 22:58:35 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: hijackdlsym.c,v 1.3 2012/08/25 18:00:06 pooka Exp $ */ +/* $NetBSD: hijackdlsym.c,v 1.4 2013/07/18 22:58:35 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -27,8 +27,9 @@ #include "rumpuser_port.h" -#include -__RCSID("$NetBSD: hijackdlsym.c,v 1.3 2012/08/25 18:00:06 pooka Exp $"); +#if !defined(lint) +__RCSID("$NetBSD: hijackdlsym.c,v 1.4 2013/07/18 22:58:35 pooka Exp $"); +#endif #include
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Oct 16 12:56:10 UTC 2012 Modified Files: src/lib/librumphijack: hijack.c Log Message: * avoid problems if the platform calls readlink() from dlsym() * alias __read_chk() to read() on Linux (technically, though, it should call host __read_chk() instead of read()) To generate a diff of this commit: cvs rdiff -u -r1.99 -r1.100 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.99 src/lib/librumphijack/hijack.c:1.100 --- src/lib/librumphijack/hijack.c:1.99 Wed Sep 12 10:35:10 2012 +++ src/lib/librumphijack/hijack.c Tue Oct 16 12:56:10 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.99 2012/09/12 10:35:10 martin Exp $ */ +/* $NetBSD: hijack.c,v 1.100 2012/10/16 12:56:10 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -31,7 +31,7 @@ #include "rumpuser_port.h" #include -__RCSID("$NetBSD: hijack.c,v 1.99 2012/09/12 10:35:10 martin Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.100 2012/10/16 12:56:10 pooka Exp $"); #include #include @@ -1769,7 +1769,8 @@ REALSELECT(int nfds, fd_set *readfds, fd int i, j; int rv, incr; - DPRINTF(("select\n")); + DPRINTF(("select %d %p %p %p %p\n", nfds, + readfds, writefds, exceptfds, timeout)); /* * Well, first we must scan the fds to figure out how many @@ -1949,7 +1950,7 @@ REALPOLLTS(struct pollfd *fds, nfds_t nf nfds_t i; int rv; - DPRINTF(("poll\n")); + DPRINTF(("poll %p %d %p %p\n", fds, (int)nfds, ts, sigmask)); checkpoll(fds, nfds, &hostcall, &rumpcall); if (hostcall && rumpcall) { @@ -2287,6 +2288,11 @@ FDCALL(ssize_t, REALREAD, DUALCALL_READ, (int, void *, size_t), \ (fd, buf, buflen)) +#ifdef __linux__ +ssize_t __read_chk(int, void *, size_t) +__attribute__((alias("read"))); +#endif + FDCALL(ssize_t, readv, DUALCALL_READV, \ (int fd, const struct iovec *iov, int iovcnt), \ (int, const struct iovec *, int),\ @@ -2438,10 +2444,31 @@ PATHCALL(int, symlink, DUALCALL_SYMLINK, (const char *, const char *), \ (target, path)) -PATHCALL(ssize_t, readlink, DUALCALL_READLINK,\ - (const char *path, char *buf, size_t bufsiz), \ - (const char *, char *, size_t), \ - (path, buf, bufsiz)) +/* + * readlink() can be called from malloc which can be called + * from dlsym() during init + */ +ssize_t +readlink(const char *path, char *buf, size_t bufsiz) +{ + int (*op_readlink)(const char *, char *, size_t); + enum pathtype pt; + + if ((pt = path_isrump(path)) != PATH_HOST) { + op_readlink = GETSYSCALL(rump, READLINK); + if (pt == PATH_RUMP) + path = path_host2rump(path); + } else { + op_readlink = GETSYSCALL(host, READLINK); + } + + if (__predict_false(op_readlink == NULL)) { + errno = ENOENT; + return -1; + } + + return op_readlink(path, buf, bufsiz); +} PATHCALL(int, mkdir, DUALCALL_MKDIR, \ (const char *path, mode_t mode),\
CVS commit: src/lib/librumphijack
Module Name:src Committed By: martin Date: Wed Sep 12 10:35:10 UTC 2012 Modified Files: src/lib/librumphijack: hijack.c Log Message: When emulating poll/select better tell the events of the host kernel apart from those received from the rump kernel. Also handle timeout. Patch from pooka. To generate a diff of this commit: cvs rdiff -u -r1.98 -r1.99 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.98 src/lib/librumphijack/hijack.c:1.99 --- src/lib/librumphijack/hijack.c:1.98 Mon Sep 3 12:07:42 2012 +++ src/lib/librumphijack/hijack.c Wed Sep 12 10:35:10 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.98 2012/09/03 12:07:42 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.99 2012/09/12 10:35:10 martin Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -31,7 +31,7 @@ #include "rumpuser_port.h" #include -__RCSID("$NetBSD: hijack.c,v 1.98 2012/09/03 12:07:42 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.99 2012/09/12 10:35:10 martin Exp $"); #include #include @@ -1502,7 +1502,7 @@ msg_convert(struct msghdr *msg, int (*fu int *fdp = (void *)CMSG_DATA(cmsg); const size_t size = cmsg->cmsg_len - __CMSG_ALIGN(sizeof(*cmsg)); - const int nfds = size / sizeof(int); + const int nfds = (int)(size / sizeof(int)); const int * const efdp = fdp + nfds; while (fdp < efdp) { @@ -1957,7 +1957,7 @@ REALPOLLTS(struct pollfd *fds, nfds_t nf int rpipe[2] = {-1,-1}, hpipe[2] = {-1,-1}; struct pollarg parg; void *trv_val; - int sverrno = 0, lrv, trv; + int sverrno = 0, rv_rump, rv_host, errno_rump, errno_host; /* * ok, this is where it gets tricky. We must support @@ -2047,30 +2047,63 @@ REALPOLLTS(struct pollfd *fds, nfds_t nf pthread_create(&pt, NULL, hostpoll, &parg); op_pollts = GETSYSCALL(rump, POLLTS); - lrv = op_pollts(pfd_rump, nfds+1, ts, NULL); - sverrno = errno; + rv_rump = op_pollts(pfd_rump, nfds+1, ts, NULL); + errno_rump = errno; write(hpipe[1], &rv, sizeof(rv)); pthread_join(pt, &trv_val); - trv = (int)(intptr_t)trv_val; + rv_host = (int)(intptr_t)trv_val; + errno_host = parg.errnum; - /* check who "won" and merge results */ - if (lrv != 0 && pfd_host[nfds].revents & POLLIN) { - rv = trv; - - for (i = 0; i < nfds; i++) { -if (pfd_rump[i].fd != -1) - fds[i].revents = pfd_rump[i].revents; + /* strip cross-thread notification from real results */ + if (pfd_host[nfds].revents & POLLIN) { + assert((pfd_rump[nfds].revents & POLLIN) == 0); + assert(rv_host > 0); + rv_host--; + } + if (pfd_rump[nfds].revents & POLLIN) { + assert((pfd_host[nfds].revents & POLLIN) == 0); + assert(rv_rump > 0); + rv_rump--; + } + + /* then merge the results into what's reported to the caller */ + if (rv_rump > 0 || rv_host > 0) { + /* SUCCESS */ + + rv = 0; + if (rv_rump > 0) { +for (i = 0; i < nfds; i++) { + if (pfd_rump[i].fd != -1) + fds[i].revents + = pfd_rump[i].revents; +} +rv += rv_rump; } - sverrno = parg.errnum; - } else if (trv != 0 && pfd_rump[nfds].revents & POLLIN) { - rv = trv; - - for (i = 0; i < nfds; i++) { -if (pfd_host[i].fd != -1) - fds[i].revents = pfd_host[i].revents; + if (rv_host > 0) { +for (i = 0; i < nfds; i++) { + if (pfd_host[i].fd != -1) + fds[i].revents + = pfd_host[i].revents; +} +rv += rv_host; + } + assert(rv > 0); + sverrno = 0; + } else if (rv_rump == -1 || rv_host == -1) { + /* ERROR */ + + /* just pick one kernel at "random" */ + rv = -1; + if (rv_host == -1) { +sverrno = errno_host; + } else if (rv_rump == -1) { +sverrno = errno_rump; } } else { + /* TIMEOUT */ + rv = 0; + assert(rv_rump == 0 && rv_host == 0); } out:
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Sep 3 12:07:42 UTC 2012 Modified Files: src/lib/librumphijack: hijack.c Log Message: one more patch for supporting linux-based networking clients To generate a diff of this commit: cvs rdiff -u -r1.97 -r1.98 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.97 src/lib/librumphijack/hijack.c:1.98 --- src/lib/librumphijack/hijack.c:1.97 Mon Sep 3 11:33:35 2012 +++ src/lib/librumphijack/hijack.c Mon Sep 3 12:07:42 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.97 2012/09/03 11:33:35 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.98 2012/09/03 12:07:42 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -31,7 +31,7 @@ #include "rumpuser_port.h" #include -__RCSID("$NetBSD: hijack.c,v 1.97 2012/09/03 11:33:35 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.98 2012/09/03 12:07:42 pooka Exp $"); #include #include @@ -102,7 +102,6 @@ enum dualcall { DUALCALL_OPEN, DUALCALL_CHDIR, DUALCALL_FCHDIR, DUALCALL_LSEEK, - DUALCALL_GETDENTS, DUALCALL_UNLINK, DUALCALL_SYMLINK, DUALCALL_READLINK, DUALCALL_LINK, DUALCALL_RENAME, DUALCALL_MKDIR, DUALCALL_RMDIR, @@ -113,6 +112,7 @@ enum dualcall { #ifndef __linux__ DUALCALL___GETCWD, + DUALCALL_GETDENTS, #endif #ifndef __linux__ @@ -211,6 +211,7 @@ int REALSTAT(const char *, struct stat * int REALLSTAT(const char *, struct stat *); int REALFSTAT(int, struct stat *); int REALMKNOD(const char *, mode_t, dev_t); +int REALGETDENTS(int, char *, size_t); int __getcwd(char *, size_t); @@ -219,7 +220,6 @@ int __getcwd(char *, size_t); #define REALREAD read #define REALPREAD pread #define REALPWRITE pwrite -#define REALGETDENTS readdir #define REALSELECT select #define REALPOLLTS ppoll #define REALUTIMES utimes @@ -242,7 +242,6 @@ int REALKEVENT(int, const struct kevent ssize_t REALREAD(int, void *, size_t); ssize_t REALPREAD(int, void *, size_t, off_t); ssize_t REALPWRITE(int, const void *, size_t, off_t); -int REALGETDENTS(int, char *, size_t); int REALUTIMES(const char *, const struct timeval [2]); int REALLUTIMES(const char *, const struct timeval [2]); int REALFUTIMES(int, const struct timeval [2]); @@ -308,7 +307,6 @@ struct sysnames { { DUALCALL_CHDIR, "chdir", RSYS_NAME(CHDIR) }, { DUALCALL_FCHDIR, "fchdir", RSYS_NAME(FCHDIR) }, { DUALCALL_LSEEK, "lseek", RSYS_NAME(LSEEK) }, - { DUALCALL_GETDENTS, S(REALGETDENTS),RSYS_NAME(GETDENTS) }, { DUALCALL_UNLINK, "unlink", RSYS_NAME(UNLINK) }, { DUALCALL_SYMLINK, "symlink", RSYS_NAME(SYMLINK) }, { DUALCALL_READLINK, "readlink", RSYS_NAME(READLINK) }, @@ -323,6 +321,7 @@ struct sysnames { #ifndef __linux__ { DUALCALL___GETCWD, "__getcwd", RSYS_NAME(__GETCWD) }, + { DUALCALL_GETDENTS, S(REALGETDENTS),RSYS_NAME(GETDENTS) }, #endif #ifndef __linux__ @@ -2307,10 +2306,12 @@ FDCALL(off_t, lseek, DUALCALL_LSEEK, __strong_alias(LSEEK_ALIAS,lseek); #endif +#ifndef __linux__ FDCALL(int, REALGETDENTS, DUALCALL_GETDENTS,\ (int fd, char *buf, size_t nbytes),\ (int, char *, size_t), \ (fd, buf, nbytes)) +#endif FDCALL(int, fchown, DUALCALL_FCHOWN, \ (int fd, uid_t owner, gid_t group),\
CVS commit: src/lib/librumphijack
Module Name:src Committed By: yamt Date: Fri Jun 29 13:20:25 UTC 2012 Modified Files: src/lib/librumphijack: hijack.c Log Message: implement descriptor passing. To generate a diff of this commit: cvs rdiff -u -r1.93 -r1.94 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.93 src/lib/librumphijack/hijack.c:1.94 --- src/lib/librumphijack/hijack.c:1.93 Mon Jun 25 22:32:47 2012 +++ src/lib/librumphijack/hijack.c Fri Jun 29 13:20:25 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.93 2012/06/25 22:32:47 abs Exp $ */ +/* $NetBSD: hijack.c,v 1.94 2012/06/29 13:20:25 yamt Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -29,7 +29,7 @@ #undef _FORTIFY_SOURCE #include -__RCSID("$NetBSD: hijack.c,v 1.93 2012/06/25 22:32:47 abs Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.94 2012/06/29 13:20:25 yamt Exp $"); #include #include @@ -1335,6 +1335,122 @@ write(int fd, const void *buf, size_t bl } /* + * file descriptor passing + * + * we intercept sendmsg and recvmsg to convert file descriptors in + * control messages. an attempt to send a descriptor from a different kernel + * is rejected. (ENOTSUP) + */ + +static int +msg_convert(struct msghdr *msg, int (*func)(int)) +{ + struct cmsghdr *cmsg; + + for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; + cmsg = CMSG_NXTHDR(msg, cmsg)) { + if (cmsg->cmsg_level == SOL_SOCKET && + cmsg->cmsg_type == SCM_RIGHTS) { + int *fdp = (void *)CMSG_DATA(cmsg); + const size_t size = + cmsg->cmsg_len - __CMSG_ALIGN(sizeof(*cmsg)); + const int nfds = size / sizeof(int); + const int * const efdp = fdp + nfds; + + while (fdp < efdp) { +const int newval = func(*fdp); + +if (newval < 0) { + return ENOTSUP; +} +*fdp = newval; +fdp++; + } + } + } + return 0; +} + +ssize_t +recvmsg(int fd, struct msghdr *msg, int flags) +{ + ssize_t (*op_recvmsg)(int, struct msghdr *, int); + ssize_t ret; + const bool isrump = fd_isrump(fd); + + if (isrump) { + fd = fd_host2rump(fd); + op_recvmsg = GETSYSCALL(rump, RECVMSG); + } else { + op_recvmsg = GETSYSCALL(host, RECVMSG); + } + ret = op_recvmsg(fd, msg, flags); + if (ret == -1) { + return ret; + } + /* + * convert descriptors in the message. + */ + if (isrump) { + msg_convert(msg, fd_rump2host); + } else { + msg_convert(msg, fd_host2host); + } + return ret; +} + +static int +fd_check_rump(int fd) +{ + + return fd_isrump(fd) ? 0 : -1; +} + +static int +fd_check_host(int fd) +{ + + return !fd_isrump(fd) ? 0 : -1; +} + +ssize_t +sendmsg(int fd, const struct msghdr *msg, int flags) +{ + ssize_t (*op_sendmsg)(int, const struct msghdr *, int); + const bool isrump = fd_isrump(fd); + int error; + + /* + * reject descriptors from a different kernel. + */ + error = msg_convert(__UNCONST(msg), + isrump ? fd_check_rump: fd_check_host); + if (error != 0) { + errno = error; + return -1; + } + /* + * convert descriptors in the message to raw values. + */ + if (isrump) { + fd = fd_host2rump(fd); + /* + * XXX we directly modify the given message assuming: + * - cmsg is writable (typically on caller's stack) + * - caller don't care cmsg's contents after calling sendmsg. + * (thus no need to restore values) + * + * it's safer to copy and modify instead. + */ + msg_convert(__UNCONST(msg), fd_host2rump); + op_sendmsg = GETSYSCALL(rump, SENDMSG); + } else { + op_sendmsg = GETSYSCALL(host, SENDMSG); + } + return op_sendmsg(fd, msg, flags); +} + +/* * dup2 is special. we allow dup2 of a rump kernel fd to 0-2 since * many programs do that. dup2 of a rump kernel fd to another value * not >= fdoff is an error. @@ -1949,16 +2065,6 @@ FDCALL(ssize_t, sendto, DUALCALL_SENDTO, const struct sockaddr *, socklen_t), \ (fd, buf, len, flags, to, tolen)) -FDCALL(ssize_t, recvmsg, DUALCALL_RECVMSG, \ - (int fd, struct msghdr *msg, int flags), \ - (int, struct msghdr *, int), \ - (fd, msg, flags)) - -FDCALL(ssize_t, sendmsg, DUALCALL_SENDMSG, \ - (int fd, const struct msghdr *msg, int flags), \ - (int, const struct msghdr *, int),\ - (fd, msg, flags)) - FDCALL(int, getsockopt, DUALCALL_GETSOCKOPT, \ (int fd, int level, int optn, void *optval, socklen_t *optlen), \ (int, int, int, void *, socklen_t *),\
CVS commit: src/lib/librumphijack
Module Name:src Committed By: martin Date: Wed Apr 18 10:37:37 UTC 2012 Modified Files: src/lib/librumphijack: hijack.c Log Message: poll(), pollts() and select() all return int values, but in the hijack emulation of them these get passed as exit values from a pthread as a void* (c.f. pthread_join(), pthread_exit()). Do not use the address of an int variable for these, but provide the address of a void* and assign the value afterwards. Fixes hijacking of pollts/select on 64bit big endian hosts. Spotted by and fix from pooka. To generate a diff of this commit: cvs rdiff -u -r1.91 -r1.92 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.91 src/lib/librumphijack/hijack.c:1.92 --- src/lib/librumphijack/hijack.c:1.91 Wed Feb 1 05:34:41 2012 +++ src/lib/librumphijack/hijack.c Wed Apr 18 10:37:37 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.91 2012/02/01 05:34:41 dholland Exp $ */ +/* $NetBSD: hijack.c,v 1.92 2012/04/18 10:37:37 martin Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -29,7 +29,7 @@ #undef _FORTIFY_SOURCE #include -__RCSID("$NetBSD: hijack.c,v 1.91 2012/02/01 05:34:41 dholland Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.92 2012/04/18 10:37:37 martin Exp $"); #include #include @@ -1654,7 +1654,7 @@ hostpoll(void *arg) parg->errnum = errno; rump_sys_write(parg->pipefd, &rv, sizeof(rv)); - return (void *)(intptr_t)rv; + return (void *)rv; } int @@ -1676,8 +1676,8 @@ REALPOLLTS(struct pollfd *fds, nfds_t nf struct pollfd *pfd_host = NULL, *pfd_rump = NULL; int rpipe[2] = {-1,-1}, hpipe[2] = {-1,-1}; struct pollarg parg; - uintptr_t lrv; - int sverrno = 0, trv; + void *trv_val; + int sverrno = 0, lrv, trv; /* * ok, this is where it gets tricky. We must support @@ -1770,7 +1770,8 @@ REALPOLLTS(struct pollfd *fds, nfds_t nf lrv = op_pollts(pfd_rump, nfds+1, ts, NULL); sverrno = errno; write(hpipe[1], &rv, sizeof(rv)); - pthread_join(pt, (void *)&trv); + pthread_join(pt, &trv_val); + trv = (int)(intptr_t)trv_val; /* check who "won" and merge results */ if (lrv != 0 && pfd_host[nfds].revents & POLLIN) {
CVS commit: src/lib/librumphijack
Module Name:src Committed By: martin Date: Thu Apr 21 08:21:13 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Backout previous, it breaks lots of tests (tests/lib/librumphijack for example). To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.89 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.88 src/lib/librumphijack/hijack.c:1.89 --- src/lib/librumphijack/hijack.c:1.88 Wed Apr 13 12:40:54 2011 +++ src/lib/librumphijack/hijack.c Thu Apr 21 08:21:13 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.88 2011/04/13 12:40:54 he Exp $ */ +/* $NetBSD: hijack.c,v 1.89 2011/04/21 08:21:13 martin Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.88 2011/04/13 12:40:54 he Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.89 2011/04/21 08:21:13 martin Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -1970,11 +1970,9 @@ (int, int), \ (fd, how)) -ssize_t _sys_readlink(const char * __restrict, char * __restrict, size_t); - #if _FORTIFY_SOURCE > 0 #define STUB(fun) __ssp_weak_name(fun) -ssize_t STUB(readlink)(const char * __restrict, char * __restrict, size_t); +ssize_t _sys_readlink(const char * __restrict, char * __restrict, size_t); ssize_t STUB(readlink)(const char * __restrict path, char * __restrict buf, size_t bufsiz) @@ -1982,7 +1980,6 @@ return _sys_readlink(path, buf, bufsiz); } -char *STUB(getcwd)(char *, size_t); char *_sys_getcwd(char *, size_t); char * STUB(getcwd)(char *buf, size_t size) @@ -2133,7 +2130,7 @@ (const char *, const char *), \ (target, path)) -PATHCALL(ssize_t, _sys_readlink, DUALCALL_READLINK, \ +PATHCALL(ssize_t, readlink, DUALCALL_READLINK,\ (const char *path, char *buf, size_t bufsiz), \ (const char *, char *, size_t), \ (path, buf, bufsiz))
CVS commit: src/lib/librumphijack
Module Name:src Committed By: he Date: Wed Apr 13 12:40:54 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Move the forward declaration of _sys_readlink() outside of the #if, so that the build succeeds even if _FORTIFY_SOURCE isn't > 0. To generate a diff of this commit: cvs rdiff -u -r1.87 -r1.88 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.87 src/lib/librumphijack/hijack.c:1.88 --- src/lib/librumphijack/hijack.c:1.87 Tue Apr 12 19:49:48 2011 +++ src/lib/librumphijack/hijack.c Wed Apr 13 12:40:54 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.87 2011/04/12 19:49:48 christos Exp $ */ +/* $NetBSD: hijack.c,v 1.88 2011/04/13 12:40:54 he Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.87 2011/04/12 19:49:48 christos Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.88 2011/04/13 12:40:54 he Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -1970,10 +1970,11 @@ (int, int), \ (fd, how)) +ssize_t _sys_readlink(const char * __restrict, char * __restrict, size_t); + #if _FORTIFY_SOURCE > 0 #define STUB(fun) __ssp_weak_name(fun) ssize_t STUB(readlink)(const char * __restrict, char * __restrict, size_t); -ssize_t _sys_readlink(const char * __restrict, char * __restrict, size_t); ssize_t STUB(readlink)(const char * __restrict path, char * __restrict buf, size_t bufsiz)
CVS commit: src/lib/librumphijack
Module Name:src Committed By: christos Date: Tue Apr 12 19:49:48 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Fix SSP builds (Vladimir Kirillov) To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.87 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.86 src/lib/librumphijack/hijack.c:1.87 --- src/lib/librumphijack/hijack.c:1.86 Mon Mar 14 11:15:47 2011 +++ src/lib/librumphijack/hijack.c Tue Apr 12 15:49:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.86 2011/03/14 15:15:47 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.87 2011/04/12 19:49:48 christos Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.86 2011/03/14 15:15:47 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.87 2011/04/12 19:49:48 christos Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -1972,6 +1972,7 @@ #if _FORTIFY_SOURCE > 0 #define STUB(fun) __ssp_weak_name(fun) +ssize_t STUB(readlink)(const char * __restrict, char * __restrict, size_t); ssize_t _sys_readlink(const char * __restrict, char * __restrict, size_t); ssize_t STUB(readlink)(const char * __restrict path, char * __restrict buf, @@ -1980,6 +1981,7 @@ return _sys_readlink(path, buf, bufsiz); } +char *STUB(getcwd)(char *, size_t); char *_sys_getcwd(char *, size_t); char * STUB(getcwd)(char *buf, size_t size) @@ -2130,7 +2132,7 @@ (const char *, const char *), \ (target, path)) -PATHCALL(ssize_t, readlink, DUALCALL_READLINK,\ +PATHCALL(ssize_t, _sys_readlink, DUALCALL_READLINK, \ (const char *path, char *buf, size_t bufsiz), \ (const char *, char *, size_t), \ (path, buf, bufsiz))
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Mar 14 15:21:23 UTC 2011 Modified Files: src/lib/librumphijack: rumphijack.3 Log Message: document fdoff To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/lib/librumphijack/rumphijack.3 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/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.11 src/lib/librumphijack/rumphijack.3:1.12 --- src/lib/librumphijack/rumphijack.3:1.11 Thu Mar 10 08:53:04 2011 +++ src/lib/librumphijack/rumphijack.3 Mon Mar 14 15:21:22 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.11 2011/03/10 08:53:04 wiz Exp $ +.\" $NetBSD: rumphijack.3,v 1.12 2011/03/14 15:21:22 pooka Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 9, 2011 +.Dd March 14, 2011 .Dt RUMPHIJACK 3 .Os .Sh NAME @@ -173,6 +173,16 @@ and .Dq no , meaning to call the rump or the host kernel, respectively. +.It Dq fdoff +Adjust the library's fd offset to the specified value. +All rump kernel descriptors have the offset added to them +before they are returned to the application. +This should be changed only if the application defines a low non-default +.Dv FD_SETSIZE +for +.Fn select +or if it opens a very large number of file descriptors. +The default value is 128. .El .Pp If the environment variable is unset, the default value
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Mar 14 15:15:47 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: fdoff is descriptive enough To generate a diff of this commit: cvs rdiff -u -r1.85 -r1.86 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.85 src/lib/librumphijack/hijack.c:1.86 --- src/lib/librumphijack/hijack.c:1.85 Mon Mar 14 15:13:26 2011 +++ src/lib/librumphijack/hijack.c Mon Mar 14 15:15:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.85 2011/03/14 15:13:26 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.86 2011/03/14 15:15:47 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.85 2011/03/14 15:13:26 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.86 2011/03/14 15:15:47 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -677,7 +677,7 @@ { blanketparser, "blanket", true }, { vfsparser, "vfs", true }, { sysctlparser, "sysctl", false }, - { fdoffparser, "fdoffset", true }, + { fdoffparser, "fdoff", true }, { NULL, NULL, false }, };
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Mar 14 15:13:26 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Make fdoffset configurable. Also, enforce that host descriptors are smaller than the offset. To generate a diff of this commit: cvs rdiff -u -r1.84 -r1.85 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.84 src/lib/librumphijack/hijack.c:1.85 --- src/lib/librumphijack/hijack.c:1.84 Thu Mar 10 23:02:56 2011 +++ src/lib/librumphijack/hijack.c Mon Mar 14 15:13:26 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.84 2011/03/10 23:02:56 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.85 2011/03/14 15:13:26 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.84 2011/03/10 23:02:56 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.85 2011/03/14 15:13:26 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -274,6 +274,9 @@ static bool fd_isrump(int); static enum pathtype path_isrump(const char *); +/* default FD_SETSIZE is 256 ==> default fdoff is 128 */ +static int hijack_fdoff = FD_SETSIZE/2; + /* * Maintain a mapping table for the usual dup2 suspects. * Could use atomic ops to operate on dup2vec, but an application @@ -647,6 +650,23 @@ errx(1, "sysctl value should be y(es)/n(o), gave: %s", buf); } +static void +fdoffparser(char *buf) +{ + unsigned long fdoff; + char *ep; + + if (*buf == '-') { + errx(1, "fdoff must not be negative"); + } + fdoff = strtoul(buf, &ep, 10); + if (*ep != '\0') + errx(1, "invalid fdoff specifier \"%s\"", buf); + if (fdoff >= INT_MAX/2 || fdoff < 3) + errx(1, "fdoff out of range"); + hijack_fdoff = fdoff; +} + static struct { void (*parsefn)(char *); const char *name; @@ -657,6 +677,7 @@ { blanketparser, "blanket", true }, { vfsparser, "vfs", true }, { sysctlparser, "sysctl", false }, + { fdoffparser, "fdoffset", true }, { NULL, NULL, false }, }; @@ -783,16 +804,13 @@ } } -/* Need runtime selection. low for now due to FD_SETSIZE */ -#define HIJACK_FDOFF 128 - static int fd_rump2host(int fd) { if (fd == -1) return fd; - return fd + HIJACK_FDOFF; + return fd + hijack_fdoff; } static int @@ -814,7 +832,7 @@ { if (!isdup2d(fd)) - return fd - HIJACK_FDOFF; + return fd - hijack_fdoff; else return mapdup2(fd); } @@ -823,10 +841,10 @@ fd_isrump(int fd) { - return isdup2d(fd) || fd >= HIJACK_FDOFF; + return isdup2d(fd) || fd >= hijack_fdoff; } -#define assertfd(_fd_) assert(ISDUP2D(_fd_) || (_fd_) >= HIJACK_FDOFF) +#define assertfd(_fd_) assert(ISDUP2D(_fd_) || (_fd_) >= hijack_fdoff) static enum pathtype path_isrump(const char *path) @@ -885,8 +903,8 @@ if (fd_isrump(oldd)) { op_fcntl = GETSYSCALL(rump, FCNTL); oldd = fd_host2rump(oldd); - if (minfd >= HIJACK_FDOFF) - minfd -= HIJACK_FDOFF; + if (minfd >= hijack_fdoff) + minfd -= hijack_fdoff; isrump = 1; } else { op_fcntl = GETSYSCALL(host, FCNTL); @@ -903,15 +921,22 @@ } /* - * dup a host file descriptor so that it doesn't collide with the dup2mask + * Check that host fd value does not exceed fdoffset and if necessary + * dup the file descriptor so that it doesn't collide with the dup2mask. */ static int -fd_dupgood(int fd) +fd_host2host(int fd) { int (*op_fcntl)(int, int, ...) = GETSYSCALL(host, FCNTL); int (*op_close)(int) = GETSYSCALL(host, CLOSE); int ofd, i; + if (fd >= hijack_fdoff) { + op_close(fd); + errno = ENFILE; + return -1; + } + for (i = 1; isdup2d(fd); i++) { ofd = fd; fd = op_fcntl(ofd, F_DUPFD, i); @@ -949,7 +974,7 @@ if (isrump) fd = fd_rump2host(fd); else - fd = fd_dupgood(fd); + fd = fd_host2host(fd); DPRINTF(("open <- %d (%s)\n", fd, whichfd(fd))); return fd; @@ -1099,7 +1124,7 @@ if (isrump) fd = fd_rump2host(fd); else - fd = fd_dupgood(fd); + fd = fd_host2host(fd); DPRINTF(("socket <- %d\n", fd)); return fd; @@ -1125,7 +1150,7 @@ if (fd != -1 && isrump) fd = fd_rump2host(fd); else - fd = fd_dupgood(fd); + fd = fd_host2host(fd); DPRINTF((" <- %d\n", fd)); @@ -1177,7 +1202,7 @@ * So, if fd < HIJACKOFF, we want to do a host closem. */ - if (fd < HIJACK_FDOFF) { + if (fd < hijack_fdoff) { int closemfd = fd; if (rumpclient__closenotify(&closemfd, @@ -1203,8 +1228,8 @@ } } - if (fd >= HIJACK_FDOFF) - fd -= HIJACK_FDOFF; + if (fd >= hijack_fdoff) + fd -= hijack_fdoff; else fd = 0; fd = MAX(maxdup2+1, fd);
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Thu Mar 10 23:02:56 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Use rumphijack_dlsym() to figure out where __sysctl() is during init. Otherwise powerpc dlsym() DTWT and returns NULL. (now i have no idea why dlsym() it works from rcinit(), but i'll opt to not care) Hah, only took 15min to debug that crap this time around. I'm quickly approaching zero-time with it. To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 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.83 src/lib/librumphijack/hijack.c:1.84 --- src/lib/librumphijack/hijack.c:1.83 Thu Mar 10 09:47:32 2011 +++ src/lib/librumphijack/hijack.c Thu Mar 10 23:02:56 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.83 2011/03/10 09:47:32 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.84 2011/03/10 23:02:56 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.83 2011/03/10 09:47:32 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.84 2011/03/10 23:02:56 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -1870,7 +1870,7 @@ op___sysctl = GETSYSCALL(host, __SYSCTL); /* we haven't inited yet */ if (__predict_false(op___sysctl == NULL)) { - op___sysctl = dlsym(RTLD_NEXT, "__sysctl"); + op___sysctl = rumphijack_dlsym(RTLD_NEXT, "__sysctl"); } }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Thu Mar 10 09:47:32 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Revert 1.81 and do it in a saner way with an ifdef. Later, when the naming crisis is resolved, we can probably support rump kernel quotas from nb5 also. To generate a diff of this commit: cvs rdiff -u -r1.82 -r1.83 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.82 src/lib/librumphijack/hijack.c:1.83 --- src/lib/librumphijack/hijack.c:1.82 Wed Mar 9 23:26:19 2011 +++ src/lib/librumphijack/hijack.c Thu Mar 10 09:47:32 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.82 2011/03/09 23:26:19 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.83 2011/03/10 09:47:32 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.82 2011/03/09 23:26:19 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.83 2011/03/10 09:47:32 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -97,7 +97,9 @@ DUALCALL___SYSCTL, DUALCALL_GETVFSSTAT, DUALCALL_NFSSVC, DUALCALL_GETFH, DUALCALL_FHOPEN, DUALCALL_FHSTAT, DUALCALL_FHSTATVFS1, +#if __NetBSD_Prereq__(5,99,48) DUALCALL_QUOTACTL, +#endif DUALCALL__NUM }; @@ -133,7 +135,6 @@ #define REALMKNOD __mknod50 #define REALFHSTAT __fhstat50 #endif - #define REALREAD _sys_read #define REALPREAD _sys_pread #define REALPWRITE _sys_pwrite @@ -173,9 +174,7 @@ enum dualcall scm_callnum; const char *scm_hostname; const char *scm_rumpname; -}; - -struct sysnames sys_mandatory[] = { +} syscnames[] = { { DUALCALL_SOCKET, "__socket30", RSYS_NAME(SOCKET) }, { DUALCALL_ACCEPT, "accept", RSYS_NAME(ACCEPT) }, { DUALCALL_BIND, "bind", RSYS_NAME(BIND) }, @@ -245,23 +244,15 @@ { DUALCALL_GETVFSSTAT, "getvfsstat", RSYS_NAME(GETVFSSTAT) }, { DUALCALL_NFSSVC, "nfssvc", RSYS_NAME(NFSSVC) }, { DUALCALL_GETFH, S(REALGETFH), RSYS_NAME(GETFH) }, - { DUALCALL_FHOPEN, S(REALFHOPEN), RSYS_NAME(FHOPEN) }, - { DUALCALL_FHSTAT, S(REALFHSTAT), RSYS_NAME(FHSTAT) }, + { DUALCALL_FHOPEN, S(REALFHOPEN),RSYS_NAME(FHOPEN) }, + { DUALCALL_FHSTAT, S(REALFHSTAT),RSYS_NAME(FHSTAT) }, { DUALCALL_FHSTATVFS1, S(REALFHSTATVFS1),RSYS_NAME(FHSTATVFS1) }, -}; - -struct sysnames sys_optional[] = { +#if __NetBSD_Prereq__(5,99,48) { DUALCALL_QUOTACTL, S(REALQUOTACTL),RSYS_NAME(QUOTACTL) }, +#endif }; #undef S -static int -nolibcstub(void) -{ - - return ENOSYS; -} - struct bothsys { void *bs_host; void *bs_rump; @@ -713,8 +704,6 @@ rcinit(void) { char buf[1024]; - struct sysnames *sysvec; - size_t totalsys; unsigned i, j; host_fork = dlsym(RTLD_NEXT, "fork"); @@ -727,38 +716,27 @@ * is a bit of a strech, but it might work. */ - totalsys = __arraycount(sys_mandatory) + __arraycount(sys_optional); for (i = 0; i < DUALCALL__NUM; i++) { /* build runtime O(1) access */ - - sysvec = sys_mandatory; - for (j = 0; j < __arraycount(sys_mandatory); j++) { - if (sys_mandatory[j].scm_callnum == i) -goto found; - } - sysvec = sys_optional; - for (j = 0; j < __arraycount(sys_optional); j++, j++) { - if (sys_optional[j].scm_callnum == i) -goto found; + for (j = 0; j < __arraycount(syscnames); j++) { + if (syscnames[j].scm_callnum == i) +break; } - errx(1, "rumphijack error: syscall pos %d missing", i); - found: + if (j == __arraycount(syscnames)) + errx(1, "rumphijack error: syscall pos %d missing", i); + syscalls[i].bs_host = dlsym(RTLD_NEXT, - sysvec[j].scm_hostname); - if (syscalls[i].bs_host == NULL) { - if (sysvec == sys_optional) -syscalls[i].bs_host = nolibcstub; - else -errx(1, "hostcall %s not found!", -sysvec[j].scm_hostname); - } + syscnames[j].scm_hostname); + if (syscalls[i].bs_host == NULL) + errx(1, "hostcall %s not found!", + syscnames[j].scm_hostname); syscalls[i].bs_rump = dlsym(RTLD_NEXT, - sysvec[j].scm_rumpname); + syscnames[j].scm_rumpname); if (syscalls[i].bs_rump == NULL) errx(1, "rumpcall %s not found!", - sysvec[j].scm_rumpname); + syscnames[j].scm_rumpname); } if (rumpclient_init() == -1) @@ -2194,10 +2172,12 @@ (const char *, int), \ (path, flags)) +#if __NetBSD_Prereq__(5,99,48) PATHCALL(int, REALQUOTACTL, DUALCALL_QUOTACTL,\ (const char *path, struct plistref *p),\ (const char *, struct plistref *),\ (path, p)) +#endif PATHCALL(int, REALGETFH, DUALCALL_GETFH,\ (const char *path, void *fhp, size_t *fh_size), \
CVS commit: src/lib/librumphijack
Module Name:src Committed By: wiz Date: Thu Mar 10 08:53:04 UTC 2011 Modified Files: src/lib/librumphijack: rumphijack.3 Log Message: Add serial commas. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/lib/librumphijack/rumphijack.3 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/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.10 src/lib/librumphijack/rumphijack.3:1.11 --- src/lib/librumphijack/rumphijack.3:1.10 Wed Mar 9 23:40:44 2011 +++ src/lib/librumphijack/rumphijack.3 Thu Mar 10 08:53:04 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.10 2011/03/09 23:40:44 pooka Exp $ +.\" $NetBSD: rumphijack.3,v 1.11 2011/03/10 08:53:04 wiz Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -144,16 +144,16 @@ there is no pathname to make the selection based on. Current possible values are .Dq nfssvc , -.Dq getvfsstat +.Dq getvfsstat , and -.Dq fhcalls. +.Dq fhcalls . They indicate hijacking .Fn nfssvc , -.Fn getvfsstat +.Fn getvfsstat , and all file handle calls, respectively. The file handle calls include .Fn fhopen , -.Fn fhstat +.Fn fhstat , and .Fn fhstatvfs1 . .Pp
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Mar 9 23:40:44 UTC 2011 Modified Files: src/lib/librumphijack: rumphijack.3 Log Message: document vfs and sysctl knobs to RUMPHIJACK To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/lib/librumphijack/rumphijack.3 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/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.9 src/lib/librumphijack/rumphijack.3:1.10 --- src/lib/librumphijack/rumphijack.3:1.9 Tue Mar 8 23:51:23 2011 +++ src/lib/librumphijack/rumphijack.3 Wed Mar 9 23:40:44 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.9 2011/03/08 23:51:23 wiz Exp $ +.\" $NetBSD: rumphijack.3,v 1.10 2011/03/09 23:40:44 pooka Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 8, 2011 +.Dd March 9, 2011 .Dt RUMPHIJACK 3 .Os .Sh NAME @@ -135,6 +135,44 @@ specifies that all protocol families except .Dv PF_INET should be hijacked. +.It Dq vfs +The specifier +.Ar value +contains a colon-separated list of which vfs-related system calls +should be hijacked. +These differ from the pathname-based file system syscalls in that +there is no pathname to make the selection based on. +Current possible values are +.Dq nfssvc , +.Dq getvfsstat +and +.Dq fhcalls. +They indicate hijacking +.Fn nfssvc , +.Fn getvfsstat +and all file handle calls, respectively. +The file handle calls include +.Fn fhopen , +.Fn fhstat +and +.Fn fhstatvfs1 . +.Pp +It is also possible to use +.Dq all +and +.Dq no +in the same fashion as with the socket hijack specifier. +.It Dq sysctl +Direct the +.Fn __sysctl +backend of the +.Xr sysctl 3 +facility to the rump kernel. +Acceptable values are +.Dq yes +and +.Dq no , +meaning to call the rump or the host kernel, respectively. .El .Pp If the environment variable is unset, the default value
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Mar 9 23:26:20 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Make getfh() a pathcall instead of a fhcall. while it does pertain to file handles, it still gets passed a path and we can DTRT based on that. To generate a diff of this commit: cvs rdiff -u -r1.81 -r1.82 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.81 src/lib/librumphijack/hijack.c:1.82 --- src/lib/librumphijack/hijack.c:1.81 Wed Mar 9 20:48:57 2011 +++ src/lib/librumphijack/hijack.c Wed Mar 9 23:26:19 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.81 2011/03/09 20:48:57 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.82 2011/03/09 23:26:19 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.81 2011/03/09 20:48:57 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.82 2011/03/09 23:26:19 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -2199,6 +2199,11 @@ (const char *, struct plistref *),\ (path, p)) +PATHCALL(int, REALGETFH, DUALCALL_GETFH,\ + (const char *path, void *fhp, size_t *fh_size), \ + (const char *, void *, size_t *),\ + (path, fhp, fh_size)) + /* * These act different on a per-process vfs configuration */ @@ -2208,11 +2213,6 @@ (struct statvfs *, size_t, int),\ (buf, buflen, flags)) -VFSCALL(VFSBIT_FHCALLS, int, REALGETFH, DUALCALL_GETFH, \ - (const char *path, void *fhp, size_t *fh_size), \ - (const char *, void *, size_t *),\ - (path, fhp, fh_size)) - VFSCALL(VFSBIT_FHCALLS, int, REALFHOPEN, DUALCALL_FHOPEN, \ (const void *fhp, size_t fh_size, int flags), \ (const char *, size_t, int), \
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Mar 9 20:48:57 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Make this compile/work on NetBSD 5 once again. To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.81 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.80 src/lib/librumphijack/hijack.c:1.81 --- src/lib/librumphijack/hijack.c:1.80 Wed Mar 9 18:45:30 2011 +++ src/lib/librumphijack/hijack.c Wed Mar 9 20:48:57 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.80 2011/03/09 18:45:30 bouyer Exp $ */ +/* $NetBSD: hijack.c,v 1.81 2011/03/09 20:48:57 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.80 2011/03/09 18:45:30 bouyer Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.81 2011/03/09 20:48:57 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -58,7 +58,6 @@ #include #include #include -#include #include "hijack.h" @@ -134,6 +133,7 @@ #define REALMKNOD __mknod50 #define REALFHSTAT __fhstat50 #endif + #define REALREAD _sys_read #define REALPREAD _sys_pread #define REALPWRITE _sys_pwrite @@ -173,7 +173,9 @@ enum dualcall scm_callnum; const char *scm_hostname; const char *scm_rumpname; -} syscnames[] = { +}; + +struct sysnames sys_mandatory[] = { { DUALCALL_SOCKET, "__socket30", RSYS_NAME(SOCKET) }, { DUALCALL_ACCEPT, "accept", RSYS_NAME(ACCEPT) }, { DUALCALL_BIND, "bind", RSYS_NAME(BIND) }, @@ -243,13 +245,23 @@ { DUALCALL_GETVFSSTAT, "getvfsstat", RSYS_NAME(GETVFSSTAT) }, { DUALCALL_NFSSVC, "nfssvc", RSYS_NAME(NFSSVC) }, { DUALCALL_GETFH, S(REALGETFH), RSYS_NAME(GETFH) }, - { DUALCALL_FHOPEN, S(REALFHOPEN),RSYS_NAME(FHOPEN) }, - { DUALCALL_FHSTAT, S(REALFHSTAT),RSYS_NAME(FHSTAT) }, + { DUALCALL_FHOPEN, S(REALFHOPEN), RSYS_NAME(FHOPEN) }, + { DUALCALL_FHSTAT, S(REALFHSTAT), RSYS_NAME(FHSTAT) }, { DUALCALL_FHSTATVFS1, S(REALFHSTATVFS1),RSYS_NAME(FHSTATVFS1) }, +}; + +struct sysnames sys_optional[] = { { DUALCALL_QUOTACTL, S(REALQUOTACTL),RSYS_NAME(QUOTACTL) }, }; #undef S +static int +nolibcstub(void) +{ + + return ENOSYS; +} + struct bothsys { void *bs_host; void *bs_rump; @@ -690,6 +702,9 @@ break; } } + + if (hijackparse[i].parsefn == NULL) + errx(1, "invalid hijack specifier name in %s", p); } } @@ -698,6 +713,8 @@ rcinit(void) { char buf[1024]; + struct sysnames *sysvec; + size_t totalsys; unsigned i, j; host_fork = dlsym(RTLD_NEXT, "fork"); @@ -710,27 +727,38 @@ * is a bit of a strech, but it might work. */ + totalsys = __arraycount(sys_mandatory) + __arraycount(sys_optional); for (i = 0; i < DUALCALL__NUM; i++) { /* build runtime O(1) access */ - for (j = 0; j < __arraycount(syscnames); j++) { - if (syscnames[j].scm_callnum == i) -break; - } - if (j == __arraycount(syscnames)) - errx(1, "rumphijack error: syscall pos %d missing", i); + sysvec = sys_mandatory; + for (j = 0; j < __arraycount(sys_mandatory); j++) { + if (sys_mandatory[j].scm_callnum == i) +goto found; + } + sysvec = sys_optional; + for (j = 0; j < __arraycount(sys_optional); j++, j++) { + if (sys_optional[j].scm_callnum == i) +goto found; + } + errx(1, "rumphijack error: syscall pos %d missing", i); + found: syscalls[i].bs_host = dlsym(RTLD_NEXT, - syscnames[j].scm_hostname); - if (syscalls[i].bs_host == NULL) - errx(1, "hostcall %s not found!", - syscnames[j].scm_hostname); + sysvec[j].scm_hostname); + if (syscalls[i].bs_host == NULL) { + if (sysvec == sys_optional) +syscalls[i].bs_host = nolibcstub; + else +errx(1, "hostcall %s not found!", +sysvec[j].scm_hostname); + } syscalls[i].bs_rump = dlsym(RTLD_NEXT, - syscnames[j].scm_rumpname); + sysvec[j].scm_rumpname); if (syscalls[i].bs_rump == NULL) errx(1, "rumpcall %s not found!", - syscnames[j].scm_rumpname); + sysvec[j].scm_rumpname); } if (rumpclient_init() == -1)
CVS commit: src/lib/librumphijack
Module Name:src Committed By: bouyer Date: Wed Mar 9 18:45:31 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Add quotactl(2) To generate a diff of this commit: cvs rdiff -u -r1.79 -r1.80 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.79 src/lib/librumphijack/hijack.c:1.80 --- src/lib/librumphijack/hijack.c:1.79 Wed Mar 9 18:06:22 2011 +++ src/lib/librumphijack/hijack.c Wed Mar 9 18:45:30 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.79 2011/03/09 18:06:22 bouyer Exp $ */ +/* $NetBSD: hijack.c,v 1.80 2011/03/09 18:45:30 bouyer Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.79 2011/03/09 18:06:22 bouyer Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.80 2011/03/09 18:45:30 bouyer Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -58,6 +58,7 @@ #include #include #include +#include #include "hijack.h" @@ -97,6 +98,7 @@ DUALCALL___SYSCTL, DUALCALL_GETVFSSTAT, DUALCALL_NFSSVC, DUALCALL_GETFH, DUALCALL_FHOPEN, DUALCALL_FHSTAT, DUALCALL_FHSTATVFS1, + DUALCALL_QUOTACTL, DUALCALL__NUM }; @@ -140,6 +142,7 @@ #define REALGETFH __getfh30 #define REALFHOPEN __fhopen40 #define REALFHSTATVFS1 __fhstatvfs140 +#define REALQUOTACTL __quotactl50 int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *); int REALPOLLTS(struct pollfd *, nfds_t, @@ -163,6 +166,7 @@ int REALFHOPEN(const void *, size_t, int); int REALFHSTAT(const void *, size_t, struct stat *); int REALFHSTATVFS1(const void *, size_t, struct statvfs *, int); +int REALQUOTACTL(const char *, struct plistref *); #define S(a) __STRING(a) struct sysnames { @@ -242,6 +246,7 @@ { DUALCALL_FHOPEN, S(REALFHOPEN),RSYS_NAME(FHOPEN) }, { DUALCALL_FHSTAT, S(REALFHSTAT),RSYS_NAME(FHSTAT) }, { DUALCALL_FHSTATVFS1, S(REALFHSTATVFS1),RSYS_NAME(FHSTATVFS1) }, + { DUALCALL_QUOTACTL, S(REALQUOTACTL),RSYS_NAME(QUOTACTL) }, }; #undef S @@ -2161,6 +2166,11 @@ (const char *, int), \ (path, flags)) +PATHCALL(int, REALQUOTACTL, DUALCALL_QUOTACTL,\ + (const char *path, struct plistref *p),\ + (const char *, struct plistref *),\ + (path, p)) + /* * These act different on a per-process vfs configuration */
CVS commit: src/lib/librumphijack
Module Name:src Committed By: bouyer Date: Wed Mar 9 18:06:22 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Fix last entries, make it work again. To generate a diff of this commit: cvs rdiff -u -r1.78 -r1.79 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.78 src/lib/librumphijack/hijack.c:1.79 --- src/lib/librumphijack/hijack.c:1.78 Wed Mar 9 15:03:18 2011 +++ src/lib/librumphijack/hijack.c Wed Mar 9 18:06:22 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.78 2011/03/09 15:03:18 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.79 2011/03/09 18:06:22 bouyer Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.78 2011/03/09 15:03:18 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.79 2011/03/09 18:06:22 bouyer Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -238,10 +238,10 @@ { DUALCALL___SYSCTL, "__sysctl", RSYS_NAME(__SYSCTL) }, { DUALCALL_GETVFSSTAT, "getvfsstat", RSYS_NAME(GETVFSSTAT) }, { DUALCALL_NFSSVC, "nfssvc", RSYS_NAME(NFSSVC) }, - { DUALCALL_GETFH, "S(REALGETFH)", RSYS_NAME(GETFH) }, - { DUALCALL_FHOPEN, "S(REALFHOPEN)",RSYS_NAME(FHOPEN) }, - { DUALCALL_FHSTAT, "S(REALFHSTAT)",RSYS_NAME(FHSTAT) }, - { DUALCALL_FHSTATVFS1, "S(REALSTATVFS1)",RSYS_NAME(FHSTATVFS1) }, + { DUALCALL_GETFH, S(REALGETFH), RSYS_NAME(GETFH) }, + { DUALCALL_FHOPEN, S(REALFHOPEN),RSYS_NAME(FHOPEN) }, + { DUALCALL_FHSTAT, S(REALFHSTAT),RSYS_NAME(FHSTAT) }, + { DUALCALL_FHSTATVFS1, S(REALFHSTATVFS1),RSYS_NAME(FHSTATVFS1) }, }; #undef S
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Mar 9 15:03:18 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Add a bunch of process-wide hijack calls. Among other things, it's now possible to use unmodified userspace binaries (rpcbind, mountd, nfsd) to start a rump nfs service and mount file systems from it. pain-rustique:42:~> mount rumpfs on / type rumpfs (local) 10.1.1.1:/export on /mnt type nfs To generate a diff of this commit: cvs rdiff -u -r1.77 -r1.78 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.77 src/lib/librumphijack/hijack.c:1.78 --- src/lib/librumphijack/hijack.c:1.77 Wed Mar 9 09:17:12 2011 +++ src/lib/librumphijack/hijack.c Wed Mar 9 15:03:18 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.77 2011/03/09 09:17:12 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.78 2011/03/09 15:03:18 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.77 2011/03/09 09:17:12 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.78 2011/03/09 15:03:18 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -94,6 +94,9 @@ DUALCALL_CHFLAGS, DUALCALL_LCHFLAGS, DUALCALL_FCHFLAGS, DUALCALL_ACCESS, DUALCALL_MKNOD, + DUALCALL___SYSCTL, + DUALCALL_GETVFSSTAT, DUALCALL_NFSSVC, + DUALCALL_GETFH, DUALCALL_FHOPEN, DUALCALL_FHSTAT, DUALCALL_FHSTATVFS1, DUALCALL__NUM }; @@ -115,6 +118,7 @@ #define REALLUTIMES lutimes #define REALFUTIMES futimes #define REALMKNOD mknod +#define REALFHSTAT __fhstat40 #else #define REALSELECT _sys___select50 #define REALPOLLTS _sys___pollts50 @@ -126,12 +130,16 @@ #define REALLUTIMES __lutimes50 #define REALFUTIMES __futimes50 #define REALMKNOD __mknod50 +#define REALFHSTAT __fhstat50 #endif #define REALREAD _sys_read #define REALPREAD _sys_pread #define REALPWRITE _sys_pwrite #define REALGETDENTS __getdents30 #define REALMOUNT __mount50 +#define REALGETFH __getfh30 +#define REALFHOPEN __fhopen40 +#define REALFHSTATVFS1 __fhstatvfs140 int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *); int REALPOLLTS(struct pollfd *, nfds_t, @@ -151,6 +159,10 @@ int REALMOUNT(const char *, const char *, int, void *, size_t); int __getcwd(char *, size_t); int REALMKNOD(const char *, mode_t, dev_t); +int REALGETFH(const char *, void *, size_t *); +int REALFHOPEN(const void *, size_t, int); +int REALFHSTAT(const void *, size_t, struct stat *); +int REALFHSTATVFS1(const void *, size_t, struct statvfs *, int); #define S(a) __STRING(a) struct sysnames { @@ -223,6 +235,13 @@ { DUALCALL_FCHFLAGS, "fchflags", RSYS_NAME(FCHFLAGS) }, { DUALCALL_ACCESS, "access", RSYS_NAME(ACCESS) }, { DUALCALL_MKNOD, S(REALMKNOD), RSYS_NAME(MKNOD) }, + { DUALCALL___SYSCTL, "__sysctl", RSYS_NAME(__SYSCTL) }, + { DUALCALL_GETVFSSTAT, "getvfsstat", RSYS_NAME(GETVFSSTAT) }, + { DUALCALL_NFSSVC, "nfssvc", RSYS_NAME(NFSSVC) }, + { DUALCALL_GETFH, "S(REALGETFH)", RSYS_NAME(GETFH) }, + { DUALCALL_FHOPEN, "S(REALFHOPEN)",RSYS_NAME(FHOPEN) }, + { DUALCALL_FHSTAT, "S(REALFHSTAT)",RSYS_NAME(FHSTAT) }, + { DUALCALL_FHSTATVFS1, "S(REALSTATVFS1)",RSYS_NAME(FHSTATVFS1) }, }; #undef S @@ -403,6 +422,21 @@ return fun vars; \ } +#define VFSCALL(bit, type, name, rcname, args, proto, vars) \ +type name args\ +{ \ + type (*fun) proto; \ + \ + DPRINTF(("%s (0x%x, 0x%x)\n", __STRING(name), bit, vfsbits)); \ + if (vfsbits & bit) { \ + fun = syscalls[rcname].bs_rump;\ + } else { \ + fun = syscalls[rcname].bs_host;\ + }\ + \ + return fun vars; \ +} + /* * These variables are set from the RUMPHIJACK string and control * which operations can product rump kernel file descriptors. @@ -462,7 +496,7 @@ } } if (socketmap[i].name == NULL) { - warnx("invalid socket specifier %s", p); + errx(1, "invalid socket specifier %s", p); } } } @@ -519,14 +553,103 @@ } } +#define VFSBIT_NFSSVC 0x01 +#define VFSBIT_GETVFSSTAT 0x02 +#define VFSBIT_FHCALLS 0x04 +static unsigned vfsbits; + +static struct { + int bit; + const char *name; +} vfscalls[] = { + { VFSBIT_NFSSVC, "nfssvc" }, + { VFSBIT_GETVFSSTAT, "getvfsstat" }, + { VFSBIT_FHCALLS, "fhcalls" }, + { -1, NULL } +}; + +static void +vfsparser(char *buf) +{ + char *p, *l; + bool turnon; + unsigned int fullmask; + int i; + + /* build the full mask and sanity-check while we're at it */ + fullmask = 0; + for (i = 0; vfscalls[i].name != NULL; i++) { + if (fullmask & vfscalls[i].bit) + errx(1, "problem exists between vi and chair"); + fullmask |= vfscalls[i].bit; + } + + + /* if "all" is present, it must be specified first */ + if (strncmp(buf, "all", strlen("all")) == 0) { + vfsbits = fullmask; + buf += strlen
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Mar 9 09:17:12 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: g/c unused global To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 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.76 src/lib/librumphijack/hijack.c:1.77 --- src/lib/librumphijack/hijack.c:1.76 Tue Mar 8 21:36:01 2011 +++ src/lib/librumphijack/hijack.c Wed Mar 9 09:17:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.76 2011/03/08 21:36:01 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.77 2011/03/09 09:17:12 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.76 2011/03/08 21:36:01 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.77 2011/03/09 09:17:12 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -234,7 +234,6 @@ static pid_t (*host_fork)(void); static int (*host_daemon)(int, int); -static int (*host_execve)(const char *, char *const[], char *const[]); static void * (*host_mmap)(void *, size_t, int, int, int, off_t); /* @@ -568,7 +567,6 @@ host_fork = dlsym(RTLD_NEXT, "fork"); host_daemon = dlsym(RTLD_NEXT, "daemon"); - host_execve = dlsym(RTLD_NEXT, "execve"); host_mmap = dlsym(RTLD_NEXT, "mmap"); /*
CVS commit: src/lib/librumphijack
Module Name:src Committed By: wiz Date: Tue Mar 8 23:51:23 UTC 2011 Modified Files: src/lib/librumphijack: rumphijack.3 Log Message: Remove trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/lib/librumphijack/rumphijack.3 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/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.8 src/lib/librumphijack/rumphijack.3:1.9 --- src/lib/librumphijack/rumphijack.3:1.8 Tue Mar 8 21:09:18 2011 +++ src/lib/librumphijack/rumphijack.3 Tue Mar 8 23:51:23 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.8 2011/03/08 21:09:18 pooka Exp $ +.\" $NetBSD: rumphijack.3,v 1.9 2011/03/08 23:51:23 wiz Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -103,7 +103,7 @@ instead of .Pa /dev unless necessary to do otherwise. -Also, note that the blanket prefix does not follow directory borders. +Also, note that the blanket prefix does not follow directory borders. In other words, setting the blanket for .Pa /dev/bpf means it is set for
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Mar 8 21:36:01 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Enforce that the path=/rump specifier specifies and actual path prefix and doesn't accept e.g. /rumpdev (only /rump/dev). To generate a diff of this commit: cvs rdiff -u -r1.75 -r1.76 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.75 src/lib/librumphijack/hijack.c:1.76 --- src/lib/librumphijack/hijack.c:1.75 Tue Mar 8 20:59:01 2011 +++ src/lib/librumphijack/hijack.c Tue Mar 8 21:36:01 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.75 2011/03/08 20:59:01 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.76 2011/03/08 21:36:01 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.75 2011/03/08 20:59:01 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.76 2011/03/08 21:36:01 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -692,14 +692,18 @@ static enum pathtype path_isrump(const char *path) { + size_t plen; int i; if (rumpprefix == NULL && nblanket == 0) return PATH_HOST; if (*path == '/') { - if (rumpprefix) { - if (strncmp(path, rumpprefix, rumpprefixlen) == 0) { + plen = strlen(path); + if (rumpprefix && plen >= rumpprefixlen) { + if (strncmp(path, rumpprefix, rumpprefixlen) == 0 + && (plen == rumpprefixlen + || *(path + rumpprefixlen) == '/')) { return PATH_RUMP; } }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Mar 8 21:09:19 UTC 2011 Modified Files: src/lib/librumphijack: rumphijack.3 Log Message: clarify blanket operation a bit more To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/lib/librumphijack/rumphijack.3 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/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.7 src/lib/librumphijack/rumphijack.3:1.8 --- src/lib/librumphijack/rumphijack.3:1.7 Tue Mar 8 21:02:22 2011 +++ src/lib/librumphijack/rumphijack.3 Tue Mar 8 21:09:18 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.7 2011/03/08 21:02:22 pooka Exp $ +.\" $NetBSD: rumphijack.3,v 1.8 2011/03/08 21:09:18 pooka Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -103,6 +103,13 @@ instead of .Pa /dev unless necessary to do otherwise. +Also, note that the blanket prefix does not follow directory borders. +In other words, setting the blanket for +.Pa /dev/bpf +means it is set for +.Em all +pathnames with the given prefix, not just ones in +.Pa /dev . .It Dq socket The specifier .Ar value
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Mar 8 21:02:22 UTC 2011 Modified Files: src/lib/librumphijack: rumphijack.3 Log Message: maybe typo To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/librumphijack/rumphijack.3 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/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.6 src/lib/librumphijack/rumphijack.3:1.7 --- src/lib/librumphijack/rumphijack.3:1.6 Tue Mar 8 20:59:01 2011 +++ src/lib/librumphijack/rumphijack.3 Tue Mar 8 21:02:22 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.6 2011/03/08 20:59:01 pooka Exp $ +.\" $NetBSD: rumphijack.3,v 1.7 2011/03/08 21:02:22 pooka Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -92,7 +92,7 @@ In case the current working directory is changed to a blanketed directory, the current working directory will still be reported with the rump prefix, if available. -Note, though, that some shells cache the directory and maybe report +Note, though, that some shells cache the directory and may report something else. In case no rump path prefix has been configured, the raw rump directory is reported.
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Mar 8 20:59:02 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c rumphijack.3 Log Message: Add ``blanket''. It acts like path, except that the prefix does _not_ get removed if the call goes to the rump namespace. So, now it's possible to use e.g. tcpdump (and most other utilities which hardcore a /dev pathname) on a rump kernel: golem> setenv RUMPHIJACK blanket=/dev/bpf golem> tcpdump -n -i virt0 tcpdump: WARNING: SIOCGIFADDR: virt0: Device not configured tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on virt0, link-type EN10MB (Ethernet), capture size 96 bytes 21:55:38.925596 IP 192.168.2.101 > 204.152.190.12: ICMP echo request, id 47811, seq 0, length 64 21:55:39.095596 IP 204.152.190.12 > 192.168.2.101: ICMP echo reply, id 47811, seq 0, length 64 (if you additionally set socket=all in RUMPHIJACK, tcpdump doesn't whine about the "not configured" interface) To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/lib/librumphijack/hijack.c cvs rdiff -u -r1.5 -r1.6 src/lib/librumphijack/rumphijack.3 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.74 src/lib/librumphijack/hijack.c:1.75 --- src/lib/librumphijack/hijack.c:1.74 Tue Mar 1 10:54:06 2011 +++ src/lib/librumphijack/hijack.c Tue Mar 8 20:59:01 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.74 2011/03/01 10:54:06 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.75 2011/03/08 20:59:01 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.74 2011/03/01 10:54:06 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.75 2011/03/08 20:59:01 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -237,8 +237,16 @@ static int (*host_execve)(const char *, char *const[], char *const[]); static void * (*host_mmap)(void *, size_t, int, int, int, off_t); -static bool fd_isrump(int); -static bool path_isrump(const char *); +/* + * This tracks if our process is in a subdirectory of /rump. + * It's preserved over exec. + */ +static bool pwdinrump; + +enum pathtype { PATH_HOST, PATH_RUMP, PATH_RUMPBLANKET }; + +static bool fd_isrump(int); +static enum pathtype path_isrump(const char *); /* * Maintain a mapping table for the usual dup2 suspects. @@ -381,12 +389,14 @@ type name args\ { \ type (*fun) proto; \ + enum pathtype pt; \ \ DPRINTF(("%s -> %s (%s)\n", __STRING(name), path, \ whichpath(path))); \ - if (path_isrump(path)) { \ + if ((pt = path_isrump(path)) != PATH_HOST) { \ fun = syscalls[rcname].bs_rump;\ - path = path_host2rump(path);\ + if (pt == PATH_RUMP) \ + path = path_host2rump(path); \ } else { \ fun = syscalls[rcname].bs_host;\ }\ @@ -395,12 +405,6 @@ } /* - * This tracks if our process is in a subdirectory of /rump. - * It's preserved over exec. - */ -static bool pwdinrump = false; - -/* * These variables are set from the RUMPHIJACK string and control * which operations can product rump kernel file descriptors. * This should be easily extendable for future needs. @@ -483,12 +487,46 @@ rumpprefixlen = strlen(rumpprefix); } +static struct blanket { + const char *pfx; + size_t len; +} *blanket; +static int nblanket; + +static void +blanketparser(char *buf) +{ + char *p, *l; + int i; + + for (nblanket = 0, p = buf; p; p = strchr(p+1, ':'), nblanket++) + continue; + + blanket = malloc(nblanket * sizeof(*blanket)); + if (blanket == NULL) + err(1, "alloc blanket %d", nblanket); + + for (p = strtok_r(buf, ":", &l), i = 0; p; + p = strtok_r(NULL, ":", &l), i++) { + blanket[i].pfx = strdup(p); + if (blanket[i].pfx == NULL) + err(1, "strdup blanket"); + blanket[i].len = strlen(p); + + if (blanket[i].len == 0 || *blanket[i].pfx != '/') + errx(1, "invalid blanket specifier %s", p); + if (*(blanket[i].pfx + blanket[i].len-1) == '/') + errx(1, "invalid blanket specifier %s", p); + } +} + static struct { void (*parsefn)(char *); const char *name; } hijackparse[] = { { sockparser, "socket" }, { pathparser, "path" }, + { blanketparser, "blanket" }, { NULL, NULL }, }; @@ -651,19 +689,28 @@ #define assertfd(_fd_) assert(ISDUP2D(_fd_) || (_fd_) >= HIJACK_FDOFF) -static bool +static enum pathtype path_isrump(const char *path) { + int i; - if (rumpprefix == NULL) - return false; + if (rumpprefix == NULL && nblanket == 0) + return PATH_HOST; if (*path == '/') { - if (strncmp(path, rumpprefix, rumpprefixlen) == 0) - return true; - return false; + if (rumpprefix) { + if (strncmp(path, rumpprefix, rumpprefixlen) == 0) { +return PATH_RUMP; + } + } + for (i = 0; i < nblanket; i++) { + if (strncmp(
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Mar 1 10:54:06 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: another comment To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 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.73 src/lib/librumphijack/hijack.c:1.74 --- src/lib/librumphijack/hijack.c:1.73 Tue Mar 1 10:47:29 2011 +++ src/lib/librumphijack/hijack.c Tue Mar 1 10:54:06 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.73 2011/03/01 10:47:29 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.74 2011/03/01 10:54:06 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.73 2011/03/01 10:47:29 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.74 2011/03/01 10:54:06 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -242,6 +242,8 @@ /* * Maintain a mapping table for the usual dup2 suspects. + * Could use atomic ops to operate on dup2vec, but an application + * racing there is not well-defined, so don't bother. */ /* note: you cannot change this without editing the env-passing code */ #define DUP2HIGH 2
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Mar 1 10:47:30 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: comment To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.73 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.72 src/lib/librumphijack/hijack.c:1.73 --- src/lib/librumphijack/hijack.c:1.72 Mon Feb 28 20:39:07 2011 +++ src/lib/librumphijack/hijack.c Tue Mar 1 10:47:29 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.72 2011/02/28 20:39:07 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.73 2011/03/01 10:47:29 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.72 2011/02/28 20:39:07 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.73 2011/03/01 10:47:29 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -1480,6 +1480,11 @@ /* * then, open two pipes, one for notifications * to each kernel. + * + * At least the rump pipe should probably be + * cached, along with the helper threads. This + * should give a microbenchmark improvement (haven't + * experienced a macro-level problem yet, though). */ if ((rv = rump_sys_pipe(rpipe)) == -1) { sverrno = errno;
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Feb 28 20:39:07 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: make compiler sign-happy To generate a diff of this commit: cvs rdiff -u -r1.71 -r1.72 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.71 src/lib/librumphijack/hijack.c:1.72 --- src/lib/librumphijack/hijack.c:1.71 Mon Feb 28 19:57:36 2011 +++ src/lib/librumphijack/hijack.c Mon Feb 28 20:39:07 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.71 2011/02/28 19:57:36 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.72 2011/02/28 20:39:07 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.71 2011/02/28 19:57:36 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.72 2011/02/28 20:39:07 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -271,7 +271,8 @@ int i; for (i = 0; i <= DUP2HIGH; i++) { - if (dup2vec[i] & DUP2BIT && (dup2vec[i] & DUP2FDMASK) == rumpfd) + if (dup2vec[i] & DUP2BIT && + (dup2vec[i] & DUP2FDMASK) == (unsigned)rumpfd) return i; } return -1; @@ -1002,8 +1003,12 @@ */ for (i = 0, maxdup2 = 0; i <= DUP2HIGH; i++) { - if (dup2vec[i] & DUP2BIT) -maxdup2 = MAX(dup2vec[i] & DUP2FDMASK, maxdup2); + if (dup2vec[i] & DUP2BIT) { +int val; + +val = dup2vec[i] & DUP2FDMASK; +maxdup2 = MAX(val, maxdup2); + } } if (fd >= HIJACK_FDOFF)
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Feb 28 19:57:37 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: A simple dup2-enforced affine transformation isn't enough when dealing with dup2() from a rump kernel fd to a host kernel fd. Consider: s1 = socket(); s2 = socket(); dup2(s2, 0); Instead, maintain a real mapping table (and get on my knees and pray i don't have to touch this hair-splitting code ever again). Apparently bourne shell scripts from a rump kernel fs work now (sh script.sh; ./script.sh doesn't work for obvious "IT'S THE WRONG FS NAMESPACE" reasons). No test regressions either, so I'm a happy camper. To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 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.70 src/lib/librumphijack/hijack.c:1.71 --- src/lib/librumphijack/hijack.c:1.70 Sun Feb 27 11:32:12 2011 +++ src/lib/librumphijack/hijack.c Mon Feb 28 19:57:36 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.70 2011/02/27 11:32:12 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.71 2011/02/28 19:57:36 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.70 2011/02/27 11:32:12 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.71 2011/02/28 19:57:36 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -232,23 +232,89 @@ } syscalls[DUALCALL__NUM]; #define GETSYSCALL(which, name) syscalls[DUALCALL_##name].bs_##which -pid_t (*host_fork)(void); -int (*host_daemon)(int, int); -int (*host_execve)(const char *, char *const[], char *const[]); -void * (*host_mmap)(void *, size_t, int, int, int, off_t); - -/* ok, we need *two* bits per dup2'd fd to track fd+HIJACKOFF aliases */ -static uint32_t dup2mask; -#define ISDUP2D(fd) (((fd) < 16) && (1<<(fd) & dup2mask)) -#define SETDUP2(fd) \ -do { if ((fd) < 16) dup2mask |= (1<<(fd)); } while (/*CONSTCOND*/0) -#define CLRDUP2(fd) \ -do { if ((fd) < 16) dup2mask &= ~(1<<(fd)); } while (/*CONSTCOND*/0) -#define ISDUP2ALIAS(fd) (((fd) < 16) && (1<<((fd)+16) & dup2mask)) -#define SETDUP2ALIAS(fd) \ -do { if ((fd) < 16) dup2mask |= (1<<((fd)+16)); } while (/*CONSTCOND*/0) -#define CLRDUP2ALIAS(fd) \ -do { if ((fd) < 16) dup2mask &= ~(1<<((fd)+16)); } while (/*CONSTCOND*/0) +static pid_t (*host_fork)(void); +static int (*host_daemon)(int, int); +static int (*host_execve)(const char *, char *const[], char *const[]); +static void * (*host_mmap)(void *, size_t, int, int, int, off_t); + +static bool fd_isrump(int); +static bool path_isrump(const char *); + +/* + * Maintain a mapping table for the usual dup2 suspects. + */ +/* note: you cannot change this without editing the env-passing code */ +#define DUP2HIGH 2 +static uint32_t dup2vec[DUP2HIGH+1]; +#define DUP2BIT (1<<31) +#define DUP2ALIAS (1<<30) +#define DUP2FDMASK ((1<<30)-1) + +static bool +isdup2d(int fd) +{ + + return fd <= DUP2HIGH && fd >= 0 && dup2vec[fd] & DUP2BIT; +} + +static int +mapdup2(int hostfd) +{ + + _DIAGASSERT(isdup2d(hostfd)); + return dup2vec[hostfd] & DUP2FDMASK; +} + +static int +unmapdup2(int rumpfd) +{ + int i; + + for (i = 0; i <= DUP2HIGH; i++) { + if (dup2vec[i] & DUP2BIT && (dup2vec[i] & DUP2FDMASK) == rumpfd) + return i; + } + return -1; +} + +static void +setdup2(int hostfd, int rumpfd) +{ + + if (hostfd > DUP2HIGH) { + _DIAGASSERT(0); + return; + } + + dup2vec[hostfd] = DUP2BIT | DUP2ALIAS | rumpfd; +} + +static void +clrdup2(int hostfd) +{ + + if (hostfd > DUP2HIGH) { + _DIAGASSERT(0); + return; + } + + dup2vec[hostfd] = 0; +} + +static bool +killdup2alias(int rumpfd) +{ + int hostfd; + + if ((hostfd = unmapdup2(rumpfd)) == -1) + return false; + + if (dup2vec[hostfd] & DUP2ALIAS) { + dup2vec[hostfd] &= ~DUP2ALIAS; + return true; + } + return false; +} //#define DEBUGJACK #ifdef DEBUGJACK @@ -258,7 +324,7 @@ { va_list ap; - if (ISDUP2D(STDERR_FILENO)) + if (isdup2d(STDERR_FILENO)) return; va_start(ap, fmt); @@ -266,6 +332,28 @@ va_end(ap); } +static const char * +whichfd(int fd) +{ + + if (fd == -1) + return "-1"; + else if (fd_isrump(fd)) + return "rump"; + else + return "host"; +} + +static const char * +whichpath(const char *path) +{ + + if (path_isrump(path)) + return "rump"; + else + return "host"; +} + #else #define DPRINTF(x) #endif @@ -275,7 +363,7 @@ { \ type (*fun) proto; \ \ - DPRINTF(("%s -> %d\n", __STRING(name), fd)); \ + DPRINTF(("%s -> %d (%s)\n", __STRING(name), fd, whichfd(fd))); \ if (fd_isrump(fd)) { \ fun = syscalls[rcname].bs_rump;\ fd = fd_host2rump(fd); \ @@ -291,7 +379,8 @@ { \ type (*fun) proto; \ \ - DPRINTF(("%s -> %s\n", __STRING(name), path)); \ + DPRINTF(("%s -> %s (
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Sun Feb 27 11:32:13 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: make error messages sensible. from uwe To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 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.69 src/lib/librumphijack/hijack.c:1.70 --- src/lib/librumphijack/hijack.c:1.69 Fri Feb 25 18:36:36 2011 +++ src/lib/librumphijack/hijack.c Sun Feb 27 11:32:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.69 2011/02/25 18:36:36 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.70 2011/02/27 11:32:12 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.69 2011/02/25 18:36:36 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.70 2011/02/27 11:32:12 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -460,13 +460,13 @@ syscalls[i].bs_host = dlsym(RTLD_NEXT, syscnames[j].scm_hostname); if (syscalls[i].bs_host == NULL) - errx(1, "hostcall %s not found missing", + errx(1, "hostcall %s not found!", syscnames[j].scm_hostname); syscalls[i].bs_rump = dlsym(RTLD_NEXT, syscnames[j].scm_rumpname); if (syscalls[i].bs_rump == NULL) - errx(1, "rumpcall %s not found missing", + errx(1, "rumpcall %s not found!", syscnames[j].scm_rumpname); }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 25 18:36:37 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: whoops, didn't mean to delete futimes in previous. also from riz To generate a diff of this commit: cvs rdiff -u -r1.68 -r1.69 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.68 src/lib/librumphijack/hijack.c:1.69 --- src/lib/librumphijack/hijack.c:1.68 Fri Feb 25 18:29:00 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 25 18:36:36 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.68 2011/02/25 18:29:00 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.69 2011/02/25 18:36:36 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.68 2011/02/25 18:29:00 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.69 2011/02/25 18:36:36 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -124,6 +124,7 @@ #define REALFSTAT __fstat50 #define REALUTIMES __utimes50 #define REALLUTIMES __lutimes50 +#define REALFUTIMES __futimes50 #define REALMKNOD __mknod50 #endif #define REALREAD _sys_read
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 25 18:29:01 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: support mknod. from riz To generate a diff of this commit: cvs rdiff -u -r1.67 -r1.68 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.67 src/lib/librumphijack/hijack.c:1.68 --- src/lib/librumphijack/hijack.c:1.67 Thu Feb 24 12:25:44 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 25 18:29:00 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.67 2011/02/24 12:25:44 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.68 2011/02/25 18:29:00 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.67 2011/02/24 12:25:44 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.68 2011/02/25 18:29:00 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -93,6 +93,7 @@ DUALCALL___GETCWD, DUALCALL_CHFLAGS, DUALCALL_LCHFLAGS, DUALCALL_FCHFLAGS, DUALCALL_ACCESS, + DUALCALL_MKNOD, DUALCALL__NUM }; @@ -113,6 +114,7 @@ #define REALUTIMES utimes #define REALLUTIMES lutimes #define REALFUTIMES futimes +#define REALMKNOD mknod #else #define REALSELECT _sys___select50 #define REALPOLLTS _sys___pollts50 @@ -122,7 +124,7 @@ #define REALFSTAT __fstat50 #define REALUTIMES __utimes50 #define REALLUTIMES __lutimes50 -#define REALFUTIMES __futimes50 +#define REALMKNOD __mknod50 #endif #define REALREAD _sys_read #define REALPREAD _sys_pread @@ -147,6 +149,7 @@ int REALFUTIMES(int, const struct timeval [2]); int REALMOUNT(const char *, const char *, int, void *, size_t); int __getcwd(char *, size_t); +int REALMKNOD(const char *, mode_t, dev_t); #define S(a) __STRING(a) struct sysnames { @@ -218,6 +221,7 @@ { DUALCALL_LCHFLAGS, "lchflags", RSYS_NAME(LCHFLAGS) }, { DUALCALL_FCHFLAGS, "fchflags", RSYS_NAME(FCHFLAGS) }, { DUALCALL_ACCESS, "access", RSYS_NAME(ACCESS) }, + { DUALCALL_MKNOD, S(REALMKNOD), RSYS_NAME(MKNOD) }, }; #undef S @@ -1808,6 +1812,11 @@ (const char *, int), \ (path, mode)) +PATHCALL(int, REALMKNOD, DUALCALL_MKNOD,\ + (const char *path, mode_t mode, dev_t dev), \ + (const char *, mode_t, dev_t), \ + (path, mode, dev)) + /* * Note: with mount the decisive parameter is the mount * destination directory. This is because we don't really know
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 25 16:01:42 UTC 2011 Modified Files: src/lib/librumphijack: Makefile hijackdlsym.c Log Message: Ok, for reasons I can't begin to understand, the binaries I tested yesterday on powerpc broke overnight. Apparently adding one more function before the call to dlsym() fixes things again. I hope I don't have to add another one tomorrow To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/lib/librumphijack/Makefile cvs rdiff -u -r1.1 -r1.2 src/lib/librumphijack/hijackdlsym.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/Makefile diff -u src/lib/librumphijack/Makefile:1.7 src/lib/librumphijack/Makefile:1.8 --- src/lib/librumphijack/Makefile:1.7 Wed Feb 23 15:23:15 2011 +++ src/lib/librumphijack/Makefile Fri Feb 25 16:01:41 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.7 2011/02/23 15:23:15 pooka Exp $ +# $NetBSD: Makefile,v 1.8 2011/02/25 16:01:41 pooka Exp $ # LIB= rumphijack @@ -14,8 +14,8 @@ WARNS= 4 -#DBG=-g -#NOGCCERROR=1 -COPTS.hijackdlsym.c+= -fno-optimize-sibling-calls +# make sure the compiler doesn't get clever, since we need +# a stack frame +COPTS.hijackdlsym.c+= -O0 .include Index: src/lib/librumphijack/hijackdlsym.c diff -u src/lib/librumphijack/hijackdlsym.c:1.1 src/lib/librumphijack/hijackdlsym.c:1.2 --- src/lib/librumphijack/hijackdlsym.c:1.1 Wed Feb 23 15:23:15 2011 +++ src/lib/librumphijack/hijackdlsym.c Fri Feb 25 16:01:41 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijackdlsym.c,v 1.1 2011/02/23 15:23:15 pooka Exp $ */ +/* $NetBSD: hijackdlsym.c,v 1.2 2011/02/25 16:01:41 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijackdlsym.c,v 1.1 2011/02/23 15:23:15 pooka Exp $"); +__RCSID("$NetBSD: hijackdlsym.c,v 1.2 2011/02/25 16:01:41 pooka Exp $"); #include @@ -36,12 +36,22 @@ * This is called from librumpclient in case of LD_PRELOAD. * It ensures correct RTLD_NEXT. * - * (note, this module is compiled with -fno-optimize-sibling-calls - * to make sure this function is not treated as a tailcall) + * (note, this module is compiled with -O0 to make sure this + * function is not treated as a tailcall or other optimizations + * applied) */ + +/* why is this indirection required for powerpc */ +static void * __noinline +bouncer(void *handle, const char *symbol) +{ + + return dlsym(handle, symbol); +} + void * rumphijack_dlsym(void *handle, const char *symbol) { - return dlsym(handle, symbol); + return bouncer(handle, symbol); }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Feb 23 18:18:24 UTC 2011 Added Files: src/lib/librumphijack: hijack.h Log Message: duh, remember to cvs add hijack.h too... from pgoyette To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/lib/librumphijack/hijack.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Added files: Index: src/lib/librumphijack/hijack.h diff -u /dev/null src/lib/librumphijack/hijack.h:1.1 --- /dev/null Wed Feb 23 18:18:24 2011 +++ src/lib/librumphijack/hijack.h Wed Feb 23 18:18:24 2011 @@ -0,0 +1,28 @@ +/* $NetBSD: hijack.h,v 1.1 2011/02/23 18:18:24 pooka Exp $ */ + +/*- + * Copyright (c) 2011 Antti Kantee. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +void *rumphijack_dlsym(void *, const char *);
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Feb 23 15:44:39 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Return value audit: properly set errno and return -1. Fixes at least cross-kernel mv(1). To generate a diff of this commit: cvs rdiff -u -r1.65 -r1.66 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.65 src/lib/librumphijack/hijack.c:1.66 --- src/lib/librumphijack/hijack.c:1.65 Wed Feb 23 15:29:21 2011 +++ src/lib/librumphijack/hijack.c Wed Feb 23 15:44:38 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.65 2011/02/23 15:29:21 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.66 2011/02/23 15:44:38 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.65 2011/02/23 15:29:21 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.66 2011/02/23 15:44:38 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -722,7 +722,8 @@ else prefixgap = rumpprefixlen; /* ``/pfx+/path'' */ if (len <= prefixgap) { - return ERANGE; + errno = ERANGE; + return -1; } op___getcwd = GETSYSCALL(rump, __GETCWD); @@ -754,15 +755,19 @@ int (*op_rename)(const char *, const char *); if (path_isrump(from)) { - if (!path_isrump(to)) - return EXDEV; + if (!path_isrump(to)) { + errno = EXDEV; + return -1; + } from = path_host2rump(from); to = path_host2rump(to); op_rename = GETSYSCALL(rump, RENAME); } else { - if (path_isrump(to)) - return EXDEV; + if (path_isrump(to)) { + errno = EXDEV; + return -1; + } op_rename = GETSYSCALL(host, RENAME); } @@ -1008,8 +1013,10 @@ DPRINTF(("dup2 -> %d (o) -> %d (n)\n", oldd, newd)); if (fd_isrump(oldd)) { - if (!(newd >= 0 && newd <= 2)) - return EBADF; + if (!(newd >= 0 && newd <= 2)) { + errno = EBADF; + return -1; + } oldd = fd_host2rump(oldd); if (oldd == newd) { SETDUP2(newd); @@ -1082,8 +1089,10 @@ if (dup2mask) { snprintf(buf, sizeof(buf), "RUMPHIJACK__DUP2MASK=%u", dup2mask); dup2str = malloc(strlen(buf)+1); - if (dup2str == NULL) - return ENOMEM; + if (dup2str == NULL) { + errno = ENOMEM; + return -1; + } strcpy(dup2str, buf); bonus++; } else { @@ -1102,7 +,8 @@ newenv = malloc(sizeof(*newenv) * nelem+bonus); if (newenv == NULL) { free(dup2str); - return ENOMEM; + errno = ENOMEM; + return -1; } memcpy(newenv, envp, nelem*sizeof(*newenv)); if (dup2str) { @@ -1502,8 +1512,10 @@ ev = &changelist[i]; if (ev->filter == EVFILT_READ || ev->filter == EVFILT_WRITE || ev->filter == EVFILT_VNODE) { - if (fd_isrump((int)ev->ident)) -return ENOTSUP; + if (fd_isrump((int)ev->ident)) { +errno = ENOTSUP; +return -1; + } } }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Feb 23 15:29:21 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: +access(2) To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 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.64 src/lib/librumphijack/hijack.c:1.65 --- src/lib/librumphijack/hijack.c:1.64 Wed Feb 23 15:23:15 2011 +++ src/lib/librumphijack/hijack.c Wed Feb 23 15:29:21 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.64 2011/02/23 15:23:15 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.65 2011/02/23 15:29:21 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.64 2011/02/23 15:23:15 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.65 2011/02/23 15:29:21 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -92,6 +92,7 @@ DUALCALL_MOUNT, DUALCALL_UNMOUNT, DUALCALL___GETCWD, DUALCALL_CHFLAGS, DUALCALL_LCHFLAGS, DUALCALL_FCHFLAGS, + DUALCALL_ACCESS, DUALCALL__NUM }; @@ -216,6 +217,7 @@ { DUALCALL_CHFLAGS, "chflags", RSYS_NAME(CHFLAGS) }, { DUALCALL_LCHFLAGS, "lchflags", RSYS_NAME(LCHFLAGS) }, { DUALCALL_FCHFLAGS, "fchflags", RSYS_NAME(FCHFLAGS) }, + { DUALCALL_ACCESS, "access", RSYS_NAME(ACCESS) }, }; #undef S @@ -1791,6 +1793,11 @@ (const char *, off_t), \ (path, length)) +PATHCALL(int, access, DUALCALL_ACCESS, \ + (const char *path, int mode), \ + (const char *, int), \ + (path, mode)) + /* * Note: with mount the decisive parameter is the mount * destination directory. This is because we don't really know
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Feb 23 15:23:16 UTC 2011 Modified Files: src/lib/librumphijack: Makefile hijack.c Added Files: src/lib/librumphijack: hijackdlsym.c Log Message: Put the dlsym-from-this-object trampoline into a separate source module which is compiled -fno-optimize-sibling-calls instead of trying to fool the optimizer in various ways in the trampoline. thanks to yamt for the tip To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/librumphijack/Makefile cvs rdiff -u -r1.63 -r1.64 src/lib/librumphijack/hijack.c cvs rdiff -u -r0 -r1.1 src/lib/librumphijack/hijackdlsym.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/Makefile diff -u src/lib/librumphijack/Makefile:1.6 src/lib/librumphijack/Makefile:1.7 --- src/lib/librumphijack/Makefile:1.6 Thu Jan 27 18:12:19 2011 +++ src/lib/librumphijack/Makefile Wed Feb 23 15:23:15 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.6 2011/01/27 18:12:19 pooka Exp $ +# $NetBSD: Makefile,v 1.7 2011/02/23 15:23:15 pooka Exp $ # LIB= rumphijack @@ -8,7 +8,7 @@ rumpclient ${.CURDIR}/../librumpclient MAN= rumphijack.3 -SRCS= hijack.c +SRCS= hijack.c hijackdlsym.c CPPFLAGS+= -D_DIAGNOSTIC -D_REENTRANT @@ -16,5 +16,6 @@ #DBG=-g #NOGCCERROR=1 +COPTS.hijackdlsym.c+= -fno-optimize-sibling-calls .include Index: src/lib/librumphijack/hijack.c diff -u src/lib/librumphijack/hijack.c:1.63 src/lib/librumphijack/hijack.c:1.64 --- src/lib/librumphijack/hijack.c:1.63 Mon Feb 21 20:11:56 2011 +++ src/lib/librumphijack/hijack.c Wed Feb 23 15:23:15 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.63 2011/02/21 20:11:56 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.64 2011/02/23 15:23:15 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.63 2011/02/21 20:11:56 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.64 2011/02/23 15:23:15 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -59,6 +59,8 @@ #include #include +#include "hijack.h" + enum dualcall { DUALCALL_WRITE, DUALCALL_WRITEV, DUALCALL_PWRITE, DUALCALL_PWRITEV, DUALCALL_IOCTL, DUALCALL_FCNTL, @@ -294,30 +296,6 @@ } /* - * This is called from librumpclient in case of LD_PRELOAD. - * It ensures correct RTLD_NEXT. - * - * ... except, it's apparently extremely difficult to force - * at least gcc to generate an actual stack frame here. So - * sprinkle some volatile foobar and baz to throw the optimizer - * off the scent and generate a variable assignment with the - * return value. The posterboy for this meltdown is amd64 - * with -O2. At least with gcc 4.1.3 i386 works regardless of - * optimization. - */ -volatile int rumphijack_unrope; /* there, unhang yourself */ -static void * -hijackdlsym(void *handle, const char *symbol) -{ - void *rv; - - rv = dlsym(handle, symbol); - rumphijack_unrope = *(volatile int *)rv; - - return (void *)rv; -} - -/* * This tracks if our process is in a subdirectory of /rump. * It's preserved over exec. */ @@ -452,7 +430,7 @@ extern void *(*rumpclient_dlsym)(void *, const char *); unsigned i, j; - rumpclient_dlsym = hijackdlsym; + rumpclient_dlsym = rumphijack_dlsym; host_fork = dlsym(RTLD_NEXT, "fork"); host_daemon = dlsym(RTLD_NEXT, "daemon"); host_execve = dlsym(RTLD_NEXT, "execve"); Added files: Index: src/lib/librumphijack/hijackdlsym.c diff -u /dev/null src/lib/librumphijack/hijackdlsym.c:1.1 --- /dev/null Wed Feb 23 15:23:16 2011 +++ src/lib/librumphijack/hijackdlsym.c Wed Feb 23 15:23:15 2011 @@ -0,0 +1,47 @@ +/* $NetBSD: hijackdlsym.c,v 1.1 2011/02/23 15:23:15 pooka Exp $ */ + +/*- + * Copyright (c) 2011 Antti Kantee. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Feb 21 20:11:57 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: If minfd for F_DUPFD is >= hijackoff, assume it means a minimum value in the rump kernel and adjust accordingly. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 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.62 src/lib/librumphijack/hijack.c:1.63 --- src/lib/librumphijack/hijack.c:1.62 Mon Feb 21 13:19:35 2011 +++ src/lib/librumphijack/hijack.c Mon Feb 21 20:11:56 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.62 2011/02/21 13:19:35 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.63 2011/02/21 20:11:56 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.62 2011/02/21 13:19:35 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.63 2011/02/21 20:11:56 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -604,6 +604,8 @@ if (fd_isrump(oldd)) { op_fcntl = GETSYSCALL(rump, FCNTL); oldd = fd_host2rump(oldd); + if (minfd >= HIJACK_FDOFF) + minfd -= HIJACK_FDOFF; isrump = 1; } else { op_fcntl = GETSYSCALL(host, FCNTL);
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Feb 21 13:19:35 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: disallow mmap(MAP_FILE) from a rump kernel fd To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 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.61 src/lib/librumphijack/hijack.c:1.62 --- src/lib/librumphijack/hijack.c:1.61 Mon Feb 21 12:55:21 2011 +++ src/lib/librumphijack/hijack.c Mon Feb 21 13:19:35 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.61 2011/02/21 12:55:21 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.62 2011/02/21 13:19:35 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.61 2011/02/21 12:55:21 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.62 2011/02/21 13:19:35 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -225,6 +226,7 @@ pid_t (*host_fork)(void); int (*host_daemon)(int, int); int (*host_execve)(const char *, char *const[], char *const[]); +void * (*host_mmap)(void *, size_t, int, int, int, off_t); /* ok, we need *two* bits per dup2'd fd to track fd+HIJACKOFF aliases */ static uint32_t dup2mask; @@ -454,6 +456,7 @@ host_fork = dlsym(RTLD_NEXT, "fork"); host_daemon = dlsym(RTLD_NEXT, "daemon"); host_execve = dlsym(RTLD_NEXT, "execve"); + host_mmap = dlsym(RTLD_NEXT, "mmap"); /* * In theory cannot print anything during lookups because @@ -1527,6 +1530,20 @@ } /* + * mmapping from a rump kernel is not supported, so disallow it. + */ +void * +mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) +{ + + if (flags & MAP_FILE && fd_isrump(fd)) { + errno = ENOSYS; + return MAP_FAILED; + } + return host_mmap(addr, len, prot, flags, fd, offset); +} + +/* * Rest are std type calls. */
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Feb 21 12:55:21 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Actually, we need both lseek and _lseek so that out-of-libc references go to the right place instead of directly to __lseek. Seeking in mplayer works now. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 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.60 src/lib/librumphijack/hijack.c:1.61 --- src/lib/librumphijack/hijack.c:1.60 Mon Feb 21 12:51:06 2011 +++ src/lib/librumphijack/hijack.c Mon Feb 21 12:55:21 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.60 2011/02/21 12:51:06 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.61 2011/02/21 12:55:21 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.60 2011/02/21 12:51:06 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.61 2011/02/21 12:55:21 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -125,7 +125,6 @@ #define REALPWRITE _sys_pwrite #define REALGETDENTS __getdents30 #define REALMOUNT __mount50 -#define REALLSEEK _lseek int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *); int REALPOLLTS(struct pollfd *, nfds_t, @@ -143,7 +142,6 @@ int REALLUTIMES(const char *, const struct timeval [2]); int REALFUTIMES(int, const struct timeval [2]); int REALMOUNT(const char *, const char *, int, void *, size_t); -off_t REALLSEEK(int, off_t, int); int __getcwd(char *, size_t); #define S(a) __STRING(a) @@ -197,7 +195,7 @@ { DUALCALL_FSTATVFS1, "fstatvfs1", RSYS_NAME(FSTATVFS1) }, { DUALCALL_CHDIR, "chdir", RSYS_NAME(CHDIR) }, { DUALCALL_FCHDIR, "fchdir", RSYS_NAME(FCHDIR) }, - { DUALCALL_LSEEK, S(REALLSEEK), RSYS_NAME(LSEEK) }, + { DUALCALL_LSEEK, "lseek", RSYS_NAME(LSEEK) }, { DUALCALL_GETDENTS, "__getdents30", RSYS_NAME(GETDENTS) }, { DUALCALL_UNLINK, "unlink", RSYS_NAME(UNLINK) }, { DUALCALL_SYMLINK, "symlink", RSYS_NAME(SYMLINK) }, @@ -1661,10 +1659,11 @@ (int, struct statvfs *, int), \ (fd, buf, flags)) -FDCALL(off_t, REALLSEEK, DUALCALL_LSEEK,\ +FDCALL(off_t, lseek, DUALCALL_LSEEK, \ (int fd, off_t offset, int whence),\ (int, off_t, int), \ (fd, offset, whence)) +__strong_alias(_lseek,lseek); FDCALL(int, REALGETDENTS, DUALCALL_GETDENTS,\ (int fd, char *buf, size_t nbytes),\
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Feb 21 12:51:06 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: hijack: 1) {,f,l}chflags (used e.g. by cp(1)) 2) p{read,write}{,v} (used by many) To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 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.59 src/lib/librumphijack/hijack.c:1.60 --- src/lib/librumphijack/hijack.c:1.59 Sun Feb 20 23:47:04 2011 +++ src/lib/librumphijack/hijack.c Mon Feb 21 12:51:06 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.59 2011/02/20 23:47:04 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.60 2011/02/21 12:51:06 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.59 2011/02/20 23:47:04 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.60 2011/02/21 12:51:06 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -59,7 +59,7 @@ #include enum dualcall { - DUALCALL_WRITE, DUALCALL_WRITEV, + DUALCALL_WRITE, DUALCALL_WRITEV, DUALCALL_PWRITE, DUALCALL_PWRITEV, DUALCALL_IOCTL, DUALCALL_FCNTL, DUALCALL_SOCKET, DUALCALL_ACCEPT, DUALCALL_BIND, DUALCALL_CONNECT, DUALCALL_GETPEERNAME, DUALCALL_GETSOCKNAME, DUALCALL_LISTEN, @@ -67,7 +67,7 @@ DUALCALL_SENDTO, DUALCALL_SENDMSG, DUALCALL_GETSOCKOPT, DUALCALL_SETSOCKOPT, DUALCALL_SHUTDOWN, - DUALCALL_READ, DUALCALL_READV, + DUALCALL_READ, DUALCALL_READV, DUALCALL_PREAD, DUALCALL_PREADV, DUALCALL_DUP2, DUALCALL_CLOSE, DUALCALL_POLLTS, @@ -88,6 +88,7 @@ DUALCALL_FSYNC, DUALCALL_FSYNC_RANGE, DUALCALL_MOUNT, DUALCALL_UNMOUNT, DUALCALL___GETCWD, + DUALCALL_CHFLAGS, DUALCALL_LCHFLAGS, DUALCALL_FCHFLAGS, DUALCALL__NUM }; @@ -120,6 +121,8 @@ #define REALFUTIMES __futimes50 #endif #define REALREAD _sys_read +#define REALPREAD _sys_pread +#define REALPWRITE _sys_pwrite #define REALGETDENTS __getdents30 #define REALMOUNT __mount50 #define REALLSEEK _lseek @@ -130,6 +133,8 @@ int REALKEVENT(int, const struct kevent *, size_t, struct kevent *, size_t, const struct timespec *); ssize_t REALREAD(int, void *, size_t); +ssize_t REALPREAD(int, void *, size_t, off_t); +ssize_t REALPWRITE(int, const void *, size_t, off_t); int REALSTAT(const char *, struct stat *); int REALLSTAT(const char *, struct stat *); int REALFSTAT(int, struct stat *); @@ -163,8 +168,12 @@ { DUALCALL_SHUTDOWN, "shutdown", RSYS_NAME(SHUTDOWN) }, { DUALCALL_READ, S(REALREAD), RSYS_NAME(READ) }, { DUALCALL_READV, "readv", RSYS_NAME(READV) }, + { DUALCALL_PREAD, S(REALPREAD), RSYS_NAME(PREAD) }, + { DUALCALL_PREADV, "preadv", RSYS_NAME(PREADV) }, { DUALCALL_WRITE, "write", RSYS_NAME(WRITE) }, { DUALCALL_WRITEV, "writev", RSYS_NAME(WRITEV) }, + { DUALCALL_PWRITE, S(REALPWRITE), RSYS_NAME(PWRITE) }, + { DUALCALL_PWRITEV, "pwritev", RSYS_NAME(PWRITEV) }, { DUALCALL_IOCTL, "ioctl", RSYS_NAME(IOCTL) }, { DUALCALL_FCNTL, "fcntl", RSYS_NAME(FCNTL) }, { DUALCALL_DUP2, "dup2", RSYS_NAME(DUP2) }, @@ -203,6 +212,9 @@ { DUALCALL_MOUNT, S(REALMOUNT), RSYS_NAME(MOUNT) }, { DUALCALL_UNMOUNT, "unmount", RSYS_NAME(UNMOUNT) }, { DUALCALL___GETCWD, "__getcwd", RSYS_NAME(__GETCWD) }, + { DUALCALL_CHFLAGS, "chflags", RSYS_NAME(CHFLAGS) }, + { DUALCALL_LCHFLAGS, "lchflags", RSYS_NAME(LCHFLAGS) }, + { DUALCALL_FCHFLAGS, "fchflags", RSYS_NAME(FCHFLAGS) }, }; #undef S @@ -1614,11 +1626,31 @@ (int, const struct iovec *, int),\ (fd, iov, iovcnt)) +FDCALL(ssize_t, REALPREAD, DUALCALL_PREAD,\ + (int fd, void *buf, size_t nbytes, off_t offset), \ + (int, void *, size_t, off_t), \ + (fd, buf, nbytes, offset)) + +FDCALL(ssize_t, preadv, DUALCALL_PREADV, \ + (int fd, const struct iovec *iov, int iovcnt, off_t offset), \ + (int, const struct iovec *, int, off_t), \ + (fd, iov, iovcnt, offset)) + FDCALL(ssize_t, writev, DUALCALL_WRITEV, \ (int fd, const struct iovec *iov, int iovcnt), \ (int, const struct iovec *, int),\ (fd, iov, iovcnt)) +FDCALL(ssize_t, REALPWRITE, DUALCALL_PWRITE,\ + (int fd, const void *buf, size_t nbytes, off_t offset), \ + (int, const void *, size_t, off_t),\ + (fd, buf, nbytes, offset)) + +FDCALL(ssize_t, pwritev, DUALCALL_PWRITEV, \ + (int fd, const struct iovec *iov, int iovcnt, off_t offset), \ + (int, const struct iovec *, int, off_t), \ + (fd, iov, iovcnt, offset)) + FDCALL(int, REALFSTAT, DUALCALL_FSTAT, \ (int fd, struct stat *sb), \ (int, struct stat *), \ @@ -1669,6 +1701,11 @@ (int, const struct timeval *), \ (fd, tv)) +FDCALL(int, fchflags, DUALCALL_FCHFLAGS,\ + (int fd, u_long flags), \ + (int, u_long), \ + (fd, flags)) + /* * path-based selectors */ @@ -1743,6 +1780,16 @@ (const char *, const struct t
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Sun Feb 20 23:47:04 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: fix tests/lib/librumphijack/t_asyncio:invafd -- dual poll on invalid fd To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 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.58 src/lib/librumphijack/hijack.c:1.59 --- src/lib/librumphijack/hijack.c:1.58 Sat Feb 19 19:17:33 2011 +++ src/lib/librumphijack/hijack.c Sun Feb 20 23:47:04 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.58 2011/02/19 19:17:33 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.59 2011/02/20 23:47:04 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.58 2011/02/19 19:17:33 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.59 2011/02/20 23:47:04 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -1353,32 +1353,51 @@ goto out; } - /* split vectors */ + /* + * then, open two pipes, one for notifications + * to each kernel. + */ + if ((rv = rump_sys_pipe(rpipe)) == -1) { + sverrno = errno; + } + if (rv == 0 && (rv = pipe(hpipe)) == -1) { + sverrno = errno; + } + + /* split vectors (or signal errors) */ for (i = 0; i < nfds; i++) { + int fd; + + fds[i].revents = 0; if (fds[i].fd == -1) { pfd_host[i].fd = -1; pfd_rump[i].fd = -1; } else if (fd_isrump(fds[i].fd)) { pfd_host[i].fd = -1; -pfd_rump[i].fd = fd_host2rump(fds[i].fd); +fd = fd_host2rump(fds[i].fd); +if (fd == rpipe[0] || fd == rpipe[1]) { + fds[i].revents = POLLNVAL; + if (rv != -1) + rv++; +} +pfd_rump[i].fd = fd; pfd_rump[i].events = fds[i].events; } else { pfd_rump[i].fd = -1; -pfd_host[i].fd = fds[i].fd; +fd = fds[i].fd; +if (fd == hpipe[0] || fd == hpipe[1]) { + fds[i].revents = POLLNVAL; + if (rv != -1) + rv++; +} +pfd_host[i].fd = fd; pfd_host[i].events = fds[i].events; } pfd_rump[i].revents = pfd_host[i].revents = 0; - fds[i].revents = 0; } - - /* - * then, open two pipes, one for notifications - * to each kernel. - */ - if (rump_sys_pipe(rpipe) == -1) - goto out; - if (pipe(hpipe) == -1) + if (rv) { goto out; + } pfd_host[nfds].fd = hpipe[0]; pfd_host[nfds].events = POLLIN;
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Sun Feb 20 14:21:04 UTC 2011 Modified Files: src/lib/librumphijack: rumphijack.3 Log Message: minor clarification To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/lib/librumphijack/rumphijack.3 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/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.4 src/lib/librumphijack/rumphijack.3:1.5 --- src/lib/librumphijack/rumphijack.3:1.4 Fri Feb 18 12:22:46 2011 +++ src/lib/librumphijack/rumphijack.3 Sun Feb 20 14:21:04 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.4 2011/02/18 12:22:46 pooka Exp $ +.\" $NetBSD: rumphijack.3,v 1.5 2011/02/20 14:21:04 pooka Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -58,9 +58,12 @@ Pathname-based system calls are hijacked if the path the system call is directed to resides under .Ar value . -In case of an absolute pathname argument, a direct comparison is made. +In case of an absolute pathname argument, a literal prefix comparison is made. In case of a relative pathname, the current working direct is examined. +This also implies that neither +.Dq .. +nor symbolic links will cause the namespace to be switched. .It Dq socket The specifier .Ar value
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Sat Feb 19 19:17:34 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: fix symlink pathname examination (rationale-to-joerg: so that it works) To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 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.57 src/lib/librumphijack/hijack.c:1.58 --- src/lib/librumphijack/hijack.c:1.57 Sat Feb 19 13:10:35 2011 +++ src/lib/librumphijack/hijack.c Sat Feb 19 19:17:33 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.57 2011/02/19 13:10:35 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.58 2011/02/19 19:17:33 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.57 2011/02/19 13:10:35 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.58 2011/02/19 19:17:33 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -1695,9 +1695,9 @@ (path)) PATHCALL(int, symlink, DUALCALL_SYMLINK,\ - (const char *path, const char *target),\ + (const char *target, const char *path),\ (const char *, const char *), \ - (path, target)) + (target, path)) PATHCALL(ssize_t, readlink, DUALCALL_READLINK,\ (const char *path, char *buf, size_t bufsiz), \
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Sat Feb 19 13:10:35 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: hijack __getcwd() To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 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.56 src/lib/librumphijack/hijack.c:1.57 --- src/lib/librumphijack/hijack.c:1.56 Sat Feb 19 13:09:40 2011 +++ src/lib/librumphijack/hijack.c Sat Feb 19 13:10:35 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.56 2011/02/19 13:09:40 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.57 2011/02/19 13:10:35 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.56 2011/02/19 13:09:40 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.57 2011/02/19 13:10:35 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -87,6 +87,7 @@ DUALCALL_TRUNCATE, DUALCALL_FTRUNCATE, DUALCALL_FSYNC, DUALCALL_FSYNC_RANGE, DUALCALL_MOUNT, DUALCALL_UNMOUNT, + DUALCALL___GETCWD, DUALCALL__NUM }; @@ -138,6 +139,7 @@ int REALFUTIMES(int, const struct timeval [2]); int REALMOUNT(const char *, const char *, int, void *, size_t); off_t REALLSEEK(int, off_t, int); +int __getcwd(char *, size_t); #define S(a) __STRING(a) struct sysnames { @@ -200,6 +202,7 @@ { DUALCALL_FSYNC_RANGE, "fsync_range", RSYS_NAME(FSYNC_RANGE) }, { DUALCALL_MOUNT, S(REALMOUNT), RSYS_NAME(MOUNT) }, { DUALCALL_UNMOUNT, "unmount", RSYS_NAME(UNMOUNT) }, + { DUALCALL___GETCWD, "__getcwd", RSYS_NAME(__GETCWD) }, }; #undef S @@ -376,8 +379,15 @@ pathparser(char *buf) { + /* sanity-check */ if (*buf != '/') errx(1, "hijack path specifier must begin with ``/''"); + rumpprefixlen = strlen(buf); + if (rumpprefixlen < 2) + errx(1, "invalid hijack prefix: %s", buf); + if (buf[rumpprefixlen-1] == '/' && strspn(buf, "/") != rumpprefixlen) + errx(1, "hijack prefix may end in slash only if pure " + "slash, gave %s", buf); if ((rumpprefix = strdup(buf)) == NULL) err(1, "strdup"); @@ -698,6 +708,52 @@ } int +__getcwd(char *bufp, size_t len) +{ + int (*op___getcwd)(char *, size_t); + int rv; + + if (pwdinrump) { + size_t prefixgap; + bool iamslash; + + if (rumpprefix[rumpprefixlen-1] == '/') + iamslash = true; + else + iamslash = false; + + if (iamslash) + prefixgap = rumpprefixlen - 1; /* ``//+path'' */ + else + prefixgap = rumpprefixlen; /* ``/pfx+/path'' */ + if (len <= prefixgap) { + return ERANGE; + } + + op___getcwd = GETSYSCALL(rump, __GETCWD); + rv = op___getcwd(bufp + prefixgap, len - prefixgap); + if (rv == -1) + return rv; + + /* augment the "/" part only for a non-root path */ + memcpy(bufp, rumpprefix, rumpprefixlen); + + /* append / only to non-root cwd */ + if (rv != 2) + bufp[prefixgap] = '/'; + + /* don't append extra slash in the purely-slash case */ + if (rv == 2 && !iamslash) + bufp[rumpprefixlen] = '\0'; + + return rv; + } else { + op___getcwd = GETSYSCALL(host, __GETCWD); + return op___getcwd(bufp, len); + } +} + +int rename(const char *from, const char *to) { int (*op_rename)(const char *, const char *);
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Sat Feb 19 13:09:40 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: and now with less crazy whitespace To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 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.55 src/lib/librumphijack/hijack.c:1.56 --- src/lib/librumphijack/hijack.c:1.55 Sat Feb 19 13:07:53 2011 +++ src/lib/librumphijack/hijack.c Sat Feb 19 13:09:40 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.55 2011/02/19 13:07:53 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.56 2011/02/19 13:09:40 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.55 2011/02/19 13:07:53 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.56 2011/02/19 13:09:40 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -326,8 +326,8 @@ { PF_INET, "inet" }, { PF_LINK, "link" }, #ifdef PF_OROUTE - { PF_OROUTE, "oroute" }, -#endif + { PF_OROUTE, "oroute" }, +#endif { PF_ROUTE, "route" }, { PF_INET6, "inet6" }, #ifdef PF_MPLS
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Sat Feb 19 13:07:53 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: support PF_OROUTE and PF_MPLS where available To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 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.54 src/lib/librumphijack/hijack.c:1.55 --- src/lib/librumphijack/hijack.c:1.54 Fri Feb 18 19:27:06 2011 +++ src/lib/librumphijack/hijack.c Sat Feb 19 13:07:53 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.54 2011/02/18 19:27:06 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.55 2011/02/19 13:07:53 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.54 2011/02/18 19:27:06 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.55 2011/02/19 13:07:53 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -325,8 +325,14 @@ { PF_LOCAL, "local" }, { PF_INET, "inet" }, { PF_LINK, "link" }, +#ifdef PF_OROUTE + { PF_OROUTE, "oroute" }, +#endif { PF_ROUTE, "route" }, { PF_INET6, "inet6" }, +#ifdef PF_MPLS + { PF_MPLS, "mpls" }, +#endif { -1, NULL } };
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 18 19:27:07 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: hijack libc-internal name for lseek so that libc-internal callers go to the right kernel too. To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 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.53 src/lib/librumphijack/hijack.c:1.54 --- src/lib/librumphijack/hijack.c:1.53 Fri Feb 18 14:44:46 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 18 19:27:06 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.53 2011/02/18 14:44:46 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.54 2011/02/18 19:27:06 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.53 2011/02/18 14:44:46 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.54 2011/02/18 19:27:06 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -121,6 +121,7 @@ #define REALREAD _sys_read #define REALGETDENTS __getdents30 #define REALMOUNT __mount50 +#define REALLSEEK _lseek int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *); int REALPOLLTS(struct pollfd *, nfds_t, @@ -136,6 +137,7 @@ int REALLUTIMES(const char *, const struct timeval [2]); int REALFUTIMES(int, const struct timeval [2]); int REALMOUNT(const char *, const char *, int, void *, size_t); +off_t REALLSEEK(int, off_t, int); #define S(a) __STRING(a) struct sysnames { @@ -184,7 +186,7 @@ { DUALCALL_FSTATVFS1, "fstatvfs1", RSYS_NAME(FSTATVFS1) }, { DUALCALL_CHDIR, "chdir", RSYS_NAME(CHDIR) }, { DUALCALL_FCHDIR, "fchdir", RSYS_NAME(FCHDIR) }, - { DUALCALL_LSEEK, "lseek", RSYS_NAME(LSEEK) }, + { DUALCALL_LSEEK, S(REALLSEEK), RSYS_NAME(LSEEK) }, { DUALCALL_GETDENTS, "__getdents30", RSYS_NAME(GETDENTS) }, { DUALCALL_UNLINK, "unlink", RSYS_NAME(UNLINK) }, { DUALCALL_SYMLINK, "symlink", RSYS_NAME(SYMLINK) }, @@ -1546,7 +1548,7 @@ (int, struct statvfs *, int), \ (fd, buf, flags)) -FDCALL(off_t, lseek, DUALCALL_LSEEK, \ +FDCALL(off_t, REALLSEEK, DUALCALL_LSEEK,\ (int fd, off_t offset, int whence),\ (int, off_t, int), \ (fd, offset, whence))
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 18 14:44:46 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: block cross-kernel rename in the other direction also To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 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.52 src/lib/librumphijack/hijack.c:1.53 --- src/lib/librumphijack/hijack.c:1.52 Fri Feb 18 14:33:11 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 18 14:44:46 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.52 2011/02/18 14:33:11 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.53 2011/02/18 14:44:46 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.52 2011/02/18 14:33:11 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.53 2011/02/18 14:44:46 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -702,6 +702,9 @@ to = path_host2rump(to); op_rename = GETSYSCALL(rump, RENAME); } else { + if (path_isrump(to)) + return EXDEV; + op_rename = GETSYSCALL(host, RENAME); }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 18 14:33:11 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: fix rename To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 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.51 src/lib/librumphijack/hijack.c:1.52 --- src/lib/librumphijack/hijack.c:1.51 Fri Feb 18 14:25:04 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 18 14:33:11 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.51 2011/02/18 14:25:04 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.52 2011/02/18 14:33:11 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.51 2011/02/18 14:25:04 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.52 2011/02/18 14:33:11 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -689,6 +689,25 @@ return rv; } +int +rename(const char *from, const char *to) +{ + int (*op_rename)(const char *, const char *); + + if (path_isrump(from)) { + if (!path_isrump(to)) + return EXDEV; + + from = path_host2rump(from); + to = path_host2rump(to); + op_rename = GETSYSCALL(rump, RENAME); + } else { + op_rename = GETSYSCALL(host, RENAME); + } + + return op_rename(from, to); +} + int __socket30(int, int, int); int __socket30(int domain, int type, int protocol) @@ -1618,12 +1637,6 @@ (const char *, char *, size_t), \ (path, buf, bufsiz)) -/* XXX: cross-kernel renames need to be blocked */ -PATHCALL(int, rename, DUALCALL_RENAME, \ - (const char *path, const char *to),\ - (const char *, const char *), \ - (path, to)) - PATHCALL(int, mkdir, DUALCALL_MKDIR, \ (const char *path, mode_t mode),\ (const char *, mode_t), \
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 18 14:25:04 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: uhm, put PF_LOCAL on the socketlist To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 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.50 src/lib/librumphijack/hijack.c:1.51 --- src/lib/librumphijack/hijack.c:1.50 Fri Feb 18 13:04:52 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 18 14:25:04 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.50 2011/02/18 13:04:52 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.51 2011/02/18 14:25:04 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.50 2011/02/18 13:04:52 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.51 2011/02/18 14:25:04 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -320,6 +320,7 @@ int pf; const char *name; } socketmap[] = { + { PF_LOCAL, "local" }, { PF_INET, "inet" }, { PF_LINK, "link" }, { PF_ROUTE, "route" },
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 18 13:04:52 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: give the signmonkey a banana To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 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.49 src/lib/librumphijack/hijack.c:1.50 --- src/lib/librumphijack/hijack.c:1.49 Fri Feb 18 11:41:32 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 18 13:04:52 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.49 2011/02/18 11:41:32 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.50 2011/02/18 13:04:52 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.49 2011/02/18 11:41:32 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.50 2011/02/18 13:04:52 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -336,7 +336,7 @@ /* if "all" is present, it must be specified first */ if (strncmp(buf, "all", strlen("all")) == 0) { - for (i = 0; i < __arraycount(rumpsockets); i++) { + for (i = 0; i < (int)__arraycount(rumpsockets); i++) { rumpsockets[i] = true; } buf += strlen("all");
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 18 12:22:46 UTC 2011 Modified Files: src/lib/librumphijack: rumphijack.3 Log Message: Document .Ev RUMPHIJACK To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/lib/librumphijack/rumphijack.3 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/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.3 src/lib/librumphijack/rumphijack.3:1.4 --- src/lib/librumphijack/rumphijack.3:1.3 Wed Feb 16 19:46:42 2011 +++ src/lib/librumphijack/rumphijack.3 Fri Feb 18 12:22:46 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.3 2011/02/16 19:46:42 pooka Exp $ +.\" $NetBSD: rumphijack.3,v 1.4 2011/02/18 12:22:46 pooka Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd February 16, 2011 +.Dd February 18, 2011 .Dt RUMPHIJACK 3 .Os .Sh NAME @@ -46,7 +46,57 @@ The behaviour of hijacked applications is affected by the following environment variables: .Bl -tag -width 12345 -.It Dv RUMPHIJACK_RETRYCONNECT +.It Ev RUMPHIJACK +If present, this variable specifies which system calls should be +hijacked. +The string is parsed as a comma-separated list of +.Dq name=value +tuples. +The possible lefthandside names are: +.Bl -tag -width xxsocketxx +.It Dq path +Pathname-based system calls are hijacked if the path the system +call is directed to resides under +.Ar value . +In case of an absolute pathname argument, a direct comparison is made. +In case of a relative pathname, the current working direct is +examined. +.It Dq socket +The specifier +.Ar value +contains a colon-separated list of which protocol families should +be hijacked. +The special value +.Dq all +can be specified as the first element. +It indicates that all protocol families should be hijacked. +Some can then be disabled by prepending +.Dq no +to the name of the protocol family. +.Pp +For example, +.Dq inet:inet6 +specifies that only +.Dv PF_INET +and +.Dv PF_INET6 +sockets should be hijacked, +while +.Dq all:noinet +specifies that all protocol families except +.Dv PF_INET +should be hijacked. +.El +.Pp +If the environment variable is unset, the default value +.Qq path=/rump,socket=all:nolocal +is used. +The rationale for this is to have networked X clients work +out-of-the-box: X clients use local sockets to communicate with +the server, so local sockets must be used as a host service. +.Pp +An empty string as a value means no calls are hijacked. +.It Ev RUMPHIJACK_RETRYCONNECT Change how .Xr rumpclient 3 attempts to reconnect to the server in case the connection is lost. @@ -70,12 +120,6 @@ .Xr rumpclient 3 for more discussion. .El -.Pp -Currently -.Nm -supports only TCP/IP related system calls. -The set of supported subsystems may change later along with the usage -of the library. .Sh EXAMPLES Use an alternate TCP/IP stack for firefox with a persistent server connection:
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 18 11:41:33 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Use the env variable RUMPHIJACK to specify what facilities should be hijacked. If it's not specified, the default is "path=/rump,socket=all:nolocal". So, if you're moof and want to relive your domain/os days (??), you can do this: pain-rustique:51:~> setenv RUMPHIJACK 'path=//' pain-rustique:52:~> df //dev Filesystem 1K-blocks Used Avail %Cap Mounted on rumpfs1 1 0 100% / pain-rustique:53:~> df /dev Filesystem 1K-blocks Used Avail %Cap Mounted on /dev/wd0a 1019864 280640 688232 28% / To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 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.48 src/lib/librumphijack/hijack.c:1.49 --- src/lib/librumphijack/hijack.c:1.48 Thu Feb 17 17:18:08 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 18 11:41:32 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.48 2011/02/17 17:18:08 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.49 2011/02/18 11:41:32 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.48 2011/02/17 17:18:08 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.49 2011/02/18 11:41:32 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -300,15 +300,124 @@ return (void *)rv; } -static int pwdinrump = 0; +/* + * This tracks if our process is in a subdirectory of /rump. + * It's preserved over exec. + */ +static bool pwdinrump = false; + +/* + * These variables are set from the RUMPHIJACK string and control + * which operations can product rump kernel file descriptors. + * This should be easily extendable for future needs. + */ +#define RUMPHIJACK_DEFAULT "path=/rump,socket=all:nolocal" +static bool rumpsockets[PF_MAX]; +static const char *rumpprefix; +static size_t rumpprefixlen; + +static struct { + int pf; + const char *name; +} socketmap[] = { + { PF_INET, "inet" }, + { PF_LINK, "link" }, + { PF_ROUTE, "route" }, + { PF_INET6, "inet6" }, + { -1, NULL } +}; + +static void +sockparser(char *buf) +{ + char *p, *l; + bool value; + int i; + + /* if "all" is present, it must be specified first */ + if (strncmp(buf, "all", strlen("all")) == 0) { + for (i = 0; i < __arraycount(rumpsockets); i++) { + rumpsockets[i] = true; + } + buf += strlen("all"); + if (*buf == ':') + buf++; + } + + for (p = strtok_r(buf, ":", &l); p; p = strtok_r(NULL, ":", &l)) { + value = true; + if (strncmp(p, "no", strlen("no")) == 0) { + value = false; + p += strlen("no"); + } -/* low calorie sockets? */ -static bool hostlocalsockets = true; + for (i = 0; socketmap[i].name; i++) { + if (strcmp(p, socketmap[i].name) == 0) { +rumpsockets[socketmap[i].pf] = value; +break; + } + } + if (socketmap[i].name == NULL) { + warnx("invalid socket specifier %s", p); + } + } +} + +static void +pathparser(char *buf) +{ + + if (*buf != '/') + errx(1, "hijack path specifier must begin with ``/''"); + + if ((rumpprefix = strdup(buf)) == NULL) + err(1, "strdup"); + rumpprefixlen = strlen(rumpprefix); +} + +static struct { + void (*parsefn)(char *); + const char *name; +} hijackparse[] = { + { sockparser, "socket" }, + { pathparser, "path" }, + { NULL, NULL }, +}; + +static void +parsehijack(char *hijack) +{ + char *p, *p2, *l; + const char *hijackcopy; + int i; + + if ((hijackcopy = strdup(hijack)) == NULL) + err(1, "strdup"); + + /* disable everything explicitly */ + for (i = 0; i < PF_MAX; i++) + rumpsockets[i] = false; + + for (p = strtok_r(hijack, ",", &l); p; p = strtok_r(NULL, ",", &l)) { + p2 = strchr(p, '='); + if (!p2) + errx(1, "invalid hijack specifier: %s", hijackcopy); + + for (i = 0; hijackparse[i].parsefn; i++) { + if (strncmp(hijackparse[i].name, p, + (size_t)(p2-p)) == 0) { +hijackparse[i].parsefn(p2+1); +break; + } + } + } + +} static void __attribute__((constructor)) rcinit(void) { - char buf[64]; + char buf[1024]; extern void *(*rumpclient_dlsym)(void *, const char *); unsigned i, j; @@ -349,6 +458,12 @@ if (rumpclient_init() == -1) err(1, "rumpclient init"); + /* check which syscalls we're supposed to hijack */ + if (getenv_r("RUMPHIJACK", buf, sizeof(buf)) == -1) { + strcpy(buf, RUMPHIJACK_DEFAULT); + } + parsehijack(buf); + /* set client persistence level */ if (getenv_r("RUMPHIJACK_RETRYCONNECT", buf, sizeof(buf)) != -1) { if (strcmp(buf, "die") == 0) @@ -375,7 +490,7 @@ unsetenv("RUMPHIJACK__DUP2MASK"); } if (getenv_r("RUMPHIJACK__PWDINRUMP", buf, sizeof(buf)) == 0) { - pwdinrump = strtoul(buf, NULL, 10); + pwdinrump = true; unsetenv("RUMPHIJACK__PWD
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Thu Feb 17 17:18:08 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Support mount/unmount too. So, things are now generally at a stage where you can mount a file system with a userspace server *without* it having to go through puffs. Say, you first start a server with ffs capability and map a host ffs image into it: rump_server -lrumpvfs -lrumpfs_ffs \ -d key=/ffsimg,hostpath=ffs2.img,size=e unix:///tmp/ffsserv Then, configure your shell to talk to the rump server: setenv RUMP_SERVER unix:///tmp/ffsserv setenv LD_PRELOAD /usr/lib/librumphijack.so Create a mountpoint and mount the file system: pain-rustique:60:~> sh $ cd /rump $ ls dev $ ls -l total 1 drwxr-xr-x 2 root wheel 512 Feb 17 18:00 dev $ mkdir mnt $ mount_ffs /ffsimg /rump/mnt mount_ffs: Warning: realpath /ffsimg: No such file or directory $ df -h mnt FilesystemSize Used Avail %Cap Mounted on /ffsimg 496M 380M91M 80% /mnt $ du -sckh * 192Kdev 380Mmnt 381Mtotal $ umount -R mnt $ df -h mnt FilesystemSize Used Avail %Cap Mounted on rumpfs1.0K 1.0K 0B 100% / $ (note, you need -R to umount due to various degrees of unsuccesful magic it attempts to perform without it) To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 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.47 src/lib/librumphijack/hijack.c:1.48 --- src/lib/librumphijack/hijack.c:1.47 Thu Feb 17 15:20:10 2011 +++ src/lib/librumphijack/hijack.c Thu Feb 17 17:18:08 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.47 2011/02/17 15:20:10 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.48 2011/02/17 17:18:08 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.47 2011/02/17 15:20:10 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.48 2011/02/17 17:18:08 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -34,8 +34,9 @@ #include #include #include -#include +#include #include +#include #include #include @@ -85,6 +86,7 @@ DUALCALL_UTIMES, DUALCALL_LUTIMES, DUALCALL_FUTIMES, DUALCALL_TRUNCATE, DUALCALL_FTRUNCATE, DUALCALL_FSYNC, DUALCALL_FSYNC_RANGE, + DUALCALL_MOUNT, DUALCALL_UNMOUNT, DUALCALL__NUM }; @@ -118,6 +120,7 @@ #endif #define REALREAD _sys_read #define REALGETDENTS __getdents30 +#define REALMOUNT __mount50 int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *); int REALPOLLTS(struct pollfd *, nfds_t, @@ -132,6 +135,7 @@ int REALUTIMES(const char *, const struct timeval [2]); int REALLUTIMES(const char *, const struct timeval [2]); int REALFUTIMES(int, const struct timeval [2]); +int REALMOUNT(const char *, const char *, int, void *, size_t); #define S(a) __STRING(a) struct sysnames { @@ -192,6 +196,8 @@ { DUALCALL_FTRUNCATE, "ftruncate", RSYS_NAME(FTRUNCATE) }, { DUALCALL_FSYNC, "fsync", RSYS_NAME(FSYNC) }, { DUALCALL_FSYNC_RANGE, "fsync_range", RSYS_NAME(FSYNC_RANGE) }, + { DUALCALL_MOUNT, S(REALMOUNT), RSYS_NAME(MOUNT) }, + { DUALCALL_UNMOUNT, "unmount", RSYS_NAME(UNMOUNT) }, }; #undef S @@ -1532,3 +1538,20 @@ (const char *path, off_t length),\ (const char *, off_t), \ (path, length)) + +/* + * Note: with mount the decisive parameter is the mount + * destination directory. This is because we don't really know + * about the "source" directory in a generic call (and besides, + * it might not even exist, cf. nfs). + */ +PATHCALL(int, REALMOUNT, DUALCALL_MOUNT,\ + (const char *type, const char *path, int flags, \ + void *data, size_t dlen), \ + (const char *, const char *, int, void *, size_t), \ + (type, path, flags, data, dlen)) + +PATHCALL(int, unmount, DUALCALL_UNMOUNT,\ + (const char *path, int flags), \ + (const char *, int), \ + (path, flags))
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Thu Feb 17 15:20:10 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: In case dup2(n, n+FDOFF) is done, the caller thinks there are two distinct file descriptors, but the rump kernel thinks they are both the same. Now, if either one is closed by the application, "both" will be closed in the rump kernel. To fix this, maintain an alias-mask. It's not a perfect solution, though (consider e.g. F_SETFL). Maybe we should actually dup the fd and maintain a mapping table? Also, prevent the host from opening file descriptors onto the places in the fd namespace that have been dupped. These together fix "cat < /rump/foo" in a hijacked /bin/sh. (the first one makes sure stdin is open in cat and the second one makes sure it doesn't try to cat something from /usr/share/locale instead of stdin) To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 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.46 src/lib/librumphijack/hijack.c:1.47 --- src/lib/librumphijack/hijack.c:1.46 Thu Feb 17 12:52:33 2011 +++ src/lib/librumphijack/hijack.c Thu Feb 17 15:20:10 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.46 2011/02/17 12:52:33 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.47 2011/02/17 15:20:10 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.46 2011/02/17 12:52:33 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.47 2011/02/17 15:20:10 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -205,12 +205,18 @@ int (*host_daemon)(int, int); int (*host_execve)(const char *, char *const[], char *const[]); +/* ok, we need *two* bits per dup2'd fd to track fd+HIJACKOFF aliases */ static uint32_t dup2mask; -#define ISDUP2D(fd) (((fd) < 32) && (1<<(fd) & dup2mask)) +#define ISDUP2D(fd) (((fd) < 16) && (1<<(fd) & dup2mask)) #define SETDUP2(fd) \ -do { if ((fd) < 32) dup2mask |= (1<<(fd)); } while (/*CONSTCOND*/0) +do { if ((fd) < 16) dup2mask |= (1<<(fd)); } while (/*CONSTCOND*/0) #define CLRDUP2(fd) \ -do { if ((fd) < 32) dup2mask &= ~(1<<(fd)); } while (/*CONSTCOND*/0) +do { if ((fd) < 16) dup2mask &= ~(1<<(fd)); } while (/*CONSTCOND*/0) +#define ISDUP2ALIAS(fd) (((fd) < 16) && (1<<((fd)+16) & dup2mask)) +#define SETDUP2ALIAS(fd) \ +do { if ((fd) < 16) dup2mask |= (1<<((fd)+16)); } while (/*CONSTCOND*/0) +#define CLRDUP2ALIAS(fd) \ +do { if ((fd) < 16) dup2mask &= ~(1<<((fd)+16)); } while (/*CONSTCOND*/0) //#define DEBUGJACK #ifdef DEBUGJACK @@ -458,6 +464,25 @@ return newd; } +/* + * dup a host file descriptor so that it doesn't collide with the dup2mask + */ +static int +fd_dupgood(int fd) +{ + int (*op_fcntl)(int, int, ...) = GETSYSCALL(host, FCNTL); + int (*op_close)(int) = GETSYSCALL(host, CLOSE); + int ofd, i; + + for (i = 1; ISDUP2D(fd); i++) { + ofd = fd; + fd = op_fcntl(ofd, F_DUPFD, i); + op_close(ofd); + } + + return fd; +} + int open(const char *path, int flags, ...) { @@ -481,6 +506,8 @@ if (isrump) fd = fd_rump2host(fd); + else + fd = fd_dupgood(fd); return fd; } @@ -556,6 +583,8 @@ if (!dohost) fd = fd_rump2host(fd); + else + fd = fd_dupgood(fd); DPRINTF(("socket <- %d\n", fd)); return fd; @@ -580,6 +609,8 @@ fd = op_accept(s, addr, addrlen); if (fd != -1 && isrump) fd = fd_rump2host(fd); + else + fd = fd_dupgood(fd); DPRINTF((" <- %d\n", fd)); @@ -650,8 +681,8 @@ */ /* why don't we offer fls()? */ - for (i = 31; i >= 0; i--) { - if (dup2mask & 1<= 0; i--) { + if (ISDUP2D(i)) break; } @@ -715,9 +746,15 @@ if (fd_isrump(fd)) { int undup2 = 0; + fd = fd_host2rump(fd); + if (ISDUP2ALIAS(fd)) { + _DIAGASSERT(ISDUP2D(fd)); + CLRDUP2ALIAS(fd); + return 0; + } + if (ISDUP2D(fd)) undup2 = 1; - fd = fd_host2rump(fd); op_close = GETSYSCALL(rump, CLOSE); rv = op_close(fd); if (rv == 0 && undup2) @@ -769,6 +806,11 @@ if (!(newd >= 0 && newd <= 2)) return EBADF; oldd = fd_host2rump(oldd); + if (oldd == newd) { + SETDUP2(newd); + SETDUP2ALIAS(newd); + return newd; + } rv = rump_sys_dup2(oldd, newd); if (rv != -1) SETDUP2(newd);
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Thu Feb 17 12:52:33 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: fix signature. from pgoyette To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 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.45 src/lib/librumphijack/hijack.c:1.46 --- src/lib/librumphijack/hijack.c:1.45 Thu Feb 17 12:23:58 2011 +++ src/lib/librumphijack/hijack.c Thu Feb 17 12:52:33 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.45 2011/02/17 12:23:58 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.46 2011/02/17 12:52:33 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.45 2011/02/17 12:23:58 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.46 2011/02/17 12:52:33 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -1455,7 +1455,7 @@ (const char *, const char *), \ (path, target)) -PATHCALL(int, readlink, DUALCALL_READLINK,\ +PATHCALL(ssize_t, readlink, DUALCALL_READLINK,\ (const char *path, char *buf, size_t bufsiz), \ (const char *, char *, size_t), \ (path, buf, bufsiz))
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Thu Feb 17 12:23:58 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Hijack pathname-based system calls. Now all paths starting with /rump are hijacked to go to the rump server. So you can e.g. start a hijacked shell and cd to /rump: $ cd /rump $ pwd /rump $ ls -l dev/null crwxr-xr-x 1 root wheel 2, 2 Feb 17 12:35 dev/null $ ls -l /dev/null crw-rw-rw- 1 root wheel 2, 2 Dec 22 2009 /dev/null $ chmod 0 /dev/null chmod: /dev/null: Operation not permitted $ chmod 0 dev/null $ ls -l /rump/dev/null c- 1 root wheel 2, 2 Feb 17 12:35 /rump/dev/null (of course the rump server must have vfs loaded for that to work) To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 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.44 src/lib/librumphijack/hijack.c:1.45 --- src/lib/librumphijack/hijack.c:1.44 Wed Feb 16 19:26:58 2011 +++ src/lib/librumphijack/hijack.c Thu Feb 17 12:23:58 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.44 2011/02/16 19:26:58 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.45 2011/02/17 12:23:58 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.44 2011/02/16 19:26:58 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.45 2011/02/17 12:23:58 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,20 @@ DUALCALL_CLOSE, DUALCALL_POLLTS, DUALCALL_KEVENT, + DUALCALL_STAT, DUALCALL_LSTAT, DUALCALL_FSTAT, + DUALCALL_CHMOD, DUALCALL_LCHMOD, DUALCALL_FCHMOD, + DUALCALL_CHOWN, DUALCALL_LCHOWN, DUALCALL_FCHOWN, + DUALCALL_OPEN, + DUALCALL_STATVFS1, DUALCALL_FSTATVFS1, + DUALCALL_CHDIR, DUALCALL_FCHDIR, + DUALCALL_LSEEK, + DUALCALL_GETDENTS, + DUALCALL_UNLINK, DUALCALL_SYMLINK, DUALCALL_READLINK, + DUALCALL_RENAME, + DUALCALL_MKDIR, DUALCALL_RMDIR, + DUALCALL_UTIMES, DUALCALL_LUTIMES, DUALCALL_FUTIMES, + DUALCALL_TRUNCATE, DUALCALL_FTRUNCATE, + DUALCALL_FSYNC, DUALCALL_FSYNC_RANGE, DUALCALL__NUM }; @@ -84,12 +99,25 @@ #define REALSELECT select #define REALPOLLTS pollts #define REALKEVENT kevent +#define REALSTAT __stat30 +#define REALLSTAT __lstat30 +#define REALFSTAT __fstat30 +#define REALUTIMES utimes +#define REALLUTIMES lutimes +#define REALFUTIMES futimes #else #define REALSELECT _sys___select50 #define REALPOLLTS _sys___pollts50 #define REALKEVENT _sys___kevent50 +#define REALSTAT __stat50 +#define REALLSTAT __lstat50 +#define REALFSTAT __fstat50 +#define REALUTIMES __utimes50 +#define REALLUTIMES __lutimes50 +#define REALFUTIMES __futimes50 #endif #define REALREAD _sys_read +#define REALGETDENTS __getdents30 int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *); int REALPOLLTS(struct pollfd *, nfds_t, @@ -97,6 +125,13 @@ int REALKEVENT(int, const struct kevent *, size_t, struct kevent *, size_t, const struct timespec *); ssize_t REALREAD(int, void *, size_t); +int REALSTAT(const char *, struct stat *); +int REALLSTAT(const char *, struct stat *); +int REALFSTAT(int, struct stat *); +int REALGETDENTS(int, char *, size_t); +int REALUTIMES(const char *, const struct timeval [2]); +int REALLUTIMES(const char *, const struct timeval [2]); +int REALFUTIMES(int, const struct timeval [2]); #define S(a) __STRING(a) struct sysnames { @@ -128,6 +163,35 @@ { DUALCALL_CLOSE, "close", RSYS_NAME(CLOSE) }, { DUALCALL_POLLTS, S(REALPOLLTS), RSYS_NAME(POLLTS) }, { DUALCALL_KEVENT, S(REALKEVENT), RSYS_NAME(KEVENT) }, + { DUALCALL_STAT, S(REALSTAT), RSYS_NAME(STAT) }, + { DUALCALL_LSTAT, S(REALLSTAT), RSYS_NAME(LSTAT) }, + { DUALCALL_FSTAT, S(REALFSTAT), RSYS_NAME(FSTAT) }, + { DUALCALL_CHOWN, "chown", RSYS_NAME(CHOWN) }, + { DUALCALL_LCHOWN, "lchown", RSYS_NAME(LCHOWN) }, + { DUALCALL_FCHOWN, "fchown", RSYS_NAME(FCHOWN) }, + { DUALCALL_CHMOD, "chmod", RSYS_NAME(CHMOD) }, + { DUALCALL_LCHMOD, "lchmod", RSYS_NAME(LCHMOD) }, + { DUALCALL_FCHMOD, "fchmod", RSYS_NAME(FCHMOD) }, + { DUALCALL_UTIMES, S(REALUTIMES), RSYS_NAME(UTIMES) }, + { DUALCALL_LUTIMES, S(REALLUTIMES), RSYS_NAME(LUTIMES) }, + { DUALCALL_FUTIMES, S(REALFUTIMES), RSYS_NAME(FUTIMES) }, + { DUALCALL_OPEN, "open", RSYS_NAME(OPEN) }, + { DUALCALL_STATVFS1, "statvfs1", RSYS_NAME(STATVFS1) }, + { DUALCALL_FSTATVFS1, "fstatvfs1", RSYS_NAME(FSTATVFS1) }, + { DUALCALL_CHDIR, "chdir", RSYS_NAME(CHDIR) }, + { DUALCALL_FCHDIR, "fchdir", RSYS_NAME(FCHDIR) }, + { DUALCALL_LSEEK, "lseek", RSYS_NAME(LSEEK) }, + { DUALCALL_GETDENTS, "__getdents30", RSYS_NAME(GETDENTS) }, + { DUALCALL_UNLINK, "unlink", RSYS_NAME(UNLINK) }, + { DUALCALL_SYMLINK, "symlink", RSYS_NAME(SYMLINK) }, + { DUALCALL_READLINK, "readlink",
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Wed Feb 16 19:46:42 UTC 2011 Modified Files: src/lib/librumphijack: rumphijack.3 Log Message: document RUMPHIJACK_RETRYCONNECT To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/lib/librumphijack/rumphijack.3 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/rumphijack.3 diff -u src/lib/librumphijack/rumphijack.3:1.2 src/lib/librumphijack/rumphijack.3:1.3 --- src/lib/librumphijack/rumphijack.3:1.2 Tue Jan 25 14:05:42 2011 +++ src/lib/librumphijack/rumphijack.3 Wed Feb 16 19:46:42 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: rumphijack.3,v 1.2 2011/01/25 14:05:42 pooka Exp $ +.\" $NetBSD: rumphijack.3,v 1.3 2011/02/16 19:46:42 pooka Exp $ .\" .\" Copyright (c) 2011 Antti Kantee. All rights reserved. .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 25, 2011 +.Dd February 16, 2011 .Dt RUMPHIJACK 3 .Os .Sh NAME @@ -43,20 +43,51 @@ to capture and redirect system call requests to a rump kernel instead of the host kernel. .Pp +The behaviour of hijacked applications is affected by the following +environment variables: +.Bl -tag -width 12345 +.It Dv RUMPHIJACK_RETRYCONNECT +Change how +.Xr rumpclient 3 +attempts to reconnect to the server in case the connection is lost. +Acceptable values are: +.Bl -tag -width xxinftimexx +.It Dq inftime +retry indefinitely +.It Dq once +retry once, when that connection fails, give up +.It Dq die +call +.Xr exit 3 +if connection failure is detected +.It n +Attempt reconnect for n seconds. +The value 0 means reconnection is not attempted. +The value n must be a positive integer. +.El +.Pp +See +.Xr rumpclient 3 +for more discussion. +.El +.Pp Currently .Nm supports only TCP/IP related system calls. The set of supported subsystems may change later along with the usage of the library. .Sh EXAMPLES -Use an alternate TCP/IP stack for firefox: +Use an alternate TCP/IP stack for firefox with a persistent server +connection: .Bd -literal -offset indent $ setenv RUMP_SERVER unix:///tmp/tcpip $ setenv LD_PRELOAD /usr/lib/librumphijack.so +$ setenv RUMPHIJACK_RETRYCONNECT inftime $ firefox .Ed .Sh SEE ALSO .Xr ld.so 1 , .Xr rump_server 1 , .Xr rump 3 , +.Xr rumpclient 3 , .Xr rump_sp 7
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Feb 15 14:01:52 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: dup() is now implemented using fcntl() To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 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.40 src/lib/librumphijack/hijack.c:1.41 --- src/lib/librumphijack/hijack.c:1.40 Tue Feb 15 13:59:28 2011 +++ src/lib/librumphijack/hijack.c Tue Feb 15 14:01:52 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.40 2011/02/15 13:59:28 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.41 2011/02/15 14:01:52 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.40 2011/02/15 13:59:28 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.41 2011/02/15 14:01:52 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -66,7 +66,7 @@ DUALCALL_GETSOCKOPT, DUALCALL_SETSOCKOPT, DUALCALL_SHUTDOWN, DUALCALL_READ, DUALCALL_READV, - DUALCALL_DUP, DUALCALL_DUP2, + DUALCALL_DUP2, DUALCALL_CLOSE, DUALCALL_POLLTS, DUALCALL_KEVENT, @@ -124,7 +124,6 @@ { DUALCALL_WRITEV, "writev", RSYS_NAME(WRITEV) }, { DUALCALL_IOCTL, "ioctl", RSYS_NAME(IOCTL) }, { DUALCALL_FCNTL, "fcntl", RSYS_NAME(FCNTL) }, - { DUALCALL_DUP, "dup", RSYS_NAME(DUP) }, { DUALCALL_DUP2, "dup2", RSYS_NAME(DUP2) }, { DUALCALL_CLOSE, "close", RSYS_NAME(CLOSE) }, { DUALCALL_POLLTS, S(REALPOLLTS), RSYS_NAME(POLLTS) },
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Feb 15 13:59:28 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Properly implement fcntl commands: F_DUPFD, F_CLOSEM, F_MAXFD To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 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.39 src/lib/librumphijack/hijack.c:1.40 --- src/lib/librumphijack/hijack.c:1.39 Mon Feb 14 14:56:23 2011 +++ src/lib/librumphijack/hijack.c Tue Feb 15 13:59:28 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.39 2011/02/14 14:56:23 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.40 2011/02/15 13:59:28 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.39 2011/02/14 14:56:23 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.40 2011/02/15 13:59:28 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -142,8 +142,12 @@ int (*host_daemon)(int, int); int (*host_execve)(const char *, char *const[], char *const[]); -static unsigned dup2mask; -#define ISDUP2D(fd) ((fd < 32) && (1<<(fd) & dup2mask)) +static uint32_t dup2mask; +#define ISDUP2D(fd) (((fd) < 32) && (1<<(fd) & dup2mask)) +#define SETDUP2(fd) \ +do { if ((fd) < 32) dup2mask |= (1<<(fd)); } while (/*CONSTCOND*/0) +#define CLRDUP2(fd) \ +do { if ((fd) < 32) dup2mask &= ~(1<<(fd)); } while (/*CONSTCOND*/0) //#define DEBUGJACK #ifdef DEBUGJACK @@ -277,13 +281,12 @@ } if (getenv_r("RUMPHIJACK__DUP2MASK", buf, sizeof(buf)) == 0) { - dup2mask = atoi(buf); + dup2mask = strtoul(buf, NULL, 10); } } /* XXX: need runtime selection. low for now due to FD_SETSIZE */ #define HIJACK_FDOFF 128 -#define HIJACK_ASSERT 128 /* XXX */ static int fd_rump2host(int fd) { @@ -313,8 +316,33 @@ return ISDUP2D(fd) || fd >= HIJACK_FDOFF; } -#define assertfd(_fd_) assert(ISDUP2D(_fd_) || (_fd_) >= HIJACK_ASSERT) -#undef HIJACK_FDOFF +#define assertfd(_fd_) assert(ISDUP2D(_fd_) || (_fd_) >= HIJACK_FDOFF) + +static int +dodup(int oldd, int minfd) +{ + int (*op_fcntl)(int, int, ...); + int newd; + int isrump; + + DPRINTF(("dup -> %d (minfd %d)\n", oldd, minfd)); + if (fd_isrump(oldd)) { + op_fcntl = GETSYSCALL(rump, FCNTL); + oldd = fd_host2rump(oldd); + isrump = 1; + } else { + op_fcntl = GETSYSCALL(host, FCNTL); + isrump = 0; + } + + newd = op_fcntl(oldd, F_DUPFD, minfd); + + if (isrump) + newd = fd_rump2host(newd); + DPRINTF(("dup <- %d\n", newd)); + + return newd; +} int __socket30(int, int, int); int @@ -388,31 +416,99 @@ return rv; } - -/* TODO: support F_DUPFD, F_CLOSEM, F_MAXFD */ +#include int fcntl(int fd, int cmd, ...) { int (*op_fcntl)(int, int, ...); va_list ap; - int rv; + int rv, minfd, i; - DPRINTF(("fcntl -> %d\n", fd)); - if (fd_isrump(fd)) { - fd = fd_host2rump(fd); - op_fcntl = GETSYSCALL(rump, FCNTL); - } else { - op_fcntl = GETSYSCALL(host, FCNTL); - if (cmd == F_CLOSEM) - if (rumpclient__closenotify(&fd, + DPRINTF(("fcntl -> %d (cmd %d)\n", fd, cmd)); + + switch (cmd) { + case F_DUPFD: + va_start(ap, cmd); + minfd = va_arg(ap, int); + va_end(ap); + return dodup(fd, minfd); + + case F_CLOSEM: + /* + * So, if fd < HIJACKOFF, we want to do a host closem. + */ + + if (fd < HIJACK_FDOFF) { + int closemfd = fd; + + if (rumpclient__closenotify(&closemfd, RUMPCLIENT_CLOSE_FCLOSEM) == -1) return -1; - } + op_fcntl = GETSYSCALL(host, FCNTL); + rv = op_fcntl(closemfd, cmd); + if (rv) +return rv; + } - va_start(ap, cmd); - rv = op_fcntl(fd, cmd, va_arg(ap, void *)); - va_end(ap); - return rv; + /* + * Additionally, we want to do a rump closem, but only + * for the file descriptors not within the dup2mask. + */ + + /* why don't we offer fls()? */ + for (i = 31; i >= 0; i--) { + if (dup2mask & 1<= HIJACK_FDOFF) + fd -= HIJACK_FDOFF; + else + fd = 0; + fd = MAX(i+1, fd); + + /* hmm, maybe we should close rump fd's not within dup2mask? */ + + return rump_sys_fcntl(fd, F_CLOSEM); + + case F_MAXFD: + /* + * For maxfd, if there's a rump kernel fd, return + * it hostified. Otherwise, return host's MAXFD + * return value. + */ + if ((rv = rump_sys_fcntl(fd, F_MAXFD)) != -1) { + /* + * This might go a little wrong in case + * of dup2 to [012], but I'm not sure if + * there's a justification for tracking + * that info. Consider e.g. + * dup2(rumpfd, 2) followed by rump_sys_open() + * returning 1. We should return 1+HIJACKOFF, + * not 2+HIJACKOFF. However, if [01] is not + * open, the correct return value is 2. + */ + return fd_rump2host(fd); + } else { + op_fcntl = GETSYSCALL(host, FCNTL); + return op_fcntl(fd, F_MAXFD); + } + /*NOTREACHED*/ + + default: + if (fd_isrump(fd)) { + fd =
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Sat Feb 12 10:25:46 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Fix select() if no fds are set. patch from Alexander Nasonov, PR lib/44552 To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 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.37 src/lib/librumphijack/hijack.c:1.38 --- src/lib/librumphijack/hijack.c:1.37 Fri Feb 11 14:02:12 2011 +++ src/lib/librumphijack/hijack.c Sat Feb 12 10:25:46 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.37 2011/02/11 14:02:12 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.38 2011/02/12 10:25:46 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.37 2011/02/11 14:02:12 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.38 2011/02/12 10:25:46 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -563,7 +563,7 @@ } if (realnfds) { - pfds = malloc(sizeof(*pfds) * realnfds); + pfds = calloc(realnfds, sizeof(*pfds)); if (!pfds) return -1; } else { @@ -572,7 +572,6 @@ for (i = 0, j = 0; i < nfds; i++) { incr = 0; - pfds[j].events = pfds[j].revents = 0; if (readfds && FD_ISSET(i, readfds)) { pfds[j].fd = i; pfds[j].events |= POLLIN;
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 11 14:02:13 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: play the important typecast game To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 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.36 src/lib/librumphijack/hijack.c:1.37 --- src/lib/librumphijack/hijack.c:1.36 Fri Feb 11 12:46:41 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 11 14:02:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.36 2011/02/11 12:46:41 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.37 2011/02/11 14:02:12 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.36 2011/02/11 12:46:41 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.37 2011/02/11 14:02:12 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -591,7 +591,7 @@ if (incr) j++; } - assert(j == realnfds); + assert(j == (int)realnfds); if (timeout) { TIMEVAL_TO_TIMESPEC(timeout, &ts);
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Fri Feb 11 12:46:41 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: ssh mostly ignores the return value of select(), so if the timeout expired it would assume that all input set descriptors had activity. In case we get rv == 0 from the poll backend, zero out the fd sets to signal that in fact no descriptors have activity. Before this commit ssh was "jittery" when run through a rump tcp/ip stack (interactive sessions kept blocking on stdin and you had to "peddle" the connection). Now it works smoothly ... or at least smoothly enough so that this commit could be done through a rump tcp/ip stack: USER COMMANDPID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS root ssh1250 tcplocalhost.65517 cvs.netbsd.org.22 To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 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.35 src/lib/librumphijack/hijack.c:1.36 --- src/lib/librumphijack/hijack.c:1.35 Tue Feb 8 19:12:54 2011 +++ src/lib/librumphijack/hijack.c Fri Feb 11 12:46:41 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.35 2011/02/08 19:12:54 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.36 2011/02/11 12:46:41 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.35 2011/02/08 19:12:54 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.36 2011/02/11 12:46:41 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -591,18 +591,27 @@ if (incr) j++; } + assert(j == realnfds); if (timeout) { TIMEVAL_TO_TIMESPEC(timeout, &ts); tsp = &ts; } rv = REALPOLLTS(pfds, realnfds, tsp, NULL); - if (rv <= 0) + /* + * "If select() returns with an error the descriptor sets + * will be unmodified" + */ + if (rv < 0) goto out; /* - * ok, harvest results. first zero out entries (can't use - * FD_ZERO for the obvious select-me-not reason). whee. + * zero out results (can't use FD_ZERO for the + * obvious select-me-not reason). whee. + * + * We do this here since some software ignores the return + * value of select, and hence if the timeout expires, it may + * assume all input descriptors have activity. */ for (i = 0; i < nfds; i++) { if (readfds) @@ -612,8 +621,12 @@ if (exceptfds) FD_CLR(i, exceptfds); } + if (rv == 0) + goto out; - /* and then plug in the results */ + /* + * We have >0 fds with activity. Harvest the results. + */ for (i = 0; i < (int)realnfds; i++) { if (readfds) { if (pfds[i].revents & POLLIN) {
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Feb 8 19:12:54 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Fix pasto, use GETSYSCALLS() where possible To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 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.34 src/lib/librumphijack/hijack.c:1.35 --- src/lib/librumphijack/hijack.c:1.34 Tue Feb 8 14:45:35 2011 +++ src/lib/librumphijack/hijack.c Tue Feb 8 19:12:54 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.34 2011/02/08 14:45:35 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.35 2011/02/08 19:12:54 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.34 2011/02/08 14:45:35 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.35 2011/02/08 19:12:54 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -684,7 +684,7 @@ struct pollarg *parg = arg; intptr_t rv; - op_pollts = syscalls[DUALCALL_POLLTS].bs_host; + op_pollts = GETSYSCALL(host, POLLTS); rv = op_pollts(parg->pfds, parg->nfds, parg->ts, parg->sigmask); if (rv == -1) parg->errnum = errno; @@ -777,7 +777,7 @@ parg.pipefd = rpipe[1]; pthread_create(&pt, NULL, hostpoll, &parg); - op_pollts = syscalls[DUALCALL_POLLTS].bs_rump; + op_pollts = GETSYSCALL(rump, POLLTS); lrv = op_pollts(pfd_rump, nfds+1, ts, NULL); sverrno = errno; write(hpipe[1], &rv, sizeof(rv)); @@ -804,7 +804,7 @@ } out: - host_close = syscalls[DUALCALL_CLOSE].bs_host; + host_close = GETSYSCALL(host, CLOSE); if (rpipe[0] != -1) rump_sys_close(rpipe[0]); if (rpipe[1] != -1) @@ -818,9 +818,9 @@ errno = sverrno; } else { if (hostcall) { - op_pollts = syscalls[DUALCALL_POLLTS].bs_host; + op_pollts = GETSYSCALL(host, POLLTS); } else { - op_pollts = syscalls[DUALCALL_POLLTS].bs_rump; + op_pollts = GETSYSCALL(rump, POLLTS); adjustpoll(fds, nfds, fd_host2rump); } @@ -873,7 +873,7 @@ } } - op_kevent = GETSYSCALL(host, ACCEPT); + op_kevent = GETSYSCALL(host, KEVENT); return op_kevent(kq, changelist, nchanges, eventlist, nevents, timeout); }
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Feb 8 14:45:35 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Make sure we can do host kevent since the -current (and recent nb5) libc resolver uses it. Error out in case of rump fd kevent (TODO). Fixes one more problem pointed out by Alexander Nasonov. Also, implement dup(). (TODO: implement it along the fcntl path too) To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 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.33 src/lib/librumphijack/hijack.c:1.34 --- src/lib/librumphijack/hijack.c:1.33 Tue Feb 8 12:20:11 2011 +++ src/lib/librumphijack/hijack.c Tue Feb 8 14:45:35 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.33 2011/02/08 12:20:11 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.34 2011/02/08 14:45:35 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.33 2011/02/08 12:20:11 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.34 2011/02/08 14:45:35 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -66,8 +66,10 @@ DUALCALL_GETSOCKOPT, DUALCALL_SETSOCKOPT, DUALCALL_SHUTDOWN, DUALCALL_READ, DUALCALL_READV, - DUALCALL_DUP2, DUALCALL_CLOSE, + DUALCALL_DUP, DUALCALL_DUP2, + DUALCALL_CLOSE, DUALCALL_POLLTS, + DUALCALL_KEVENT, DUALCALL__NUM }; @@ -81,15 +83,19 @@ #if !__NetBSD_Prereq__(5,99,7) #define REALSELECT select #define REALPOLLTS pollts +#define REALKEVENT kevent #else #define REALSELECT _sys___select50 #define REALPOLLTS _sys___pollts50 +#define REALKEVENT _sys___kevent50 #endif #define REALREAD _sys_read int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *); int REALPOLLTS(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); +int REALKEVENT(int, const struct kevent *, size_t, struct kevent *, size_t, + const struct timespec *); ssize_t REALREAD(int, void *, size_t); #define S(a) __STRING(a) @@ -118,9 +124,11 @@ { DUALCALL_WRITEV, "writev", RSYS_NAME(WRITEV) }, { DUALCALL_IOCTL, "ioctl", RSYS_NAME(IOCTL) }, { DUALCALL_FCNTL, "fcntl", RSYS_NAME(FCNTL) }, + { DUALCALL_DUP, "dup", RSYS_NAME(DUP) }, { DUALCALL_DUP2, "dup2", RSYS_NAME(DUP2) }, { DUALCALL_CLOSE, "close", RSYS_NAME(CLOSE) }, { DUALCALL_POLLTS, S(REALPOLLTS), RSYS_NAME(POLLTS) }, + { DUALCALL_KEVENT, S(REALKEVENT), RSYS_NAME(KEVENT) }, }; #undef S @@ -269,7 +277,6 @@ /* XXX: need runtime selection. low for now due to FD_SETSIZE */ #define HIJACK_FDOFF 128 -#define HIJACK_SELECT 128 /* XXX */ #define HIJACK_ASSERT 128 /* XXX */ static int fd_rump2host(int fd) @@ -375,6 +382,8 @@ return rv; } + +/* TODO: support F_DUPFD, F_CLOSEM, F_MAXFD */ int fcntl(int fd, int cmd, ...) { @@ -444,6 +453,28 @@ return rv; } +int +dup(int oldd) +{ + int (*op_dup)(int); + int newd; + + DPRINTF(("dup -> %d\n", oldd)); + if (fd_isrump(oldd)) { + op_dup = GETSYSCALL(rump, DUP); + } else { + op_dup = GETSYSCALL(host, DUP); + } + + newd = op_dup(oldd); + + if (fd_isrump(oldd)) + newd = fd_rump2host(newd); + DPRINTF(("dup <- %d\n", newd)); + + return newd; +} + /* * We just wrap fork the appropriate rump client calls to preserve * the file descriptors of the forked parent in the child, but @@ -818,26 +849,32 @@ } int -kqueue(void) -{ - - if (!ISDUP2D(STDERR_FILENO) && isatty(STDERR_FILENO)) { - fprintf(stderr, "rumphijack: kqueue currently unsupported\n"); - } - errno = ENOSYS; - return -1; -} - -/*ARGSUSED*/ -int -kevent(int kq, const struct kevent *changelist, size_t nchanges, +REALKEVENT(int kq, const struct kevent *changelist, size_t nchanges, struct kevent *eventlist, size_t nevents, const struct timespec *timeout) { + int (*op_kevent)(int, const struct kevent *, size_t, + struct kevent *, size_t, const struct timespec *); + const struct kevent *ev; + size_t i; + + /* + * Check that we don't attempt to kevent rump kernel fd's. + * That needs similar treatment to select/poll, but is slightly + * trickier since we need to manage to different kq descriptors. + * (TODO, in case you're wondering). + */ + for (i = 0; i < nchanges; i++) { + ev = &changelist[i]; + if (ev->filter == EVFILT_READ || ev->filter == EVFILT_WRITE || + ev->filter == EVFILT_VNODE) { + if (fd_isrump(ev->ident)) +return ENOTSUP; + } + } - fprintf(stderr, "kevent impossible\n"); - abort(); - /*NOTREACHED*/ + op_kevent = GETSYSCALL(host, ACCEPT); + return op_kevent(kq, changelist, nchanges, eventlist, nevents, timeout); } /*
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Tue Feb 8 12:20:11 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: add std dprint to fdcall To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 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.32 src/lib/librumphijack/hijack.c:1.33 --- src/lib/librumphijack/hijack.c:1.32 Mon Feb 7 19:34:39 2011 +++ src/lib/librumphijack/hijack.c Tue Feb 8 12:20:11 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.32 2011/02/07 19:34:39 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.33 2011/02/08 12:20:11 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.32 2011/02/07 19:34:39 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.33 2011/02/08 12:20:11 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -161,6 +161,7 @@ { \ type (*fun) proto; \ \ + DPRINTF(("%s -> %d\n", __STRING(name), fd)); \ if (fd_isrump(fd)) { \ fun = syscalls[rcname].bs_rump;\ fd = fd_host2rump(fd); \
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Feb 7 19:34:39 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: Force gcc to generate a stack frame for the call to dlsym(RTLD_NEXT). Without this hack at least amd64 -O2 just used jmp and The Wrong Thing happened. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 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.31 src/lib/librumphijack/hijack.c:1.32 --- src/lib/librumphijack/hijack.c:1.31 Mon Feb 7 12:23:05 2011 +++ src/lib/librumphijack/hijack.c Mon Feb 7 19:34:39 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.31 2011/02/07 12:23:05 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.32 2011/02/07 19:34:39 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.31 2011/02/07 12:23:05 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.32 2011/02/07 19:34:39 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -174,12 +174,25 @@ /* * This is called from librumpclient in case of LD_PRELOAD. * It ensures correct RTLD_NEXT. + * + * ... except, it's apparently extremely difficult to force + * at least gcc to generate an actual stack frame here. So + * sprinkle some volatile foobar and baz to throw the optimizer + * off the scent and generate a variable assignment with the + * return value. The posterboy for this meltdown is amd64 + * with -O2. At least with gcc 4.1.3 i386 works regardless of + * optimization. */ +volatile int rumphijack_unrope; /* there, unhang yourself */ static void * hijackdlsym(void *handle, const char *symbol) { + void *rv; + + rv = dlsym(handle, symbol); + rumphijack_unrope = *(volatile int *)rv; - return dlsym(handle, symbol); + return (void *)rv; } /* low calorie sockets? */
CVS commit: src/lib/librumphijack
Module Name:src Committed By: pooka Date: Mon Feb 7 12:23:05 UTC 2011 Modified Files: src/lib/librumphijack: hijack.c Log Message: duh, _sys_read, not read. STAY FIXED, DAMNIT! To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 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.30 src/lib/librumphijack/hijack.c:1.31 --- src/lib/librumphijack/hijack.c:1.30 Mon Feb 7 11:51:02 2011 +++ src/lib/librumphijack/hijack.c Mon Feb 7 12:23:05 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hijack.c,v 1.30 2011/02/07 11:51:02 pooka Exp $ */ +/* $NetBSD: hijack.c,v 1.31 2011/02/07 12:23:05 pooka Exp $ */ /*- * Copyright (c) 2011 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: hijack.c,v 1.30 2011/02/07 11:51:02 pooka Exp $"); +__RCSID("$NetBSD: hijack.c,v 1.31 2011/02/07 12:23:05 pooka Exp $"); #define __ssp_weak_name(fun) _hijack_ ## fun @@ -85,10 +85,12 @@ #define REALSELECT _sys___select50 #define REALPOLLTS _sys___pollts50 #endif +#define REALREAD _sys_read int REALSELECT(int, fd_set *, fd_set *, fd_set *, struct timeval *); int REALPOLLTS(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); +ssize_t REALREAD(int, void *, size_t); #define S(a) __STRING(a) struct sysnames { @@ -110,7 +112,7 @@ { DUALCALL_GETSOCKOPT, "getsockopt", RSYS_NAME(GETSOCKOPT) }, { DUALCALL_SETSOCKOPT, "setsockopt", RSYS_NAME(SETSOCKOPT) }, { DUALCALL_SHUTDOWN, "shutdown", RSYS_NAME(SHUTDOWN) }, - { DUALCALL_READ, "read", RSYS_NAME(READ) }, + { DUALCALL_READ, S(REALREAD), RSYS_NAME(READ) }, { DUALCALL_READV, "readv", RSYS_NAME(READV) }, { DUALCALL_WRITE, "write", RSYS_NAME(WRITE) }, { DUALCALL_WRITEV, "writev", RSYS_NAME(WRITEV) }, @@ -912,7 +914,7 @@ #define STUB(fun) fun #endif -FDCALL(ssize_t, read, DUALCALL_READ, \ +FDCALL(ssize_t, REALREAD, DUALCALL_READ,\ (int fd, void *buf, size_t buflen),\ (int, void *, size_t), \ (fd, buf, buflen))