From: Rodrigo Rivas Costa Date: Thu, 5 Apr 2018 23:09:36 +0000 (+0200) Subject: HID: hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device X-Git-Tag: v4.1.52~93 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9c76f2e7de2588082b485d992a02a8372e3a4628;p=users%2Fdwmw2%2Flinux.git HID: hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device [ Upstream commit a955358d54695e4ad9f7d6489a7ac4d69a8fc711 ] Doing `ioctl(HIDIOCGFEATURE)` in a tight loop on a hidraw device and then disconnecting the device, or unloading the driver, can cause a NULL pointer dereference. When a hidraw device is destroyed it sets 0 to `dev->exist`. Most functions check 'dev->exist' before doing its work, but `hidraw_get_report()` was missing that check. Cc: stable@vger.kernel.org Signed-off-by: Rodrigo Rivas Costa Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index 9c2d7c23f2966..c0c4df1987259 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c @@ -197,6 +197,11 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t int ret = 0, len; unsigned char report_number; + if (!hidraw_table[minor] || !hidraw_table[minor]->exist) { + ret = -ENODEV; + goto out; + } + dev = hidraw_table[minor]->hid; if (!dev->ll_driver->raw_request) {