Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp802164imm; Mon, 21 May 2018 14:45:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr+QiNxgBei8XQVtfq+FMvunMt7AP7T2Dzl7JIYnm0pQgqqR9KTj7t9lznbU93vAW6jrDh7 X-Received: by 2002:a63:7317:: with SMTP id o23-v6mr5717626pgc.59.1526939156247; Mon, 21 May 2018 14:45:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526939156; cv=none; d=google.com; s=arc-20160816; b=u7H+9U8njI7rSunqOoiNrl2+/zX+W63RWqB7PCVK0f48c47O2kIPvytQyH2+Pho5Qb FCRjiGITFrF9M0Mf+c8hzx8qobdZ21ejjA7dMUFLZHr1n3VuLFf9UKQYmEq2Alzsijs4 bkYooSl4tbFp0SnPM4n3hjQ4EmSkrhfM+wDMx1+L102ueAX09g0CT1Aq1JeNlD0muv4G cYrx93p3qxs+d6l/k5waDnHui7km4kT3etHji7yJTxCJD/qCo+7mPO4QXk589OEC96rl 5UtfJmTBAWw+Qo+NTsD/iCAAEcE4blF1W9s3cF759CyfXAIVdnsmcjm5FCg4z5pfPWQb DktA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ZMCjYibgX63eJAZHxTQTfXeBKhap+MeoLgtV0WwDQcc=; b=lvIaNUakGye5cOjNiooalyIxxaWdgSI6kzrnnJqKGi/FKnY58Yuin4wLd6qabQOAqb YXgEev0h56kmZBRaeS6EPWbz6v0SicwPmR3mwwvGzhinn8eaetSigVQIdl+VT7C8O6/Z aXbxi4HXiMAmfObXNihnE+pGa+5+EPh8f4ymAKZFjz/faZh9+jjCAHXAA2qextuZ7e2G DhmUlaPs29XiobPxMaxYip/c8CZjSCwuxvc3mBlfmOon8NzPJlo7hfq8x7Z0KiMFfMK3 SkgY2HCBDrG6jQ7723MOV/UHFEhRntBUZEF7Q8o/wP9VkDWjN8Ly5QSzE0RS5T1NZwY3 IyFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Rsyk6kH3; 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 5-v6si14718784pfi.285.2018.05.21.14.45.41; Mon, 21 May 2018 14:45:56 -0700 (PDT) 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=Rsyk6kH3; 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 S932243AbeEUVYL (ORCPT + 99 others); Mon, 21 May 2018 17:24:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:38996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932223AbeEUVYF (ORCPT ); Mon, 21 May 2018 17:24:05 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 23BC320872; Mon, 21 May 2018 21:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937844; bh=8vpYCPHOSAv025mCRhVHX8LwMtmWZDRqVjX9agBkScs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rsyk6kH3z1FEGBNtd0uM8QLZhe3ETtmQWxX5a89twGovZDPetqRlip/HZBDhiHMyE wkvfJMJJlbWhHHmqZ43TISWybRwYv4s9QeN0dTSAy8lHygMjPCpi1HyiMLWCsRqD0/ z5JfuzZvCFQTmwUr4577LuMc4aoBhlXw9ITFjVl4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , Ard Biesheuvel , Linus Torvalds , Matt Fleming , Peter Zijlstra , Thomas Gleixner , linux-efi@vger.kernel.org, Ingo Molnar Subject: [PATCH 4.16 047/110] efi: Avoid potential crashes, fix the struct efi_pci_io_protocol_32 definition for mixed mode Date: Mon, 21 May 2018 23:11:44 +0200 Message-Id: <20180521210508.645245136@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ard Biesheuvel commit 0b3225ab9407f557a8e20f23f37aa7236c10a9b1 upstream. Mixed mode allows a kernel built for x86_64 to interact with 32-bit EFI firmware, but requires us to define all struct definitions carefully when it comes to pointer sizes. 'struct efi_pci_io_protocol_32' currently uses a 'void *' for the 'romimage' field, which will be interpreted as a 64-bit field on such kernels, potentially resulting in bogus memory references and subsequent crashes. Tested-by: Hans de Goede Signed-off-by: Ard Biesheuvel Cc: Cc: Linus Torvalds Cc: Matt Fleming Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20180504060003.19618-13-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/boot/compressed/eboot.c | 6 ++++-- include/linux/efi.h | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -163,7 +163,8 @@ __setup_efi_pci32(efi_pci_io_protocol_32 if (status != EFI_SUCCESS) goto free_struct; - memcpy(rom->romdata, pci->romimage, pci->romsize); + memcpy(rom->romdata, (void *)(unsigned long)pci->romimage, + pci->romsize); return status; free_struct: @@ -269,7 +270,8 @@ __setup_efi_pci64(efi_pci_io_protocol_64 if (status != EFI_SUCCESS) goto free_struct; - memcpy(rom->romdata, pci->romimage, pci->romsize); + memcpy(rom->romdata, (void *)(unsigned long)pci->romimage, + pci->romsize); return status; free_struct: --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -395,8 +395,8 @@ typedef struct { u32 attributes; u32 get_bar_attributes; u32 set_bar_attributes; - uint64_t romsize; - void *romimage; + u64 romsize; + u32 romimage; } efi_pci_io_protocol_32; typedef struct { @@ -415,8 +415,8 @@ typedef struct { u64 attributes; u64 get_bar_attributes; u64 set_bar_attributes; - uint64_t romsize; - void *romimage; + u64 romsize; + u64 romimage; } efi_pci_io_protocol_64; typedef struct {