usb: gadget: f_ecm: Use atomic_t to track in-flight request
Currently ecm->notify_req is used to flag when a request is in-flight.
ecm->notify_req is set to NULL and when a request completes it is
subsequently reset.
This is fundamentally buggy in that the unbind logic of the ECM driver will
unconditionally free ecm->notify_req leading to a NULL pointer dereference.
Fixes: da741b8c56
("usb ethernet gadget: split CDC Ethernet function")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
5b24c28cfe
commit
d710562e01
@@ -52,6 +52,7 @@ struct f_ecm {
|
|||||||
struct usb_ep *notify;
|
struct usb_ep *notify;
|
||||||
struct usb_request *notify_req;
|
struct usb_request *notify_req;
|
||||||
u8 notify_state;
|
u8 notify_state;
|
||||||
|
atomic_t notify_count;
|
||||||
bool is_open;
|
bool is_open;
|
||||||
|
|
||||||
/* FIXME is_open needs some irq-ish locking
|
/* FIXME is_open needs some irq-ish locking
|
||||||
@@ -380,7 +381,7 @@ static void ecm_do_notify(struct f_ecm *ecm)
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
/* notification already in flight? */
|
/* notification already in flight? */
|
||||||
if (!req)
|
if (atomic_read(&ecm->notify_count))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
event = req->buf;
|
event = req->buf;
|
||||||
@@ -420,10 +421,10 @@ static void ecm_do_notify(struct f_ecm *ecm)
|
|||||||
event->bmRequestType = 0xA1;
|
event->bmRequestType = 0xA1;
|
||||||
event->wIndex = cpu_to_le16(ecm->ctrl_id);
|
event->wIndex = cpu_to_le16(ecm->ctrl_id);
|
||||||
|
|
||||||
ecm->notify_req = NULL;
|
atomic_inc(&ecm->notify_count);
|
||||||
status = usb_ep_queue(ecm->notify, req, GFP_ATOMIC);
|
status = usb_ep_queue(ecm->notify, req, GFP_ATOMIC);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ecm->notify_req = req;
|
atomic_dec(&ecm->notify_count);
|
||||||
DBG(cdev, "notify --> %d\n", status);
|
DBG(cdev, "notify --> %d\n", status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -448,17 +449,19 @@ static void ecm_notify_complete(struct usb_ep *ep, struct usb_request *req)
|
|||||||
switch (req->status) {
|
switch (req->status) {
|
||||||
case 0:
|
case 0:
|
||||||
/* no fault */
|
/* no fault */
|
||||||
|
atomic_dec(&ecm->notify_count);
|
||||||
break;
|
break;
|
||||||
case -ECONNRESET:
|
case -ECONNRESET:
|
||||||
case -ESHUTDOWN:
|
case -ESHUTDOWN:
|
||||||
|
atomic_set(&ecm->notify_count, 0);
|
||||||
ecm->notify_state = ECM_NOTIFY_NONE;
|
ecm->notify_state = ECM_NOTIFY_NONE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DBG(cdev, "event %02x --> %d\n",
|
DBG(cdev, "event %02x --> %d\n",
|
||||||
event->bNotificationType, req->status);
|
event->bNotificationType, req->status);
|
||||||
|
atomic_dec(&ecm->notify_count);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ecm->notify_req = req;
|
|
||||||
ecm_do_notify(ecm);
|
ecm_do_notify(ecm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -907,6 +910,11 @@ static void ecm_unbind(struct usb_configuration *c, struct usb_function *f)
|
|||||||
|
|
||||||
usb_free_all_descriptors(f);
|
usb_free_all_descriptors(f);
|
||||||
|
|
||||||
|
if (atomic_read(&ecm->notify_count)) {
|
||||||
|
usb_ep_dequeue(ecm->notify, ecm->notify_req);
|
||||||
|
atomic_set(&ecm->notify_count, 0);
|
||||||
|
}
|
||||||
|
|
||||||
kfree(ecm->notify_req->buf);
|
kfree(ecm->notify_req->buf);
|
||||||
usb_ep_free_request(ecm->notify, ecm->notify_req);
|
usb_ep_free_request(ecm->notify, ecm->notify_req);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user