Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1586274ybv; Thu, 20 Feb 2020 23:47:30 -0800 (PST) X-Google-Smtp-Source: APXvYqwOOxGxJf7pjKQ7vTVhWxifbqmS1rQ9mcuTc20sBlY8d9amQocAKPAfBMCzrVs6W7dU/4kv X-Received: by 2002:aca:c256:: with SMTP id s83mr931197oif.57.1582271250166; Thu, 20 Feb 2020 23:47:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582271250; cv=none; d=google.com; s=arc-20160816; b=VP2yzH/X1kBYS5E7gKK1oweMtjK5I/hZaDP5VBwhBRJ4oPUTmE1YgOm86TgbKu7UDg 8ihhIAEmETyaC2YMcB6jV1320sZDsWeYay4/MjViYAMU54UJOgq2xvSx9XrDp96+b+Es mLuHMsMDiMJw3b6zKeoNtGgumY7s7jrVVv0KkNFQILB0A2kc2AeBUE40oRIFLE8X9g3h AG7fCU35uFNOrNBYXi7/lw2I4c1ZpcyUa+sMqQw5rapHq/oSJxk2nxDcwLYUeHr4P0o5 hVzhTp0/f0Qt+LhVII/S1kx2Hzom6JYe2rcKcx5ZZri8HoDyS7FaYSxXaizsLCyyrnD0 fLgA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zWC8GsvfR85mtciwBIT9KXnIJrRJIovEumnisyw4LTc=; b=Rml6l4RDjZVKofCeiQ6ypJFDTbCRBu9BcoEdmpYQ+3zKby+Tz33gNS5ihjbUuCMzKo M4GUSGr8hWapn95S01w2DxhX5uA+aRXPiG6h3ilaZOzMDlZYhr9UltTzwPMuPIiD/Wnm xh2sAaw0B0G4ScZJuNomunQrAl8Fzih2CGaqFIxoaT/2RqCegIm3jNyquPw1ex9G+Gs5 W06aGvSkE9P7nTh3Drsa573UuBl9EkipczxsoWJGrCIZTSd+moHMokh895YURT1EftUM K2uErvPR5Im9hvz0pApywUhQ9r+oDmTBl3ut6dEEtHsd9+Bpb/N51X2JtCzYr9j39Q0a OS8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oS4+2Lh8; 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 a14si1228388otk.2.2020.02.20.23.47.17; Thu, 20 Feb 2020 23:47:30 -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=oS4+2Lh8; 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 S1728512AbgBUHpu (ORCPT + 99 others); Fri, 21 Feb 2020 02:45:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:41070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727867AbgBUHpt (ORCPT ); Fri, 21 Feb 2020 02:45:49 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6C53F222C4; Fri, 21 Feb 2020 07:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271148; bh=SX59StiBv01BZsQL/M6GsKcpiCvE0GOavYHZERRX5mk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oS4+2Lh8MB7OuhWIR5bN3I91vOqgKVJym5wOgECL6DTm6HU51bs+3XdL81/+JjABw TX3i+w8cW0HzSiaw6qeWcNBwoRXnz+QhG92m7S349ZI2qfOyVur6Natwa1dhKLfPY5 dC44GI0hOI7tYu8kjPjqqkN96JV7FJvEhYp2APXA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Andy Lutomirski , Ard Biesheuvel , Arvind Sankar , Matthew Garrett , linux-efi@vger.kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH 5.5 057/399] efi/x86: Map the entire EFI vendor string before copying it Date: Fri, 21 Feb 2020 08:36:22 +0100 Message-Id: <20200221072407.895325178@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 38d44f36d5ede..06f69bcd233fe 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -541,7 +541,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 || @@ -566,14 +565,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