Skip to content

Commit 4307a28

Browse files
Andrea Righigregkh
Andrea Righi
authored andcommitted
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. At the moment no driver seems to hit this bug, so I should consider this a low-priority fix. Signed-off-by: Andrea Righi <[email protected]> Acked-by: Alan Stern <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e10fa47 commit 4307a28

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

drivers/usb/core/hcd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,11 @@ static int hcd_alloc_coherent(struct usb_bus *bus,
12181218
{
12191219
unsigned char *vaddr;
12201220

1221+
if (*vaddr_handle == NULL) {
1222+
WARN_ON_ONCE(1);
1223+
return -EFAULT;
1224+
}
1225+
12211226
vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr),
12221227
mem_flags, dma_handle);
12231228
if (!vaddr)

drivers/usb/host/ehci-hcd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ static int ehci_init(struct usb_hcd *hcd)
629629
ehci->command = temp;
630630

631631
/* Accept arbitrarily long scatter-gather lists */
632-
hcd->self.sg_tablesize = ~0;
632+
if (!(hcd->driver->flags & HCD_LOCAL_MEM))
633+
hcd->self.sg_tablesize = ~0;
633634
return 0;
634635
}
635636

0 commit comments

Comments
 (0)