mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
efi/x86: Align GUIDs to their size in the mixed mode runtime wrapper
commit63056e8b5eupstream. Hans reports that his mixed mode systems running v5.6-rc1 kernels hit the WARN_ON() in virt_to_phys_or_null_size(), caused by the fact that efi_guid_t objects on the vmap'ed stack happen to be misaligned with respect to their sizes. As a quick (i.e., backportable) fix, copy GUID pointer arguments to the local stack into a buffer that is naturally aligned to its size, so that it is guaranteed to cover only one physical page. Note that on x86, we cannot rely on the stack pointer being aligned the way the compiler expects, so we need to allocate an 8-byte aligned buffer of sufficient size, and copy the GUID into that buffer at an offset that is aligned to 16 bytes. Fixes:f6697df36b("x86/efi: Prevent mixed mode boot corruption with CONFIG_VMAP_STACK=y") Reported-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Tested-by: Hans de Goede <hdegoede@redhat.com> Cc: linux-efi@vger.kernel.org Cc: Ingo Molnar <mingo@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20200221084849.26878-2-ardb@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
da44902fcf
commit
61a7f1e13b
@@ -791,6 +791,8 @@ static efi_status_t
|
||||
efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
|
||||
u32 *attr, unsigned long *data_size, void *data)
|
||||
{
|
||||
u8 buf[24] __aligned(8);
|
||||
efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
|
||||
efi_status_t status;
|
||||
u32 phys_name, phys_vendor, phys_attr;
|
||||
u32 phys_data_size, phys_data;
|
||||
@@ -798,8 +800,10 @@ efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
|
||||
|
||||
spin_lock_irqsave(&efi_runtime_lock, flags);
|
||||
|
||||
*vnd = *vendor;
|
||||
|
||||
phys_data_size = virt_to_phys_or_null(data_size);
|
||||
phys_vendor = virt_to_phys_or_null(vendor);
|
||||
phys_vendor = virt_to_phys_or_null(vnd);
|
||||
phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
|
||||
phys_attr = virt_to_phys_or_null(attr);
|
||||
phys_data = virt_to_phys_or_null_size(data, *data_size);
|
||||
@@ -816,14 +820,18 @@ static efi_status_t
|
||||
efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor,
|
||||
u32 attr, unsigned long data_size, void *data)
|
||||
{
|
||||
u8 buf[24] __aligned(8);
|
||||
efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
|
||||
u32 phys_name, phys_vendor, phys_data;
|
||||
efi_status_t status;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&efi_runtime_lock, flags);
|
||||
|
||||
*vnd = *vendor;
|
||||
|
||||
phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
|
||||
phys_vendor = virt_to_phys_or_null(vendor);
|
||||
phys_vendor = virt_to_phys_or_null(vnd);
|
||||
phys_data = virt_to_phys_or_null_size(data, data_size);
|
||||
|
||||
/* If data_size is > sizeof(u32) we've got problems */
|
||||
@@ -840,6 +848,8 @@ efi_thunk_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor,
|
||||
u32 attr, unsigned long data_size,
|
||||
void *data)
|
||||
{
|
||||
u8 buf[24] __aligned(8);
|
||||
efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
|
||||
u32 phys_name, phys_vendor, phys_data;
|
||||
efi_status_t status;
|
||||
unsigned long flags;
|
||||
@@ -847,8 +857,10 @@ efi_thunk_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor,
|
||||
if (!spin_trylock_irqsave(&efi_runtime_lock, flags))
|
||||
return EFI_NOT_READY;
|
||||
|
||||
*vnd = *vendor;
|
||||
|
||||
phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
|
||||
phys_vendor = virt_to_phys_or_null(vendor);
|
||||
phys_vendor = virt_to_phys_or_null(vnd);
|
||||
phys_data = virt_to_phys_or_null_size(data, data_size);
|
||||
|
||||
/* If data_size is > sizeof(u32) we've got problems */
|
||||
@@ -865,14 +877,18 @@ efi_thunk_get_next_variable(unsigned long *name_size,
|
||||
efi_char16_t *name,
|
||||
efi_guid_t *vendor)
|
||||
{
|
||||
u8 buf[24] __aligned(8);
|
||||
efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
|
||||
efi_status_t status;
|
||||
u32 phys_name_size, phys_name, phys_vendor;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&efi_runtime_lock, flags);
|
||||
|
||||
*vnd = *vendor;
|
||||
|
||||
phys_name_size = virt_to_phys_or_null(name_size);
|
||||
phys_vendor = virt_to_phys_or_null(vendor);
|
||||
phys_vendor = virt_to_phys_or_null(vnd);
|
||||
phys_name = virt_to_phys_or_null_size(name, *name_size);
|
||||
|
||||
status = efi_thunk(get_next_variable, phys_name_size,
|
||||
@@ -880,6 +896,7 @@ efi_thunk_get_next_variable(unsigned long *name_size,
|
||||
|
||||
spin_unlock_irqrestore(&efi_runtime_lock, flags);
|
||||
|
||||
*vendor = *vnd;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user