[PATCH 44/47] This patch fixes another disconnect oops in hiddev.

From: Vojtech Pavlik
Date: Thu Jul 29 2004 - 13:48:44 EST


You can pull this changeset from:
bk://kernel.bkbits.net/vojtech/input

===================================================================

ChangeSet@xxxxxxxxxxx, 2004-07-05 13:38:52+02:00, akropel1@xxxxxxxxxxxxxxxx
This patch fixes another disconnect oops in hiddev.

hid-core calls hiddev_disconnect() when the underlying device goes away
(hot unplug or system shutdown). Normally, hiddev_disconnect() will
clean up nicely and return to hid-core who then frees the hid structure.
However, if the corresponding hiddev node is open at disconnect time,
hiddev delays the majority of disconnect work until the device is closed
via hiddev_release(). hiddev_release() calls hiddev_cleanup() which
proceeds to dereference the hid struct which hid-core freed back when
the hardware was disconnected. Oops.

To solve this, we change hiddev_disconnect() to deregister the hiddev
minor and invalidate its table entry immediately and delay only the
freeing of the hiddev structure itself. We're protected against future
operations on the fd since the major fops check hiddev->exists.

There may still be an ordering of events that causes a problem but I can
no longer reproduce any manually. There are enough different subsystems
and object lifetimes interacting here that I may have screwed something
else up; review is certainly welcome.

Signed-off-by: Adam Kropelin <akropel1@xxxxxxxxxxxxxxxx>
Signed-off-by: Vojtech Pavlik <vojtech@xxxxxxx>


hiddev.c | 18 ++++++------------
1 files changed, 6 insertions(+), 12 deletions(-)

===================================================================

diff -Nru a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
--- a/drivers/usb/input/hiddev.c Thu Jul 29 14:38:38 2004
+++ b/drivers/usb/input/hiddev.c Thu Jul 29 14:38:38 2004
@@ -226,16 +226,6 @@
return retval < 0 ? retval : 0;
}

-/*
- * De-allocate a hiddev structure
- */
-static struct usb_class_driver hiddev_class;
-static void hiddev_cleanup(struct hiddev *hiddev)
-{
- hiddev_table[hiddev->hid->minor - HIDDEV_MINOR_BASE] = NULL;
- usb_deregister_dev(hiddev->hid->intf, &hiddev_class);
- kfree(hiddev);
-}

/*
* release file op
@@ -256,7 +246,7 @@
if (list->hiddev->exist)
hid_close(list->hiddev->hid);
else
- hiddev_cleanup(list->hiddev);
+ kfree(list->hiddev);
}

kfree(list);
@@ -804,17 +794,21 @@
* This is where hid.c calls us to disconnect a hiddev device from the
* corresponding hid device (usually because the usb device has disconnected)
*/
+static struct usb_class_driver hiddev_class;
void hiddev_disconnect(struct hid_device *hid)
{
struct hiddev *hiddev = hid->hiddev;

hiddev->exist = 0;

+ hiddev_table[hiddev->hid->minor - HIDDEV_MINOR_BASE] = NULL;
+ usb_deregister_dev(hiddev->hid->intf, &hiddev_class);
+
if (hiddev->open) {
hid_close(hiddev->hid);
wake_up_interruptible(&hiddev->wait);
} else {
- hiddev_cleanup(hiddev);
+ kfree(hiddev);
}
}


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/