From patchwork Thu Nov 19 14:41:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11917867 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 C32E5C63697 for ; Thu, 19 Nov 2020 15:02:39 +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 3AD54246A7 for ; Thu, 19 Nov 2020 15:02:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AUdVqNGJ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jPI6Heo9"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="VdR4TRQW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3AD54246A7 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=DjZj4/e3U6WRmeD8q9EzazZYr9hlnE9SWwC5ad3EgQk=; b=AUdVqNGJhkwB+9wvoETslEbza PeR9mdYCxg9Fj37gY9ztzrQN9q8xmE38rIaABLxvU827nYCNY3jyoLOYdEqqTcAtSS10MSEcwQVMV v35qPqwt+YxH/hqCJoTu/dVCeAsgtpJrO0ENQKTnHeu7Aj7g5L4o2Dsr08XCJ4O8jvebLvoKA24xy Dcq4dOLlATN1zqw+IAd/Ry547+PB+5TRKuFPs++upe79rUwJ7WshX+qcDzJRw+Ch6BeZ7ZK9OT9O9 89KfCqP8Fa8pYhQKYbuC0XsFNdmRFJ3fqkmO1qw37keT46LpADQVva7XF7sd5UrxecUDJ07B/UqDn pLyLEoCmg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kflRl-0008Rj-2y; Thu, 19 Nov 2020 15:02:05 +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 1kflRY-0008K3-Kr for linux-arm-kernel@merlin.infradead.org; Thu, 19 Nov 2020 15:01:52 +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=rOg+qp39SVj5WC86VkdFnTzL9jP06PEcpQhmqKQ3t14=; b=jPI6Heo96WExiO86rquzCqbr/o V+dwj1A1df3IffpK3i2zCnRRSfeVb+DfFIYkW5eq3odYbXJSzhrndLHfQcrkDjUR5DuzRT/Gj0mmR tVKkVI6jdv14LwCVpig0rV8R5BSd8qPBfGzTX7VALznPZUAuHB7U9/91NNrf4q01Gpc1/yU5g8I0V cA6VoEFC/T23WOpbEn8mXOA6Qj6aepNXjlzbUr8aU/HmZJ2z1mR7VzkldHq/jGH5bzmV47WPD7qiK lBNXlv6cLH/bGuK/eyKrMvHiWojeYmItWGvuuJ0XPZniTBcmyV4CTTBC7P0vPYcoqMfB/v0lhG/95 DHlH8E5g==; 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 1kfl8V-0000Dn-Mk for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 14:42:18 +0000 Received: by mail-wr1-x442.google.com with SMTP id d12so6620053wrr.13 for ; Thu, 19 Nov 2020 06:42:09 -0800 (PST) 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=rOg+qp39SVj5WC86VkdFnTzL9jP06PEcpQhmqKQ3t14=; b=VdR4TRQWQACxogAeI8bpxISw4lYuZMDpigTJtM/VpnCefzKALSPbEG99bZ5Wbe+gKp gTbBqPkoFOSHKBnAtnkpkRQRBwBUcqVexaUuZzvjGnAeBUC4W8Sgv2HdBZTVCRr0iXOw AVEvBuq1VDgLMzYgPJsacfSZW0w7f2MUd4t1c= 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=rOg+qp39SVj5WC86VkdFnTzL9jP06PEcpQhmqKQ3t14=; b=CerzAlEQStImQjMweyQQ+0sybVkTjTbipZPLYIiReKKVks3XZ62bTb2AnHxDGtayLt UAJJTutqmdSJbu3wWtsLbeZlmZv81Zi47UIJEWMqv937fWhjaxn7+2yhKVm3AAMD269D WKrcZxVRHj9PJm1fIVbp114LZYYXT7TF55rDWNOPoVD6v6mPpRFoJ+wGSJIzm6dp038f HJ34WLtkWSv9pbQBtZBrwTL4fcsFMtmabuWSo7jXKrzJSN1U8c/l16n4Og5CaY4IPjrz vCpaO9HM1pGBaPnkTVnQY4YY2bFQdg2aVwLQIwzwYfplY+kr3jwhi5Vi7ZMk1683wVHp zmDw== X-Gm-Message-State: AOAM531BAVhR2TcAU/llAMEnw72bYF6beyX1YvqNkUi6bISuClRbtdQw +rNTrE4M1yfKWRiXQl+ahlBp3Q== X-Google-Smtp-Source: ABdhPJxkxIZb1Dvgqd+l4qpBOUdvHL2JTzWDAAwF5TWOoMRtyTV7FCLmBVro+JG8yHOq0sr6nntY2g== X-Received: by 2002:a05:6000:372:: with SMTP id f18mr11447766wrf.149.1605796928322; Thu, 19 Nov 2020 06:42:08 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id x63sm51292wmb.48.2020.11.19.06.42.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 06:42:07 -0800 (PST) From: Daniel Vetter To: DRI Development , LKML Subject: [PATCH v6 11/17] PCI: Obey iomem restrictions for procfs mmap Date: Thu, 19 Nov 2020 15:41:40 +0100 Message-Id: <20201119144146.1045202-12-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201119144146.1045202-1-daniel.vetter@ffwll.ch> References: <20201119144146.1045202-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-20201119_144212_189369_34DFD234 X-CRM114-Status: GOOD ( 16.17 ) 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-samsung-soc@vger.kernel.org, Jan Kara , Kees Cook , kvm@vger.kernel.org, Jason Gunthorpe , Daniel Vetter , linux-pci@vger.kernel.org, linux-mm@kvack.org, =?utf-8?b?SsOpcsO0bWUgR2xp?= =?utf-8?b?c3Nl?= , 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(). Acked-by: Bjorn Helgaas 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)