]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_dis...
authorJia-Ju Bai <baijiaju1990@gmail.com>
Tue, 18 Dec 2018 12:04:25 +0000 (20:04 +0800)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
commitd50a8b4aba9254712af9f55a06fc450cdbb996af
treeebd84dcc78e243c5e56d8bad7851bc9171221ecd
parent02a4c5e989e0d8ca7087027cc125e5e787807e0e
usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable()

BugLink: https://bugs.launchpad.net/bugs/1837257
commit c85400f886e3d41e69966470879f635a2b50084c upstream.

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: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/usb/host/r8a66597-hcd.c