Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp783340imu; Tue, 20 Nov 2018 06:57:43 -0800 (PST) X-Google-Smtp-Source: AJdET5dtTWDwwE06igL3bZTzsH5dYBogZYdzw5/PHt3eEWwqNeDXXzmnsRwDZ3IC0wlfv+bBgsCD X-Received: by 2002:a62:da5a:: with SMTP id w26mr2520590pfl.106.1542725863208; Tue, 20 Nov 2018 06:57:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542725863; cv=none; d=google.com; s=arc-20160816; b=acPTxAvKwxG9iovLLo51etN8kUnaYfX9rP3xLtHmNno0IbybPN/xiL5RLp7CeNCVX3 N6Rf3tVLo9VPdRB/SKvyOl5FRV0F1Fn3idLGGAg8NOslIBFeb2UAFMJ6oc5qPuLGOtnG gkyWW5rn3mKR9ZAhtRGQsNqjddg3NjX5iZtei6c+YfFzx3a3fRsivycdSxMH+iIYw1JP HMQVo6KxAPH3TSS78SUDxoYhUIWd/w3wR/VBmWNaeK2TvgaxVL6V8sXQmRFFxqt7SDaf uuzvAWAVm++tCVjOdQ4XguDMK8+bDkxV78n4ve+Aw4/hbPXiTTPatgBV3ZvlHH4VlzQb nHRw== 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=nUJeRKWHJzD/M3nYNIgkyel8Fi67ZBJcl/RxLVIaljs=; b=U+TtA+Wmsz3LQRwS63lM3T3UY5PZPrFqsCAZJOPH9WH6ubdAqcK1KprupPI0VS2Fx/ i+Vk/9IvzMgZwrihEl8o49aIMG9hezfb09KS7J6J4ORUCzQgBIARzJVRF8seJwTcKv14 6vvvob9BXmIB4fdo/ZFrtXyOj6il1NYTG6WbA7G75F13l07+lPsbUMxTrQU8EzKFfmxW Qk2YKUGk7nz8hsxhkzF4C4aW7a+OFR0Y+ZQfXFhzjzxjtQst8rEu1rcSNJJ7iuxfDA7A GNHRuAq4Y03XIX8PeMyhKrpmyAa3Ah/eroVU/T8Q6qMDFKlMR7oHqPM6idSOHm/8lmZe FR5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=AxLfjSqL; 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 z14si43940107pgj.73.2018.11.20.06.57.28; Tue, 20 Nov 2018 06:57:43 -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=AxLfjSqL; 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 S1728085AbeKTX4S (ORCPT + 99 others); Tue, 20 Nov 2018 18:56:18 -0500 Received: from mail.kmu-office.ch ([178.209.48.109]:47266 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726457AbeKTX4S (ORCPT ); Tue, 20 Nov 2018 18:56:18 -0500 Received: from trochilidae.toradex.int (unknown [46.140.72.82]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 4055C5C0E11; Tue, 20 Nov 2018 14:27:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1542720429; 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=nUJeRKWHJzD/M3nYNIgkyel8Fi67ZBJcl/RxLVIaljs=; b=AxLfjSqLl5tGC6lz8ABoHt6AGw94XE1mpRWjbeirVTCE5knm/dC0y5HhNr+eu4V5p6JoEX 5DpyPlSUWEtmBuG0pgWrdJTLH7u3Jx+n5VAUoq1bdnE5r5hERT3Og9tTed32rzGPwS/cFG gLMScQjZK14//PVmhKU1wOoxGecAMRg= From: Stefan Agner To: jingoohan1@gmail.com, gustavo.pimentel@synopsys.com, l.stach@pengutronix.de, tpiepho@impinj.com Cc: bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Agner Subject: [PATCH v2 1/3] PCI: dwc: allow to limit registers set length Date: Tue, 20 Nov 2018 14:27:03 +0100 Message-Id: <20181120132705.6917-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)_own_conf() do not read/write beyond that point. Signed-off-by: Stefan Agner --- 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; -- 2.19.1