summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_jail.c
diff options
context:
space:
mode:
authorjamie <jamie@FreeBSD.org>2009-02-05 14:15:18 +0000
committerjamie <jamie@FreeBSD.org>2009-02-05 14:15:18 +0000
commit8f639d4b9ab34b25f907b609cbfdc7610647394f (patch)
tree52b30eb1b41e3912554ac0506d04abbeb25da407 /sys/kern/kern_jail.c
parent12bbe1869f5926ca7e3457f5424afdca31a1189b (diff)
downloadFreeBSD-src-8f639d4b9ab34b25f907b609cbfdc7610647394f.zip
FreeBSD-src-8f639d4b9ab34b25f907b609cbfdc7610647394f.tar.gz
Don't allow creating a socket with a protocol family that the current
jail doesn't support. This involves a new function prison_check_af, like prison_check_ip[46] but that checks only the family. With this change, most of the errors generated by jailed sockets shouldn't ever occur, at least until jails are changeable. Approved by: bz (mentor)
Diffstat (limited to 'sys/kern/kern_jail.c')
-rw-r--r--sys/kern/kern_jail.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c
index 9b2f6d8..e802780 100644
--- a/sys/kern/kern_jail.c
+++ b/sys/kern/kern_jail.c
@@ -1099,6 +1099,48 @@ prison_check_ip6(struct ucred *cred, struct in6_addr *ia6)
#endif
/*
+ * Check if a jail supports the given address family.
+ *
+ * Returns 0 if not jailed or the address family is supported, EAFNOSUPPORT
+ * if not.
+ */
+int
+prison_check_af(struct ucred *cred, int af)
+{
+ int error;
+
+ KASSERT(cred != NULL, ("%s: cred is NULL", __func__));
+
+
+ if (!jailed(cred))
+ return (0);
+
+ error = 0;
+ switch (af)
+ {
+#ifdef INET
+ case AF_INET:
+ if (cred->cr_prison->pr_ip4 == NULL)
+ error = EAFNOSUPPORT;
+ break;
+#endif
+#ifdef INET6
+ case AF_INET6:
+ if (cred->cr_prison->pr_ip6 == NULL)
+ error = EAFNOSUPPORT;
+ break;
+#endif
+ case AF_LOCAL:
+ case AF_ROUTE:
+ break;
+ default:
+ if (jail_socket_unixiproute_only)
+ error = EAFNOSUPPORT;
+ }
+ return (error);
+}
+
+/*
* Check if given address belongs to the jail referenced by cred (wrapper to
* prison_check_ip[46]).
*
OpenPOWER on IntegriCloud