aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/hid/hid-microsoft.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2019-10-03 14:53:59 -0400
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>2019-10-03 15:36:40 -0400
commitd9d4b1e46d9543a82c23f6df03f4ad697dab361b (patch)
tree5a405a2f78b1029f4cc6d6ee743f0bec31319b42 /drivers/hid/hid-microsoft.c
parentHID: prodikeys: make array keys static const, makes object smaller (diff)
downloadwireguard-linux-d9d4b1e46d9543a82c23f6df03f4ad697dab361b.tar.xz
wireguard-linux-d9d4b1e46d9543a82c23f6df03f4ad697dab361b.zip
HID: Fix assumption that devices have inputs
The syzbot fuzzer found a slab-out-of-bounds write bug in the hid-gaff driver. The problem is caused by the driver's assumption that the device must have an input report. While this will be true for all normal HID input devices, a suitably malicious device can violate the assumption. The same assumption is present in over a dozen other HID drivers. This patch fixes them by checking that the list of hid_inputs for the hid_device is nonempty before allowing it to be used. Reported-and-tested-by: syzbot+403741a091bf41d4ae79@syzkaller.appspotmail.com Signed-off-by: Alan Stern <stern@rowland.harvard.edu> CC: <stable@vger.kernel.org> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Diffstat (limited to 'drivers/hid/hid-microsoft.c')
-rw-r--r--drivers/hid/hid-microsoft.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index 2cf83856f2e4..2d8b589201a4 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -328,11 +328,17 @@ static int ms_play_effect(struct input_dev *dev, void *data,
static int ms_init_ff(struct hid_device *hdev)
{
- struct hid_input *hidinput = list_entry(hdev->inputs.next,
- struct hid_input, list);
- struct input_dev *input_dev = hidinput->input;
+ struct hid_input *hidinput;
+ struct input_dev *input_dev;
struct ms_data *ms = hid_get_drvdata(hdev);
+ if (list_empty(&hdev->inputs)) {
+ hid_err(hdev, "no inputs found\n");
+ return -ENODEV;
+ }
+ hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
+ input_dev = hidinput->input;
+
if (!(ms->quirks & MS_QUIRK_FF))
return 0;