From: Linn Crosetto <linn@hp.com>
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 <linn@hp.com>
Subject: [PATCH v2] x86: selective remapping in parse_setup_data()
Date: Mon, 12 Aug 2013 17:01:22 -0600 [thread overview]
Message-ID: <1376348482-1357-1-git-send-email-linn@hp.com> (raw)
In-Reply-To: <52094ED2.1000308@zytor.com>
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 <linn@hp.com>
---
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
next prev parent reply other threads:[~2013-08-12 23:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-12 21:00 [PATCH] x86: selective remapping in parse_setup_data() Linn Crosetto
2013-08-12 21:08 ` H. Peter Anvin
2013-08-12 23:01 ` Linn Crosetto [this message]
2013-08-12 23:30 ` [PATCH v2] " Yinghai Lu
2013-08-13 21:46 ` [PATCH v3] x86: avoid remapping data " Linn Crosetto
2013-08-13 22:22 ` Yinghai Lu
2013-08-14 6:26 ` Pekka Enberg
2013-09-01 11:40 ` [tip:x86/mm] " tip-bot for Linn Crosetto
2013-09-01 23:15 ` [PATCH v3] " H. Peter Anvin
2013-09-06 18:06 ` [PATCH 0/3] x86/mm: fix early_memremap() sparse warnings Linn Crosetto
2013-09-06 18:06 ` [PATCH 1/3] x86/mm: fix sparse warnings from early_memremap() Linn Crosetto
2013-09-06 18:06 ` [PATCH 2/3] x86: fix sparse warning in parse_e820_ext() Linn Crosetto
2013-09-06 18:06 ` [PATCH 3/3] x86: fix early_iounmap() sparse warnings in setup.c Linn Crosetto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1376348482-1357-1-git-send-email-linn@hp.com \
--to=linn@hp.com \
--cc=hpa@zytor.com \
--cc=jacob.shin@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=penberg@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=yinghai@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).