From a9183883b88bfccd1c6a62e27621b2c892d50b67 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Mon, 20 Sep 2010 06:00:22 -0400 Subject: [PATCH] map kernel instructions r/o --- usertests.c | 28 ++++++++++++++++++++++++++++ vm.c | 9 +++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/usertests.c b/usertests.c index e62703d..177ffba 100644 --- a/usertests.c +++ b/usertests.c @@ -1419,6 +1419,7 @@ validatetest(void) printf(stdout, "validate ok\n"); } +// does unintialized data start out zero? char uninit[10000]; void bsstest(void) @@ -1434,6 +1435,32 @@ bsstest(void) printf(stdout, "bss test ok\n"); } +// does exec do something sensible if the arguments +// are larger than a page? +void +bigargtest(void) +{ + int pid, ppid; + + ppid = getpid(); + pid = fork(); + if(pid == 0){ + char *args[100]; + int i; + for(i = 0; i < 99; i++) + args[i] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; + args[99] = 0; + printf(stdout, "bigarg test\n"); + exec("echo", args); + printf(stdout, "bigarg test ok\n"); + exit(); + } else if(pid < 0){ + printf(stdout, "bigargtest: fork failed\n"); + exit(); + } + wait(); +} + int main(int argc, char *argv[]) { @@ -1445,6 +1472,7 @@ main(int argc, char *argv[]) } close(open("usertests.ran", O_CREATE)); + // bigargtest(); bsstest(); sbrktest(); validatetest(); diff --git a/vm.c b/vm.c index c57fa53..cd6b255 100644 --- a/vm.c +++ b/vm.c @@ -125,6 +125,9 @@ pde_t* setupkvm(void) { pde_t *pgdir; + extern char etext[]; + char *rwstart = PGROUNDDOWN(etext) - PGSIZE; + uint rwlen = (uint)rwstart - 0x100000; // Allocate page directory if(!(pgdir = (pde_t *) kalloc())) @@ -132,8 +135,10 @@ setupkvm(void) memset(pgdir, 0, PGSIZE); if(// Map IO space from 640K to 1Mbyte !mappages(pgdir, (void *)USERTOP, 0x60000, USERTOP, PTE_W) || - // Map kernel and free memory pool - !mappages(pgdir, (void *)0x100000, PHYSTOP-0x100000, 0x100000, PTE_W) || + // Map kernel instructions + !mappages(pgdir, (void *)0x100000, rwlen, 0x100000, 0) || + // Map kernel data and free memory pool + !mappages(pgdir, rwstart, PHYSTOP-(uint)rwstart, (uint)rwstart, PTE_W) || // Map devices such as ioapic, lapic, ... !mappages(pgdir, (void *)0xFE000000, 0x2000000, 0xFE000000, PTE_W)) return 0;