From patchwork Fri Oct 30 10:08:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11868989 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8C43139F for ; Fri, 30 Oct 2020 10:09:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 74C5D20825 for ; Fri, 30 Oct 2020 10:09:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="OzUM7mbx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74C5D20825 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 12CB86B0085; Fri, 30 Oct 2020 06:08:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0E32B6B0087; Fri, 30 Oct 2020 06:08:56 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEACD6B0088; Fri, 30 Oct 2020 06:08:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id C0AA96B0085 for ; Fri, 30 Oct 2020 06:08:55 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6A85B181AEF1A for ; Fri, 30 Oct 2020 10:08:55 +0000 (UTC) X-FDA: 77428168230.18.roll07_560283027295 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 419BA100ED0E0 for ; Fri, 30 Oct 2020 10:08:55 +0000 (UTC) X-Spam-Summary: 1,0,0,748bc48eb0361dc1,d41d8cd98f00b204,daniel.vetter@ffwll.ch,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1535:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2901:3138:3139:3140:3141:3142:3352:3865:3867:3868:3870:3871:3872:5007:6261:6653:6742:7903:10004:10400:11026:11473:11658:11914:12043:12297:12438:12517:12519:12555:12663:12679:12895:13069:13095:13161:13184:13229:13311:13357:13846:13894:14181:14394:14659:14721:21080:21433:21444:21451:21627:21990:30054:30064:30070:30090,0,RBL:209.85.128.65:@ffwll.ch:.lbl8.mailshell.net-62.8.0.100 66.201.201.201;04y8onfxduw33at66n8zfskph7e5noc7eqo7uf5bc6thm9pu9tw1jbet4zkujd9.n4oksd71jerhjgj161i8eotz5s4s3hdeon94wcydjfeep7r37cnczq5bbbxz8j1.y-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:69,LUA_SUMMARY:none X-HE-Tag: roll07_560283027295 X-Filterd-Recvd-Size: 5114 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 10:08:54 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id v5so2311923wmh.1 for ; Fri, 30 Oct 2020 03:08:54 -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=OzUM7mbx2/F/oW9bbPe7In3qrMb9VgdikqTSY/EoMsPyXGAHuRv65Nms3OB0mjtIqw GVQCRCl/bcb/ABRytGNQRec8qj5WedF9qpRoNXq/7Q2qAH3BZRTXvZHES4rNIMYTppYX ZyoeN/ZtxE8PEeZM/6gBTeLfJXnqEXHLZdrKg= 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=ZDSbo5od8ayeSn2C9nsp0sxGl9QaOT3syMxyMl+6A/ZRSZUX84xuyMCthrJ/KcCTIv WhHKgPwhGdYoG4Sqws2InSkGJh4IthWfD04aBq09wLS02pOrBxMleeRle2njTgLGJS35 OzvYxT7E9oVFG/XDGBJWTHGHp/UDgiDn1aM21F+zOtgbrEA6Na+8CX1dPWbCyyggrXj1 A4VzotahD3mkjAiGbj+6G+rotEF/QqX945kURs9Y7bbRIzJt14FBe5grUZ5esQDZxFy4 Xzwg/C2jRhvMFG9Q3f0mdnWkQLnvnJ025fyvTG+E/uRJlsVzc5ugmqig25aOJ9wwcpUh CPMQ== X-Gm-Message-State: AOAM530D4FpIQvkzPicvzWmHKc3xmzX683dwnGgf8u3br4A66YlFJU3L HO4gIniI/DNHJHjqZlQcsDG7pw== X-Google-Smtp-Source: ABdhPJwkuxWq70OZDDHUvlvKxagck9TRjPZKU3g23XqCmDUUZEe9Y01RmcL6G8BKldTXxtndJYt3iA== X-Received: by 2002:a7b:c085:: with SMTP id r5mr1669161wmh.17.1604052533716; Fri, 30 Oct 2020 03:08:53 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id v189sm4430947wmg.14.2020.10.30.03.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 03:08:52 -0700 (PDT) From: Daniel Vetter To: DRI Development , LKML Cc: kvm@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-media@vger.kernel.org, Daniel Vetter , Daniel Vetter , Jason Gunthorpe , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Bjorn Helgaas , linux-pci@vger.kernel.org Subject: [PATCH v5 11/15] PCI: Obey iomem restrictions for procfs mmap Date: Fri, 30 Oct 2020 11:08:11 +0100 Message-Id: <20201030100815.2269-12-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201030100815.2269-1-daniel.vetter@ffwll.ch> References: <20201030100815.2269-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Bjorn Helgaas --- 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)