From 45ec0ee0c36ac4cff65cb1d00b9ae2534cb70da9 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 28 Mar 2012 01:26:58 +0200 Subject: enforce a stack limit. --- userprog/process.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'userprog/process.c') diff --git a/userprog/process.c b/userprog/process.c index fdfb5dd..c13c051 100644 --- a/userprog/process.c +++ b/userprog/process.c @@ -595,7 +595,8 @@ setup_stack (uint32_t **esp, const char *args) const char *name = thread_current ()->name; char *argv_cur; uint32_t argc = 0; - unsigned namelen, argslen = strlen(args); + unsigned namelen, argslen = 0; + uint32_t *stack_end; kpage = palloc_get_page (PAL_USER | PAL_ZERO); if (kpage == NULL) @@ -608,7 +609,14 @@ setup_stack (uint32_t **esp, const char *args) *esp = PHYS_BASE; + /* calculate end of stack which we'll enforce, + we need at least 4 entries for a correct stack and an + additional entry due to the way our argv[]-entries-loop works */ + stack_end = PHYS_BASE - PGSIZE; + stack_end += 4 + 1; + /* copy arguments to stack */ + argslen = strlen(args); if (argslen > 0) { argslen += 1; /* add the trailing \0 */ @@ -651,6 +659,10 @@ setup_stack (uint32_t **esp, const char *args) (*esp)--; **esp = (uint32_t) argv_cur + 1; argc++; + + /* check for possible stack overflow */ + if (*esp <= stack_end) + return false; } } } -- cgit v1.2.3