1/*- 2 * Copyright (c) 1994-1995 S�ren Schmidt 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 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * |
28 * $FreeBSD: head/sys/compat/linux/linux_misc.c 70061 2000-12-15 19:41:27Z jhb $ |
29 */ 30 31#include "opt_compat.h" 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/sysproto.h> 36#include <sys/kernel.h> --- 143 unchanged lines hidden (view full) --- 180 181int 182linux_uselib(struct proc *p, struct linux_uselib_args *args) 183{ 184 struct nameidata ni; 185 struct vnode *vp; 186 struct exec *a_out; 187 struct vattr attr; |
188 struct ucred *uc; |
189 vm_offset_t vmaddr; 190 unsigned long file_offset; 191 vm_offset_t buffer; 192 unsigned long bss_size; 193 int error; 194 caddr_t sg; 195 int locked; 196 --- 35 unchanged lines hidden (view full) --- 232 if (vp->v_writecount) { 233 error = ETXTBSY; 234 goto cleanup; 235 } 236 237 /* 238 * Executable? 239 */ |
240 PROC_LOCK(p); 241 uc = p->p_ucred; 242 crhold(uc); 243 PROC_UNLOCK(p); 244 error = VOP_GETATTR(vp, &attr, uc, p); 245 if (error) { 246 crfree(uc); |
247 goto cleanup; |
248 } |
249 250 if ((vp->v_mount->mnt_flag & MNT_NOEXEC) || 251 ((attr.va_mode & 0111) == 0) || 252 (attr.va_type != VREG)) { 253 error = ENOEXEC; |
254 crfree(uc); |
255 goto cleanup; 256 } 257 258 /* 259 * Sensible size? 260 */ 261 if (attr.va_size == 0) { 262 error = ENOEXEC; |
263 crfree(uc); |
264 goto cleanup; 265 } 266 267 /* 268 * Can we access it? 269 */ |
270 error = VOP_ACCESS(vp, VEXEC, uc, p); 271 if (error) { 272 crfree(uc); |
273 goto cleanup; |
274 } |
275 |
276 error = VOP_OPEN(vp, FREAD, uc, p); 277 crfree(uc); |
278 if (error) 279 goto cleanup; 280 281 /* 282 * Lock no longer needed 283 */ 284 VOP_UNLOCK(vp, 0, p); 285 locked = 0; --- 42 unchanged lines hidden (view full) --- 328 } 329 330 /* text + data can't exceed file size */ 331 if (a_out->a_data + a_out->a_text > attr.va_size) { 332 error = EFAULT; 333 goto cleanup; 334 } 335 |
336 /* To protect p->p_rlimit in the if condition. */ 337 mtx_assert(&Giant, MA_OWNED); 338 |
339 /* 340 * text/data/bss must not exceed limits 341 * XXX: this is not complete. it should check current usage PLUS 342 * the resources needed by this library. 343 */ 344 if (a_out->a_text > MAXTSIZ || 345 a_out->a_data + bss_size > p->p_rlimit[RLIMIT_DATA].rlim_cur) { 346 error = ENOMEM; --- 811 unchanged lines hidden --- |