Commit Graph

45 Commits

Author SHA1 Message Date
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
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
pooka
847a170bc4 call the non-compat pollts() from inside the library 2011-02-07 10:28:18 +00:00
pooka
b5dd289bbd make it possible to specify client connection retry model in
RUMPHIJACK_RETRY
2011-02-06 15:48:20 +00:00
pooka
c4359a17f8 be kinder about kqueue()
(but paradoxically omit the surprise)
2011-02-06 13:05:19 +00:00
pooka
54828d050f uncommit part of previous which wasn't supposed to change 2011-02-05 16:59:24 +00:00
pooka
23134bfed1 Wrap daemon() since it forks. Otherwise we lose the rumpclient kq
descriptor and have multiple processes using the commfd.
2011-02-05 16:57:39 +00:00
pooka
fe247b6f0a Fix some snafus to allow rumphijack to work on -current.
reported by Alexander Nasonov
2011-02-05 12:38:19 +00:00
pooka
fd79a76046 Use NEEDED for librumpclient instead of loading it manually. 2011-01-27 18:12:19 +00:00
pooka
e96a54f450 Set server reconnection timeout to infinite. There probably need
to be some toggle eventually, but for now I'm optimizing the default
for my firefox use ;)
2011-01-27 18:05:16 +00:00
christos
9a37731036 make SSP friendly 2011-01-26 18:48:32 +00:00
pooka
8c818e7121 fix compilation on -current 2011-01-25 17:37:00 +00:00
pooka
f4ef6bac83 the usual fun for WARNS=4
signed,
  unsigned
2011-01-25 12:53:45 +00:00
pooka
14186479f2 dramatic whitespace fix 2011-01-25 12:21:36 +00:00
pooka
9d0409a087 Rewrite to declare most dual-kernel calls with macros. This helps
with adding new calls and makes all existing fd-accepting hijacked
calls dual-kernel.  It would be better to autogenerate the code
from syscalls.master, but this is easier for now.
2011-01-25 12:18:33 +00:00
pooka
11b5103ee7 Do the standard dance for sendto/recvfrom since nspluginwrapper
wants to use them.  XXX: need to fold the dance sequence into a
common routine.
2011-01-19 11:27:01 +00:00
pooka
dda8526653 fix lp64 snafu (hopefully)
from pgoyette
2011-01-18 23:43:21 +00:00
pooka
f6eee6f557 * attempt to match libc non-compat names (XXX: needs work)
* make shutdown() a dual-stack call
* flip the default to use host for PF_UNIX, since that's generally
  the desired case (because of X)
2011-01-18 19:41:02 +00:00
pooka
2c78c39d6a pollts:
Since fds[] does not go to both kernels, set revents to 0 when
splitting the vector.  Now any stale revents passed by the caller
do not get counted as results for the kernel which did not "win"
the poll.

This fixes a situation where a firefox transfer would occasionally
stall.  Now firefox works full speed with a rump networking stack.
2011-01-18 16:00:04 +00:00
pooka
613ebae808 Don't count sparse elements in the poll vector for host fds. 2011-01-18 14:51:14 +00:00
pooka
ac1dfbf509 Fix conversion: there are 1000*1000 nanoseconds in a millisecond, not 1000. 2011-01-18 14:45:30 +00:00
pooka
07d03119a0 Fix dup2 mask so that dup2'ing a rump kernel fd to 1 does not cause
stderr to be treated as a rump kernel fd as well.  Makes e.g.
bozohttpd work better with stderr logging.

Also, add aborty stubs for kqueue.
(implementing kqueue is even trickier than implementing select/poll
since we need to keep state for two kqueue fd's)
2011-01-18 11:04:10 +00:00
pooka
d8244e0b17 Use host_close() instead of close() where we know it to be the
right interface.
2011-01-17 16:30:09 +00:00
pooka
6054dbc060 Adapt to rump syscall changes. The correct rump compat syscall is
now automatically picked based on the ABI of the target the library
is compiled for.

(the host libc symbolname to override still needs a little attention
based on the system version)
2011-01-17 16:27:54 +00:00
pooka
81131c3a38 Networked X11 clients have the annoying property that they need to
contact the X server.  Since most of the useful cases these days
are local, add a toggle which forwards PF_LOCAL sockets to the host
and all other protocol families to the rump kernel.

This makes an unmodified firefox work with a rump TCP/IP stack.
I'm sure someone will find applications for being able to run
multiple web browser profiles on one OS with each browser having
a different IP address in the same subnet ...
2011-01-09 19:56:33 +00:00
pooka
2ec0087d6f Don't depend on malloc(0) returning non-NULL. 2011-01-09 14:15:06 +00:00
pooka
bfa098ff96 dprintf to stderr. stop doing it if stderr_fileno gets dup2()'d 2011-01-09 10:28:46 +00:00
pooka
8ee1967622 Support dual kernel select() by emulating it with pollts(). It
would have been much easier if up to and including 5.0 we wouldn't
silently cap the nfds argument to poll(!!!).

Makes things like socket(1) work out-of-the-box, and pretty much
every other decidedly prehistoric select() user.
(netcat is a slight exception since it sets FD_SETSIZE, a.k.a.
interface-of-the-year, to 16)
2011-01-08 21:30:24 +00:00
pooka
270275f700 support pollts and rewrite poll in terms of pollts 2011-01-08 18:11:46 +00:00
pooka
1cc3ec9f1f Support fork() and dup2().
This is sufficient to make an unmodified httpd(8) be able to serve
pages via a rump networking stack.
2011-01-08 14:19:27 +00:00
pooka
e9d1107acf Begin work on a syscall hijacking library which can be LD_PRELOADed
to convince non-rumped applications to communicate with a rump
kernel instead of the host kernel.  The precision of what goes
where is not exactly surgical, but for example when wanting to
debug a web server's TCP/IP stack interaction, it might be enough.
When all you have is a hand grenade, all problems look like a ....
hmm?

There's still plenty to figure out.  For example, I'm not sure what
the user interface will be like.  Now it just attempts to hijack
network communication.  It also needs to sync with symbol renaming
in libc, and maybe autogenerate the non-schizophrenic wrappers
where the communication is heading to exactly one destination, lest
I'll be a mummmy by the time I finish writing them all.  As a fun
example of a non-non-schizophrenic one, consider poll().

Work in progress, but I managed to get two non-rumped netcats
talking to each other or fetching the index from a non-rumped
thttpd.  telnet works in one direction (i can read the data from
netcat, but anything i send back is not printed).  bozohttpd uses
dup2() which i haven't bothered to address yet, etcetc.

(not hooking this up the build for now)
2011-01-07 19:52:43 +00:00