From patchwork Mon Oct 26 10:58:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11856633 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 702BBC55178 for ; Mon, 26 Oct 2020 11:02:52 +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 28917207DE for ; Mon, 26 Oct 2020 11:02:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rHjMEZc8"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ZKPGj+0b"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="KLr497mr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28917207DE 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=R7U8yAvcJh1TIOoNKZz88RSyAoTSzrhbMoG3ezwfiWU=; b=rHjMEZc8EJI70Ffh2+jIEXMAk qc9H3mVzfy8L0nYik13ajZxmOvwuHHyRIwO5FjOIjqwYK9oofBReiRASVN3df+S/+sSX39TF+rKSl sZynv/QaA9BiBwpRYlodLifdOaUzqzbKneUlmBt+mo36eg3JLI0Z0Wf4w8hvgVtA4eBbejgTzeK9n 5NSjFYmvFMgCbEvaKMj/Yw7RcMAxKaLbXtKSIhjJ/dm1NFlf/A8IPjtrbOJOIGBOqGS97B/n/KXBH Td5vhtgZyRQOJ7Stb4vp6jsHuC10+iTe/cyO/ycgkngMOycpUc0Pi6wGKNaN7H41uZbHquKhHWnk7 RybNFR5Vw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kX0FC-0002x5-QC; Mon, 26 Oct 2020 11:00:54 +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 1kX0DC-00027G-W7 for linux-arm-kernel@merlin.infradead.org; Mon, 26 Oct 2020 10:58:51 +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=5W4UqFTJMoDRzu7XpmV7m/mIx7tbXZK4TFNNVek8jNg=; b=ZKPGj+0bnxT7tRylR7TyuY2Euf TFDixoVfOj1zc8ymSWmSE9eFUepNarvJchieS7rPVrE1FFRV2GYwtz19YfIpaAhP77M0weLk4wzSa u7IbV19z2/RShnC/81l1ux6cJETN5Yzwfx5ttc2ql93YK1uOOEBIz/wNFmjB9avNhX+Rm9Uw/FURP zWv6M8cbIK2c9CEPhXCUIeASkkRBQwJAt3QJrdINxlsRP1rfwJPaEeP5D4AY9a6zpoi4RTSqW3nde oj4lzLE4tAni1Z21AR/4hWparbjkZwFd1NJZp3qtkU8t+8D2GvKDGZcsAWGaROVWPKX6fhtexHD+d ATrR50rQ==; Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kX0D7-0005cC-0r for linux-arm-kernel@lists.infradead.org; Mon, 26 Oct 2020 10:58:49 +0000 Received: by mail-wr1-x443.google.com with SMTP id e17so11866730wru.12 for ; Mon, 26 Oct 2020 03:58:42 -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=5W4UqFTJMoDRzu7XpmV7m/mIx7tbXZK4TFNNVek8jNg=; b=KLr497mrTXuUWmZaofaXk1hyxgArLSK5Z8LFA7VwpBwSz2E3+nE1glgvLx0JiQdQzn dm5kaVp9H5reVf+JjmNdCZ0s9dozztPh2nQ4nrraI1YOy9mqE/zZOpL+5xkTYVff+uRk JdfMqSudDhC/KCWc2IX1OVFNm25KGK/VrwkWA= 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=5W4UqFTJMoDRzu7XpmV7m/mIx7tbXZK4TFNNVek8jNg=; b=bD0VH0cVJrORTKHg4h/VZ0yJwLbFOgrqSn2CO1URjp38PFTjIVt4CtFFRTt2QpngbG qxN8VeLriDMuRfTxl4eeesa1x9TiMLjMBh4ttS1iDGhDTbTsFYGIh7fmIZg/EKTnUWWI mACeEdQMpG9OwoxXqzL/cG2XaBSO8FZc4K92OKsbNIeS372Bh4ABISTYXwaDAiu2Vb9p r/596noDTVLuJhS+WA5RzkXe2HI/x0v6319zdkvIbxV6Zx5VCU4spyIgoObgMkbXDJTp xRAJW0L7VU1x8PFtHRjbY+HnNd4ITrCpRKxrrbLq7r6ekbun7P7mJ7cLkq34PwOT7IFk +Kmg== X-Gm-Message-State: AOAM531PjeNtGovZLT9b19ybzX3vNVHNpEGZLSGqFT8V+XtNijglshh7 z9kfNVNrfbWf29minVOC1bNNOw== X-Google-Smtp-Source: ABdhPJz2su0SrOVqm3DeypSb7RJN8qc1fEsNaBh1v2aKMDuErJYYfZ5yJi5C/1uI817lBc+Ai9qYTQ== X-Received: by 2002:adf:f3cb:: with SMTP id g11mr18177850wrp.210.1603709921142; Mon, 26 Oct 2020 03:58:41 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id w83sm21165156wmg.48.2020.10.26.03.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 03:58:40 -0700 (PDT) From: Daniel Vetter To: DRI Development , LKML Subject: [PATCH v4 11/15] PCI: Obey iomem restrictions for procfs mmap Date: Mon, 26 Oct 2020 11:58:14 +0100 Message-Id: <20201026105818.2585306-12-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201026105818.2585306-1-daniel.vetter@ffwll.ch> References: <20201026105818.2585306-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-20201026_105845_614459_B34D6163 X-CRM114-Status: GOOD ( 16.28 ) 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, linux-mm@kvack.org, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , 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)