Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8474622imu; Tue, 4 Dec 2018 08:57:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/W+uuVnDFu4n7SJRPYf9fFDMtTFf0LI622KZAhrfGQ5H4HdDed//72M4qagdSNV+W12zXWv X-Received: by 2002:a17:902:e290:: with SMTP id cf16mr21255210plb.81.1543942621214; Tue, 04 Dec 2018 08:57:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543942621; cv=none; d=google.com; s=arc-20160816; b=eveeod2+necl8tXMDqwA4cgq5X0d67b5KMpyFksV2ZgUWKxbYH/jCJDkZDLKpRdSk3 aqRLzN5lynnZIy4e352S2ZpDfNMKq315LEqS2WngtAx6Ek94cWDqXqpOwnUgAnF32uDk D5arJC+YlfbNQyfk9zfUkr4nBU5nfps18ACzIOwdDcJyDli4QhQVVnE9yEoWqpoh8FPj NVXzfhDhUp2K5WrNMvqj3pxXaX/AxqGjJtEBEdqsSuSAEzg1MVEwyl7MupcqR2iHAkqm GfyWEZ5dFIclIo0dRU6eERTCXvpuFQyiggPOjQzX7SeJRG9H/+rloon1fNn1W9awNkb7 heEA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=NX10ckMc3R1dgUUnyidEtTbBw4+aPrqKIUVwguJm7Rg=; b=eEyES6g/staa9QQbt8NsFC4KI4pkfxJCGhc0WPcp5m+UgUk8IS3XA17jrCu04LYYe2 CXoS0+aggnBjT4vkG6bYtmc36hvZuQKM8BsZ47Ca/v1wviYoiF4il2IACYiJ3BLbJG07 XqcFbuNFJxHYB5ULvvhFJ2GLsTdUmTlOkgi7DU8Zi3+1jLYT69fneSyuJSfSZ35x01kT juHkKIZlg3Yir0kuza9adL18ddm1EDp+w9tE0pgIJRFueYJfCDAMASPIJE/PC3ALfDuP v2TYxw6QEXxUrm5ZKy/pn1Ni+ytaiVm+3CP3pIFdybcs2LUKzBgy77o0BeENZYEsztkS ZU9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=pU3TnJAN; 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 s80si17150335pfa.130.2018.12.04.08.56.46; Tue, 04 Dec 2018 08:57:01 -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=pU3TnJAN; 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 S1726975AbeLDQzg (ORCPT + 99 others); Tue, 4 Dec 2018 11:55:36 -0500 Received: from mail.kmu-office.ch ([178.209.48.109]:36306 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726367AbeLDQzf (ORCPT ); Tue, 4 Dec 2018 11:55:35 -0500 Received: from trochilidae.toradex.int (unknown [46.140.72.82]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 2703B5C03A3; Tue, 4 Dec 2018 17:55:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1543942534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=NX10ckMc3R1dgUUnyidEtTbBw4+aPrqKIUVwguJm7Rg=; b=pU3TnJANc2kHJTwA+xUVlziR+rumLqmSwYEEQql0ngmEJgt4B+DNEWBd06mxqUaCevWYWx iRPIYt6C7nPMUV4o4c3one08i1vIt/Eqo2rIBA2oZvBw2yNNffT0jzuKJMVfEWueUZWha6 nptpCuqaX2xfX32PpoloDy13n8DWHyc= From: Stefan Agner To: lorenzo.pieralisi@arm.com, jingoohan1@gmail.com, gustavo.pimentel@synopsys.com, l.stach@pengutronix.de, tpiepho@impinj.com Cc: leonard.crestez@nxp.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Agner Subject: [PATCH v4 1/3] PCI: dwc: allow to limit registers set length Date: Tue, 4 Dec 2018 17:55:26 +0100 Message-Id: <20181204165528.15534-1-stefan@agner.ch> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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