imgact_elf: handle unaligned phdrs
Althought non-compliant, there are binaries which have the phdrs placed unaligned in the image. Since we have the code to allocate memory for off-page phdrs, the same code path can be used to handle unaligned phdrs. Relax the requirement for both the activated image and interpreter. PR: 295629 Reviewed by: emaste, markj, olce Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D57498
This commit is contained in:
@@ -858,12 +858,12 @@ __elfN(load_file)(struct thread *td, const char *file, u_long *addr,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!aligned(imgp->image_header + hdr->e_phoff, Elf_Addr) ||
|
||||
hdr->e_phnum > __elfN(phnums)) {
|
||||
if (hdr->e_phnum > __elfN(phnums)) {
|
||||
error = ENOEXEC;
|
||||
goto fail;
|
||||
}
|
||||
if (__elfN(phdr_in_zero_page)(hdr)) {
|
||||
if (__elfN(phdr_in_zero_page)(hdr) &&
|
||||
aligned(imgp->image_header + hdr->e_phoff, Elf_Addr)) {
|
||||
phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff);
|
||||
} else {
|
||||
VOP_UNLOCK(imgp->vp);
|
||||
@@ -1157,10 +1157,6 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
|
||||
free_interp = false;
|
||||
m_phdrs = NULL;
|
||||
|
||||
if (!aligned(imgp->image_header + hdr->e_phoff, Elf_Addr)) {
|
||||
uprintf("Unaligned program headers\n");
|
||||
return (ENOEXEC);
|
||||
}
|
||||
if (hdr->e_phoff + hdr->e_phnum * hdr->e_phentsize < hdr->e_phoff) {
|
||||
uprintf("PHDRS wrap\n");
|
||||
return (ENOEXEC);
|
||||
@@ -1170,7 +1166,8 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
|
||||
hdr->e_phnum, __elfN(phnums));
|
||||
return (ENOEXEC);
|
||||
}
|
||||
if (__elfN(phdr_in_zero_page)(hdr)) {
|
||||
if (__elfN(phdr_in_zero_page)(hdr) &&
|
||||
aligned(imgp->image_header + hdr->e_phoff, Elf_Addr)) {
|
||||
phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff);
|
||||
} else {
|
||||
VOP_UNLOCK(imgp->vp);
|
||||
|
||||
Reference in New Issue
Block a user