imgact_elf.c (43208) | imgact_elf.c (43301) |
---|---|
1/*- 2 * Copyright (c) 1995-1996 S�ren Schmidt 3 * Copyright (c) 1996 Peter Wemm 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 1995-1996 S�ren Schmidt 3 * Copyright (c) 1996 Peter Wemm 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * |
29 * $Id: imgact_elf.c,v 1.44 1998/12/19 02:55:33 julian Exp $ | 29 * $Id: imgact_elf.c,v 1.45 1999/01/26 02:38:10 julian Exp $ |
30 */ 31 32#include "opt_rlimit.h" 33 34#include <sys/param.h> 35#include <sys/acct.h> 36#include <sys/exec.h> 37#include <sys/fcntl.h> --- 236 unchanged lines hidden (view full) --- 274 FALSE); 275 276 return error; 277} 278 279static int 280elf_load_file(struct proc *p, char *file, u_long *addr, u_long *entry) 281{ | 30 */ 31 32#include "opt_rlimit.h" 33 34#include <sys/param.h> 35#include <sys/acct.h> 36#include <sys/exec.h> 37#include <sys/fcntl.h> --- 236 unchanged lines hidden (view full) --- 274 FALSE); 275 276 return error; 277} 278 279static int 280elf_load_file(struct proc *p, char *file, u_long *addr, u_long *entry) 281{ |
282 Elf_Ehdr *hdr = NULL; 283 Elf_Phdr *phdr = NULL; | 282 const Elf_Ehdr *hdr = NULL; 283 const Elf_Phdr *phdr = NULL; |
284 struct nameidata nd; 285 struct vmspace *vmspace = p->p_vmspace; 286 struct vattr attr; 287 struct image_params image_params, *imgp; 288 vm_prot_t prot; 289 unsigned long text_size = 0, data_size = 0; 290 unsigned long text_addr = 0, data_addr = 0; 291 int error, i; --- 11 unchanged lines hidden (view full) --- 303 if (imgp->image_header == NULL) { 304 nd.ni_vp = NULL; 305 error = ENOMEM; 306 goto fail; 307 } 308 309 NDINIT(&nd, LOOKUP, LOCKLEAF|FOLLOW, UIO_SYSSPACE, file, p); 310 | 284 struct nameidata nd; 285 struct vmspace *vmspace = p->p_vmspace; 286 struct vattr attr; 287 struct image_params image_params, *imgp; 288 vm_prot_t prot; 289 unsigned long text_size = 0, data_size = 0; 290 unsigned long text_addr = 0, data_addr = 0; 291 int error, i; --- 11 unchanged lines hidden (view full) --- 303 if (imgp->image_header == NULL) { 304 nd.ni_vp = NULL; 305 error = ENOMEM; 306 goto fail; 307 } 308 309 NDINIT(&nd, LOOKUP, LOCKLEAF|FOLLOW, UIO_SYSSPACE, file, p); 310 |
311 if (error = namei(&nd)) { | 311 if ((error = namei(&nd)) != 0) { |
312 nd.ni_vp = NULL; 313 goto fail; 314 } 315 316 imgp->vp = nd.ni_vp; 317 318 /* 319 * Check permissions, modes, uid, etc on the file, and "open" it. --- 4 unchanged lines hidden (view full) --- 324 goto fail; 325 } 326 327 error = exec_map_first_page(imgp); 328 VOP_UNLOCK(nd.ni_vp, 0, p); 329 if (error) 330 goto fail; 331 | 312 nd.ni_vp = NULL; 313 goto fail; 314 } 315 316 imgp->vp = nd.ni_vp; 317 318 /* 319 * Check permissions, modes, uid, etc on the file, and "open" it. --- 4 unchanged lines hidden (view full) --- 324 goto fail; 325 } 326 327 error = exec_map_first_page(imgp); 328 VOP_UNLOCK(nd.ni_vp, 0, p); 329 if (error) 330 goto fail; 331 |
332 hdr = (Elf_Ehdr *)imgp->image_header; 333 if (error = elf_check_header(hdr, ET_DYN)) | 332 hdr = (const Elf_Ehdr *)imgp->image_header; 333 if ((error = elf_check_header(hdr, ET_DYN)) != 0) |
334 goto fail; 335 336 /* Only support headers that fit within first page for now */ 337 if ((hdr->e_phoff > PAGE_SIZE) || 338 (hdr->e_phoff + hdr->e_phentsize * hdr->e_phnum) > PAGE_SIZE) { 339 error = ENOEXEC; 340 goto fail; 341 } 342 | 334 goto fail; 335 336 /* Only support headers that fit within first page for now */ 337 if ((hdr->e_phoff > PAGE_SIZE) || 338 (hdr->e_phoff + hdr->e_phentsize * hdr->e_phnum) > PAGE_SIZE) { 339 error = ENOEXEC; 340 goto fail; 341 } 342 |
343 phdr = (Elf_Phdr *)(imgp->image_header + hdr->e_phoff); | 343 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); |
344 345 for (i = 0; i < hdr->e_phnum; i++) { 346 if (phdr[i].p_type == PT_LOAD) { /* Loadable segment */ 347 prot = 0; 348 if (phdr[i].p_flags & PF_X) 349 prot |= VM_PROT_EXECUTE; 350 if (phdr[i].p_flags & PF_W) 351 prot |= VM_PROT_WRITE; 352 if (phdr[i].p_flags & PF_R) 353 prot |= VM_PROT_READ; 354 | 344 345 for (i = 0; i < hdr->e_phnum; i++) { 346 if (phdr[i].p_type == PT_LOAD) { /* Loadable segment */ 347 prot = 0; 348 if (phdr[i].p_flags & PF_X) 349 prot |= VM_PROT_EXECUTE; 350 if (phdr[i].p_flags & PF_W) 351 prot |= VM_PROT_WRITE; 352 if (phdr[i].p_flags & PF_R) 353 prot |= VM_PROT_READ; 354 |
355 if (error = elf_load_section(p, vmspace, nd.ni_vp, | 355 if ((error = elf_load_section(p, vmspace, nd.ni_vp, |
356 phdr[i].p_offset, 357 (caddr_t)phdr[i].p_vaddr + 358 (*addr), 359 phdr[i].p_memsz, | 356 phdr[i].p_offset, 357 (caddr_t)phdr[i].p_vaddr + 358 (*addr), 359 phdr[i].p_memsz, |
360 phdr[i].p_filesz, prot)) | 360 phdr[i].p_filesz, prot)) != 0) |
361 goto fail; 362 363 /* 364 * Is this .text or .data ?? 365 * 366 * We only handle one each of those yet XXX 367 */ 368 if (hdr->e_entry >= phdr[i].p_vaddr && --- 33 unchanged lines hidden (view full) --- 402 struct vmspace *vmspace; 403 vm_prot_t prot; 404 u_long text_size = 0, data_size = 0; 405 u_long text_addr = 0, data_addr = 0; 406 u_long addr, entry = 0, proghdr = 0; 407 int error, i; 408 const char *interp = NULL; 409 Elf_Brandinfo *brand_info; | 361 goto fail; 362 363 /* 364 * Is this .text or .data ?? 365 * 366 * We only handle one each of those yet XXX 367 */ 368 if (hdr->e_entry >= phdr[i].p_vaddr && --- 33 unchanged lines hidden (view full) --- 402 struct vmspace *vmspace; 403 vm_prot_t prot; 404 u_long text_size = 0, data_size = 0; 405 u_long text_addr = 0, data_addr = 0; 406 u_long addr, entry = 0, proghdr = 0; 407 int error, i; 408 const char *interp = NULL; 409 Elf_Brandinfo *brand_info; |
410 char *brand; | 410 const char *brand; |
411 char path[MAXPATHLEN]; 412 413 /* 414 * Do we have a valid ELF header ? 415 */ 416 if (elf_check_header(hdr, ET_EXEC)) 417 return -1; 418 --- 7 unchanged lines hidden (view full) --- 426 /* Only support headers in first page for now */ 427 return ENOEXEC; 428 } 429 phdr = (const Elf_Phdr*)(imgp->image_header + hdr->e_phoff); 430 431 /* 432 * From this point on, we may have resources that need to be freed. 433 */ | 411 char path[MAXPATHLEN]; 412 413 /* 414 * Do we have a valid ELF header ? 415 */ 416 if (elf_check_header(hdr, ET_EXEC)) 417 return -1; 418 --- 7 unchanged lines hidden (view full) --- 426 /* Only support headers in first page for now */ 427 return ENOEXEC; 428 } 429 phdr = (const Elf_Phdr*)(imgp->image_header + hdr->e_phoff); 430 431 /* 432 * From this point on, we may have resources that need to be freed. 433 */ |
434 if (error = exec_extract_strings(imgp)) | 434 if ((error = exec_extract_strings(imgp)) != 0) |
435 goto fail; 436 437 exec_new_vmspace(imgp); 438 439 vmspace = imgp->proc->p_vmspace; 440 441 for (i = 0; i < hdr->e_phnum; i++) { 442 switch(phdr[i].p_type) { 443 444 case PT_LOAD: /* Loadable segment */ 445 prot = 0; 446 if (phdr[i].p_flags & PF_X) 447 prot |= VM_PROT_EXECUTE; 448 if (phdr[i].p_flags & PF_W) 449 prot |= VM_PROT_WRITE; 450 if (phdr[i].p_flags & PF_R) 451 prot |= VM_PROT_READ; 452 | 435 goto fail; 436 437 exec_new_vmspace(imgp); 438 439 vmspace = imgp->proc->p_vmspace; 440 441 for (i = 0; i < hdr->e_phnum; i++) { 442 switch(phdr[i].p_type) { 443 444 case PT_LOAD: /* Loadable segment */ 445 prot = 0; 446 if (phdr[i].p_flags & PF_X) 447 prot |= VM_PROT_EXECUTE; 448 if (phdr[i].p_flags & PF_W) 449 prot |= VM_PROT_WRITE; 450 if (phdr[i].p_flags & PF_R) 451 prot |= VM_PROT_READ; 452 |
453 if (error = elf_load_section(imgp->proc, | 453 if ((error = elf_load_section(imgp->proc, |
454 vmspace, imgp->vp, 455 phdr[i].p_offset, 456 (caddr_t)phdr[i].p_vaddr, 457 phdr[i].p_memsz, | 454 vmspace, imgp->vp, 455 phdr[i].p_offset, 456 (caddr_t)phdr[i].p_vaddr, 457 phdr[i].p_memsz, |
458 phdr[i].p_filesz, prot)) | 458 phdr[i].p_filesz, prot)) != 0) |
459 goto fail; 460 461 /* 462 * Is this .text or .data ?? 463 * 464 * We only handle one each of those yet XXX 465 */ 466 if (hdr->e_entry >= phdr[i].p_vaddr && --- 32 unchanged lines hidden (view full) --- 499 vmspace->vm_daddr = (caddr_t)(uintptr_t)data_addr; 500 501 addr = 2L*MAXDSIZ; /* May depend on OS type XXX */ 502 503 imgp->entry_addr = entry; 504 505 /* If the executable has a brand, search for it in the brand list. */ 506 brand_info = NULL; | 459 goto fail; 460 461 /* 462 * Is this .text or .data ?? 463 * 464 * We only handle one each of those yet XXX 465 */ 466 if (hdr->e_entry >= phdr[i].p_vaddr && --- 32 unchanged lines hidden (view full) --- 499 vmspace->vm_daddr = (caddr_t)(uintptr_t)data_addr; 500 501 addr = 2L*MAXDSIZ; /* May depend on OS type XXX */ 502 503 imgp->entry_addr = entry; 504 505 /* If the executable has a brand, search for it in the brand list. */ 506 brand_info = NULL; |
507 brand = (char *)&hdr->e_ident[EI_BRAND]; | 507 brand = (const char *)&hdr->e_ident[EI_BRAND]; |
508 if (brand[0] != '\0') { 509 for (i = 0; i < MAX_BRANDS; i++) { 510 Elf_Brandinfo *bi = elf_brand_list[i]; 511 512 if (bi != NULL && strcmp(brand, bi->brand) == 0) { 513 brand_info = bi; 514 break; 515 } --- 473 unchanged lines hidden --- | 508 if (brand[0] != '\0') { 509 for (i = 0; i < MAX_BRANDS; i++) { 510 Elf_Brandinfo *bi = elf_brand_list[i]; 511 512 if (bi != NULL && strcmp(brand, bi->brand) == 0) { 513 brand_info = bi; 514 break; 515 } --- 473 unchanged lines hidden --- |