nanovms / nanos

A kernel designed to run one and only one application in a virtualized environment
https://nanos.org
Apache License 2.0
2.58k stars 133 forks source link

x86: setup_initmap(): fix mapping of initial pages #2019

Closed francescolavra closed 4 months ago

francescolavra commented 4 months ago

Depending on the address of the initial pages allocated in setup_initmap(), the map_setup_2mbpages() function may not find an existing PDPT and or PDT in the page tables, and thus may need to use a new PDPT and/or a new PDT. However, the PDPT and PDT addresses passed to this function correspond to in-use pages, and as such cannot be reused and assigned to new PTEs. Moreover, when creating a new PTE, the map_setup_2mbpages() function is simply OR-ing the page address with the page flags, failing to set the USER flag and thereby preventing any pages referenced by this directory entry from being mapped for user space access; this may cause bogus segmentation fault signals to be delivered to the user process (https://github.com/nanovms/nanos/issues/1999#issuecomment-2072735021).

This change fixes the above issues by amending map_setup_2mbpages() so that it takes a physical memory region from which to allocate any new pages it may need, and calls new_level_pte() when creating a new PTE.