git: 9facb187c9aa - stable/15 - link_elf: Make phdrs first page check actually fatal

Jessica Clarke <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a74cc71.32892.76042a04__6297.32662798546$1786039475$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=9facb187c9aa02ced20338bf69c6f6e59ac1030a

commit 9facb187c9aa02ced20338bf69c6f6e59ac1030a
Author:     Jessica Clarke <[email protected]>
AuthorDate: 2026-07-29 14:09:42 +0000
Commit:     Jessica Clarke <[email protected]>
CommitDate: 2026-08-06 18:02:34 +0000

    link_elf: Make phdrs first page check actually fatal
    
    Otherwise we'll print an error but carry on regardless, presumably
    destined to walk off the end of the mapping.
    
    Reported by:    [email protected]
    MFC after:      1 week
    
    (cherry picked from commit 1e39a314d870e312f623199e146eda6bdbc293a3)
---
 sys/kern/link_elf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c
index d12495504c81..ef4609333d3d 100644
--- a/sys/kern/link_elf.c
+++ b/sys/kern/link_elf.c
@@ -1086,8 +1086,11 @@ link_elf_load_file(linker_class_t cls, const char* filename,
 	 */
 	if (!((hdr->e_phentsize == sizeof(Elf_Phdr)) &&
 	      (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= PAGE_SIZE) &&
-	      (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= nbytes)))
+	      (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= nbytes))) {
 		link_elf_error(filename, "Unreadable program headers");
+		error = ENOEXEC;
+		goto out;
+	}
 
 	/*
 	 * Scan the program header entries, and save key information.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.