Commit 670515c5 authored by Oliver Neukum's avatar Oliver Neukum Committed by Ben Hutchings

USB: cdc-wdm: fix race leading leading to memory corruption

commit 5c22837a upstream.

This patch fixes a race whereby a pointer to a buffer
would be overwritten while the buffer was in use leading
to a double free and a memory leak. This causes crashes.
This bug was introduced in 2.6.34
Signed-off-by: default avatarOliver Neukum <oneukum@suse.de>
Tested-by: default avatarBjørn Mork <bjorn@mork.no>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 54f74773
...@@ -108,8 +108,9 @@ static void wdm_out_callback(struct urb *urb) ...@@ -108,8 +108,9 @@ static void wdm_out_callback(struct urb *urb)
spin_lock(&desc->iuspin); spin_lock(&desc->iuspin);
desc->werr = urb->status; desc->werr = urb->status;
spin_unlock(&desc->iuspin); spin_unlock(&desc->iuspin);
clear_bit(WDM_IN_USE, &desc->flags);
kfree(desc->outbuf); kfree(desc->outbuf);
desc->outbuf = NULL;
clear_bit(WDM_IN_USE, &desc->flags);
wake_up(&desc->wait); wake_up(&desc->wait);
} }
...@@ -312,7 +313,7 @@ static ssize_t wdm_write ...@@ -312,7 +313,7 @@ static ssize_t wdm_write
if (we < 0) if (we < 0)
return -EIO; return -EIO;
desc->outbuf = buf = kmalloc(count, GFP_KERNEL); buf = kmalloc(count, GFP_KERNEL);
if (!buf) { if (!buf) {
rv = -ENOMEM; rv = -ENOMEM;
goto outnl; goto outnl;
...@@ -376,10 +377,12 @@ static ssize_t wdm_write ...@@ -376,10 +377,12 @@ static ssize_t wdm_write
req->wIndex = desc->inum; req->wIndex = desc->inum;
req->wLength = cpu_to_le16(count); req->wLength = cpu_to_le16(count);
set_bit(WDM_IN_USE, &desc->flags); set_bit(WDM_IN_USE, &desc->flags);
desc->outbuf = buf;
rv = usb_submit_urb(desc->command, GFP_KERNEL); rv = usb_submit_urb(desc->command, GFP_KERNEL);
if (rv < 0) { if (rv < 0) {
kfree(buf); kfree(buf);
desc->outbuf = NULL;
clear_bit(WDM_IN_USE, &desc->flags); clear_bit(WDM_IN_USE, &desc->flags);
dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv); dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv);
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment