1 From stable-bounces@linux.kernel.org Mon Feb 5 06:57:55 2007
2 From: Alan Stern <stern@rowland.harvard.edu>
3 Date: Mon, 5 Feb 2007 09:56:15 -0500 (EST)
4 Subject: USB: fix concurrent buffer access in the hub driver
5 To: Greg KH <greg@kroah.com>
6 Cc: stable@kernel.org, USB development list <linux-usb-devel@lists.sourceforge.net>, Adrian Bunk <bunk@stusta.de>
7 Message-ID: <Pine.LNX.4.44L0.0702050950390.3533-100000@iolanthe.rowland.org>
10 This patch (as849) fixes a bug in the USB hub driver. A single
11 pre-allocated buffer is used for all port status reads, but nothing
12 guarantees exclusive use of the buffer. A mutex is added to provide
15 Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
16 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
19 drivers/usb/core/hub.c | 6 ++++++
20 1 file changed, 6 insertions(+)
22 --- linux-2.6.20.1.orig/drivers/usb/core/hub.c
23 +++ linux-2.6.20.1/drivers/usb/core/hub.c
24 @@ -44,6 +44,7 @@ struct usb_hub {
25 struct usb_hub_status hub;
26 struct usb_port_status port;
27 } *status; /* buffer for status reports */
28 + struct mutex status_mutex; /* for the status buffer */
30 int error; /* last reported error */
31 int nerrors; /* track consecutive errors */
32 @@ -538,6 +539,7 @@ static int hub_hub_status(struct usb_hub
36 + mutex_lock(&hub->status_mutex);
37 ret = get_hub_status(hub->hdev, &hub->status->hub);
39 dev_err (hub->intfdev,
40 @@ -547,6 +549,7 @@ static int hub_hub_status(struct usb_hub
41 *change = le16_to_cpu(hub->status->hub.wHubChange);
44 + mutex_unlock(&hub->status_mutex);
48 @@ -620,6 +623,7 @@ static int hub_configure(struct usb_hub
52 + mutex_init(&hub->status_mutex);
54 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);
55 if (!hub->descriptor) {
56 @@ -1418,6 +1422,7 @@ static int hub_port_status(struct usb_hu
60 + mutex_lock(&hub->status_mutex);
61 ret = get_port_status(hub->hdev, port1, &hub->status->port);
63 dev_err (hub->intfdev,
64 @@ -1429,6 +1434,7 @@ static int hub_port_status(struct usb_hu
65 *change = le16_to_cpu(hub->status->port.wPortChange);
68 + mutex_unlock(&hub->status_mutex);