diff options
author | Lee Jones <lee@kernel.org> | 2023-03-20 13:09:22 +0000 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-03-22 13:26:16 +0100 |
commit | 73a02ee4904e7eaae10601468d6074e5898fb45e (patch) | |
tree | 32bcf2b59dc23f708caee02060d7e3734153fa14 /include/linux | |
parent | f05c52ed99af9996645d4770e59ceeab8da4dfb0 (diff) | |
download | linux-stable-73a02ee4904e7eaae10601468d6074e5898fb45e.tar.gz linux-stable-73a02ee4904e7eaae10601468d6074e5898fb45e.tar.bz2 linux-stable-73a02ee4904e7eaae10601468d6074e5898fb45e.zip |
HID: core: Provide new max_buffer_size attribute to over-ride the default
commit b1a37ed00d7908a991c1d0f18a8cba3c2aa99bdc upstream.
Presently, when a report is processed, its proposed size, provided by
the user of the API (as Report Size * Report Count) is compared against
the subsystem default HID_MAX_BUFFER_SIZE (16k). However, some
low-level HID drivers allocate a reduced amount of memory to their
buffers (e.g. UHID only allocates UHID_DATA_MAX (4k) buffers), rending
this check inadequate in some cases.
In these circumstances, if the received report ends up being smaller
than the proposed report size, the remainder of the buffer is zeroed.
That is, the space between sizeof(csize) (size of the current report)
and the rsize (size proposed i.e. Report Size * Report Count), which can
be handled up to HID_MAX_BUFFER_SIZE (16k). Meaning that memset()
shoots straight past the end of the buffer boundary and starts zeroing
out in-use values, often resulting in calamity.
This patch introduces a new variable into 'struct hid_ll_driver' where
individual low-level drivers can over-ride the default maximum value of
HID_MAX_BUFFER_SIZE (16k) with something more sympathetic to the
interface.
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
[Lee: Backported to v4.14.y]
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/hid.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/hid.h b/include/linux/hid.h index f2a1f34f41e8..b5fcc8b0b7ce 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -770,6 +770,7 @@ struct hid_driver { * @raw_request: send raw report request to device (e.g. feature report) * @output_report: send output report to device * @idle: send idle request to device + * @max_buffer_size: over-ride maximum data buffer size (default: HID_MAX_BUFFER_SIZE) */ struct hid_ll_driver { int (*start)(struct hid_device *hdev); @@ -794,6 +795,8 @@ struct hid_ll_driver { int (*output_report) (struct hid_device *hdev, __u8 *buf, size_t len); int (*idle)(struct hid_device *hdev, int report, int idle, int reqtype); + + unsigned int max_buffer_size; }; extern struct hid_ll_driver i2c_hid_ll_driver; |