Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/amd64/stand/prekern Mprotect the segments in mm.c u...
details: https://anonhg.NetBSD.org/src/rev/c1dba1a7c48e
branches: trunk
changeset: 357315:c1dba1a7c48e
user: maxv <maxv%NetBSD.org@localhost>
date: Sun Nov 05 16:26:15 2017 +0000
description:
Mprotect the segments in mm.c using bootspace, and remove the now unused
fields of elfinfo.
diffstat:
sys/arch/amd64/stand/prekern/elf.c | 44 +++++----------------------------
sys/arch/amd64/stand/prekern/mm.c | 24 ++++++++++++++---
sys/arch/amd64/stand/prekern/prekern.c | 3 +-
sys/arch/amd64/stand/prekern/prekern.h | 10 +++---
4 files changed, 33 insertions(+), 48 deletions(-)
diffs (238 lines):
diff -r 9763fc89fa78 -r c1dba1a7c48e sys/arch/amd64/stand/prekern/elf.c
--- a/sys/arch/amd64/stand/prekern/elf.c Sun Nov 05 16:16:26 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/elf.c Sun Nov 05 16:26:15 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: elf.c,v 1.6 2017/11/01 17:00:17 maxv Exp $ */
+/* $NetBSD: elf.c,v 1.7 2017/11/05 16:26:15 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -42,18 +42,6 @@
size_t symcnt;
char *strtab;
size_t strsz;
- struct {
- vaddr_t va;
- size_t sz;
- } text;
- struct {
- vaddr_t va;
- size_t sz;
- } rodata;
- struct {
- vaddr_t va;
- size_t sz;
- } data;
};
extern paddr_t kernpa_start, kernpa_end;
@@ -361,15 +349,12 @@
}
void
-elf_build_text(vaddr_t textva, paddr_t textpa, size_t textsz)
+elf_build_text(vaddr_t textva, paddr_t textpa)
{
const paddr_t basepa = kernpa_start;
const vaddr_t headva = (vaddr_t)eif.ehdr;
size_t i, offtext;
- eif.text.va = textva;
- eif.text.sz = textsz;
-
for (i = 0; i < eif.ehdr->e_shnum; i++) {
if (!elf_section_is_text(&eif.shdr[i])) {
continue;
@@ -379,7 +364,7 @@
offtext = basepa + eif.shdr[i].sh_offset - textpa;
/* We want (headva + sh_offset) to be the VA of the section. */
- eif.shdr[i].sh_offset = (eif.text.va + offtext - headva);
+ eif.shdr[i].sh_offset = (textva + offtext - headva);
}
}
@@ -411,15 +396,12 @@
}
void
-elf_build_rodata(vaddr_t rodatava, paddr_t rodatapa, size_t rodatasz)
+elf_build_rodata(vaddr_t rodatava, paddr_t rodatapa)
{
const paddr_t basepa = kernpa_start;
const vaddr_t headva = (vaddr_t)eif.ehdr;
size_t i, offrodata;
- eif.rodata.va = rodatava;
- eif.rodata.sz = rodatasz;
-
for (i = 0; i < eif.ehdr->e_shnum; i++) {
if (!elf_section_is_rodata(&eif.shdr[i])) {
continue;
@@ -429,7 +411,7 @@
offrodata = basepa + eif.shdr[i].sh_offset - rodatapa;
/* We want (headva + sh_offset) to be the VA of the section. */
- eif.shdr[i].sh_offset = (eif.rodata.va + offrodata - headva);
+ eif.shdr[i].sh_offset = (rodatava + offrodata - headva);
}
}
@@ -461,15 +443,12 @@
}
void
-elf_build_data(vaddr_t datava, paddr_t datapa, size_t datasz)
+elf_build_data(vaddr_t datava, paddr_t datapa)
{
const paddr_t basepa = kernpa_start;
const vaddr_t headva = (vaddr_t)eif.ehdr;
size_t i, offdata;
- eif.data.va = datava;
- eif.data.sz = datasz;
-
for (i = 0; i < eif.ehdr->e_shnum; i++) {
if (!elf_section_is_data(&eif.shdr[i])) {
continue;
@@ -479,7 +458,7 @@
offdata = basepa + eif.shdr[i].sh_offset - datapa;
/* We want (headva + sh_offset) to be the VA of the section. */
- eif.shdr[i].sh_offset = (eif.data.va + offdata - headva);
+ eif.shdr[i].sh_offset = (datava + offdata - headva);
}
}
@@ -644,15 +623,6 @@
print_state(true, "Entry point found");
- /*
- * Remap the code segments with proper permissions.
- */
- mm_mprotect(eif.text.va, eif.text.sz, MM_PROT_READ|MM_PROT_EXECUTE);
- mm_mprotect(eif.rodata.va, eif.rodata.sz, MM_PROT_READ);
- mm_mprotect(eif.data.va, eif.data.sz, MM_PROT_READ|MM_PROT_WRITE);
-
- print_state(true, "Segments protection updated");
-
return ent;
}
diff -r 9763fc89fa78 -r c1dba1a7c48e sys/arch/amd64/stand/prekern/mm.c
--- a/sys/arch/amd64/stand/prekern/mm.c Sun Nov 05 16:16:26 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/mm.c Sun Nov 05 16:26:15 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mm.c,v 1.7 2017/10/29 11:38:43 maxv Exp $ */
+/* $NetBSD: mm.c,v 1.8 2017/11/05 16:26:15 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -96,7 +96,7 @@
return (PTE_BASE[pl1_i(va)] & PG_FRAME);
}
-void
+static void
mm_mprotect(vaddr_t startva, size_t size, int prot)
{
size_t i, npages;
@@ -114,6 +114,20 @@
}
}
+void
+mm_bootspace_mprotect()
+{
+ /*
+ * Remap the kernel segments with proper permissions.
+ */
+ mm_mprotect(bootspace.text.va, bootspace.text.sz,
+ MM_PROT_READ|MM_PROT_EXECUTE);
+ mm_mprotect(bootspace.rodata.va, bootspace.rodata.sz,
+ MM_PROT_READ);
+
+ print_state(true, "Segments protection updated");
+}
+
static size_t
mm_nentries_range(vaddr_t startva, vaddr_t endva, size_t pgsz)
{
@@ -277,7 +291,7 @@
mm_enter_pa(pa + i * PAGE_SIZE,
randva + i * PAGE_SIZE, MM_PROT_READ|MM_PROT_WRITE);
}
- elf_build_text(randva, pa, size);
+ elf_build_text(randva, pa);
/* Register the values in bootspace */
bootspace.text.va = randva;
@@ -296,7 +310,7 @@
mm_enter_pa(pa + i * PAGE_SIZE,
randva + i * PAGE_SIZE, MM_PROT_READ|MM_PROT_WRITE);
}
- elf_build_rodata(randva, pa, size);
+ elf_build_rodata(randva, pa);
/* Register the values in bootspace */
bootspace.rodata.va = randva;
@@ -315,7 +329,7 @@
mm_enter_pa(pa + i * PAGE_SIZE,
randva + i * PAGE_SIZE, MM_PROT_READ|MM_PROT_WRITE);
}
- elf_build_data(randva, pa, size);
+ elf_build_data(randva, pa);
/* Register the values in bootspace */
bootspace.data.va = randva;
diff -r 9763fc89fa78 -r c1dba1a7c48e sys/arch/amd64/stand/prekern/prekern.c
--- a/sys/arch/amd64/stand/prekern/prekern.c Sun Nov 05 16:16:26 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/prekern.c Sun Nov 05 16:26:15 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: prekern.c,v 1.3 2017/10/29 11:28:30 maxv Exp $ */
+/* $NetBSD: prekern.c,v 1.4 2017/11/05 16:26:15 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -338,6 +338,7 @@
*/
mm_map_kernel();
ent = elf_kernel_reloc();
+ mm_bootspace_mprotect();
/*
* Build the arguments.
diff -r 9763fc89fa78 -r c1dba1a7c48e sys/arch/amd64/stand/prekern/prekern.h
--- a/sys/arch/amd64/stand/prekern/prekern.h Sun Nov 05 16:16:26 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/prekern.h Sun Nov 05 16:26:15 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: prekern.h,v 1.3 2017/10/29 11:28:30 maxv Exp $ */
+/* $NetBSD: prekern.h,v 1.4 2017/11/05 16:26:15 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -102,11 +102,11 @@
size_t elf_get_head_size(vaddr_t);
void elf_build_head(vaddr_t);
void elf_get_text(paddr_t *, size_t *);
-void elf_build_text(vaddr_t, paddr_t, size_t);
+void elf_build_text(vaddr_t, paddr_t);
void elf_get_rodata(paddr_t *, size_t *);
-void elf_build_rodata(vaddr_t, paddr_t, size_t);
+void elf_build_rodata(vaddr_t, paddr_t);
void elf_get_data(paddr_t *, size_t *);
-void elf_build_data(vaddr_t, paddr_t, size_t);
+void elf_build_data(vaddr_t, paddr_t);
void elf_build_boot(vaddr_t, paddr_t);
vaddr_t elf_kernel_reloc();
@@ -118,7 +118,7 @@
/* mm.c */
void mm_init(paddr_t);
paddr_t mm_vatopa(vaddr_t);
-void mm_mprotect(vaddr_t, size_t, int);
+void mm_bootspace_mprotect();
void mm_map_kernel();
/* prekern.c */
Home |
Main Index |
Thread Index |
Old Index