summaryrefslogtreecommitdiffstats
path: root/sys/netinet
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1999-04-28 11:38:52 +0000
committerphk <phk@FreeBSD.org>1999-04-28 11:38:52 +0000
commitca21a25f173ed030b0093e4d83140e3b0b43db01 (patch)
tree0ced832ca84afcb7423214e45fa0bc0cdd71a660 /sys/netinet
parent58c42d9a16bbdef6b833ed08531a2a3541db6595 (diff)
downloadFreeBSD-src-ca21a25f173ed030b0093e4d83140e3b0b43db01.zip
FreeBSD-src-ca21a25f173ed030b0093e4d83140e3b0b43db01.tar.gz
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/
Diffstat (limited to 'sys/netinet')
-rw-r--r--sys/netinet/in.h5
-rw-r--r--sys/netinet/in_pcb.c30
-rw-r--r--sys/netinet/in_pcb.h3
-rw-r--r--sys/netinet/tcp_subr.c4
-rw-r--r--sys/netinet/tcp_timewait.c4
-rw-r--r--sys/netinet/tcp_usrreq.c4
-rw-r--r--sys/netinet/udp_usrreq.c10
7 files changed, 45 insertions, 15 deletions
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 1542e24..0fe16f4 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)in.h 8.3 (Berkeley) 1/3/94
- * $Id: in.h,v 1.38 1998/12/14 18:09:13 luigi Exp $
+ * $Id: in.h,v 1.39 1999/04/20 13:32:04 peter Exp $
*/
#ifndef _NETINET_IN_H_
@@ -433,6 +433,9 @@ int in_cksum __P((struct mbuf *, int));
int in_localaddr __P((struct in_addr));
char *inet_ntoa __P((struct in_addr)); /* in libkern */
+int prison_ip __P((struct proc *p, int flag, u_int32_t *ip));
+void prison_remote_ip __P((struct proc *p, int flag, u_int32_t *ip));
+
#endif /* KERNEL */
#endif
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index 7788c9b..2f13bf1 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)in_pcb.c 8.4 (Berkeley) 5/24/95
- * $Id: in_pcb.c,v 1.47 1999/01/27 22:42:24 dillon Exp $
+ * $Id: in_pcb.c,v 1.48 1999/04/27 11:17:31 phk Exp $
*/
#include <sys/param.h>
@@ -42,6 +42,7 @@
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/proc.h>
+#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
@@ -154,7 +155,7 @@ in_pcbbind(inp, nam, p)
struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
u_short lport = 0;
int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
- int error;
+ int error, prison = 0;
if (TAILQ_EMPTY(&in_ifaddrhead)) /* XXX broken! */
return (EADDRNOTAVAIL);
@@ -174,6 +175,8 @@ in_pcbbind(inp, nam, p)
if (sin->sin_family != AF_INET)
return (EAFNOSUPPORT);
#endif
+ if (prison_ip(p, 0, &sin->sin_addr.s_addr))
+ return(EINVAL);
lport = sin->sin_port;
if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
/*
@@ -195,12 +198,15 @@ in_pcbbind(inp, nam, p)
/* GROSS */
if (ntohs(lport) < IPPORT_RESERVED && p &&
- suser(p))
+ suser_xxx(0, p, PRISON_ROOT))
return (EACCES);
+ if (p && p->p_prison)
+ prison = 1;
if (so->so_uid &&
!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
t = in_pcblookup_local(inp->inp_pcbinfo,
- sin->sin_addr, lport, INPLOOKUP_WILDCARD);
+ sin->sin_addr, lport,
+ prison ? 0 : INPLOOKUP_WILDCARD);
if (t &&
(ntohl(sin->sin_addr.s_addr) != INADDR_ANY ||
ntohl(t->inp_laddr.s_addr) != INADDR_ANY ||
@@ -210,7 +216,7 @@ in_pcbbind(inp, nam, p)
return (EADDRINUSE);
}
t = in_pcblookup_local(pcbinfo, sin->sin_addr,
- lport, wild);
+ lport, prison ? 0 : wild);
if (t && (reuseport & t->inp_socket->so_options) == 0)
return (EADDRINUSE);
}
@@ -220,6 +226,8 @@ in_pcbbind(inp, nam, p)
ushort first, last;
int count;
+ if (prison_ip(p, 0, &inp->inp_laddr.s_addr ))
+ return (EINVAL);
inp->inp_flags |= INP_ANONPORT;
if (inp->inp_flags & INP_HIGHPORT) {
@@ -227,7 +235,7 @@ in_pcbbind(inp, nam, p)
last = ipport_hilastauto;
lastport = &pcbinfo->lasthi;
} else if (inp->inp_flags & INP_LOWPORT) {
- if (p && (error = suser(p)))
+ if (p && (error = suser_xxx(0, p, PRISON_ROOT)))
return error;
first = ipport_lowfirstauto; /* 1023 */
last = ipport_lowlastauto; /* 600 */
@@ -895,3 +903,13 @@ in_pcbremlists(inp)
LIST_REMOVE(inp, inp_list);
inp->inp_pcbinfo->ipi_count--;
}
+
+int
+prison_xinpcb(struct proc *p, struct inpcb *inp)
+{
+ if (!p->p_prison)
+ return (0);
+ if (ntohl(inp->inp_laddr.s_addr) == p->p_prison->pr_ip)
+ return (0);
+ return (1);
+}
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
index aa2d0be..33d8d7a 100644
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)in_pcb.h 8.1 (Berkeley) 6/10/93
- * $Id: in_pcb.h,v 1.25 1998/03/28 10:18:22 bde Exp $
+ * $Id: in_pcb.h,v 1.26 1998/05/15 20:11:33 wollman Exp $
*/
#ifndef _NETINET_IN_PCB_H_
@@ -168,6 +168,7 @@ void in_pcbnotify __P((struct inpcbhead *, struct sockaddr *,
void in_pcbrehash __P((struct inpcb *));
int in_setpeeraddr __P((struct socket *so, struct sockaddr **nam));
int in_setsockaddr __P((struct socket *so, struct sockaddr **nam));
+int prison_xinpcb __P((struct proc *p, struct inpcb *inp));
#endif /* KERNEL */
#endif /* !_NETINET_IN_PCB_H_ */
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index b9355da..ed0acd4 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95
- * $Id: tcp_subr.c,v 1.51 1999/02/04 03:02:56 msmith Exp $
+ * $Id: tcp_subr.c,v 1.52 1999/02/04 03:27:43 msmith Exp $
*/
#include "opt_compat.h"
@@ -541,7 +541,7 @@ tcp_pcblist SYSCTL_HANDLER_ARGS
s = splnet();
for (inp = tcbinfo.listhead->lh_first, i = 0; inp && i < n;
inp = inp->inp_list.le_next) {
- if (inp->inp_gencnt <= gencnt)
+ if (inp->inp_gencnt <= gencnt && !prison_xinpcb(req->p, inp))
inp_list[i++] = inp;
}
splx(s);
diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c
index b9355da..ed0acd4 100644
--- a/sys/netinet/tcp_timewait.c
+++ b/sys/netinet/tcp_timewait.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95
- * $Id: tcp_subr.c,v 1.51 1999/02/04 03:02:56 msmith Exp $
+ * $Id: tcp_subr.c,v 1.52 1999/02/04 03:27:43 msmith Exp $
*/
#include "opt_compat.h"
@@ -541,7 +541,7 @@ tcp_pcblist SYSCTL_HANDLER_ARGS
s = splnet();
for (inp = tcbinfo.listhead->lh_first, i = 0; inp && i < n;
inp = inp->inp_list.le_next) {
- if (inp->inp_gencnt <= gencnt)
+ if (inp->inp_gencnt <= gencnt && !prison_xinpcb(req->p, inp))
inp_list[i++] = inp;
}
splx(s);
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 5d231c9..02a281f 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
- * $Id: tcp_usrreq.c,v 1.40 1999/01/20 17:31:59 fenner Exp $
+ * $Id: tcp_usrreq.c,v 1.41 1999/04/24 18:25:35 ache Exp $
*/
#include "opt_tcpdebug.h"
@@ -239,6 +239,8 @@ tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct proc *p)
goto out;
}
+ prison_remote_ip(p, 0, &sinp->sin_addr.s_addr);
+
if ((error = tcp_connect(tp, nam, p)) != 0)
goto out;
error = tcp_output(tp);
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index 3462c70..7fc09d2c 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
- * $Id: udp_usrreq.c,v 1.48 1998/08/24 07:47:39 dfr Exp $
+ * $Id: udp_usrreq.c,v 1.49 1998/12/03 20:23:21 dillon Exp $
*/
#include <sys/param.h>
@@ -410,7 +410,7 @@ udp_pcblist SYSCTL_HANDLER_ARGS
s = splnet();
for (inp = udbinfo.listhead->lh_first, i = 0; inp && i < n;
inp = inp->inp_list.le_next) {
- if (inp->inp_gencnt <= gencnt)
+ if (inp->inp_gencnt <= gencnt && !prison_xinpcb(req->p, inp))
inp_list[i++] = inp;
}
splx(s);
@@ -462,6 +462,7 @@ udp_output(inp, m, addr, control, p)
register struct udpiphdr *ui;
register int len = m->m_pkthdr.len;
struct in_addr laddr;
+ struct sockaddr_in *sin;
int s = 0, error = 0;
if (control)
@@ -473,6 +474,8 @@ udp_output(inp, m, addr, control, p)
}
if (addr) {
+ sin = (struct sockaddr_in *)addr;
+ prison_remote_ip(p, 0, &sin->sin_addr.s_addr);
laddr = inp->inp_laddr;
if (inp->inp_faddr.s_addr != INADDR_ANY) {
error = EISCONN;
@@ -614,6 +617,7 @@ udp_connect(struct socket *so, struct sockaddr *nam, struct proc *p)
{
struct inpcb *inp;
int s, error;
+ struct sockaddr_in *sin;
inp = sotoinpcb(so);
if (inp == 0)
@@ -621,6 +625,8 @@ udp_connect(struct socket *so, struct sockaddr *nam, struct proc *p)
if (inp->inp_faddr.s_addr != INADDR_ANY)
return EISCONN;
s = splnet();
+ sin = (struct sockaddr_in *)nam;
+ prison_remote_ip(p, 0, &sin->sin_addr.s_addr);
error = in_pcbconnect(inp, nam, p);
splx(s);
if (error == 0)
OpenPOWER on IntegriCloud