Skip to content

Commit

Permalink
USB: EHCI: fix NULL pointer dererence in HCDs that use HCD_LOCAL_MEM
Browse files Browse the repository at this point in the history
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 <arighi@develer.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Andrea Righi authored and Greg Kroah-Hartman committed Aug 10, 2010
1 parent e10fa47 commit 4307a28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions drivers/usb/core/hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,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)
Expand Down
3 changes: 2 additions & 1 deletion drivers/usb/host/ehci-hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,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;
}

Expand Down

0 comments on commit 4307a28

Please sign in to comment.