f79936545f
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: 1aa9aa8ee517 ("x86/sev-es: Setup GHCB-based boot #VC handler") Suggested-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Adam Dunlap <acdunlap@google.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Tested-by: Jacob Xu <jacobhxu@google.com> Link: https://lore.kernel.org/r/20230912002703.3924521-2-acdunlap@google.com
34 lines
838 B
C
34 lines
838 B
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
#include <linux/uaccess.h>
|
|
#include <linux/kernel.h>
|
|
|
|
#ifdef CONFIG_X86_64
|
|
bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
|
|
{
|
|
unsigned long vaddr = (unsigned long)unsafe_src;
|
|
|
|
/*
|
|
* Do not allow userspace addresses. This disallows
|
|
* normal userspace and the userspace guard page:
|
|
*/
|
|
if (vaddr < TASK_SIZE_MAX + PAGE_SIZE)
|
|
return false;
|
|
|
|
/*
|
|
* Allow everything during early boot before 'x86_virt_bits'
|
|
* is initialized. Needed for instruction decoding in early
|
|
* exception handlers.
|
|
*/
|
|
if (!boot_cpu_data.x86_virt_bits)
|
|
return true;
|
|
|
|
return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
|
|
}
|
|
#else
|
|
bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
|
|
{
|
|
return (unsigned long)unsafe_src >= TASK_SIZE_MAX;
|
|
}
|
|
#endif
|