]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
amd64: Protect the kernel text, data, and BSS by setting the RW/NX bits
authorjtl <jtl@FreeBSD.org>
Tue, 6 Mar 2018 14:28:37 +0000 (14:28 +0000)
committerjtl <jtl@FreeBSD.org>
Tue, 6 Mar 2018 14:28:37 +0000 (14:28 +0000)
commit8e9b6569cb716c11866c9c79fdb68b507c3e23f4
treecb513f21901aa6017dd8da719b6a866a6d839032
parent403e82edfec56a4aa95044b6d88906eb97ebf1f6
amd64: Protect the kernel text, data, and BSS by setting the RW/NX bits
correctly for the data contained on each memory page.

There are several components to this change:
 * Add a variable to indicate the start of the R/W portion of the
   initial memory.
 * Stop detecting NX bit support for each AP.  Instead, use the value
   from the BSP and, if supported, activate the feature on the other
   APs just before loading the correct page table.  (Functionally, we
   already assume that the BSP and all APs had the same support or
   lack of support for the NX bit.)
 * Set the RW and NX bits correctly for the kernel text, data, and
   BSS (subject to some caveats below).
 * Ensure DDB can write to memory when necessary (such as to set a
   breakpoint).
 * Ensure GDB can write to memory when necessary (such as to set a
   breakpoint).  For this purpose, add new MD functions gdb_begin_write()
   and gdb_end_write() which the GDB support code can call before and
   after writing to memory.

This change is not comprehensive:
 * It doesn't do anything to protect modules.
 * It doesn't do anything for kernel memory allocated after the kernel
   starts running.
 * In order to avoid excessive memory inefficiency, it may let multiple
   types of data share a 2M page, and assigns the most permissions
   needed for data on that page.

Reviewed by: jhb, kib
Discussed with: emaste
MFC after: 2 weeks
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D14282
14 files changed:
sys/amd64/amd64/db_interface.c
sys/amd64/amd64/gdb_machdep.c
sys/amd64/amd64/initcpu.c
sys/amd64/amd64/mpboot.S
sys/amd64/amd64/pmap.c
sys/amd64/include/cpu.h
sys/amd64/include/gdb_machdep.h
sys/arm/include/gdb_machdep.h
sys/conf/ldscript.amd64
sys/gdb/gdb_packet.c
sys/i386/include/gdb_machdep.h
sys/mips/include/gdb_machdep.h
sys/powerpc/include/gdb_machdep.h
sys/sparc64/include/gdb_machdep.h