linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* re: HID: hiddev: protect against disconnect/NULL-dereference race
@ 2010-08-20 21:24 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2010-08-20 21:24 UTC (permalink / raw)
  To: Chris Ball
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-input-u79uwXL29TY76Z2rM5mHXA

The patch 7032269e87a "HID: hiddev: protect against
disconnect/NULL-dereference race" added a check to make sure that "hid"
was non-NULL.  The problem is that it added the check after "hid" had
already been dereferenced.

drivers/hid/usbhid/hiddev.c +606 hiddev_ioctl(19)
	warn: variable dereferenced before check 'hid'

   599          struct usbhid_device *usbhid = hid->driver_data;
                                               ^^^^^^^^^^^^^^^^
	dereferenced here.

   600          void __user *user_arg = (void __user *)arg;
   601          int i, r;
   602          
   603          /* Called without BKL by compat methods so no BKL taken */
   604  
   605          /* FIXME: Who or what stop this racing with a disconnect ?? */
   606          if (!hiddev->exist || !hid)
                                      ^^^^
	new check added here.

   607                  return -EIO;

So obviously in hind-sight this patch didn't fix the user's problem.  
Also the user reported a NULL dereference, yes, but the stack dump which
says: "BUG: unable to handle kernel paging request at 6b6b6b6b" is a use
after free bug and that isn't addressed by adding a check for NULL.

I am just looking at this because it showed up with my static checker
and I'm not very familiar with this code.  I think we need to take 
"hiddev->existancelock" and make sure that exist is true before we 
dereference hiddev in the ioctl function?  Also it seems like there
should probably be some locking in hiddev_release().

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-08-20 21:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-20 21:24 HID: hiddev: protect against disconnect/NULL-dereference race Dan Carpenter

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).