kld: Reject kernel modules with PT_LOAD segments where filesz > memsz

All sorts of places in the ELF loading code assume that filesz <=
memsz, so check that explicitly up front.

Reported by:	Jane Smith <[email protected]> (via D57785)
Reviewed by:	jrtc27, kib
Differential Revision:	https://reviews.freebsd.org/D58542
This commit is contained in:
John Baldwin committed 2026-07-31 13:52:42 -04:00
1 parent b9eaf9b7ce
commit 486dfbb67e
1 file changed
+8
+8
View File
@@ -1110,6 +1110,14 @@ link_elf_load_file(linker_class_t cls, const char* filename,
error = ENOEXEC;
goto out;
}
if (phdr->p_memsz < phdr->p_filesz) {
link_elf_error(filename,
"Invalid program header");
error = ENOEXEC;
goto out;
}
/*
* XXX: We just trust they come in right order ??
*/