Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/imgact_elf.c
Show First 20 Lines • Show All 951 Lines • ▼ Show 20 Lines | __elfN(get_interp)(struct image_params *imgp, const Elf_Phdr *phdr, | ||||
if (phdr->p_filesz < 2 || phdr->p_filesz > MAXPATHLEN) { | if (phdr->p_filesz < 2 || phdr->p_filesz > MAXPATHLEN) { | ||||
uprintf("Invalid PT_INTERP\n"); | uprintf("Invalid PT_INTERP\n"); | ||||
return (ENOEXEC); | return (ENOEXEC); | ||||
} | } | ||||
interp_name_len = phdr->p_filesz; | interp_name_len = phdr->p_filesz; | ||||
if (phdr->p_offset > PAGE_SIZE || | if (phdr->p_offset > PAGE_SIZE || | ||||
interp_name_len > PAGE_SIZE - phdr->p_offset) { | interp_name_len > PAGE_SIZE - phdr->p_offset) { | ||||
interp = malloc(interp_name_len + 1, M_TEMP, M_NOWAIT); | |||||
if (interp == NULL) { | |||||
VOP_UNLOCK(imgp->vp, 0); | VOP_UNLOCK(imgp->vp, 0); | ||||
interp = malloc(interp_name_len + 1, M_TEMP, M_WAITOK); | interp = malloc(interp_name_len + 1, M_TEMP, M_WAITOK); | ||||
vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY); | vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY); | ||||
} | |||||
error = vn_rdwr(UIO_READ, imgp->vp, interp, | error = vn_rdwr(UIO_READ, imgp->vp, interp, | ||||
interp_name_len, phdr->p_offset, | interp_name_len, phdr->p_offset, | ||||
UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, | UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, | ||||
NOCRED, NULL, td); | NOCRED, NULL, td); | ||||
if (error != 0) { | if (error != 0) { | ||||
free(interp, M_TEMP); | free(interp, M_TEMP); | ||||
uprintf("i/o error PT_INTERP %d\n", error); | uprintf("i/o error PT_INTERP %d\n", error); | ||||
return (error); | return (error); | ||||
▲ Show 20 Lines • Show All 302 Lines • ▼ Show 20 Lines | if (interp != NULL) { | ||||
if (error != 0) | if (error != 0) | ||||
goto ret; | goto ret; | ||||
} else | } else | ||||
addr = et_dyn_addr; | addr = et_dyn_addr; | ||||
/* | /* | ||||
* Construct auxargs table (used by the fixup routine) | * Construct auxargs table (used by the fixup routine) | ||||
*/ | */ | ||||
elf_auxargs = malloc(sizeof(Elf_Auxargs), M_TEMP, M_NOWAIT); | |||||
if (elf_auxargs == NULL) { | |||||
VOP_UNLOCK(imgp->vp, 0); | |||||
elf_auxargs = malloc(sizeof(Elf_Auxargs), M_TEMP, M_WAITOK); | elf_auxargs = malloc(sizeof(Elf_Auxargs), M_TEMP, M_WAITOK); | ||||
vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY); | |||||
} | |||||
elf_auxargs->execfd = -1; | elf_auxargs->execfd = -1; | ||||
elf_auxargs->phdr = proghdr + et_dyn_addr; | elf_auxargs->phdr = proghdr + et_dyn_addr; | ||||
elf_auxargs->phent = hdr->e_phentsize; | elf_auxargs->phent = hdr->e_phentsize; | ||||
elf_auxargs->phnum = hdr->e_phnum; | elf_auxargs->phnum = hdr->e_phnum; | ||||
elf_auxargs->pagesz = PAGE_SIZE; | elf_auxargs->pagesz = PAGE_SIZE; | ||||
elf_auxargs->base = addr; | elf_auxargs->base = addr; | ||||
elf_auxargs->flags = 0; | elf_auxargs->flags = 0; | ||||
elf_auxargs->entry = entry; | elf_auxargs->entry = entry; | ||||
▲ Show 20 Lines • Show All 1,263 Lines • ▼ Show 20 Lines | __elfN(parse_notes)(struct image_params *imgp, Elf_Note *checknote, | ||||
boolean_t res; | boolean_t res; | ||||
/* We need some limit, might as well use PAGE_SIZE. */ | /* We need some limit, might as well use PAGE_SIZE. */ | ||||
if (pnote == NULL || pnote->p_filesz > PAGE_SIZE) | if (pnote == NULL || pnote->p_filesz > PAGE_SIZE) | ||||
return (FALSE); | return (FALSE); | ||||
ASSERT_VOP_LOCKED(imgp->vp, "parse_notes"); | ASSERT_VOP_LOCKED(imgp->vp, "parse_notes"); | ||||
if (pnote->p_offset > PAGE_SIZE || | if (pnote->p_offset > PAGE_SIZE || | ||||
pnote->p_filesz > PAGE_SIZE - pnote->p_offset) { | pnote->p_filesz > PAGE_SIZE - pnote->p_offset) { | ||||
buf = malloc(pnote->p_filesz, M_TEMP, M_NOWAIT); | |||||
if (buf == NULL) { | |||||
VOP_UNLOCK(imgp->vp, 0); | VOP_UNLOCK(imgp->vp, 0); | ||||
buf = malloc(pnote->p_filesz, M_TEMP, M_WAITOK); | buf = malloc(pnote->p_filesz, M_TEMP, M_WAITOK); | ||||
vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY); | vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY); | ||||
} | |||||
error = vn_rdwr(UIO_READ, imgp->vp, buf, pnote->p_filesz, | error = vn_rdwr(UIO_READ, imgp->vp, buf, pnote->p_filesz, | ||||
pnote->p_offset, UIO_SYSSPACE, IO_NODELOCKED, | pnote->p_offset, UIO_SYSSPACE, IO_NODELOCKED, | ||||
curthread->td_ucred, NOCRED, NULL, curthread); | curthread->td_ucred, NOCRED, NULL, curthread); | ||||
if (error != 0) { | if (error != 0) { | ||||
uprintf("i/o error PT_NOTE\n"); | uprintf("i/o error PT_NOTE\n"); | ||||
goto retf; | goto retf; | ||||
} | } | ||||
note = note0 = (const Elf_Note *)buf; | note = note0 = (const Elf_Note *)buf; | ||||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |