summaryrefslogtreecommitdiffstats
path: root/sys/netinet6
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2006-11-06 13:42:10 +0000
committerrwatson <rwatson@FreeBSD.org>2006-11-06 13:42:10 +0000
commit10d0d9cf473dc5f0ce1bf263ead445ffe7819154 (patch)
treeb9dd284620eeaddbff089cef10e4b1afb7918279 /sys/netinet6
parent7288104e2094825a9c98b9923f039817a76e2983 (diff)
downloadFreeBSD-src-10d0d9cf473dc5f0ce1bf263ead445ffe7819154.zip
FreeBSD-src-10d0d9cf473dc5f0ce1bf263ead445ffe7819154.tar.gz
Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net>
Diffstat (limited to 'sys/netinet6')
-rw-r--r--sys/netinet6/in6.c58
-rw-r--r--sys/netinet6/in6_pcb.c7
-rw-r--r--sys/netinet6/in6_src.c5
-rw-r--r--sys/netinet6/ipsec.c11
-rw-r--r--sys/netinet6/udp6_usrreq.c4
5 files changed, 63 insertions, 22 deletions
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index 8177313..52b57aa 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -71,6 +71,7 @@
#include <sys/socketvar.h>
#include <sys/sockio.h>
#include <sys/systm.h>
+#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/time.h>
#include <sys/kernel.h>
@@ -325,12 +326,8 @@ in6_control(so, cmd, data, ifp, td)
struct in6_ifreq *ifr = (struct in6_ifreq *)data;
struct in6_ifaddr *ia = NULL;
struct in6_aliasreq *ifra = (struct in6_aliasreq *)data;
- int error, privileged;
struct sockaddr_in6 *sa6;
-
- privileged = 0;
- if (td == NULL || !suser(td))
- privileged++;
+ int error;
switch (cmd) {
case SIOCGETSGCNT_IN6:
@@ -341,8 +338,11 @@ in6_control(so, cmd, data, ifp, td)
switch(cmd) {
case SIOCAADDRCTL_POLICY:
case SIOCDADDRCTL_POLICY:
- if (!privileged)
- return (EPERM);
+ if (td != NULL) {
+ error = priv_check(td, PRIV_NETINET_ADDRCTRL6);
+ if (error)
+ return (error);
+ }
return (in6_src_ioctl(cmd, data));
}
@@ -355,8 +355,11 @@ in6_control(so, cmd, data, ifp, td)
case SIOCSRTRFLUSH_IN6:
case SIOCSDEFIFACE_IN6:
case SIOCSIFINFO_FLAGS:
- if (!privileged)
- return (EPERM);
+ if (td != NULL) {
+ error = priv_check(td, PRIV_NETINET_ND6);
+ if (error)
+ return (error);
+ }
/* FALLTHROUGH */
case OSIOCGIFINFO_IN6:
case SIOCGIFINFO_IN6:
@@ -383,8 +386,11 @@ in6_control(so, cmd, data, ifp, td)
switch (cmd) {
case SIOCSSCOPE6:
- if (!privileged)
- return (EPERM);
+ if (td != NULL) {
+ error = priv_check(td, PRIV_NETINET_SCOPE6);
+ if (error)
+ return (error);
+ }
return (scope6_set(ifp,
(struct scope6_id *)ifr->ifr_ifru.ifru_scope_id));
case SIOCGSCOPE6:
@@ -398,8 +404,15 @@ in6_control(so, cmd, data, ifp, td)
switch (cmd) {
case SIOCALIFADDR:
case SIOCDLIFADDR:
- if (!privileged)
- return (EPERM);
+ /*
+ * XXXRW: Is this checked at another layer? What priv to use
+ * here?
+ */
+ if (td != NULL) {
+ error = suser(td);
+ if (error)
+ return (error);
+ }
/* FALLTHROUGH */
case SIOCGLIFADDR:
return in6_lifaddr_ioctl(so, cmd, data, ifp, td);
@@ -488,8 +501,16 @@ in6_control(so, cmd, data, ifp, td)
if (ifra->ifra_addr.sin6_family != AF_INET6 ||
ifra->ifra_addr.sin6_len != sizeof(struct sockaddr_in6))
return (EAFNOSUPPORT);
- if (!privileged)
- return (EPERM);
+
+ /*
+ * XXXRW: Is this checked at another layer? What priv to use
+ * here?
+ */
+ if (td != NULL) {
+ error = suser(td);
+ if (error)
+ return (error);
+ }
break;
@@ -508,8 +529,11 @@ in6_control(so, cmd, data, ifp, td)
{
struct in6_addrlifetime *lt;
- if (!privileged)
- return (EPERM);
+ if (td != NULL) {
+ error = priv_check(td, PRIV_NETINET_ALIFETIME6);
+ if (error)
+ return (error);
+ }
if (ia == NULL)
return (EADDRNOTAVAIL);
/* sanity for overflow - beware unsigned */
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
index 9305ed9..5e7da80 100644
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -77,6 +77,7 @@
#include <sys/sockio.h>
#include <sys/errno.h>
#include <sys/time.h>
+#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/jail.h>
@@ -190,8 +191,12 @@ in6_pcbbind(inp, nam, cred)
/* GROSS */
if (ntohs(lport) <= ipport_reservedhigh &&
ntohs(lport) >= ipport_reservedlow &&
- suser_cred(cred, SUSER_ALLOWJAIL))
+ priv_check_cred(cred, PRIV_NETINET_RESERVEDPORT,
+ SUSER_ALLOWJAIL))
return (EACCES);
+ /*
+ * XXXRW: What priv to use here?
+ */
if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr) &&
suser_cred(so->so_cred, SUSER_ALLOWJAIL) != 0) {
t = in6_pcblookup_local(pcbinfo,
diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c
index 233d79b..b9457dc 100644
--- a/sys/netinet6/in6_src.c
+++ b/sys/netinet6/in6_src.c
@@ -68,6 +68,7 @@
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
+#include <sys/priv.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
@@ -772,7 +773,9 @@ in6_pcbsetport(laddr, inp, cred)
last = ipport_hilastauto;
lastport = &pcbinfo->lasthi;
} else if (inp->inp_flags & INP_LOWPORT) {
- if ((error = suser_cred(cred, 0)))
+ error = priv_check_cred(cred, PRIV_NETINET_RESERVEDPORT,
+ SUSER_ALLOWJAIL);
+ if (error)
return error;
first = ipport_lowfirstauto; /* 1023 */
last = ipport_lowlastauto; /* 600 */
diff --git a/sys/netinet6/ipsec.c b/sys/netinet6/ipsec.c
index 5ce3989..a0b356b 100644
--- a/sys/netinet6/ipsec.c
+++ b/sys/netinet6/ipsec.c
@@ -43,6 +43,7 @@
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/domain.h>
+#include <sys/priv.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
@@ -1221,8 +1222,14 @@ ipsec_init_pcbpolicy(so, pcb_sp)
}
bzero(new, sizeof(*new));
- if (so->so_cred != NULL &&
- suser_cred(so->so_cred, SUSER_ALLOWJAIL) == 0)
+ /*
+ * XXXRW: Can we avoid caching the privilege decision here, and
+ * instead cache the credential?
+ *
+ * XXXRW: Why is suser_allowjail set here?
+ */
+ if (so->so_cred != NULL && priv_check_cred(so->so_cred,
+ PRIV_NETINET_IPSEC, 0) == 0)
new->priv = 1;
else
new->priv = 0;
diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c
index cec632c..b91f9b6 100644
--- a/sys/netinet6/udp6_usrreq.c
+++ b/sys/netinet6/udp6_usrreq.c
@@ -70,6 +70,7 @@
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mbuf.h>
+#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/protosw.h>
#include <sys/signalvar.h>
@@ -434,7 +435,8 @@ udp6_getcred(SYSCTL_HANDLER_ARGS)
struct inpcb *inp;
int error;
- error = suser(req->td);
+ error = priv_check_cred(req->td->td_ucred, PRIV_NETINET_GETCRED,
+ SUSER_ALLOWJAIL);
if (error)
return (error);
OpenPOWER on IntegriCloud