From patchwork Wed Mar 22 13:25:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 9638801 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 C885A6020B for ; Wed, 22 Mar 2017 13:26:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB5E527D5E for ; Wed, 22 Mar 2017 13:26:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B01492845C; Wed, 22 Mar 2017 13:26:21 +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=ham 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 4A30F27D5E for ; Wed, 22 Mar 2017 13:26:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934546AbdCVN0S (ORCPT ); Wed, 22 Mar 2017 09:26:18 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:49729 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934214AbdCVNZp (ORCPT ); Wed, 22 Mar 2017 09:25:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=T8tpDu80eRJKWIy6NryqCXUKI YheR3j4iE5Kq1yH+ADivdcn3y3CEhUuGnU+seuTjN+ekFQ3jIa6yUxQT5g2YEopDqNU5Adw+FixAu R5z3AD6ZsTy55/jKHZsry0+jfLUyXA7E/WDgKpFBsSWjaCgYJdSs+FupwpiX6wckUyovYPWyT4YyA CGMomUXfbwid526bMzx/bVWShk/2gbWHseV5j/2m4v/iPCXhTlqExyxH56k6MBRZSTmO7tEncgKf3 j9oS8GqDNO8TplkAyWzCfZHb5Yt4uIl3ifiroNyjl8uLJiyJ0eqV4+tKylJ9Aj38UiBhYTO03HzBS Lgdt9k18Q==; Received: from i7.infradead.org ([90.155.92.213]) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1cqgGa-00071z-RD; Wed, 22 Mar 2017 13:25:33 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1cqgGZ-0005qJ-2e; Wed, 22 Mar 2017 13:25:31 +0000 From: David Woodhouse To: linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/17] pci: Fix another sanity check bug in /proc/pci mmap Date: Wed, 22 Mar 2017 13:25:16 +0000 Message-Id: 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 bombadil.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; }