From patchwork Wed Oct 21 08:56:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11848861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36A3AC56201 for ; Wed, 21 Oct 2020 09:22:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A617E21D6C for ; Wed, 21 Oct 2020 09:22:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AovndmUO"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="W0/9v9/b"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="GUK8bAu/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A617E21D6C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZiJlDnaAFHuxm7K6sN+0HXs5UxSoVGxZ9yTuV2mKslA=; b=AovndmUOS9attiW7RhzqewGBL FeP03AvQJ+91f6i64dok4cssA2XbIWqlCCHTiQr3yO7q/PLrgBqZ8WUHRo2QXVpQQrgN7xd+INeuP ZvKoeWY6EZyw6LVm185nJd/vfTowYF+klUUcZ/XEmu14SCdmgTUM9jjf2FSfwAJdj58+r/DQm1kmM xaLaCaotO0+NYr148e/oB1xtusJzrL7inDo3b/5ydjzZrhYv0NfxTzlaoyf28C1anV0vyCYI/w3aN GA8SKlZU+Fk8wx5O/U0BU9T0cFUcxeoulKCbCtuwEfjfxOLwvBbt8eEnZUKaCKRLbrYftP6w3qAYN NjNwllKEQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVAJ8-0006PZ-5w; Wed, 21 Oct 2020 09:21:22 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVAIu-0006Es-4G for linux-arm-kernel@merlin.infradead.org; Wed, 21 Oct 2020 09:21:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=7XJE+hSH/S5sf+J2AcmYCFMIcTxnQzpOZqEdbmMuzFE=; b=W0/9v9/bifx/ccxiHd4f6i2Fgb 9wY7H/tCSw9lHgGtV/AMKiY8Fio7lW1ktRrp7Th3lUqZFvJpeQi4KBLeNjtfCWtd2lqarhJEhWsDn nSUXCGiHDJcv6qZnMCrhLZ+sdrnjCW8nUbXe+zgd/hpiepeMBySeOymuCU0Pr9kTtwBpRUbYakdpp sIWnXi1cgX0jjCR3SwHEPkyDbAca6yq3qUr+GBeJVUiQDPDF92k5Liq5CnGh98O3+Xx16IxkkxBBN JFTIdekmdvLUKdYmpHtjxMZeGg7L+cy2mGdNKiqWgF8OPy7TBs2jUrB9vlgu4nwL0WvQea0ILY3iQ RA6gQ3Vg==; Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kV9vw-00013m-9y for linux-arm-kernel@lists.infradead.org; Wed, 21 Oct 2020 08:57:34 +0000 Received: by mail-wr1-x442.google.com with SMTP id e17so2017066wru.12 for ; Wed, 21 Oct 2020 01:57:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7XJE+hSH/S5sf+J2AcmYCFMIcTxnQzpOZqEdbmMuzFE=; b=GUK8bAu/rOwhstjfCCL4jyz79EWKlxKCEPzbQk67yqQgL5JdMMK9qYFAwYpDisTw7I i418204vlPkRGtUhsDK0/5TGt4bPzoR91GVgS9OWMA2nj4HmDeVE9XWPk7FPp7l7XoFa ZYmkpZjMTP6Ea3nY9tfKU2e09YncWgauHxbSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7XJE+hSH/S5sf+J2AcmYCFMIcTxnQzpOZqEdbmMuzFE=; b=kSd5jUAN5vL1cbwMDzkdtQyiomkiqRLou390KVsTL5MvQ76UN6xM0MZ0dD433bc64b EaYZMN0Gf6f1ifjxstXO68B3EMm7rRu9mHKcboFw4mMEhYu5iUsNMkpZvlAxOWlzLXDC NsEOxxCIszhDjSDows/2oKPub9CFHbgjriGrdi2PDU2UuO7YfTfD5aZjZ4vJTSqG/GOE G/2UADozblUFj4r6/a6ZzC7jhV96KLkK7s+oYW1fyO+typ0aFQp4jdnuU8dyigb4XPo0 OiUsAhTWdrNXwgTXV5IOdtu6Z0hwP+BhrJFCERSReORqLLqus9IFo7FXh7SVSro0bpn7 ESwg== X-Gm-Message-State: AOAM530M9bY9gGyg8NdPD8QYLfBI0+XSIV+ikKinRnZqZy+Bncmx/O7M FeYSI8vS/nCyiQTCXDVgSoO3FLVezmSICR/7 X-Google-Smtp-Source: ABdhPJx37Cjmlb4fgq/grqKCCp37y8t5Mz28eOZMNIB2vWtdgu/4b448hmjy5S8hmkcygKAt/hypYw== X-Received: by 2002:a5d:5009:: with SMTP id e9mr3539688wrt.104.1603270640046; Wed, 21 Oct 2020 01:57:20 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id q8sm2675939wro.32.2020.10.21.01.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 01:57:19 -0700 (PDT) From: Daniel Vetter To: DRI Development , LKML Subject: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap Date: Wed, 21 Oct 2020 10:56:51 +0200 Message-Id: <20201021085655.1192025-13-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201021085655.1192025-1-daniel.vetter@ffwll.ch> References: <20201021085655.1192025-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201021_095726_218525_A12F955C X-CRM114-Status: GOOD ( 16.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Jan Kara , Kees Cook , kvm@vger.kernel.org, Jason Gunthorpe , Daniel Vetter , linux-pci@vger.kernel.org, Daniel Vetter , linux-mm@kvack.org, =?utf-8?b?SsOp?= =?utf-8?b?csO0bWUgR2xpc3Nl?= , John Hubbard , Bjorn Helgaas , Daniel Vetter , Dan Williams , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There's three ways to access PCI BARs from userspace: /dev/mem, sysfs files, and the old proc interface. Two check against iomem_is_exclusive, proc never did. And with CONFIG_IO_STRICT_DEVMEM, this starts to matter, since we don't want random userspace having access to PCI BARs while a driver is loaded and using it. Fix this by adding the same iomem_is_exclusive() check we already have on the sysfs side in pci_mmap_resource(). References: 90a545e98126 ("restrict /dev/mem to idle io memory ranges") Signed-off-by: Daniel Vetter Cc: Jason Gunthorpe Cc: Kees Cook Cc: Dan Williams Cc: Andrew Morton Cc: John Hubbard Cc: Jérôme Glisse Cc: Jan Kara Cc: Dan Williams Cc: linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-samsung-soc@vger.kernel.org Cc: linux-media@vger.kernel.org Cc: Bjorn Helgaas Cc: linux-pci@vger.kernel.org Signed-off-by: Daniel Vetter --- v2: Improve commit message (Bjorn) --- drivers/pci/proc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c index d35186b01d98..3a2f90beb4cb 100644 --- a/drivers/pci/proc.c +++ b/drivers/pci/proc.c @@ -274,6 +274,11 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) else return -EINVAL; } + + if (dev->resource[i].flags & IORESOURCE_MEM && + iomem_is_exclusive(dev->resource[i].start)) + return -EINVAL; + ret = pci_mmap_page_range(dev, i, vma, fpriv->mmap_state, write_combine); if (ret < 0)