diff options
author | bz <bz@FreeBSD.org> | 2009-01-09 13:06:56 +0000 |
---|---|---|
committer | bz <bz@FreeBSD.org> | 2009-01-09 13:06:56 +0000 |
commit | 60c950d4ff05ccd0e88e7333e5b3d64868165843 (patch) | |
tree | 84cf148c8aae2a216120bb00e5abe0953a078f4b | |
parent | aa56a975c17dac5562552bb238277fd96c124da2 (diff) | |
download | FreeBSD-src-60c950d4ff05ccd0e88e7333e5b3d64868165843.zip FreeBSD-src-60c950d4ff05ccd0e88e7333e5b3d64868165843.tar.gz |
Make SIOCGIFADDR and related, as well as SIOCGIFADDR_IN6 and related
jail-aware. Up to now we returned the first address of the interface
for SIOCGIFADDR w/o an ifr_addr in the query. This caused problems for
programs querying for an address but running inside a jail, as the
address returned usually did not belong to the jail.
Like for v6, if there was an ifr_addr given on v4, you could probe
for more addresses on the interfaces that you were not allowed to see
from inside a jail. Return an error (EADDRNOTAVAIL) in that case
now unless the address is on the given interface and valid for the
jail.
PR: kern/114325
Reviewed by: rwatson
MFC after: 4 weeks
-rw-r--r-- | sys/netinet/in.c | 10 | ||||
-rw-r--r-- | sys/netinet6/in6.c | 4 |
2 files changed, 13 insertions, 1 deletions
diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 8c40586..18a3155 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -41,7 +41,9 @@ __FBSDID("$FreeBSD$"); #include <sys/malloc.h> #include <sys/priv.h> #include <sys/socket.h> +#include <sys/jail.h> #include <sys/kernel.h> +#include <sys/proc.h> #include <sys/sysctl.h> #include <sys/vimage.h> @@ -261,13 +263,19 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp, LIST_FOREACH(iap, INADDR_HASH(dst.s_addr), ia_hash) if (iap->ia_ifp == ifp && iap->ia_addr.sin_addr.s_addr == dst.s_addr) { - ia = iap; + if (td == NULL || prison_check_ip4( + td->td_ucred, &dst)) + ia = iap; break; } if (ia == NULL) TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { iap = ifatoia(ifa); if (iap->ia_addr.sin_family == AF_INET) { + if (td != NULL && + !prison_check_ip4(td->td_ucred, + &iap->ia_addr.sin_addr)) + continue; ia = iap; break; } diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 4c97999..e36c2dd 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/errno.h> +#include <sys/jail.h> #include <sys/malloc.h> #include <sys/socket.h> #include <sys/socketvar.h> @@ -329,6 +330,9 @@ in6_control(struct socket *so, u_long cmd, caddr_t data, error = in6_setscope(&sa6->sin6_addr, ifp, NULL); if (error != 0) return (error); + if (td != NULL && !prison_check_ip6(td->td_ucred, + &sa6->sin6_addr)) + return (EADDRNOTAVAIL); ia = in6ifa_ifpwithaddr(ifp, &sa6->sin6_addr); } else ia = NULL; |