aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/hidp/core.c
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2013-07-10 13:56:27 -0400
committerJiri Kosina <jkosina@suse.cz>2013-07-22 10:16:40 -0400
commit27ce405039bfe6d3f4143415c638f56a3df77dca (patch)
tree5419dac5ff32335c81bb1d753a2c0df181ed44c7 /net/bluetooth/hidp/core.c
parent0adb9c2c5ed42f199cb2a630c37d18dee385fae2 (diff)
HID: fix data access in implement()
implement() is setting bytes in LE data stream. In case the data is not aligned to 64bits, it reads past the allocated buffer. It doesn't really change any value there (it's properly bitmasked), but in case that this read past the boundary hits a page boundary, pagefault happens when accessing 64bits of 'x' in implement(), and kernel oopses. This happens much more often when numbered reports are in use, as the initial 8bit skip in the buffer makes the whole process work on values which are not aligned to 64bits. This problem dates back to attempts in 2005 and 2006 to make implement() and extract() as generic as possible, and even back then the problem was realized by Adam Kroperlin, but falsely assumed to be impossible to cause any harm: http://www.mail-archive.com/linux-usb-devel@lists.sourceforge.net/msg47690.html I have made several attempts at fixing it "on the spot" directly in implement(), but the results were horrible; the special casing for processing last 64bit chunk and switching to different math makes it unreadable mess. I therefore took a path to allocate a few bytes more which will never make it into final report, but are there as a cushion for all the 64bit math operations happening in implement() and extract(). All callers of hid_output_report() are converted at the same time to allocate the buffer by newly introduced hid_alloc_report_buf() helper. Bruno noticed that the whole raw_size test can be dropped as well, as hid_alloc_report_buf() makes sure that the buffer is always of a proper size. Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'net/bluetooth/hidp/core.c')
-rw-r--r--net/bluetooth/hidp/core.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 46c6a148f0b3..212980ff99b9 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -231,17 +231,21 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
231 231
232static int hidp_send_report(struct hidp_session *session, struct hid_report *report) 232static int hidp_send_report(struct hidp_session *session, struct hid_report *report)
233{ 233{
234 unsigned char buf[32], hdr; 234 unsigned char hdr;
235 int rsize; 235 u8 *buf;
236 int rsize, ret;
236 237
237 rsize = ((report->size - 1) >> 3) + 1 + (report->id > 0); 238 buf = hid_alloc_report_buf(report, GFP_ATOMIC);
238 if (rsize > sizeof(buf)) 239 if (!buf)
239 return -EIO; 240 return -EIO;
240 241
241 hid_output_report(report, buf); 242 hid_output_report(report, buf);
242 hdr = HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT; 243 hdr = HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT;
243 244
244 return hidp_send_intr_message(session, hdr, buf, rsize); 245 ret = hidp_send_intr_message(session, hdr, buf, rsize);
246
247 kfree(buf);
248 return ret;
245} 249}
246 250
247static int hidp_get_raw_report(struct hid_device *hid, 251static int hidp_get_raw_report(struct hid_device *hid,