Module Name: src
Committed By: maxv
Date: Mon Nov 13 21:32:21 UTC 2017
Modified Files:
src/sys/arch/amd64/stand/prekern: elf.c
src/sys/lib/libsa: loadfile_elf32.c
Log Message:
Don't process ELF sections that don't have the ALLOC flag set.
NOTE: you need to update both the prekern and the bootloader after this
change.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/amd64/stand/prekern/elf.c
cvs rdiff -u -r1.49 -r1.50 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/arch/amd64/stand/prekern/elf.c
diff -u src/sys/arch/amd64/stand/prekern/elf.c:1.10 src/sys/arch/amd64/stand/prekern/elf.c:1.11
--- src/sys/arch/amd64/stand/prekern/elf.c:1.10 Mon Nov 13 21:14:04 2017
+++ src/sys/arch/amd64/stand/prekern/elf.c Mon Nov 13 21:32:21 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: elf.c,v 1.10 2017/11/13 21:14:04 maxv Exp $ */
+/* $NetBSD: elf.c,v 1.11 2017/11/13 21:32:21 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -272,6 +272,9 @@ elf_map_sections()
for (i = 0; i < eif.ehdr->e_shnum; i++) {
shdr = &eif.shdr[i];
+ if (!(shdr->sh_flags & SHF_ALLOC)) {
+ continue;
+ }
if (shdr->sh_type != SHT_NOBITS &&
shdr->sh_type != SHT_PROGBITS) {
continue;
Index: src/sys/lib/libsa/loadfile_elf32.c
diff -u src/sys/lib/libsa/loadfile_elf32.c:1.49 src/sys/lib/libsa/loadfile_elf32.c:1.50
--- src/sys/lib/libsa/loadfile_elf32.c:1.49 Mon Nov 13 20:21:10 2017
+++ src/sys/lib/libsa/loadfile_elf32.c Mon Nov 13 21:32:21 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: loadfile_elf32.c,v 1.49 2017/11/13 20:21:10 maxv Exp $ */
+/* $NetBSD: loadfile_elf32.c,v 1.50 2017/11/13 21:32:21 maxv Exp $ */
/*
* Copyright (c) 1997, 2008, 2017 The NetBSD Foundation, Inc.
@@ -390,6 +390,10 @@ ELFNAMEEND(loadfile_dynamic)(int fd, Elf
addr = maxp;
size = (size_t)shdr[i].sh_size;
+ if (!(shdr[i].sh_flags & SHF_ALLOC)) {
+ continue;
+ }
+
loaded = 0;
switch (shdr[i].sh_type) {
case SHT_NOBITS: