Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4307a28e authored by Andrea Righi's avatar Andrea Righi Committed by Greg Kroah-Hartman
Browse files

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: default avatarAndrea Righi <arighi@develer.com>
Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent e10fa478
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -1218,6 +1218,11 @@ static int hcd_alloc_coherent(struct usb_bus *bus,
{
{
	unsigned char *vaddr;
	unsigned char *vaddr;


	if (*vaddr_handle == NULL) {
		WARN_ON_ONCE(1);
		return -EFAULT;
	}

	vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr),
	vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr),
				 mem_flags, dma_handle);
				 mem_flags, dma_handle);
	if (!vaddr)
	if (!vaddr)
+2 −1
Original line number Original line Diff line number Diff line
@@ -629,6 +629,7 @@ static int ehci_init(struct usb_hcd *hcd)
	ehci->command = temp;
	ehci->command = temp;


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