From: "Fenghua Yu" <fenghua.yu@intel.com>
To: Len Brown <len.brown@intel.com>, Andi Kleen <andi@firstfloor.org>,
linux-acpi <linux-acpi@vger.kernel.org>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Subject: [PATCH] acpi/tables.c: Harden acpi_table_parse_entries
Date: Tue, 25 Sep 2012 11:11:43 -0700 [thread overview]
Message-ID: <1348596703-6178-1-git-send-email-fenghua.yu@intel.com> (raw)
From: Fenghua Yu <fenghua.yu@intel.com>
Parsing acpi table entries may fall into an infinite loop on a buggy BIOS
which has entry length=0 in acpi table.
Instead of kernel hang with few failure clue which leads to heavy lifting debug
effort, this patch hardens kernel boot by booting into non NUMA mode. The debug
info left in log buffer helps people identify the issue.
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
---
drivers/acpi/tables.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index f336bca7..2572d97 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -240,10 +240,17 @@ acpi_table_parse_entries(char *id,
table_end) {
if (entry->type == entry_id
&& (!max_entries || count++ < max_entries))
- if (handler(entry, table_end)) {
- early_acpi_os_unmap_memory((char *)table_header, tbl_size);
- return -EINVAL;
- }
+ if (handler(entry, table_end))
+ goto err;
+
+ /*
+ * If entry->length is 0, break from this loop to avoid
+ * infinite loop.
+ */
+ if (entry->length == 0) {
+ pr_err(PREFIX "[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
+ goto err;
+ }
entry = (struct acpi_subtable_header *)
((unsigned long)entry + entry->length);
@@ -255,6 +262,9 @@ acpi_table_parse_entries(char *id,
early_acpi_os_unmap_memory((char *)table_header, tbl_size);
return count;
+err:
+ early_acpi_os_unmap_memory((char *)table_header, tbl_size);
+ return -EINVAL;
}
int __init
--
1.7.2
next reply other threads:[~2012-09-25 18:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-25 18:11 Fenghua Yu [this message]
2012-10-06 20:23 ` [PATCH] acpi/tables.c: Harden acpi_table_parse_entries Len Brown
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=1348596703-6178-1-git-send-email-fenghua.yu@intel.com \
--to=fenghua.yu@intel.com \
--cc=andi@firstfloor.org \
--cc=len.brown@intel.com \
--cc=linux-acpi@vger.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).