Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp221324ybl; Fri, 17 Jan 2020 22:34:39 -0800 (PST) X-Google-Smtp-Source: APXvYqz/chlyZOAnRx6RzrZSlRPnm0h2QLlzFuC6YB2lMln3wUeMNOhnSLBUwTiFQAVXjzJItKWd X-Received: by 2002:a9d:7410:: with SMTP id n16mr9073214otk.23.1579329279447; Fri, 17 Jan 2020 22:34:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579329279; cv=none; d=google.com; s=arc-20160816; b=HqppsPLeASTkjQRjHLm/idyWlvgDs0dY30t4spVHx57SpD413VW21GvpmiOkNQaXDM QZHaXu/UgIf3vah8MdpwF3MiSdcCSJIZEPX0Bt4OMn+zluUeyE3TCIBvvrbIPrK/I8qX mlPhSuAS0AXH6MmZilaeqNg8bfDBQ56CsYz1hpsTfMfQfHAn+YmtkZShk9dhElFFtFlF pHHII0m+hgAt43uAcM4rfK3GeYCY1KIpsPNX40AKoPpZ9mKTCMme3J4LLv938e4AkJwV 8YK2H7eQ9Ftce/D1Hg8IMXsXlkCXgQUofcHMWToVAeKm02KK7WvaLadZ+e1nt3p0Qgco CIKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=rS4UKrLn3wFLir64JOAKmcnkWFvXo9oMWz1xNRyZqa0=; b=n9Rw2tMv472iUvmb1pbz0CgvV/kOiUHFWTtVMZFAmg7pM99JposMEfIQnC9/aft7sh Plfg8ctiWgHEIRr8I9+KJvjZCiM68i7TcEeqpFbj1PgU5vzwlhLSu+XWcrFGNrp9XNQD EQgIJDt58Iea2QABsiniuYHUeziH3HRCS1XGL8I7+fu4O55akoQuaHwh2/rtjY/hukG+ FeriwCVmyD3Wp4rL2zsLvRhzvA+6Ab8YBSBOCJ69h5VUakIGUuTtnm8vagai+b4+9jzi BTI91Vi3IvuyWDJJX7WWsGySrD8D9jMTRn534eGLuUABBF5JQrfF6J/s/ZQXBnq+qZxf k2kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=eUVvGMBg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8si14484093oii.249.2020.01.17.22.33.55; Fri, 17 Jan 2020 22:34:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=eUVvGMBg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726060AbgARGav (ORCPT + 99 others); Sat, 18 Jan 2020 01:30:51 -0500 Received: from mail-qv1-f67.google.com ([209.85.219.67]:35112 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbgARGav (ORCPT ); Sat, 18 Jan 2020 01:30:51 -0500 Received: by mail-qv1-f67.google.com with SMTP id u10so11768371qvi.2 for ; Fri, 17 Jan 2020 22:30:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rS4UKrLn3wFLir64JOAKmcnkWFvXo9oMWz1xNRyZqa0=; b=eUVvGMBgNG2WezfPIJ1ccDmNM3UaJoZwBsbIm/Ki9yMpPQy6NV7WJJhLbvBPQNjSQ3 ggeNc6ZaiM2MJ/Vke9Qy7r5/J56CeKxXiTkRD1P1on2O4HNJV2DR1MsnzCQArVW67b4X GRHi4sw5un0fhmqzIWs9JLrvHF9HR6Q1zbDFY16N2A1JbijP9GgRJtchhukzUGrvRV+n 9u/vLtHHBH7S21eTB5Eq02DOpz7NxtbJPOQQNm/uh5ZnR6j1cmF6Jv14ar31cjx8lJrp c78WDrseoY1eLEqNkp3CJdOrioyoIr2Le51RJG9obtDFK1nnZ12YLkpwUywf3pwuTOYA kIMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rS4UKrLn3wFLir64JOAKmcnkWFvXo9oMWz1xNRyZqa0=; b=X0nzi6yxkqKCZSSQ2e9hMUUtyVhjfEiZ7KsplRscNPNWMsL+yQnMn5SznZpGK0ypY6 yTyHUsRfBu0g6ABewteCChxVkM1k4/lgfQkM54/KfdRxYs8WBWbY+x6s8e3g74ex9Sbp WXY8BMaV+7fiIUL7NDSf83YXvdCyi8nf7iWermyrECr8s+qmEjP7EbV6wPk/aK8Jx3sm 7S5lLdh4oh920sYdrK8YER7YkiVVvk7Ygdq8Nd4cKlgE048zRNMz8FanTvR58H5z+e48 +9GCMQQTdAzTLMdfeP3KdC6WCnOqcYg85W/30R4fStmU0gEpZF6NU05/zQoprMaBha7D 8Brg== X-Gm-Message-State: APjAAAUePCUdWKpq99sgdRynk2XoAW47uRa3kMXg+D2dCgGoOuzbJsCb RZ8cr6krfKzE4P7JxbIJGlzSUQ== X-Received: by 2002:a05:6214:287:: with SMTP id l7mr11513554qvv.142.1579329050165; Fri, 17 Jan 2020 22:30:50 -0800 (PST) Received: from ovpn-120-112.rdu2.redhat.com (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id u55sm14693498qtc.28.2020.01.17.22.30.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jan 2020 22:30:49 -0800 (PST) From: Qian Cai To: ardb@kernel.org Cc: mingo@redhat.com, kasan-dev@googlegroups.com, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next] x86/efi_64: fix a user-memory-access in runtime Date: Sat, 18 Jan 2020 01:30:22 -0500 Message-Id: <20200118063022.21743-1-cai@lca.pw> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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)