linux/drivers/hid/usbhid
Jiri Kosina 27ce405039 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>
2013-07-22 16:16:40 +02:00
..
hid-core.c HID: fix data access in implement() 2013-07-22 16:16:40 +02:00
hid-pidff.c HID: use hid_hw_wait() instead of direct call to usbhid 2013-02-25 13:26:41 +01:00
hid-quirks.c HID: usbhid: fix build problem 2013-03-18 15:50:10 +01:00
hiddev.c HID: use hid_hw_wait() instead of direct call to usbhid 2013-02-25 13:26:41 +01:00
Kconfig HID: Fix the generic Kconfig options 2012-06-25 17:25:00 +02:00
Makefile HID: usbhid: Clean up makefile (-y instead of -objs) 2010-11-18 10:43:18 +01:00
usbhid.h HID: use hid_hw_wait() instead of direct call to usbhid 2013-02-25 13:26:41 +01:00
usbkbd.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid 2012-01-10 10:48:28 -08:00
usbmouse.c USB: usbmouse.c: remove err() usage 2012-04-25 14:48:20 -07:00