From patchwork Wed Apr 12 12:25:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 9677419 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EC3B7601C3 for ; Wed, 12 Apr 2017 12:32:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD5E828665 for ; Wed, 12 Apr 2017 12:32:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFC5A2866A; Wed, 12 Apr 2017 12:32:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BAFB28665 for ; Wed, 12 Apr 2017 12:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753915AbdDLMbS (ORCPT ); Wed, 12 Apr 2017 08:31:18 -0400 Received: from merlin.infradead.org ([205.233.59.134]:38096 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753382AbdDLM0S (ORCPT ); Wed, 12 Apr 2017 08:26:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Sender:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=oazu4RqGlM3A+RuJhqVoFzJFzehvgv11QGmgwYrbEc0=; b=AMQaQ45xcetEbWRkDd+rje2sH L0ObKkEIgSgNh8tjzWxnpAWlU9lLjV0T1CyzI9aNsXX2s+v3sJ/5t8F8JVmQHFrCNArkG0eQE8rdy A7HlX4TASk/ii4BOTlvQVhwk1n1MIaTWXxk9oYZnpizCZZfPqlSAeiU7kRbUWOSIzXozh6Al0JpJD tU9rSl3MxNpO1KnOR8rRVBROEGj8AWTKWPu94SdSQ/Oa3Doh7s9QX/emwb+V8P4wo1tfh2wivvJgx luHssKmbbACnIVhOHhN416loDe862sv5Otl16mLzAminuZCyB9JOUyD+YtEHO2bO1TM8leFD1ugeE L94Ic3/tg==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by merlin.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1cyHLl-00018g-L9; Wed, 12 Apr 2017 12:26:17 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1cyHLk-000bYh-BO; Wed, 12 Apr 2017 13:26:16 +0100 From: David Woodhouse To: linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 02/27] pci: Fix another sanity check bug in /proc/pci mmap Date: Wed, 12 Apr 2017 13:25:51 +0100 Message-Id: <08d0400c6bf711e3b26824eaa2870c1502f79834.1491999859.git.dwmw2@infradead.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: References: In-Reply-To: References: X-SRS-Rewrite: SMTP reverse-path rewritten from by merlin.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Woodhouse Don't match MMIO maps with I/O BARs and vice versa. Signed-off-by: David Woodhouse Cc: stable@vger.kernel.org --- drivers/pci/proc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c index f82710a..62a0c3e 100644 --- a/drivers/pci/proc.c +++ b/drivers/pci/proc.c @@ -231,14 +231,20 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) { struct pci_dev *dev = PDE_DATA(file_inode(file)); struct pci_filp_private *fpriv = file->private_data; - int i, ret, write_combine; + int i, ret, write_combine, res_bit; if (!capable(CAP_SYS_RAWIO)) return -EPERM; + if (fpriv->mmap_state == pci_mmap_io) + res_bit = IORESOURCE_IO; + else + res_bit = IORESOURCE_MEM; + /* Make sure the caller is mapping a real resource for this device */ for (i = 0; i < PCI_ROM_RESOURCE; i++) { - if (pci_mmap_fits(dev, i, vma, PCI_MMAP_PROCFS)) + if (dev->resource[i].flags & res_bit && + pci_mmap_fits(dev, i, vma, PCI_MMAP_PROCFS)) break; }