From: Qian Cai <cai@lca.pw>
To: ardb@kernel.org
Cc: mingo@redhat.com, kasan-dev@googlegroups.com,
linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
Qian Cai <cai@lca.pw>
Subject: [PATCH -next] x86/efi_64: fix a user-memory-access in runtime
Date: Sat, 18 Jan 2020 01:30:22 -0500 [thread overview]
Message-ID: <20200118063022.21743-1-cai@lca.pw> (raw)
The commit 698294704573 ("efi/x86: Split SetVirtualAddresMap() wrappers
into 32 and 64 bit versions") introduced a KASAN error during boot,
BUG: KASAN: user-memory-access in efi_set_virtual_address_map+0x4d3/0x574
Read of size 8 at addr 00000000788fee50 by task swapper/0/0
Hardware name: HP ProLiant XL450 Gen9 Server/ProLiant XL450 Gen9
Server, BIOS U21 05/05/2016
Call Trace:
dump_stack+0xa0/0xea
__kasan_report.cold.8+0xb0/0xc0
kasan_report+0x12/0x20
__asan_load8+0x71/0xa0
efi_set_virtual_address_map+0x4d3/0x574
efi_enter_virtual_mode+0x5f3/0x64e
start_kernel+0x53a/0x5dc
x86_64_start_reservations+0x24/0x26
x86_64_start_kernel+0xf4/0xfb
secondary_startup_64+0xb6/0xc0
It points to this line,
status = efi_call(efi.systab->runtime->set_virtual_address_map,
efi.systab->runtime's address is 00000000788fee18 which is an address in
EFI runtime service and does not have a KASAN shadow page. Fix it by
doing a copy_from_user() first instead.
Fixes: 698294704573 ("efi/x86: Split SetVirtualAddresMap() wrappers into 32 and 64 bit versions")
Signed-off-by: Qian Cai <cai@lca.pw>
---
arch/x86/platform/efi/efi_64.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index 515eab388b56..d6712c9cb9d8 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -1023,6 +1023,7 @@ efi_status_t __init efi_set_virtual_address_map(unsigned long memory_map_size,
u32 descriptor_version,
efi_memory_desc_t *virtual_map)
{
+ efi_runtime_services_t runtime;
efi_status_t status;
unsigned long flags;
pgd_t *save_pgd = NULL;
@@ -1041,13 +1042,15 @@ efi_status_t __init efi_set_virtual_address_map(unsigned long memory_map_size,
efi_switch_mm(&efi_mm);
}
+ if (copy_from_user(&runtime, efi.systab->runtime, sizeof(runtime)))
+ return EFI_ABORTED;
+
kernel_fpu_begin();
/* Disable interrupts around EFI calls: */
local_irq_save(flags);
- status = efi_call(efi.systab->runtime->set_virtual_address_map,
- memory_map_size, descriptor_size,
- descriptor_version, virtual_map);
+ status = efi_call(runtime.set_virtual_address_map, memory_map_size,
+ descriptor_size, descriptor_version, virtual_map);
local_irq_restore(flags);
kernel_fpu_end();
--
2.21.0 (Apple Git-122.2)
next reply other threads:[~2020-01-18 6:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-18 6:30 Qian Cai [this message]
2020-01-18 8:00 ` [PATCH -next] x86/efi_64: fix a user-memory-access in runtime Ard Biesheuvel
2020-01-18 11:04 ` Qian Cai
2020-01-18 13:34 ` Ard Biesheuvel
2020-01-18 13:37 ` Dmitry Vyukov
2020-01-18 13:41 ` Ard Biesheuvel
2020-01-27 23:29 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200118063022.21743-1-cai@lca.pw \
--to=cai@lca.pw \
--cc=ardb@kernel.org \
--cc=kasan-dev@googlegroups.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).