freebsd32_misc.c (190466) | freebsd32_misc.c (191673) |
---|---|
1/*- 2 * Copyright (c) 2002 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2002 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/compat/freebsd32/freebsd32_misc.c 190466 2009-03-27 13:13:59Z jamie $"); | 28__FBSDID("$FreeBSD: head/sys/compat/freebsd32/freebsd32_misc.c 191673 2009-04-29 21:14:15Z jamie $"); |
29 30#include "opt_compat.h" | 29 30#include "opt_compat.h" |
31#include "opt_inet.h" 32#include "opt_inet6.h" |
|
31 32#include <sys/param.h> 33#include <sys/bus.h> 34#include <sys/clock.h> 35#include <sys/exec.h> 36#include <sys/fcntl.h> 37#include <sys/filedesc.h> 38#include <sys/imgact.h> --- 32 unchanged lines hidden (view full) --- 71#include <sys/ucontext.h> 72#include <sys/vnode.h> 73#include <sys/wait.h> 74#include <sys/ipc.h> 75#include <sys/msg.h> 76#include <sys/sem.h> 77#include <sys/shm.h> 78 | 33 34#include <sys/param.h> 35#include <sys/bus.h> 36#include <sys/clock.h> 37#include <sys/exec.h> 38#include <sys/fcntl.h> 39#include <sys/filedesc.h> 40#include <sys/imgact.h> --- 32 unchanged lines hidden (view full) --- 73#include <sys/ucontext.h> 74#include <sys/vnode.h> 75#include <sys/wait.h> 76#include <sys/ipc.h> 77#include <sys/msg.h> 78#include <sys/sem.h> 79#include <sys/shm.h> 80 |
81#ifdef INET 82#include <netinet/in.h> 83#endif 84 |
|
79#include <vm/vm.h> 80#include <vm/vm_kern.h> 81#include <vm/vm_param.h> 82#include <vm/pmap.h> 83#include <vm/vm_map.h> 84#include <vm/vm_object.h> 85#include <vm/vm_extern.h> 86 --- 14 unchanged lines hidden (view full) --- 101CTASSERT(sizeof(struct rusage32) == 72); 102CTASSERT(sizeof(struct sigaltstack32) == 12); 103CTASSERT(sizeof(struct kevent32) == 20); 104CTASSERT(sizeof(struct iovec32) == 8); 105CTASSERT(sizeof(struct msghdr32) == 28); 106CTASSERT(sizeof(struct stat32) == 96); 107CTASSERT(sizeof(struct sigaction32) == 24); 108 | 85#include <vm/vm.h> 86#include <vm/vm_kern.h> 87#include <vm/vm_param.h> 88#include <vm/pmap.h> 89#include <vm/vm_map.h> 90#include <vm/vm_object.h> 91#include <vm/vm_extern.h> 92 --- 14 unchanged lines hidden (view full) --- 107CTASSERT(sizeof(struct rusage32) == 72); 108CTASSERT(sizeof(struct sigaltstack32) == 12); 109CTASSERT(sizeof(struct kevent32) == 20); 110CTASSERT(sizeof(struct iovec32) == 8); 111CTASSERT(sizeof(struct msghdr32) == 28); 112CTASSERT(sizeof(struct stat32) == 96); 113CTASSERT(sizeof(struct sigaction32) == 24); 114 |
115extern int jail_max_af_ips; 116 |
|
109static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count); 110static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count); 111 112int 113freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap) 114{ 115 int error, status; 116 struct rusage32 ru32; --- 1914 unchanged lines hidden (view full) --- 2031 if (uap->oldlenp) 2032 suword32(uap->oldlenp, j); 2033 return (0); 2034} 2035 2036int 2037freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap) 2038{ | 117static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count); 118static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count); 119 120int 121freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap) 122{ 123 int error, status; 124 struct rusage32 ru32; --- 1914 unchanged lines hidden (view full) --- 2039 if (uap->oldlenp) 2040 suword32(uap->oldlenp, j); 2041 return (0); 2042} 2043 2044int 2045freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap) 2046{ |
2047 struct iovec optiov[10]; 2048 struct uio opt; 2049 char *u_path, *u_hostname, *u_name; 2050#ifdef INET 2051 struct in_addr *u_ip4; 2052#endif 2053#ifdef INET6 2054 struct in6_addr *u_ip6; 2055#endif |
|
2039 uint32_t version; 2040 int error; | 2056 uint32_t version; 2057 int error; |
2041 struct jail j; | |
2042 2043 error = copyin(uap->jail, &version, sizeof(uint32_t)); 2044 if (error) 2045 return (error); 2046 2047 switch (version) { 2048 case 0: 2049 { 2050 /* FreeBSD single IPv4 jails. */ 2051 struct jail32_v0 j32_v0; 2052 | 2058 2059 error = copyin(uap->jail, &version, sizeof(uint32_t)); 2060 if (error) 2061 return (error); 2062 2063 switch (version) { 2064 case 0: 2065 { 2066 /* FreeBSD single IPv4 jails. */ 2067 struct jail32_v0 j32_v0; 2068 |
2053 bzero(&j, sizeof(struct jail)); | |
2054 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0)); 2055 if (error) 2056 return (error); | 2069 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0)); 2070 if (error) 2071 return (error); |
2057 CP(j32_v0, j, version); 2058 PTRIN_CP(j32_v0, j, path); 2059 PTRIN_CP(j32_v0, j, hostname); 2060 j.ip4s = j32_v0.ip_number; | 2072 u_path = malloc(MAXPATHLEN + MAXHOSTNAMELEN, M_TEMP, M_WAITOK); 2073 u_hostname = u_path + MAXPATHLEN; 2074 opt.uio_iov = optiov; 2075 opt.uio_iovcnt = 4; 2076 opt.uio_offset = -1; 2077 opt.uio_resid = -1; 2078 opt.uio_segflg = UIO_SYSSPACE; 2079 opt.uio_rw = UIO_READ; 2080 opt.uio_td = td; 2081 optiov[0].iov_base = "path"; 2082 optiov[0].iov_len = sizeof("path"); 2083 optiov[1].iov_base = u_path; 2084 error = copyinstr(PTRIN(j32_v0.path), u_path, MAXPATHLEN, 2085 &optiov[1].iov_len); 2086 if (error) { 2087 free(u_path, M_TEMP); 2088 return (error); 2089 } 2090 optiov[2].iov_base = "host.hostname"; 2091 optiov[2].iov_len = sizeof("host.hostname"); 2092 optiov[3].iov_base = u_hostname; 2093 error = copyinstr(PTRIN(j32_v0.hostname), u_hostname, 2094 MAXHOSTNAMELEN, &optiov[3].iov_len); 2095 if (error) { 2096 free(u_path, M_TEMP); 2097 return (error); 2098 } 2099#ifdef INET 2100 optiov[opt.uio_iovcnt].iov_base = "ip4.addr"; 2101 optiov[opt.uio_iovcnt].iov_len = sizeof("ip4.addr"); 2102 opt.uio_iovcnt++; 2103 optiov[opt.uio_iovcnt].iov_base = &j32_v0.ip_number; 2104 j32_v0.ip_number = htonl(j32_v0.ip_number); 2105 optiov[opt.uio_iovcnt].iov_len = sizeof(j32_v0.ip_number); 2106 opt.uio_iovcnt++; 2107#endif |
2061 break; 2062 } 2063 2064 case 1: 2065 /* 2066 * Version 1 was used by multi-IPv4 jail implementations 2067 * that never made it into the official kernel. 2068 */ 2069 return (EINVAL); 2070 2071 case 2: /* JAIL_API_VERSION */ 2072 { 2073 /* FreeBSD multi-IPv4/IPv6,noIP jails. */ 2074 struct jail32 j32; | 2108 break; 2109 } 2110 2111 case 1: 2112 /* 2113 * Version 1 was used by multi-IPv4 jail implementations 2114 * that never made it into the official kernel. 2115 */ 2116 return (EINVAL); 2117 2118 case 2: /* JAIL_API_VERSION */ 2119 { 2120 /* FreeBSD multi-IPv4/IPv6,noIP jails. */ 2121 struct jail32 j32; |
2122 size_t tmplen; |
|
2075 2076 error = copyin(uap->jail, &j32, sizeof(struct jail32)); 2077 if (error) 2078 return (error); | 2123 2124 error = copyin(uap->jail, &j32, sizeof(struct jail32)); 2125 if (error) 2126 return (error); |
2079 CP(j32, j, version); 2080 PTRIN_CP(j32, j, path); 2081 PTRIN_CP(j32, j, hostname); 2082 PTRIN_CP(j32, j, jailname); 2083 CP(j32, j, ip4s); 2084 CP(j32, j, ip6s); 2085 PTRIN_CP(j32, j, ip4); 2086 PTRIN_CP(j32, j, ip6); | 2127 tmplen = MAXPATHLEN + MAXHOSTNAMELEN + MAXHOSTNAMELEN; 2128#ifdef INET 2129 if (j32.ip4s > jail_max_af_ips) 2130 return (EINVAL); 2131 tmplen += j32.ip4s * sizeof(struct in_addr); 2132#else 2133 if (j32.ip4s > 0) 2134 return (EINVAL); 2135#endif 2136#ifdef INET6 2137 if (j32.ip6s > jail_max_af_ips) 2138 return (EINVAL); 2139 tmplen += j32.ip6s * sizeof(struct in6_addr); 2140#else 2141 if (j32.ip6s > 0) 2142 return (EINVAL); 2143#endif 2144 u_path = malloc(tmplen, M_TEMP, M_WAITOK); 2145 u_hostname = u_path + MAXPATHLEN; 2146 u_name = u_hostname + MAXHOSTNAMELEN; 2147#ifdef INET 2148 u_ip4 = (struct in_addr *)(u_name + MAXHOSTNAMELEN); 2149#endif 2150#ifdef INET6 2151#ifdef INET 2152 u_ip6 = (struct in6_addr *)(u_ip4 + j32.ip4s); 2153#else 2154 u_ip6 = (struct in6_addr *)(u_name + MAXHOSTNAMELEN); 2155#endif 2156#endif 2157 opt.uio_iov = optiov; 2158 opt.uio_iovcnt = 4; 2159 opt.uio_offset = -1; 2160 opt.uio_resid = -1; 2161 opt.uio_segflg = UIO_SYSSPACE; 2162 opt.uio_rw = UIO_READ; 2163 opt.uio_td = td; 2164 optiov[0].iov_base = "path"; 2165 optiov[0].iov_len = sizeof("path"); 2166 optiov[1].iov_base = u_path; 2167 error = copyinstr(PTRIN(j32.path), u_path, MAXPATHLEN, 2168 &optiov[1].iov_len); 2169 if (error) { 2170 free(u_path, M_TEMP); 2171 return (error); 2172 } 2173 optiov[2].iov_base = "host.hostname"; 2174 optiov[2].iov_len = sizeof("host.hostname"); 2175 optiov[3].iov_base = u_hostname; 2176 error = copyinstr(PTRIN(j32.hostname), u_hostname, 2177 MAXHOSTNAMELEN, &optiov[3].iov_len); 2178 if (error) { 2179 free(u_path, M_TEMP); 2180 return (error); 2181 } 2182 if (PTRIN(j32.jailname) != NULL) { 2183 optiov[opt.uio_iovcnt].iov_base = "name"; 2184 optiov[opt.uio_iovcnt].iov_len = sizeof("name"); 2185 opt.uio_iovcnt++; 2186 optiov[opt.uio_iovcnt].iov_base = u_name; 2187 error = copyinstr(PTRIN(j32.jailname), u_name, 2188 MAXHOSTNAMELEN, &optiov[opt.uio_iovcnt].iov_len); 2189 if (error) { 2190 free(u_path, M_TEMP); 2191 return (error); 2192 } 2193 opt.uio_iovcnt++; 2194 } 2195#ifdef INET 2196 optiov[opt.uio_iovcnt].iov_base = "ip4.addr"; 2197 optiov[opt.uio_iovcnt].iov_len = sizeof("ip4.addr"); 2198 opt.uio_iovcnt++; 2199 optiov[opt.uio_iovcnt].iov_base = u_ip4; 2200 optiov[opt.uio_iovcnt].iov_len = 2201 j32.ip4s * sizeof(struct in_addr); 2202 error = copyin(PTRIN(j32.ip4), u_ip4, 2203 optiov[opt.uio_iovcnt].iov_len); 2204 if (error) { 2205 free(u_path, M_TEMP); 2206 return (error); 2207 } 2208 opt.uio_iovcnt++; 2209#endif 2210#ifdef INET6 2211 optiov[opt.uio_iovcnt].iov_base = "ip6.addr"; 2212 optiov[opt.uio_iovcnt].iov_len = sizeof("ip6.addr"); 2213 opt.uio_iovcnt++; 2214 optiov[opt.uio_iovcnt].iov_base = u_ip6; 2215 optiov[opt.uio_iovcnt].iov_len = 2216 j32.ip6s * sizeof(struct in6_addr); 2217 error = copyin(PTRIN(j32.ip6), u_ip6, 2218 optiov[opt.uio_iovcnt].iov_len); 2219 if (error) { 2220 free(u_path, M_TEMP); 2221 return (error); 2222 } 2223 opt.uio_iovcnt++; 2224#endif |
2087 break; 2088 } 2089 2090 default: 2091 /* Sci-Fi jails are not supported, sorry. */ 2092 return (EINVAL); 2093 } | 2225 break; 2226 } 2227 2228 default: 2229 /* Sci-Fi jails are not supported, sorry. */ 2230 return (EINVAL); 2231 } |
2094 return (kern_jail(td, &j)); | 2232 error = kern_jail_set(td, &opt, JAIL_CREATE | JAIL_ATTACH); 2233 free(u_path, M_TEMP); 2234 return (error); |
2095} 2096 2097int | 2235} 2236 2237int |
2238freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap) 2239{ 2240 struct uio *auio; 2241 int error; 2242 2243 /* Check that we have an even number of iovecs. */ 2244 if (uap->iovcnt & 1) 2245 return (EINVAL); 2246 2247 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio); 2248 if (error) 2249 return (error); 2250 error = kern_jail_set(td, auio, uap->flags); 2251 free(auio, M_IOV); 2252 return (error); 2253} 2254 2255int 2256freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap) 2257{ 2258 struct iovec32 iov32; 2259 struct uio *auio; 2260 int error, i; 2261 2262 /* Check that we have an even number of iovecs. */ 2263 if (uap->iovcnt & 1) 2264 return (EINVAL); 2265 2266 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio); 2267 if (error) 2268 return (error); 2269 error = kern_jail_get(td, auio, uap->flags); 2270 if (error == 0) 2271 for (i = 0; i < uap->iovcnt; i++) { 2272 PTROUT_CP(auio->uio_iov[i], iov32, iov_base); 2273 CP(auio->uio_iov[i], iov32, iov_len); 2274 error = copyout(&iov32, uap->iovp + i, sizeof(iov32)); 2275 if (error != 0) 2276 break; 2277 } 2278 free(auio, M_IOV); 2279 return (error); 2280} 2281 2282int |
|
2098freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap) 2099{ 2100 struct sigaction32 s32; 2101 struct sigaction sa, osa, *sap; 2102 int error; 2103 2104 if (uap->act) { 2105 error = copyin(uap->act, &s32, sizeof(s32)); --- 671 unchanged lines hidden --- | 2283freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap) 2284{ 2285 struct sigaction32 s32; 2286 struct sigaction sa, osa, *sap; 2287 int error; 2288 2289 if (uap->act) { 2290 error = copyin(uap->act, &s32, sizeof(s32)); --- 671 unchanged lines hidden --- |