Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6890430imu; Thu, 31 Jan 2019 01:10:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN49fDfhL+PXHuDPHkmFEf/zHOoqoFoQr5WZDqhbBWSlFr5wAjnGAhid7K2pUi9R+YR7hHkz X-Received: by 2002:a17:902:bcc7:: with SMTP id o7mr34616910pls.281.1548925804817; Thu, 31 Jan 2019 01:10:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548925804; cv=none; d=google.com; s=arc-20160816; b=yJObbf1OFQ7a6sVQkow+g26vWLQsf79OLcvNC2kPKYgm4wekae6cpixKimw1TyggG3 pMvw0/xMmOGL0XiqcD5VZqupJmzjYsKJXqDhWeBRMWdipHmLw2wiPRXcnDb4MOgyzDVf 0g5EHpqiTcWMbAZACxcFnMe2I5lO2e1I94QkWGHWK/7px25qWECWS82zfVQfcfx2c6E4 F256CqCsik/a6tgX5g0fRK056bh44F7XDCYtftqAXknXQsyr8lm+CKV9vxiNO8xgbpbY w1KFO97tk2PkAMMbb0nQTtRJMNqY5IskrxIQEENcSvOzfrcmeMXV1zY3m0D241GTqSbm bYaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=2gMcYLQvmtqqAnUFCyazvkTeryFQH+1faRdY9BvOSck=; b=DCDB3B8EHkWTpWP591vDWzFAgwyRBaymQ4Fz+Ii94hsM82SSMW9iigmW4v1ma9SFo6 RV6K3IZLerPc6igcRACDrtVDHLx9Vi5XM7bvLjNt1QvBBMsmqBLE38cFaVrqsoYZxXWO Abr5NKiTnKSPaeJSQDY7tveT4Lo6qo/OfHOmp/2S7zq1i1JX9WaAle4O9lFr4+OUhbnG Em/lGAsF7M6oNH6s6WmSVFrzW7Sv3CcU/jhGVUrED5qWonj0+d9vkboXHtJ7ZKher5w7 Ut7g7f3X479P48119wzQHZI3dfvtNOzqgvoE7683JIrGW+3dQTW9FcCjnTwNzWIZSQKR ZS6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=XBOGwLwJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si3984988ply.126.2019.01.31.01.09.49; Thu, 31 Jan 2019 01:10:04 -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=@agner.ch header.s=dkim header.b=XBOGwLwJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726464AbfAaJIO (ORCPT + 99 others); Thu, 31 Jan 2019 04:08:14 -0500 Received: from mail.kmu-office.ch ([178.209.48.109]:54508 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725857AbfAaJIO (ORCPT ); Thu, 31 Jan 2019 04:08:14 -0500 Received: from webmail.kmu-office.ch (unknown [IPv6:2a02:418:6a02::a3]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 657B05C017F; Thu, 31 Jan 2019 10:08:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1548925691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2gMcYLQvmtqqAnUFCyazvkTeryFQH+1faRdY9BvOSck=; b=XBOGwLwJyr7cIB2BENOvmkogJDn6WnIhLbIXNGVLLYnLvuEzg40WAJDiLksJbCm/e0ptC7 Bp/+7UpTye8G3+iSg6PH559eRq6zOsAAmNiONv/q35BhLtjgqbmV1o2R3JWWY0f6pzyA+U 76pnPC9pztPN9hS80Cl0+Bg56WlnM1Q= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: Thu, 31 Jan 2019 10:08:11 +0100 From: Stefan Agner To: Lorenzo Pieralisi Cc: jingoohan1@gmail.com, gustavo.pimentel@synopsys.com, l.stach@pengutronix.de, tpiepho@impinj.com, leonard.crestez@nxp.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/3] PCI: dwc: allow to limit registers set length In-Reply-To: <20190130175415.GA7715@e107981-ln.cambridge.arm.com> References: <20181204165528.15534-1-stefan@agner.ch> <20190130175415.GA7715@e107981-ln.cambridge.arm.com> Message-ID: X-Sender: stefan@agner.ch User-Agent: Roundcube Webmail/1.3.7 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30.01.2019 18:54, Lorenzo Pieralisi wrote: > On Tue, Dec 04, 2018 at 05:55:26PM +0100, Stefan Agner wrote: >> Add length to the struct dw_pcie and check that the accessors >> dw_pcie_(rd|wr)_conf() do not read/write beyond that point. >> >> Suggested-by: Trent Piepho >> Signed-off-by: Stefan Agner >> --- >> Changes in v4: >> - Move length check to dw_pcie_rd_conf >> >> .../pci/controller/dwc/pcie-designware-host.c | 16 ++++++++++++++-- >> drivers/pci/controller/dwc/pcie-designware.h | 1 + >> 2 files changed, 15 insertions(+), 2 deletions(-) > > Hi Stefan, > > I wanted to ask you if this series should be considered for v5.1 > inclusion, it is in the PCI backlog. If it is, let me have a look > and if it is OK to go I will likely ask you to rebase it. Yes please. With this last change I did not see any regression anymore so far. Andrey Smirnov picked up the second patch: "PCI: imx6: introduce drvdata". Not sure what the plan is with his patchset, if it gets merged into v5.1 too then I probably better drop this patch and rebase ontop of his series. -- Stefan > > Thanks, > Lorenzo > >> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c >> index 692dd1b264fb..9fc0f7bd99f0 100644 >> --- a/drivers/pci/controller/dwc/pcie-designware-host.c >> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c >> @@ -606,14 +606,20 @@ static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where, >> int size, u32 *val) >> { >> struct pcie_port *pp = bus->sysdata; >> + struct dw_pcie *pci; >> >> if (!dw_pcie_valid_device(pp, bus, PCI_SLOT(devfn))) { >> *val = 0xffffffff; >> return PCIBIOS_DEVICE_NOT_FOUND; >> } >> >> - if (bus->number == pp->root_bus_nr) >> + if (bus->number == pp->root_bus_nr) { >> + pci = to_dw_pcie_from_pp(pp); >> + if (pci->dbi_length && where + size > pci->dbi_length) >> + return PCIBIOS_BAD_REGISTER_NUMBER; >> + >> return dw_pcie_rd_own_conf(pp, where, size, val); >> + } >> >> return dw_pcie_rd_other_conf(pp, bus, devfn, where, size, val); >> } >> @@ -622,12 +628,18 @@ static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn, >> int where, int size, u32 val) >> { >> struct pcie_port *pp = bus->sysdata; >> + struct dw_pcie *pci; >> >> if (!dw_pcie_valid_device(pp, bus, PCI_SLOT(devfn))) >> return PCIBIOS_DEVICE_NOT_FOUND; >> >> - if (bus->number == pp->root_bus_nr) >> + if (bus->number == pp->root_bus_nr) { >> + pci = to_dw_pcie_from_pp(pp); >> + if (pci->dbi_length && where + size > pci->dbi_length) >> + return PCIBIOS_BAD_REGISTER_NUMBER; >> + >> return dw_pcie_wr_own_conf(pp, where, size, val); >> + } >> >> return dw_pcie_wr_other_conf(pp, bus, devfn, where, size, val); >> } >> diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h >> index 9943d8c68335..9cd7bdc94200 100644 >> --- a/drivers/pci/controller/dwc/pcie-designware.h >> +++ b/drivers/pci/controller/dwc/pcie-designware.h >> @@ -229,6 +229,7 @@ struct dw_pcie { >> void __iomem *dbi_base2; >> /* Used when iatu_unroll_enabled is true */ >> void __iomem *atu_base; >> + int dbi_length; >> u32 num_viewport; >> u8 iatu_unroll_enabled; >> struct pcie_port pp; >> -- >> 2.19.1 >>