Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Change the protection of the kernel modules segment...



details:   https://anonhg.NetBSD.org/src/rev/db46be58004a
branches:  trunk
changeset: 816724:db46be58004a
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Jul 20 13:11:58 2016 +0000

description:
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.

diffstat:

 sys/kern/subr_kobj.c |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (29 lines):

diff -r f955deba64f6 -r db46be58004a sys/kern/subr_kobj.c
--- a/sys/kern/subr_kobj.c      Wed Jul 20 12:38:43 2016 +0000
+++ b/sys/kern/subr_kobj.c      Wed Jul 20 13:11:58 2016 +0000
@@ -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 @@
        /* 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.
         *



Home | Main Index | Thread Index | Old Index