Commit c85400f8 authored by Jia-Ju Bai's avatar Jia-Ju Bai Committed by Greg Kroah-Hartman

usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable()

The function r8a66597_endpoint_disable() and r8a66597_urb_enqueue() may
be concurrently executed.
The two functions both access a possible shared variable "hep->hcpriv".

This shared variable is freed by r8a66597_endpoint_disable() via the
call path:
r8a66597_endpoint_disable
  kfree(hep->hcpriv) (line 1995 in Linux-4.19)

This variable is read by r8a66597_urb_enqueue() via the call path:
r8a66597_urb_enqueue
  spin_lock_irqsave(&r8a66597->lock)
  init_pipe_info
    enable_r8a66597_pipe
      pipe = hep->hcpriv (line 802 in Linux-4.19)

The read operation is protected by a spinlock, but the free operation
is not protected by this spinlock, thus a concurrency use-after-free bug
may occur.

To fix this bug, the spin-lock and spin-unlock function calls in
r8a66597_endpoint_disable() are moved to protect the free operation.
Signed-off-by: default avatarJia-Ju Bai <baijiaju1990@gmail.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c710d0bb
...@@ -1979,6 +1979,8 @@ static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, ...@@ -1979,6 +1979,8 @@ static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
static void r8a66597_endpoint_disable(struct usb_hcd *hcd, static void r8a66597_endpoint_disable(struct usb_hcd *hcd,
struct usb_host_endpoint *hep) struct usb_host_endpoint *hep)
__acquires(r8a66597->lock)
__releases(r8a66597->lock)
{ {
struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
struct r8a66597_pipe *pipe = (struct r8a66597_pipe *)hep->hcpriv; struct r8a66597_pipe *pipe = (struct r8a66597_pipe *)hep->hcpriv;
...@@ -1991,13 +1993,14 @@ static void r8a66597_endpoint_disable(struct usb_hcd *hcd, ...@@ -1991,13 +1993,14 @@ static void r8a66597_endpoint_disable(struct usb_hcd *hcd,
return; return;
pipenum = pipe->info.pipenum; pipenum = pipe->info.pipenum;
spin_lock_irqsave(&r8a66597->lock, flags);
if (pipenum == 0) { if (pipenum == 0) {
kfree(hep->hcpriv); kfree(hep->hcpriv);
hep->hcpriv = NULL; hep->hcpriv = NULL;
spin_unlock_irqrestore(&r8a66597->lock, flags);
return; return;
} }
spin_lock_irqsave(&r8a66597->lock, flags);
pipe_stop(r8a66597, pipe); pipe_stop(r8a66597, pipe);
pipe_irq_disable(r8a66597, pipenum); pipe_irq_disable(r8a66597, pipenum);
disable_irq_empty(r8a66597, pipenum); disable_irq_empty(r8a66597, pipenum);
......
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