Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp857574imu; Tue, 20 Nov 2018 08:01:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/VAyim3pgpVphy+gU6Tm97NzrdiyRQQAgTS2Xh8C4jD9KmKVlwSPsGlUNH+59fIuXuD34w+ X-Received: by 2002:a63:7556:: with SMTP id f22mr2204362pgn.231.1542729698687; Tue, 20 Nov 2018 08:01:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542729698; cv=none; d=google.com; s=arc-20160816; b=I45x5LjNYXpsylqRJVHVh2WzCxfB7GxradVuXUYWm1zKbs8QvoEzNITIq+dB3bGjZB AsnJRTeOWhyRvQpJVtUoaarmCBE+sgbcbm9s2SGTmMT0yFOnLh7dt9TDYtanQmoJiQbV qra2zGD2UMcvas1N+ZH9blRhjIKrBAsKw+aRJfuTGD5xhSO/1h75RZy7TFLoyw939uAr /vB1vEHmkx/BpMAC9b+59OVPrNsixJde3/w8HE2MPN4QLfmZ/esVTdIxDjxDKLJDDwp5 L8+4rSFGpQJcc0Y06VKI/hqi/szstrSY0afBUdLp2Yvk8nScL3xvOq94PBWO4G6NV5xp 6eGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=W+L63grqqp5F1/TsNm/GWYsNSX2VzyRdJEzZgncBqqg=; b=yqExxdEkXcaxxtJ9P8JIsKy5ZjUP2w8/8tma/zM5ulG48vt1dWUxkU7zNR8B54sYuN iyoBSiH+Q50V0Zakna5/jd1eORCAoIt4EjtJUzKG6jtotPx/NgzQFdyn0mqB7qtdNqWg hhAJASNqvobL8vxgFfeiqSX4FlRLvFo3kzVpy4tQXrnuw5F9gP3j6JXEnHTznHBZjzXX ShVsL7CB+g52ny0tTQCvXv50YaeQwmH6qQiN85NZJdajwIwxJsPcPWHyQirg0VVg/LYO sogF5q8tDmHblWWbfXSVOS6I6A+modB8a565HirTgKKsD2GYeRm+5RDKf9XTbHZRLGqq H/cg== ARC-Authentication-Results: i=1; mx.google.com; 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 m8si2593534pgd.555.2018.11.20.08.01.22; Tue, 20 Nov 2018 08:01:38 -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; 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 S1726510AbeKUBFa (ORCPT + 99 others); Tue, 20 Nov 2018 20:05:30 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:38743 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbeKUBFa (ORCPT ); Tue, 20 Nov 2018 20:05:30 -0500 Received: from kresse.hi.pengutronix.de ([2001:67c:670:100:1d::2a]) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1gP78A-0008Cy-8d; Tue, 20 Nov 2018 15:35:58 +0100 Message-ID: <1542724556.2508.14.camel@pengutronix.de> Subject: Re: [PATCH v2 1/3] PCI: dwc: allow to limit registers set length From: Lucas Stach To: Stefan Agner , jingoohan1@gmail.com, gustavo.pimentel@synopsys.com, tpiepho@impinj.com Cc: bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 20 Nov 2018 15:35:56 +0100 In-Reply-To: <20181120132705.6917-1-stefan@agner.ch> References: <20181120132705.6917-1-stefan@agner.ch> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::2a X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Dienstag, den 20.11.2018, 14:27 +0100 schrieb Stefan Agner: > Add length to the struct dw_pcie and check that the accessors > dw_pcie_(rd|wr)_own_conf() do not read/write beyond that point. > > Signed-off-by: Stefan Agner FWIW: Reviewed-by: Lucas Stach > --- >  drivers/pci/controller/dwc/pcie-designware-host.c | 4 ++++ >  drivers/pci/controller/dwc/pcie-designware.h      | 1 + >  2 files changed, 5 insertions(+) > > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c > index 29a05759a294..b422538ee0bb 100644 > --- a/drivers/pci/controller/dwc/pcie-designware-host.c > +++ b/drivers/pci/controller/dwc/pcie-designware-host.c > @@ -29,6 +29,8 @@ static int dw_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, > >   return pp->ops->rd_own_conf(pp, where, size, val); >   > >   pci = to_dw_pcie_from_pp(pp); > > + if (pci->dbi_length && where + size > pci->dbi_length) > > + return PCIBIOS_BAD_REGISTER_NUMBER; > >   return dw_pcie_read(pci->dbi_base + where, size, val); >  } >   > @@ -41,6 +43,8 @@ static int dw_pcie_wr_own_conf(struct pcie_port *pp, int where, int size, > >   return pp->ops->wr_own_conf(pp, where, size, val); >   > >   pci = to_dw_pcie_from_pp(pp); > > + if (pci->dbi_length && where + size > pci->dbi_length) > > + return PCIBIOS_BAD_REGISTER_NUMBER; > >   return dw_pcie_write(pci->dbi_base + where, size, val); >  } >   > diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h > index 9f1a5e399b70..5be5f369abf2 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.h > +++ b/drivers/pci/controller/dwc/pcie-designware.h > @@ -215,6 +215,7 @@ struct dw_pcie { > > >   struct device *dev; > > >   void __iomem *dbi_base; > > >   void __iomem *dbi_base2; > > > + int dbi_length; > > >   u32 num_viewport; > > >   u8 iatu_unroll_enabled; > > >   struct pcie_port pp;