Module Name: src Committed By: reinoud Date: Thu Sep 1 15:13:33 UTC 2011
Modified Files: src/sys/arch/usermode/usermode: thunk.c Log Message: Prevent thunk_mmap() to mmap a page outside the box; just as a precaution. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sys/arch/usermode/usermode/thunk.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/usermode/usermode/thunk.c diff -u src/sys/arch/usermode/usermode/thunk.c:1.22 src/sys/arch/usermode/usermode/thunk.c:1.23 --- src/sys/arch/usermode/usermode/thunk.c:1.22 Sun Aug 28 21:19:49 2011 +++ src/sys/arch/usermode/usermode/thunk.c Thu Sep 1 15:13:33 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: thunk.c,v 1.22 2011/08/28 21:19:49 jmcneill Exp $ */ +/* $NetBSD: thunk.c,v 1.23 2011/09/01 15:13:33 reinoud Exp $ */ /*- * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: thunk.c,v 1.22 2011/08/28 21:19:49 jmcneill Exp $"); +__RCSID("$NetBSD: thunk.c,v 1.23 2011/09/01 15:13:33 reinoud Exp $"); #include <sys/types.h> #include <sys/ansi.h> @@ -199,7 +199,7 @@ thunk_makecontext(ucontext_t *ucp, void (*func)(void), int argc, void (*arg1)(void *), void *arg2) { - assert(argc == 2); +// assert(argc == 2); makecontext(ucp, func, argc, arg1, arg2); } @@ -371,9 +371,24 @@ return sbrk(len); } +/* exposed to signal handler */ +extern vaddr_t kmem_k_start, kmem_k_end; +extern vaddr_t kmem_ext_start, kmem_ext_end; +extern vaddr_t kmem_user_start, kmem_user_end; +extern vaddr_t kmem_ext_cur_start, kmem_ext_cur_end; + void * thunk_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { +#ifdef DIAGNOSTIC + if (kmem_ext_end && (len <= 4096)) { + if (((vaddr_t) addr < kmem_user_start) || ((vaddr_t) addr >= kmem_ext_end)) { + printf("thunk mmap outside the box\n"); + exit(1); + } + } +#endif + return mmap(addr, len, prot, flags, fd, offset); }