All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device
@ 2018-04-05 23:09 Rodrigo Rivas Costa
  2018-04-09  7:30 ` Jiri Kosina
  2018-04-10 13:50 ` Sasha Levin
  0 siblings, 2 replies; 4+ messages in thread
From: Rodrigo Rivas Costa @ 2018-04-05 23:09 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel
  Cc: Rodrigo Rivas Costa

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.

Signed-off-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>
---
 drivers/hid/hidraw.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 5fbe0f81ab2e..01b5a9f01814 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -192,6 +192,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) {
-- 
2.16.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device
  2018-04-05 23:09 [PATCH] hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device Rodrigo Rivas Costa
@ 2018-04-09  7:30 ` Jiri Kosina
  2018-04-10 13:50 ` Sasha Levin
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2018-04-09  7:30 UTC (permalink / raw)
  To: Rodrigo Rivas Costa; +Cc: Benjamin Tissoires, linux-input, linux-kernel

On Fri, 6 Apr 2018, Rodrigo Rivas Costa wrote:

> 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.
> 
> Signed-off-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>

Applied, thank you.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device
  2018-04-05 23:09 [PATCH] hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device Rodrigo Rivas Costa
  2018-04-09  7:30 ` Jiri Kosina
@ 2018-04-10 13:50 ` Sasha Levin
  2018-04-10 17:28   ` Jiri Kosina
  1 sibling, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2018-04-10 13:50 UTC (permalink / raw)
  To: Sasha Levin, Rodrigo Rivas Costa, Jiri Kosina; +Cc: Rodrigo Rivas Costa, stable

Hi,

[This is an automated email]

This commit has been processed by the -stable helper bot and determined
to be a high probability candidate for -stable trees. (score: 20.3359)

The bot has tested the following trees: v4.16.1, v4.15.16, v4.14.33, v4.9.93, v4.4.127.

v4.16.1: Build OK!
v4.15.16: Build OK!
v4.14.33: Build OK!
v4.9.93: Build OK!
v4.4.127: Build OK!

Please let us know if you'd like to have this patch included in a stable tree.

--
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device
  2018-04-10 13:50 ` Sasha Levin
@ 2018-04-10 17:28   ` Jiri Kosina
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2018-04-10 17:28 UTC (permalink / raw)
  To: Sasha Levin; +Cc: Rodrigo Rivas Costa, stable

On Tue, 10 Apr 2018, Sasha Levin wrote:

> [This is an automated email]
> 
> This commit has been processed by the -stable helper bot and determined
> to be a high probability candidate for -stable trees. (score: 20.3359)
> 
> The bot has tested the following trees: v4.16.1, v4.15.16, v4.14.33, v4.9.93, v4.4.127.
> 
> v4.16.1: Build OK!
> v4.15.16: Build OK!
> v4.14.33: Build OK!
> v4.9.93: Build OK!
> v4.4.127: Build OK!
> 
> Please let us know if you'd like to have this patch included in a stable tree.

Yes, it is a stable material. Thanks,

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-04-10 17:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-05 23:09 [PATCH] hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device Rodrigo Rivas Costa
2018-04-09  7:30 ` Jiri Kosina
2018-04-10 13:50 ` Sasha Levin
2018-04-10 17:28   ` Jiri Kosina

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.