Return-Path: Received: from mga14.intel.com ([192.55.52.115]:57014 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754137AbcCXJm0 (ORCPT ); Thu, 24 Mar 2016 05:42:26 -0400 Message-ID: <49329.10.237.137.88.1458815407.squirrel@linux.intel.com> Date: Thu, 24 Mar 2016 03:30:07 -0700 (PDT) Subject: [PATCH v3] usb: hcd: out of bounds access in for_each_companion From: "Robert Dobrowolski" To: linux-usb@vger.kernel.org Cc: stable@vger.kernel.org, mathias.nyman@intel.com, gregkh@linuxfoundation.org, bhelgaas@google.com MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7BIT Sender: stable-owner@vger.kernel.org List-ID: From: Robert Dobrowolski On BXT platform Host Controller and Device Controller figure as same PCI device but with different device function. HCD should not pass data to Device Controller but only to Host Controllers. Checking if companion device is Host Controller, otherwise skip. Cc: Signed-off-by: Robert Dobrowolski --- Changes in v3: - Removed footer from patch, added CC Changes in v2: - Changed condition to skip companion if its not known host controller type drivers/usb/core/hcd-pci.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index f9d42cf..7859d73 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c @@ -73,6 +73,15 @@ static void for_each_companion(struct pci_dev *pdev, struct usb_hcd *hcd, if (companion->bus != pdev->bus || PCI_SLOT(companion->devfn) != slot) continue; + + /* + * Companion device should be either UHCI,OHCI or EHCI host + * controller, otherwise skip. + */ + if (companion->class != CL_UHCI && companion->class != CL_OHCI && + companion->class != CL_EHCI) + continue; + companion_hcd = pci_get_drvdata(companion); if (!companion_hcd || !companion_hcd->self.root_hub) continue; -- 1.9.1