Module Name: src Committed By: maxv Date: Wed Jul 20 13:11:58 UTC 2016
Modified Files: src/sys/kern: subr_kobj.c Log Message: Change the protection of the kernel modules segments once we are done relocating them. The text is allocated as RWX, and then mprotected to RW. There is a bug that prevents us from doing RW->RX on amd64 and perhaps sparc64. On x86, the pmap waits for the page to fault before granting it the X permission. But in the trap handler, such a page is considered as belonging to kernel_map, while it actually belongs to module_map. The kernel then finds out the page is not present in kernel_map, and panics. In all cases, module_map is non pageable, so even if the trap were handled properly, it still wouldn't work. Therefore, there is a small window in which the segment is RWX. But that's fine enough, for now. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/sys/kern/subr_kobj.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/kern/subr_kobj.c diff -u src/sys/kern/subr_kobj.c:1.55 src/sys/kern/subr_kobj.c:1.56 --- src/sys/kern/subr_kobj.c:1.55 Sat Jul 9 07:25:00 2016 +++ src/sys/kern/subr_kobj.c Wed Jul 20 13:11:58 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kobj.c,v 1.55 2016/07/09 07:25:00 maxv Exp $ */ +/* $NetBSD: subr_kobj.c,v 1.56 2016/07/20 13:11:58 maxv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.55 2016/07/09 07:25:00 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.56 2016/07/20 13:11:58 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_modular.h" @@ -706,6 +706,10 @@ kobj_affix(kobj_t ko, const char *name) /* Jettison unneeded memory post-link. */ kobj_jettison(ko); + /* Change the memory protections, when needed. */ + uvm_km_protect(module_map, ko->ko_text_address, ko->ko_text_size, + VM_PROT_READ|VM_PROT_EXECUTE); + /* * Notify MD code that a module has been loaded. *