On bootup, the amd64 pmap initialization code creates page-table

mappings for the pages used for the kernel and some initial allocations
used for the page table. It maps the kernel and the blocks used for
these initial allocations using 2MB pages.

However, if the kernel does not end on a 2MB boundary, it still maps the
last portion using a 2MB page, but reports that the unused 4K blocks
within this 2MB allocation are free physical blocks. This means that
these same physical blocks could also be mapped elsewhere - for example,
into a user process. Given the proximity to the kernel text and data
area, it seems wise to avoid allowing someone to write data to physical
blocks also mapped into these virtual addresses.

(Note that this isn't a security vulnerability: the direct map makes
most/all memory on the system mapped into kernel space. And, nothing
in the kernel should be trying to access these pages, as the virtual
addresses are unused. It simply seems wise to avoid reusing these
physical blocks while they are mapped to virtual addresses so close
to the kernel text and data area.)

Consequently, let's reserve the physical blocks covered by the
page-table mappings for these initial allocations.

Reviewed by:	kib, markj
MFC after:	2 weeks
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D14268
This commit is contained in:
Jonathan T. Looney 2018-02-09 17:46:33 +00:00
parent ad4bbe575b
commit 31ba4c7b5b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329071

View File

@ -957,6 +957,13 @@ create_pagetables(vm_paddr_t *firstaddr)
pd_p[i] = (i << PDRSHIFT) | X86_PG_RW | X86_PG_V | PG_PS |
pg_g;
/*
* Because we map the physical blocks in 2M pages, adjust firstaddr
* to record the physical blocks we've actually mapped into kernel
* virtual address space.
*/
*firstaddr = round_2mpage(*firstaddr);
/* And connect up the PD to the PDP (leaving room for L4 pages) */
pdp_p = (pdp_entry_t *)(KPDPphys + ptoa(KPML4I - KPML4BASE));
for (i = 0; i < nkpdpe; i++)