From: Benjamin Tissoires <benjamin.tissoires@gmail.com>
To: Benjamin Tissoires <benjamin.tissoires@gmail.com>,
Jiri Kosina <jkosina@suse.cz>, Jean Delvare <khali@linux-fr.org>,
linux-input@vger.kernel.org, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/4] HID: i2c-hid: fix memory corruption due to missing hid declaration
Date: Wed, 5 Dec 2012 15:02:53 +0100 [thread overview]
Message-ID: <1354716176-12558-2-git-send-email-benjamin.tissoires@gmail.com> (raw)
In-Reply-To: <1354716176-12558-1-git-send-email-benjamin.tissoires@gmail.com>
HID descriptors contains 4 bytes of reserved field.
The previous implementation was overriding the next fields in struct i2c_hid.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
---
drivers/hid/i2c-hid/i2c-hid.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 7062df2..34cca42 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -69,6 +69,7 @@ struct i2c_hid_desc {
__le16 wVendorID;
__le16 wProductID;
__le16 wVersionID;
+ __le32 reserved;
} __packed;
struct i2c_hid_cmd {
@@ -776,7 +777,13 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
}
dsize = le16_to_cpu(hdesc->wHIDDescLength);
- if (!dsize || dsize > HID_MAX_DESCRIPTOR_SIZE) {
+ /*
+ * the size of the HID descriptor should at least contain
+ * its size and the bcdVersion (4 bytes), and should not be greater
+ * than sizeof(struct i2c_hid_desc) as we directly fill this struct
+ * through i2c_hid_command.
+ */
+ if (dsize < 4 || dsize > sizeof(struct i2c_hid_desc)) {
dev_err(&client->dev, "weird size of HID descriptor (%u)\n",
dsize);
return -ENODEV;
--
1.8.0.1
next prev parent reply other threads:[~2012-12-05 14:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-05 14:02 [PATCH v2 0/4] i2c-hid cleanup and bug fixes Benjamin Tissoires
2012-12-05 14:02 ` Benjamin Tissoires [this message]
2012-12-05 17:25 ` [PATCH v2 1/4] HID: i2c-hid: fix memory corruption due to missing hid declaration Jean Delvare
2012-12-06 9:54 ` Jiri Kosina
2012-12-05 14:02 ` [PATCH v2 2/4] HID: i2c-hid: reorder allocation/free of buffers Benjamin Tissoires
[not found] ` <1354716176-12558-3-git-send-email-benjamin.tissoires-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-12-06 9:56 ` Jiri Kosina
2012-12-05 14:02 ` [PATCH v2 3/4] HID: i2c-hid: remove extra .irq field in struct i2c_hid Benjamin Tissoires
2012-12-05 17:28 ` Jean Delvare
[not found] ` <20121205182812.57262216-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-12-06 9:56 ` Jiri Kosina
2012-12-05 14:02 ` [PATCH v2 4/4] HID: i2c-hid: fix i2c_hid_get_raw_report count mismatches Benjamin Tissoires
2012-12-05 19:59 ` Jean Delvare
2012-12-06 10:01 ` Jiri Kosina
2012-12-07 15:13 ` Benjamin Tissoires
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=1354716176-12558-2-git-send-email-benjamin.tissoires@gmail.com \
--to=benjamin.tissoires@gmail.com \
--cc=jkosina@suse.cz \
--cc=khali@linux-fr.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@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).