From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755937Ab3HLXCx (ORCPT ); Mon, 12 Aug 2013 19:02:53 -0400 Received: from g5t0007.atlanta.hp.com ([15.192.0.44]:29840 "EHLO g5t0007.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755614Ab3HLXCx (ORCPT ); Mon, 12 Aug 2013 19:02:53 -0400 From: Linn Crosetto To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, yinghai@kernel.org, penberg@kernel.org, jacob.shin@amd.com Cc: linux-kernel@vger.kernel.org, Linn Crosetto Subject: [PATCH v2] x86: selective remapping in parse_setup_data() Date: Mon, 12 Aug 2013 17:01:22 -0600 Message-Id: <1376348482-1357-1-git-send-email-linn@hp.com> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <52094ED2.1000308@zytor.com> References: <52094ED2.1000308@zytor.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Type SETUP_PCI, added by setup_efi_pci(), may advertise a ROM size larger than early_memremap() is able to handle, which is currently limited to 256kB. If this occurs it leads to a NULL dereference in parse_setup_data(). To avoid this, first remap the setup_data header, and remap the data only for types actually parsed in parse_setup_data(). Type SETUP_PCI is handled later by pcibios_add_device(), when ioremap() is available. Signed-off-by: Linn Crosetto --- v2: add more detail to the explanation as requested by hpa --- arch/x86/kernel/setup.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index f8ec578..2063a49 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -423,6 +423,17 @@ static void __init reserve_initrd(void) } #endif /* CONFIG_BLK_DEV_INITRD */ +static void __init remap_setup_data(u64 pa_data, u32 data_len, + struct setup_data **data, u32 *map_len) +{ + if (data_len <= *map_len) + return; + + early_iounmap(*data, *map_len); + *data = early_memremap(pa_data, data_len); + *map_len = data_len; +} + static void __init parse_setup_data(void) { struct setup_data *data; @@ -432,18 +443,16 @@ static void __init parse_setup_data(void) while (pa_data) { u32 data_len, map_len; + /* The data length may be too large for early remapping, + remap the data only when needed. */ map_len = max(PAGE_SIZE - (pa_data & ~PAGE_MASK), (u64)sizeof(struct setup_data)); data = early_memremap(pa_data, map_len); data_len = data->len + sizeof(struct setup_data); - if (data_len > map_len) { - early_iounmap(data, map_len); - data = early_memremap(pa_data, data_len); - map_len = data_len; - } switch (data->type) { case SETUP_E820_EXT: + remap_setup_data(pa_data, data_len, &data, &map_len); parse_e820_ext(data); break; case SETUP_DTB: -- 1.7.11.3