USB: EHCI: fix NULL pointer dererence in HCDs that use HCD_LOCAL_MEM
Subsystems (2)
PATCH 1/1 USB: EHCI: fix NULL pointer dererence in HCDs that use HCD_LOCAL_MEM
If we use the HCD_LOCAL_MEM flag and dma_declare_coherent_memory() to enforce the host controller's local memory utilization we also need to disable native scatter-gather support, otherwise hcd_alloc_coherent() in map_urb_for_dma() is called with urb->transfer_buffer == NULL, that triggers a NULL pointer dereference.
We can also consider to add a WARN_ON() and return an error code to better catch this problem in the future.
--- drivers/usb/core/hcd.c | 5 +++++ drivers/usb/host/ehci-hcd.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletions(-)
drivers/usb/core/hcd.c +5 -0
@@ -1219,6 +1219,11 @@ static int hcd_alloc_coherent(struct usb_bus *bus, {unsigned char *vaddr; +if (*vaddr_handle ==NULL ) { +WARN_ON_ONCE (1 ); +return -EFAULT ; + } + vaddr =hcd_buffer_alloc (bus, size +sizeof (vaddr), mem_flags, dma_handle);if (!vaddr)
drivers/usb/host/ehci-hcd.c +2 -1
@@ -606,7 +606,8 @@ static int ehci_init(struct usb_hcd *hcd) ehci->command = temp;/* Accept arbitrarily long scatter-gather lists */ - hcd->self.sg_tablesize = ~0 ; +if (!(hcd->driver->flags &HCD_LOCAL_MEM )) + hcd->self.sg_tablesize = ~0 ;return 0 ; }
Alan Stern
maintainerQuoted 36 lines · Andrea Righi
If we use the
HCD_LOCAL_MEMflag anddma_declare_coherent_memory()to enforce the host controller's local memory utilization we also need to disable native scatter-gather support, otherwisehcd_alloc_coherent()inmap_urb_for_dma()is called withurb->transfer_buffer== NULL, that triggers a NULL pointer dereference.We can also consider to add a
WARN_ON()and return an error code to better catch this problem in the future.Signed-off-by Andrea Righi <[email protected]>--- drivers/usb/core/hcd.c | 5 +++++ drivers/usb/host/ehci-hcd.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletions(-)drivers/usb/core/hcd.c +5
-0@@ -1219,6 +1219,11 @@ static int hcd_alloc_coherent(struct usb_bus *bus, {unsigned char *vaddr; +if (*vaddr_handle ==NULL ) { +WARN_ON_ONCE (1 ); +return -EFAULT ; + } + vaddr =hcd_buffer_alloc (bus, size +sizeof (vaddr), mem_flags, dma_handle);if (!vaddr)drivers/usb/host/ehci-hcd.c +0
-0
drivers/usb/host/ehci-hcd.c static int ehci_init(struct usb_hcd *hcd) · line 612
Quoted 8 lines
drivers/usb/host/ehci-hcd.c +2
-1@@ -606,7 +606,8 @@ static int ehci_init(struct usb_hcd *hcd) ehci->command = temp;/* Accept arbitrarily long scatter-gather lists */ - hcd->self.sg_tablesize = ~0 ; +if (!(hcd->driver->flags &HCD_LOCAL_MEM )) + hcd->self.sg_tablesize = ~0 ;return 0 ; }
Looks okay to me. You can add my Acked-by: when you submit this to Greg KH.
Alan Stern