Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1947015ybv; Fri, 14 Feb 2020 08:41:25 -0800 (PST) X-Google-Smtp-Source: APXvYqym9Z6UQS6yzxhTUU8DXkTjikUL3IhFUNLWOaqRBIvKw0Uq/+OqijPn2Y6RCJWQctlIB1SM X-Received: by 2002:a05:6830:1294:: with SMTP id z20mr2989538otp.60.1581698485424; Fri, 14 Feb 2020 08:41:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581698485; cv=none; d=google.com; s=arc-20160816; b=in5mAcghJA6A/4RdYuvaNi+Y/QzQq7/bQL7J4XyiDev1pw3PYWVDDMMfEGaxtHtb6O 6ZaZfwwSfYhM/4MfY0GrDQc0xNvHrRVwCmH1bVAim+a0MZ2qR0CQVw4ISvIMjHJwMQ/j 0ffTHW0y2C0j9/1IlxkqWwJjs7myKgYxcUY+QxDuK2uU2N3Y15V0f/HdzcMD48MPOqF2 GJSObPGP/vkbIrRUJU6C32M8CWZYF8/aD2TwYSNpZxjFUmASKUbErQNCyrrhP5xQzw6P bQjFuEeXHszBqpE555xV59LLJW2bio/7Ynmu1UFIIfRG0OvtTMg7m3qmjBhdxMIVdWE5 hImg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kijDHG3FUK8+4FYFsmr+dcrzW92cqGv49v84UGqWnSM=; b=XnP3Ot/SWc+zBxFI4izaS0FjejiftWVh1nPnFS583njeyS63hBq6C4x24OT4Jz8j79 rk3DrzhLYX01beoyJpgqXBzl/3tHoyLznwJYvGymlDze4Vu12wgYeVwRDBOIx4qx0Nch 3A80jsLPVcWXs6yOp+LF9Yt1YEnPBUBIimEWsRQT9+ua1B/pgXYhcObCJveDWX4Sh4Qw N69AZgSeYVnzQ13PxmTarNv+/ClQ/JrfhGC/9Zgs8dmPHA5x573Gj9a9I9RdV50/sLdB tZxy2ZqjheELfUOV2PwKUIdj5IfSSgaqztank0L0PpaiAyANhyX1yljt0xlOo9uWQUMQ 864w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SEuBJEFz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si3143428otn.53.2020.02.14.08.41.13; Fri, 14 Feb 2020 08:41:25 -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=@kernel.org header.s=default header.b=SEuBJEFz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405144AbgBNQXI (ORCPT + 99 others); Fri, 14 Feb 2020 11:23:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:56574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393075AbgBNQVo (ORCPT ); Fri, 14 Feb 2020 11:21:44 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9CB37246C5; Fri, 14 Feb 2020 16:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697304; bh=lL4pFfsrsx5IvHqyB0CeDf2N+rjFEBCQR0PaBMWEcVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SEuBJEFzuMbG758vb88vmeye+U0Hy+XSdtlLJNuf8UgnJ/BbUu0kFEYkRLNPawEbH t92d50sSk3Wjt1DF7zvA97IEZEVDdxF6d8vuRLCoWxbSYvJel16kSeqNv6Pg032Xkb Ty9E2pOyZmyUFKHq6spzoykMeHDpoH3j2uoZHriM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ard Biesheuvel , Andy Lutomirski , Ard Biesheuvel , Arvind Sankar , Matthew Garrett , linux-efi@vger.kernel.org, Ingo Molnar , Sasha Levin , platform-driver-x86@vger.kernel.org, x86@kernel.org Subject: [PATCH AUTOSEL 4.9 016/141] efi/x86: Map the entire EFI vendor string before copying it Date: Fri, 14 Feb 2020 11:19:16 -0500 Message-Id: <20200214162122.19794-16-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit ffc2760bcf2dba0dbef74013ed73eea8310cc52c ] Fix a couple of issues with the way we map and copy the vendor string: - we map only 2 bytes, which usually works since you get at least a page, but if the vendor string happens to cross a page boundary, a crash will result - only call early_memunmap() if early_memremap() succeeded, or we will call it with a NULL address which it doesn't like, - while at it, switch to early_memremap_ro(), and array indexing rather than pointer dereferencing to read the CHAR16 characters. Signed-off-by: Ard Biesheuvel Cc: Andy Lutomirski Cc: Ard Biesheuvel Cc: Arvind Sankar Cc: Matthew Garrett Cc: linux-efi@vger.kernel.org Fixes: 5b83683f32b1 ("x86: EFI runtime service support") Link: https://lkml.kernel.org/r/20200103113953.9571-5-ardb@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- arch/x86/platform/efi/efi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index b6669d326545a..f08abdf8bb676 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -478,7 +478,6 @@ void __init efi_init(void) efi_char16_t *c16; char vendor[100] = "unknown"; int i = 0; - void *tmp; #ifdef CONFIG_X86_32 if (boot_params.efi_info.efi_systab_hi || @@ -503,14 +502,16 @@ void __init efi_init(void) /* * Show what we know for posterity */ - c16 = tmp = early_memremap(efi.systab->fw_vendor, 2); + c16 = early_memremap_ro(efi.systab->fw_vendor, + sizeof(vendor) * sizeof(efi_char16_t)); if (c16) { - for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i) - vendor[i] = *c16++; + for (i = 0; i < sizeof(vendor) - 1 && c16[i]; ++i) + vendor[i] = c16[i]; vendor[i] = '\0'; - } else + early_memunmap(c16, sizeof(vendor) * sizeof(efi_char16_t)); + } else { pr_err("Could not map the firmware vendor!\n"); - early_memunmap(tmp, 2); + } pr_info("EFI v%u.%.02u by %s\n", efi.systab->hdr.revision >> 16, -- 2.20.1