----- Original Message -----
> From: gre...@linuxfoundation.org
> To: jwer...@chromium.org, "sarah a sharp" <sarah.a.sh...@linux.intel.com>
> Cc: stable@vger.kernel.org
> Sent: Wednesday, January 9, 2013 4:47:43 AM
> Subject: FAILED: patch "[PATCH] xhci: fix null-pointer dereference when 
> destroying half-built" failed to apply to
> 3.0-stable tree
> 
> 
> The patch below does not apply to the 3.0-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git
> commit
> id to <stable@vger.kernel.org>.
I'll working on this too.
> 
> thanks,
> 
> greg k-h
> 
> ------------------ original commit in Linus's tree ------------------
> 
> From 68e5254adb88bede68285f11fb442a4d34fb550c Mon Sep 17 00:00:00
> 2001
> From: Julius Werner <jwer...@chromium.org>
> Date: Thu, 1 Nov 2012 12:47:59 -0700
> Subject: [PATCH] xhci: fix null-pointer dereference when destroying
> half-built
>  segment rings
> 
> xhci_alloc_segments_for_ring() builds a list of xhci_segments and
> links
> the tail to head at the end (forming a ring). When it bails out for
> OOM
> reasons half-way through, it tries to destroy its half-built list
> with
> xhci_free_segments_for_ring(), even though it is not a ring yet. This
> causes a null-pointer dereference upon hitting the last element.
> 
> Furthermore, one of its callers (xhci_ring_alloc()) mistakenly
> believes
> the output parameters to be valid upon this kind of OOM failure, and
> calls xhci_ring_free() on them. Since the (incomplete) list/ring
> should
> already be destroyed in that case, this would lead to a use after
> free.
> 
> This patch fixes those issues by having
> xhci_alloc_segments_for_ring()
> destroy its half-built, non-circular list manually and destroying the
> invalid struct xhci_ring in xhci_ring_alloc() with a plain kfree().
> 
> This patch should be backported to kernels as old as 2.6.31, that
> contains the commit 0ebbab37422315a5d0cb29792271085bafdf38c0 "USB:
> xhci:
> Ring allocation and initialization."
> 
> A separate patch will need to be developed for kernels older than
> 3.4,
> since the ring allocation code was refactored in that kernel.
> 
> Signed-off-by: Julius Werner <jwer...@chromium.org>
> Signed-off-by: Sarah Sharp <sarah.a.sh...@linux.intel.com>
> Cc: stable@vger.kernel.org
> 
> diff --git a/drivers/usb/host/xhci-mem.c
> b/drivers/usb/host/xhci-mem.c
> index 487bc08..fb51c70 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -205,7 +205,12 @@ static int xhci_alloc_segments_for_ring(struct
> xhci_hcd *xhci,
>  
>               next = xhci_segment_alloc(xhci, cycle_state, flags);
>               if (!next) {
> -                     xhci_free_segments_for_ring(xhci, *first);
> +                     prev = *first;
> +                     while (prev) {
> +                             next = prev->next;
> +                             xhci_segment_free(xhci, prev);
> +                             prev = next;
> +                     }
>                       return -ENOMEM;
>               }
>               xhci_link_segments(xhci, prev, next, type);
> @@ -258,7 +263,7 @@ static struct xhci_ring *xhci_ring_alloc(struct
> xhci_hcd *xhci,
>       return ring;
>  
>  fail:
> -     xhci_ring_free(xhci, ring);
> +     kfree(ring);
>       return NULL;
>  }
>  
> 
> --
> To unsubscribe from this list: send the line "unsubscribe stable" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to