From patchwork Wed Aug 27 18:57:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 4790571 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 706F9C0338 for ; Wed, 27 Aug 2014 18:57:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B0D420142 for ; Wed, 27 Aug 2014 18:57:41 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C908020123 for ; Wed, 27 Aug 2014 18:57:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0A5106E4EF; Wed, 27 Aug 2014 11:57:40 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTP id D43D86E4FA for ; Wed, 27 Aug 2014 11:57:38 -0700 (PDT) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7RIvZsa028394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 Aug 2014 14:57:35 -0400 Received: from gimli.home (ovpn-113-173.phx2.redhat.com [10.3.113.173]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7RIvYee010413; Wed, 27 Aug 2014 14:57:34 -0400 From: Alex Williamson Subject: [PATCH] drm: Test for PCI root bus to avoid NULL pointer dereference To: airlied@linux.ie, dri-devel@lists.freedesktop.org Date: Wed, 27 Aug 2014 12:57:33 -0600 Message-ID: <20140827185651.29388.16082.stgit@gimli.home> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Cc: alex.williamson@redhat.com, linux-kernel@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we have a GPU on the PCI root bus that calls drm_pcie_get_speed_cap_mask() we end up with a NULL pointer dereference since pdev->bus->self is NULL. We already protect against callers passing non-PCI devices, so let's also catch this case and return -EINVAL. Root complex graphics are not terribly likely outside of IGD, but when we assign a standard plugin GPU to a virtual machine, our assumption that we have a parent device quickly becomes invalid. Signed-off-by: Alex Williamson Reviewed-by: Alex Deucher --- drivers/gpu/drm/drm_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c index 020cfd9..411e806 100644 --- a/drivers/gpu/drm/drm_pci.c +++ b/drivers/gpu/drm/drm_pci.c @@ -390,7 +390,7 @@ int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *mask) u32 lnkcap, lnkcap2; *mask = 0; - if (!dev->pdev) + if (!dev->pdev || pci_is_root_bus(dev->pdev->bus)) return -EINVAL; root = dev->pdev->bus->self;