* [PATCH] USB: EHCI: fix NULL pointer dererence in HCDs that use HCD_LOCAL_MEM
@ 2010-06-28 14:14 Andrea Righi
2010-06-28 14:18 ` Alan Stern
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Righi @ 2010-06-28 14:14 UTC (permalink / raw)
To: Alan Stern
Cc: Rodolfo Giometti, Amit Walambe, Chris Leahy, Giovanni Bajo,
linux-usb, LKML
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.
Signed-off-by: Andrea Righi <arighi@develer.com>
---
drivers/usb/core/hcd.c | 5 +++++
drivers/usb/host/ehci-hcd.c | 3 ++-
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 12742f1..161c757 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -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)
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index a3ef2a9..27e0351 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -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;
}
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] USB: EHCI: fix NULL pointer dererence in HCDs that use HCD_LOCAL_MEM
2010-06-28 14:14 [PATCH] USB: EHCI: fix NULL pointer dererence in HCDs that use HCD_LOCAL_MEM Andrea Righi
@ 2010-06-28 14:18 ` Alan Stern
0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2010-06-28 14:18 UTC (permalink / raw)
To: Andrea Righi
Cc: Rodolfo Giometti, Amit Walambe, Chris Leahy, Giovanni Bajo,
linux-usb, LKML
On Mon, 28 Jun 2010, Andrea Righi wrote:
> 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.
>
> Signed-off-by: Andrea Righi <arighi@develer.com>
> ---
> drivers/usb/core/hcd.c | 5 +++++
> drivers/usb/host/ehci-hcd.c | 3 ++-
> 2 files changed, 7 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 12742f1..161c757 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -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)
> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
> index a3ef2a9..27e0351 100644
> --- a/drivers/usb/host/ehci-hcd.c
> +++ b/drivers/usb/host/ehci-hcd.c
> @@ -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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-06-28 14:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-28 14:14 [PATCH] USB: EHCI: fix NULL pointer dererence in HCDs that use HCD_LOCAL_MEM Andrea Righi
2010-06-28 14:18 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®