From: Andy Lutomirski <luto@kernel.org>
To: "Pali Rohár" <pali.rohar@gmail.com>,
platform-driver-x86@vger.kernel.org,
"Jean Delvare" <jdelvare@suse.de>
Cc: linux-kernel@vger.kernel.org, Andy Lutomirski <luto@kernel.org>
Subject: [PATCH v3 3/3] dell-wmi: Clean up hotkey table size check
Date: Tue, 19 Jan 2016 11:07:26 -0800 [thread overview]
Message-ID: <d5bc1864a695ba892a2657f559261fc5ec25ee31.1453229127.git.luto@kernel.org> (raw)
In-Reply-To: <cover.1453229127.git.luto@kernel.org>
In-Reply-To: <cover.1453229127.git.luto@kernel.org>
Checking the table for a minimum size of 7 bytes makes no sense: any valid
hotkey table has a size that's a multiple of 4.
Clean this up: replace the hardcoded header length with a sizeof and
change the check to ignore an empty hotkey table. The only behavior
change is that a 7-byte table (which is nonsensical) will now be
treated as absent instead of as valid but empty.
Reported-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
Changes from v2:
- Total rewrite.
drivers/platform/x86/dell-wmi.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell-wmi.c
index 5f5b321062a4..ae1e643e3464 100644
--- a/drivers/platform/x86/dell-wmi.c
+++ b/drivers/platform/x86/dell-wmi.c
@@ -329,13 +329,24 @@ static void __init handle_dmi_entry(const struct dmi_header *dm,
if (results->err || results->keymap)
return; /* We already found the hotkey table. */
- if (dm->type != 0xb2 || dm->length <= 6)
+ if (dm->type != 0xb2)
return;
table = container_of(dm, struct dell_bios_hotkey_table, header);
- hotkey_num = (table->header.length - 4) /
+ hotkey_num = (table->header.length -
+ sizeof(struct dell_bios_hotkey_table)) /
sizeof(struct dell_bios_keymap_entry);
+ if (hotkey_num < 1) {
+ /*
+ * Historically, dell-wmi would ignore a DMI entry of
+ * fewer than 7 bytes. Sizes between 4 and 8 bytes are
+ * nonsensical (both the header and all entries are 4
+ * bytes), so we approximate the old behavior by
+ * ignoring tables with fewer than one entry.
+ */
+ return;
+ }
keymap = kcalloc(hotkey_num + 1, sizeof(struct key_entry), GFP_KERNEL);
if (!keymap) {
--
2.5.0
prev parent reply other threads:[~2016-01-19 19:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-19 19:07 [PATCH v3 0/3] dell-wmi: DMI misuse fixes Andy Lutomirski
2016-01-19 19:07 ` [PATCH v3 1/3] dell-wmi: Stop storing pointers to DMI tables Andy Lutomirski
2016-01-19 19:07 ` [PATCH v3 2/3] dell-wmi, dell-laptop: select DMI Andy Lutomirski
2016-01-19 19:07 ` Andy Lutomirski [this message]
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=d5bc1864a695ba892a2657f559261fc5ec25ee31.1453229127.git.luto@kernel.org \
--to=luto@kernel.org \
--cc=jdelvare@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=pali.rohar@gmail.com \
--cc=platform-driver-x86@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
all inboxes | Powered by JetHome®