Commit Graph

84 Commits

Author SHA1 Message Date
pooka
c6cd7e8f80 another comment 2011-03-01 10:54:06 +00:00
pooka
691e852f03 comment 2011-03-01 10:47:29 +00:00
pooka
060e3527df make compiler sign-happy 2011-02-28 20:39:07 +00:00
pooka
9ec87a7764 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.
2011-02-28 19:57:36 +00:00
pooka
ee9b785d83 make error messages sensible. from uwe 2011-02-27 11:32:12 +00:00
pooka
f70541ba1f whoops, didn't mean to delete futimes in previous. also from riz 2011-02-25 18:36:36 +00:00
pooka
b183f0392f support mknod. from riz 2011-02-25 18:29:00 +00:00
pooka
da73d5bcb9 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 ....
2011-02-25 16:01:41 +00:00
pooka
b8eb9b59e8 Make the rumphijack dlsym trampoline call from rumpclient a "real"
function call instead of a call through a function pointer.
Apparently powerpc ld.elf_so gets __hackish_return_address() wrong
if the call is done through a function pointer (digging deeper into
that stuff is beyond my interest).

Thanks to riz for providing access to a macppc for debugging.
Unthanks to the broken toolchain in the default installation which
wasted approximately 4 hours of time last night.
2011-02-24 12:25:44 +00:00
pooka
edac4b359f duh, remember to cvs add hijack.h too...
from pgoyette
2011-02-23 18:18:24 +00:00
pooka
7e61a6ce53 Return value audit: properly set errno and return -1.
Fixes at least cross-kernel mv(1).
2011-02-23 15:44:38 +00:00
pooka
2350034b27 +access(2) 2011-02-23 15:29:21 +00:00
pooka
247a92b203 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
2011-02-23 15:23:15 +00:00
pooka
a63f48d68d If minfd for F_DUPFD is >= hijackoff, assume it means a minimum
value in the rump kernel and adjust accordingly.
2011-02-21 20:11:56 +00:00
pooka
b1f4a8807b disallow mmap(MAP_FILE) from a rump kernel fd 2011-02-21 13:19:35 +00:00
pooka
dc0a4e21dd 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.
2011-02-21 12:55:21 +00:00
pooka
463ea53fc5 hijack:
1) {,f,l}chflags (used e.g. by cp(1))
  2) p{read,write}{,v} (used by many)
2011-02-21 12:51:06 +00:00
pooka
3c9255c1a2 fix tests/lib/librumphijack/t_asyncio:invafd -- dual poll on invalid fd 2011-02-20 23:47:04 +00:00
pooka
d9a5e73fe5 minor clarification 2011-02-20 14:21:04 +00:00
pooka
6d9d147305 fix symlink pathname examination (rationale-to-joerg: so that it works) 2011-02-19 19:17:33 +00:00
pooka
9c67a5d8a0 hijack __getcwd() 2011-02-19 13:10:35 +00:00
pooka
bfd70564a0 and now with less crazy whitespace 2011-02-19 13:09:40 +00:00
pooka
9cb130af6b support PF_OROUTE and PF_MPLS where available 2011-02-19 13:07:53 +00:00
pooka
5191458a1c hijack libc-internal name for lseek so that libc-internal callers
go to the right kernel too.
2011-02-18 19:27:06 +00:00
pooka
c0f2e1965c block cross-kernel rename in the other direction also 2011-02-18 14:44:46 +00:00
pooka
ff90450826 fix rename 2011-02-18 14:33:11 +00:00
pooka
b8883bd5ec uhm, put PF_LOCAL on the socketlist 2011-02-18 14:25:04 +00:00
pooka
0e29006e71 give the signmonkey a banana 2011-02-18 13:04:52 +00:00
pooka
c89b586dc4 Document .Ev RUMPHIJACK 2011-02-18 12:22:46 +00:00
pooka
45c58b6c6a 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
rumpfs                1          1          0 100% /
pain-rustique:53:~> df /dev
Filesystem   1K-blocks       Used      Avail %Cap Mounted on
/dev/wd0a       1019864     280640     688232  28% /
2011-02-18 11:41:32 +00:00
pooka
7379975cf9 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
	Filesystem        Size       Used      Avail %Cap Mounted on
	/ffsimg           496M       380M        91M  80% /mnt
	$ du -sckh *
	192K    dev
	380M    mnt
	381M    total
	$ umount -R mnt
	$ df -h mnt
	Filesystem        Size       Used      Avail %Cap Mounted on
	rumpfs            1.0K       1.0K         0B 100% /
	$

(note, you need -R to umount due to various degrees of unsuccesful
magic it attempts to perform without it)
2011-02-17 17:18:08 +00:00
pooka
b4ff8b5f63 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)
2011-02-17 15:20:10 +00:00
pooka
df19bb20b9 fix signature. from pgoyette 2011-02-17 12:52:33 +00:00
pooka
4d5a38cb17 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)
2011-02-17 12:23:58 +00:00
pooka
246da2148a document RUMPHIJACK_RETRYCONNECT 2011-02-16 19:46:42 +00:00
pooka
2e5776377c * set default server connection retry to 0 (no reconnection attempts).
while for some cases attempting retry after server restart works
  brilliantly (e.g. firefox), in other cases it's quite disasterous
  (sshd doesn't like its file descriptors going missing and does not
  attempt to reopen them, leading to a quite catastophic loop of
  EBADF once the server does come back)
* rename RUMPHIJACK_RETRY to the slightly more sensible
  RUMPHIJACK_RETRYCONNECT
2011-02-16 19:26:58 +00:00
pooka
36f6818061 Support vfork. Add rumpclient wrapper for daemon(3). 2011-02-16 17:56:46 +00:00
pooka
f4ba3dcd9e Push the fiddly tasks for exec and fork from rumphijack to rumpclient.
This makes it possible easily execute those operations also from
non-hijacked rump clients (plus fixes one memory leak in an error
branch).
2011-02-16 15:33:46 +00:00
pooka
172a314918 dup() is now implemented using fcntl() 2011-02-15 14:01:52 +00:00
pooka
8b62780ace Properly implement fcntl commands: F_DUPFD, F_CLOSEM, F_MAXFD 2011-02-15 13:59:28 +00:00
pooka
2ba7fe5525 A bunch of changes which essentially make sshd work with a hijacked
rump tcp/ip stack:

* sshd likes to fork and then re-exec itself
  ==> trap execve() and augment the env with the current parameters
      essential to a rump kernel (kernel communication fd, information
      about dup2'd file descriptors)

* sshd likes to play lots of games with pipes, socketpairs and dup{,2}()
  ==> make sure we do not close essential rump client descriptors:
      dup() them to a safe place, except for F_CLOSEM where we
      simply leave them alone.  also, partially solved by the above,
      make sure the process's set of rump kernel descriptors persists
      over exec()

* sshd likes to chdir() before exec
  ==> for unix-style rump_sp(7) sockets save the full path on the
      initial exec and use it afterwards.  thread the path through
      the environment in execve()
2011-02-14 14:56:23 +00:00
pooka
b981a177b2 Fix select() if no fds are set.
patch from Alexander Nasonov, PR lib/44552
2011-02-12 10:25:46 +00:00
pooka
84d55c436c play the important typecast game 2011-02-11 14:02:12 +00:00
pooka
7f4c3562b7 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     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
root     ssh        125    0 tcp    localhost.65517       cvs.netbsd.org.22
2011-02-11 12:46:41 +00:00
pooka
8ffa45b220 Fix pasto, use GETSYSCALLS() where possible 2011-02-08 19:12:54 +00:00
pooka
8331b66064 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)
2011-02-08 14:45:35 +00:00
pooka
0d0ce98254 add std dprint to fdcall 2011-02-08 12:20:11 +00:00
pooka
6aea514dcb 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.
2011-02-07 19:34:39 +00:00
pooka
ac3cf3ec89 duh, _sys_read, not read. STAY FIXED, DAMNIT! 2011-02-07 12:23:05 +00:00
pooka
46b90f129d Unbreak the ssp lossage from the default -current build by removing
it.  I still don't have any idea what the ssp stuff is supposed to
do and how it's supposed to even begin to work.  If someone wants
to change this now, run tests/lib/librumphijack before commit so
that I can avoid another multihour debugging session!
2011-02-07 11:51:02 +00:00