Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4855973imc; Mon, 25 Feb 2019 12:20:21 -0800 (PST) X-Google-Smtp-Source: AHgI3IY7xg4wjewZKsNh22O06JN88t47E3D2rMMpVLnBmy/h2v8DyoYPQrVXjGmSyQgVhihGxOOw X-Received: by 2002:a65:5184:: with SMTP id h4mr20794741pgq.32.1551126021486; Mon, 25 Feb 2019 12:20:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551126021; cv=none; d=google.com; s=arc-20160816; b=dHqTwWfP/NDOX6PSxFVKHjekjYXjphLgdkr9iE2mdbQ71mTp+pqgrvt6bsMS6QnZ3U qH5y8QRnQzwoq9cHtoRzx7X1hcLtF2t6LrqLDGMVNZQ3Ac1iD+uTvrJ1068f+55LAP9R BiFF6Sskz/088kAJ0gxMgr8rMRE02X+HhKr/ILpM92Er9VOktJfoj6ajgweK8p27ZmU8 Q1sCm1+NZmwlL+SKm8JeLtxOLabfJm2E/Ru308JAGv/U7yd5IjYMAVnVyVLnpk88oScR i/ZqOM6mdnqmezdfKTdfueGjI43hUAyqfluzVSEVcYqPGatfohHHAQ1LIDeW39BsIOK+ +u3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=4zH89Zq9SqbJJu7X0gOSlL1cMnZgSF1TBndwsxSXR2g=; b=egCgRH57ixehiC2hPknuM/h2ETaZZw5TgVwMqJXFal9STCxXnN2xr4ZAfc3jfhSV+/ rNvzrxCl9l3X/EZGyKDTmyc4HUFF6rcY1/ZTTRSCGiJuiGevmXNIv1sUvjQa2Yd1887A Osl6e778h6sU3p05UcRwtPjYCyti/wIvGxwCclpgCLP3VwshBYL6vbgeIhBh9sPUO5rq W42pId8YdI9s3Q1cDGMy038OlM3D1P0YWog98+cMJUvuJycXGtPOkDoeSeJ/xnVFMrjh vbhIyz87V+JqITvD+0maQycTUFOHi3NOrnUsgEeDMZiu1Kqmk7Zgc39HEfMqTTNyW6am gXxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JxH8EWIn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si485152plx.421.2019.02.25.12.20.04; Mon, 25 Feb 2019 12:20:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JxH8EWIn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727230AbfBYUTo (ORCPT + 99 others); Mon, 25 Feb 2019 15:19:44 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:45531 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727021AbfBYUTo (ORCPT ); Mon, 25 Feb 2019 15:19:44 -0500 Received: by mail-wr1-f67.google.com with SMTP id w17so11368251wrn.12 for ; Mon, 25 Feb 2019 12:19:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4zH89Zq9SqbJJu7X0gOSlL1cMnZgSF1TBndwsxSXR2g=; b=JxH8EWInUFaoaG/PYRjMl0vHlFqBoX4GsxzppxKlaiQBtf3eBujQ4mnHkxI8b8bvpS bFtVL8OR57GUxBkbJb/jMqs+6sbEibQLY/nfWfmW8kVmRNiCH3qHPk42aa2JZbQBnMzv 3Wp0ikvAwBW0eQgIy3xQ6yOtb+0x7JLg+qLDJOYBnBj+bKLSsRViaRFpIeb3f/chXBO/ syxYHi2OSB8QlLQZIBsq9PDSKmNu5DROnVSBReyfJWUtJn/MIdwKH1rBk6rc2SwJ8k3D mDvRXMMEIhd2bvWZQ3bDa8X0WYszIQ/oZAF3zQseQ2KSU/BjgDucTmooyj1eUr+yhZGd zCTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4zH89Zq9SqbJJu7X0gOSlL1cMnZgSF1TBndwsxSXR2g=; b=ShRIK0sjUOgS71wBOToxLRPZ+OXmaP3TLvUwdReTLF4kBmkphN+cUaauuUoZ00TndW nLBwsYLz5vV7ifcN2A1c0WieenVn2tbjvR/WVLHmLMLGWklBCVm6DEV7xbdqxnguP7Xn BAKYcZZAxgjTEh8q+9iHxvsMwtW/YQyi37g9r3xuM/An2VNKE1bFKqONGJPwH1hkh3Mw fqtGnw48utAIw59iJdNo/1eGaej9IbgXkoDy/o8GEq0udSuMeLz+EDAx6X4PKmJUlgtY o4ZENRdGjdFaUHnuR2idF2LzMAhzDeIfownd/vw4fjNvijWWGybaPbUadKZtC1Exelfu 2BVw== X-Gm-Message-State: AHQUAubBcTfN+AA/tLhxOMKeexJnLeAbI1xmlLoETNZcbFFw9zDTKGLv Tw0oDdpF/nIyBfWNctH0+FB0wrkmn7lM6iWhVvGV3JB8/27h X-Received: by 2002:a5d:66c1:: with SMTP id k1mr13385818wrw.120.1551125982379; Mon, 25 Feb 2019 12:19:42 -0800 (PST) MIME-Version: 1.0 References: <20190225160226.11924-1-stefan@agner.ch> <34b23c031a8e0964b3e87a6252dd5cefaa62cc95.camel@nxp.com> <1551113572.3075.172.camel@impinj.com> In-Reply-To: <1551113572.3075.172.camel@impinj.com> From: Bjorn Helgaas Date: Mon, 25 Feb 2019 14:19:31 -0600 Message-ID: Subject: Re: [PATCH v7] PCI: imx6: limit DBI register length To: Trent Piepho Cc: "stefan@agner.ch" , "leonard.crestez@nxp.com" , "hongxing.zhu@nxp.com" , "linux-kernel@vger.kernel.org" , "jingoohan1@gmail.com" , "lorenzo.pieralisi@arm.com" , "gustavo.pimentel@synopsys.com" , "linux-pci@vger.kernel.org" , "l.stach@pengutronix.de" , Thinh Nguyen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [+cc Thinh] On Mon, Feb 25, 2019 at 10:52 AM Trent Piepho wrote: > On Mon, 2019-02-25 at 16:15 +0000, Leonard Crestez wrote: > > On Mon, 2019-02-25 at 17:02 +0100, Stefan Agner wrote: > > > Define the length of the DBI registers and limit config space to its > > > length. This makes sure that the kernel does not access registers > > > beyond that point, avoiding the following abort on a i.MX 6Quad: > > > > > > +static void imx6_pcie_quirk(struct pci_dev *dev) > > > +{ > > > + struct pci_bus *bus = dev->bus; > > > + struct pcie_port *pp = bus->sysdata; > > > + > > > + if (bus->number == pp->root_bus_nr) { > > > + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); > > > + struct imx6_pcie *imx6_pcie = to_imx6_pcie(pci); > > > + > > > + /* > > > + * Limit config length to avoid the kernel reading beyond > > > + * the register set and causing an abort on i.MX 6Quad > > > + */ > > > + if (imx6_pcie->drvdata->dbi_length) > > > + dev->cfg_size = imx6_pcie->drvdata->dbi_length; > > > + } > > > +} > > > +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SYNOPSYS, 0xabcd, imx6_pcie_quirk); > > > > This looks like a default from SYNOPSYS so it likely run on other SOCs > > using the DesignWare PCI IP and crash because of those unchecked casts. > > Yes, it's used on IMX7d too. But it's worse than that, there's a USB > controller core that uses the same vendor and device id, > PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3. The quirk for that one uses class == > PCI_CLASS_SERIAL_USB_DEVICE to avoid matching this PCI-e IP. See > thread "PCI: Check for USB xHCI class for HAPS platform" If we could get these vendors to allocate their own Vendor/Device IDs, maybe we could consider a DECLARE_PCI_FIXUP_EARLY quirk that would fix up pdev->vendor and pdev->device? That might be cleaner than cluttering all these quirks with details of this screwup. Bjorn