linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: hidraw, fix a NULL pointer dereference in hidraw_ioctl
@ 2010-10-02 11:25 Antonio Ospite
  2010-10-04 13:50 ` Jiri Kosina
  2010-10-04 13:54 ` [PATCH] HID: hidraw, fix a NULL pointer dereference in hidraw_ioctl Alan Ott
  0 siblings, 2 replies; 21+ messages in thread
From: Antonio Ospite @ 2010-10-02 11:25 UTC (permalink / raw)
  To: linux-input
  Cc: Antonio Ospite, Jiri Kosina, Alan Ott, Oliver Neukum,
	linux-kernel

BUG: unable to handle kernel NULL pointer dereference at 0000000000000028
IP: [<ffffffffa02c66b4>] hidraw_ioctl+0xfc/0x32c [hid]
[...]

This is reproducible by disconnecting the device while userspace does ioctl in
a loop and doesn't check return values in order to exit the loop, like in the
following test program:

int main(int argc, char *argv[])
{
	int fd = -1;
	unsigned char name[256];
	int ret;

	if (argc != 2) {
		fprintf(stderr, "usage: %s </dev/hidrawX>\n",
				argv[0]);
		exit(1);
	}

	fd = open(argv[1], O_RDWR);
	if (fd < 0) {
		perror("hidraw open");
		exit(1);
	}

	while (1) {
		ret = ioctl(fd, HIDIOCGRAWNAME(256), name);
		printf("ret: %d name: %s\n", ret, name);
	}

	close(fd);
	exit(0);
}

Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
---
Should this be applied to older stable kernels too?

Alan, Jiri,

there is a similar problem when _writing_ to the device, but Alan's
changes in that area are shuffling the code a bit, should I send a patch
[to hidraw_send_report()] on top of Alan's work for that, or a fix for
current mainline [in hidraw_write()] on which Alan should rebase his
work would be better?

The same pattern of unchecked hidraw_table[minor] is also present in
hidraw_get_report but this function is called only after the NULL check
in hidraw_ioctl _for_now_, so that is currently safe.

Thanks,
   Antonio Ospite
   http://ao2.it

 drivers/hid/hidraw.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 47d70c5..9eaf6ae 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -244,6 +244,10 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
 
 	mutex_lock(&minors_lock);
 	dev = hidraw_table[minor];
+	if (!dev) {
+		ret = -ENODEV;
+		goto out;
+	}
 
 	switch (cmd) {
 		case HIDIOCGRDESCSIZE:
@@ -317,6 +321,7 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
 
 		ret = -ENOTTY;
 	}
+out:
 	mutex_unlock(&minors_lock);
 	return ret;
 }
-- 
1.7.1


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

end of thread, other threads:[~2010-10-20 14:55 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-02 11:25 [PATCH] HID: hidraw, fix a NULL pointer dereference in hidraw_ioctl Antonio Ospite
2010-10-04 13:50 ` Jiri Kosina
2010-10-04 14:11   ` Antonio Ospite
2010-10-05 15:20   ` [PATCH 0/2] HID: hidraw, fix two NULL pointer dereferences Antonio Ospite
2010-10-05 17:42     ` [stable] " Greg KH
2010-10-05 20:16       ` Antonio Ospite
2010-10-06  9:31         ` Jiri Kosina
2010-10-15  7:44           ` Antonio Ospite
2010-10-15  9:10             ` Jiri Kosina
2010-10-05 21:12     ` Jiri Slaby
2010-10-06 10:01       ` Antonio Ospite
2010-10-06 10:09         ` Jiri Slaby
2010-10-09 12:40           ` Antonio Ospite
2010-10-19  9:24             ` [PATCH 1/1] HID: hidraw, fix window in hidraw_release Jiri Slaby
2010-10-19  9:28               ` Jiri Slaby
2010-10-19  9:29               ` Jiri Slaby
2010-10-20 14:55                 ` Jiri Kosina
2010-10-05 15:20   ` [PATCH 1/2] HID: hidraw, fix a NULL pointer dereference in hidraw_ioctl Antonio Ospite
2010-10-05 15:20   ` [PATCH 2/2] HID: hidraw, fix a NULL pointer dereference in hidraw_write Antonio Ospite
2010-10-04 13:54 ` [PATCH] HID: hidraw, fix a NULL pointer dereference in hidraw_ioctl Alan Ott
2010-10-05 20:29   ` Antonio Ospite

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).