freebsd-dev/sys/miscfs/procfs
Poul-Henning Kamp 75c1354190 This Implements the mumbled about "Jail" feature.
This is a seriously beefed up chroot kind of thing.  The process
is jailed along the same lines as a chroot does it, but with
additional tough restrictions imposed on what the superuser can do.

For all I know, it is safe to hand over the root bit inside a
prison to the customer living in that prison, this is what
it was developed for in fact:  "real virtual servers".

Each prison has an ip number associated with it, which all IP
communications will be coerced to use and each prison has its own
hostname.

Needless to say, you need more RAM this way, but the advantage is
that each customer can run their own particular version of apache
and not stomp on the toes of their neighbors.

It generally does what one would expect, but setting up a jail
still takes a little knowledge.

A few notes:

   I have no scripts for setting up a jail, don't ask me for them.

   The IP number should be an alias on one of the interfaces.

   mount a /proc in each jail, it will make ps more useable.

   /proc/<pid>/status tells the hostname of the prison for
   jailed processes.

   Quotas are only sensible if you have a mountpoint per prison.

   There are no privisions for stopping resource-hogging.

   Some "#ifdef INET" and similar may be missing (send patches!)

If somebody wants to take it from here and develop it into
more of a "virtual machine" they should be most welcome!

Tools, comments, patches & documentation most welcome.

Have fun...

Sponsored by:   http://www.rndassociates.com/
Run for almost a year by:       http://www.servetheweb.com/
1999-04-28 11:38:52 +00:00
..
procfs_ctl.c Removed unused #includes. 1997-08-02 14:33:27 +00:00
procfs_fpregs.c Check permissions for fp regs as well as normal regs. 1997-08-12 05:23:51 +00:00
procfs_map.c Hide access to vmspace:vm_pmap with inline function vmspace_pmap(). This 1999-02-19 14:25:37 +00:00
procfs_mem.c Change suser_xxx() to suser() where it applies. 1999-04-27 12:21:16 +00:00
procfs_note.c Removed unused #includes. 1997-08-02 14:33:27 +00:00
procfs_regs.c Fix procfs security hole -- check permissions on meaningful I/Os (namely, 1997-08-12 04:34:30 +00:00
procfs_status.c This Implements the mumbled about "Jail" feature. 1999-04-28 11:38:52 +00:00
procfs_subr.c Fix warnings in preparation for adding -Wall -Wcast-qual to the 1999-01-27 22:42:27 +00:00
procfs_type.c Removed unused #includes. 1997-08-02 14:33:27 +00:00
procfs_vfsops.c Removed statically configured mount type numbers (MOUNT_*) and all 1998-09-07 13:17:06 +00:00
procfs_vnops.c This Implements the mumbled about "Jail" feature. 1999-04-28 11:38:52 +00:00
procfs.h This Implements the mumbled about "Jail" feature. 1999-04-28 11:38:52 +00:00
README Back out part 1 of the MCFH that changed $Id$ to $FreeBSD$. We are not 1997-02-22 09:48:43 +00:00

saute procfs lyonnais

procfs supports two levels of directory.  the filesystem root
directory contains a representation of the system process table.
this consists of an entry for each active and zombie process, and
an additional entry "curproc" which always represents the process
making the lookup request.

each of the sub-directories contains several files.  these files
are used to control and interrogate processes.  the files implemented
are:

	file	- xxx.  the exec'ed file.

	status  - r/o.  returns process status.

	ctl	- w/o.  sends a control message to the process.
			for example:
				echo hup > /proc/curproc/note
			will send a SIGHUP to the shell.
			whereas
				echo attach > /proc/1293/ctl
			would set up process 1293 for debugging.
			see below for more details.

	mem	- r/w.  virtual memory image of the process.
			parts of the address space are readable
			only if they exist in the target process.
			a more reasonable alternative might be
			to return zero pages instead of an error.
			comments?

	note	- w/o.  writing a string here sends the
			equivalent note to the process.
			[ not implemented. ]

	notepg	- w/o.  the same as note, but sends to all
			members of the process group.
			[ not implemented. ]

	regs	- r/w.	process register set.  this can be read
			or written any time even if the process
			is not stopped.  since the bsd kernel
			is single-processor, this implementation
			will get the "right" register values.
			a multi-proc kernel would need to do some
			synchronisation.

this then looks like:

% ls -li /proc
total 0
   9 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 0
  17 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 1
  89 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 10
  25 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 2
2065 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 257
2481 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 309
 265 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 32
3129 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 390
3209 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 400
3217 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 401
3273 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 408
 393 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 48
 409 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 50
 465 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 57
 481 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 59
 537 dr-xr-xr-x  2 root  kmem   0 Sep 21 15:06 66
 545 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 67
 657 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 81
 665 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 82
 673 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 83
 681 dr-xr-xr-x  2 root  wheel  0 Sep 21 15:06 84
3273 dr-xr-xr-x  2 jsp   staff  0 Sep 21 15:06 curproc
% ls -li /proc/curproc
total 408
3341 --w-------  1 jsp  staff       0 Sep 21 15:06 ctl
1554 -r-xr-xr-x  1 bin  bin     90112 Mar 29 04:52 file
3339 -rw-------  1 jsp  staff  118784 Sep 21 15:06 mem
3343 --w-------  1 jsp  staff       0 Sep 21 15:06 note
3344 --w-------  1 jsp  staff       0 Sep 21 15:06 notepg
3340 -rw-------  1 jsp  staff       0 Sep 21 15:06 regs
3342 -r--r--r--  1 jsp  staff       0 Sep 21 15:06 status
% df /proc/curproc /proc/curproc/file
Filesystem  512-blocks    Used   Avail Capacity  Mounted on
proc                 2       2       0   100%    /proc
/dev/wd0a        16186   13548    1018    93%    /
% cat /proc/curproc/status
cat 446 439 400 81 12,0 ctty 748620684 270000 0 0 0 20000 nochan 11 20 20 20 0 21 117



the basic sequence of commands written to "ctl" would be

	attach		- this stops the target process and
			  arranges for the sending process
			  to become the debug control process
	wait		- wait for the target process to come to
			  a steady state ready for debugging.
	step		- single step, with no signal delivery.
	run		- continue running, with no signal delivery,
			  until next trap or breakpoint.
	<signame>	- deliver signal <signame> and continue running.
	detach		- continue execution of the target process
			  and remove it from control by the debug process

in a normal debugging environment, where the target is fork/exec'd by
the debugger, the debugger should fork and the child should stop itself
(with a self-inflicted SIGSTOP).  the parent should do a "wait" then an
"attach".  as before, the child will hit a breakpoint on the first
instruction in any newly exec'd image.

$Id$