From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754402Ab0JEPVQ (ORCPT ); Tue, 5 Oct 2010 11:21:16 -0400 Received: from smtp208.alice.it ([82.57.200.104]:40417 "EHLO smtp208.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754145Ab0JEPVN (ORCPT ); Tue, 5 Oct 2010 11:21:13 -0400 From: Antonio Ospite To: linux-input@vger.kernel.org Cc: Antonio Ospite , Jiri Kosina , Alan Ott , Oliver Neukum , linux-kernel@vger.kernel.org, stable@kernel.org Subject: [PATCH 1/2] HID: hidraw, fix a NULL pointer dereference in hidraw_ioctl Date: Tue, 5 Oct 2010 17:20:16 +0200 Message-Id: <1286292017-6746-2-git-send-email-ospite@studenti.unina.it> X-Mailer: git-send-email 1.7.1 In-Reply-To: References: X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM/Vb;]yA5\I~93>J<_`<4)A{':UrE Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org BUG: unable to handle kernel NULL pointer dereference at 0000000000000028 IP: [] 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 \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 --- 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