Skip to content

Commit f799365

Browse files
AdamCDunlapIngo Molnar
authored and
Ingo Molnar
committed
x86/sev-es: Allow copy_from_kernel_nofault() in earlier boot
Previously, if copy_from_kernel_nofault() was called before boot_cpu_data.x86_virt_bits was set up, then it would trigger undefined behavior due to a shift by 64. This ended up causing boot failures in the latest version of ubuntu2204 in the gcp project when using SEV-SNP. Specifically, this function is called during an early #VC handler which is triggered by a CPUID to check if NX is implemented. Fixes: 1aa9aa8 ("x86/sev-es: Setup GHCB-based boot #VC handler") Suggested-by: Dave Hansen <[email protected]> Signed-off-by: Adam Dunlap <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Tested-by: Jacob Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f4c5ca9 commit f799365

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

arch/x86/mm/maccess.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
99
unsigned long vaddr = (unsigned long)unsafe_src;
1010

1111
/*
12-
* Range covering the highest possible canonical userspace address
13-
* as well as non-canonical address range. For the canonical range
14-
* we also need to include the userspace guard page.
12+
* Do not allow userspace addresses. This disallows
13+
* normal userspace and the userspace guard page:
1514
*/
16-
return vaddr >= TASK_SIZE_MAX + PAGE_SIZE &&
17-
__is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
15+
if (vaddr < TASK_SIZE_MAX + PAGE_SIZE)
16+
return false;
17+
18+
/*
19+
* Allow everything during early boot before 'x86_virt_bits'
20+
* is initialized. Needed for instruction decoding in early
21+
* exception handlers.
22+
*/
23+
if (!boot_cpu_data.x86_virt_bits)
24+
return true;
25+
26+
return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
1827
}
1928
#else
2029
bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)

0 commit comments

Comments
 (0)