Skip to content

Commit f4c8960

Browse files
committed
svsm: validate memory correctly during kernel region expansion
By the time the kernel region is expanded, the memory to be used for the heap has already been validated. Therefore, as the kernel region is expanded, newly added memory must be validated as it is added, and there is no reason to validate new page table pages as they are allocated from existing heap space. Signed-off-by: Jon Lange <jlange@microsoft.com>
1 parent 3a3b47c commit f4c8960

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

kernel/src/kernel_region.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,6 @@ pub unsafe fn expand_kernel_heap(
121121
let new_pdpe_vaddr = VirtAddr::from(u64::from(new_pdpe_paddr) + phys_virt_diff);
122122
allocated_pages += 1;
123123

124-
// Prior to full heap initialization, unallocated heap pages
125-
// are not validated. Since this page is now allocated, it
126-
// must be validated before it can be used.
127-
// SAFETY: the newly mapped page is being used for the first
128-
// time, so it can be validated safely.
129-
unsafe {
130-
platform
131-
.validate_virtual_page_range(
132-
MemoryRegion::new(new_pdpe_vaddr, PAGE_SIZE),
133-
PageValidateOp::Validate,
134-
)
135-
.expect("Failed to validate heap memory");
136-
}
137-
138124
// Ensure that the newly allocated page is filled with zeroes.
139125
// SAFETY: the newly allocated page is known to be unused
140126
// because it is outside the bounds of allocated hep pages, and
@@ -156,6 +142,20 @@ pub unsafe fn expand_kernel_heap(
156142
// Fill in the PDE for the next direct map address in sequence.
157143
pdt[pde_index].set(make_private_address(paddr), pte_flags);
158144

145+
// By the time kernel region expansion is performed, the heap area has
146+
// been fully validated. Now that a new large page has been added,
147+
// that memory must be validated as well.
148+
// SAFETY: the newly mapped page is being used for the first
149+
// time, so it can be validated safely.
150+
unsafe {
151+
platform
152+
.validate_virtual_page_range(
153+
MemoryRegion::new(vaddr, PAGE_SIZE_2M),
154+
PageValidateOp::Validate,
155+
)
156+
.expect("Failed to validate heap memory");
157+
}
158+
159159
paddr = paddr + PAGE_SIZE_2M;
160160
vaddr = vaddr + PAGE_SIZE_2M;
161161
expansion_size -= PAGE_SIZE_2M as u64;

0 commit comments

Comments
 (0)