Module Name:    src
Committed By:   maxv
Date:           Thu Oct 17 14:00:28 UTC 2019

Modified Files:
        src/sys/lib/libsa: loadfile_elf32.c

Log Message:
Make sure we're dealing with a static binary. Otherwise we could crash if
the user mistakenly tries to boot a KASLR kernel with 'boot' instead of
'pkboot'. Now we fail cleanly. Reported by cryo@.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/lib/libsa/loadfile_elf32.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/lib/libsa/loadfile_elf32.c
diff -u src/sys/lib/libsa/loadfile_elf32.c:1.55 src/sys/lib/libsa/loadfile_elf32.c:1.56
--- src/sys/lib/libsa/loadfile_elf32.c:1.55	Sun Jul 21 16:53:17 2019
+++ src/sys/lib/libsa/loadfile_elf32.c	Thu Oct 17 14:00:28 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: loadfile_elf32.c,v 1.55 2019/07/21 16:53:17 rin Exp $ */
+/* $NetBSD: loadfile_elf32.c,v 1.56 2019/10/17 14:00:28 maxv Exp $ */
 
 /*
  * Copyright (c) 1997, 2008, 2017 The NetBSD Foundation, Inc.
@@ -699,6 +699,11 @@ ELFNAMEEND(loadfile_static)(int fd, Elf_
 
 	internalize_ehdr(elf->e_ident[EI_DATA], elf);
 
+	if (elf->e_type != ET_EXEC) {
+		errno = EINVAL;
+		return 1;
+	}
+
 	sz = elf->e_phnum * sizeof(Elf_Phdr);
 	phdr = ALLOC(sz);
 	ret = ELFNAMEEND(readfile_local)(fd, elf->e_phoff, phdr, sz);

Reply via email to