From patchwork Wed Oct 7 16:44:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11821123 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 CAE08139F for ; Wed, 7 Oct 2020 16:45:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 71491206BE for ; Wed, 7 Oct 2020 16:45:00 +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="jOfg2aPb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71491206BE 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 4DE338E0006; Wed, 7 Oct 2020 12:44:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 443F18E0003; Wed, 7 Oct 2020 12:44:48 -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 2DDEF8E0006; Wed, 7 Oct 2020 12:44:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id EF4848E0003 for ; Wed, 7 Oct 2020 12:44:47 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9484B3628 for ; Wed, 7 Oct 2020 16:44:47 +0000 (UTC) X-FDA: 77345703414.12.party12_5f0e27b271d0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 720B9180188AB for ; Wed, 7 Oct 2020 16:44:47 +0000 (UTC) X-Spam-Summary: 1,0,0,2350a22446eeed04,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:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2901:3138:3139:3140:3141:3142:3352:3865:3867:3868:3871:3872:5007:6261:6653:6742:10004:10400:11026:11473:11658:11914:12043:12297:12438:12517:12519:12555:12679:12895:13069:13161:13184:13229:13311:13357:13846:13894:14181:14394:14659:14721:21080:21444:21451:21627:21990:30054:30064:30070:30090,0,RBL:209.85.221.65:@ffwll.ch:.lbl8.mailshell.net-66.201.201.201 62.8.0.100;04yfoum5ddpdgwjxaqh64gmi73f8hocjog4c8cafh6thm9pu9tpqskq6cxo4ny4.e94qo3p1jerhjgj1nzpxkpp7hzysx91z1dif1uoqgghxqyuruddrx9mbbbxz8j1.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:24,LUA_SUMMARY:none X-HE-Tag: party12_5f0e27b271d0 X-Filterd-Recvd-Size: 4953 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 16:44:47 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id z1so2978946wrt.3 for ; Wed, 07 Oct 2020 09:44:46 -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=P02GBIE7m0UGj1Ja16VfRtl1rny8rrQDbz10f0cDTbo=; b=jOfg2aPb+p2PctbbcpGPk2VTV8x+SKSCmFeHr5kNnGpMzP9+KndzTdMPcmKSmVIBOL Sn8AtpmXpRju+60FUKJKw5WoTBtH4QSJvymhz/0+3ZeCxQuRUo3jPklVq4Ib9EuOwEj2 sPoeQoG2BgasR1J/L7Iui7jQ8XopY468hCzwc= 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=P02GBIE7m0UGj1Ja16VfRtl1rny8rrQDbz10f0cDTbo=; b=fsUAF6Cr+PUtRA+rvprxYPbwjXqnaQmkI7z1M+F79upi9oNz3Ydo18k07UASBn/WKO ZEfX/uC1zt1Hk71rthJV7wt6OIB44in6SuQWiM9th7J4aKoSKMkcew17ipgdfRhu2fsu RJ1TwP9vBEZ5GitBhB5yZdL56vEmROr7Z7Z8Q1DXEMX2n4Qd5qccOCBtqsbu9jkgdplw yMduSfV0WMcyrUUcqrHfLZHXM7yxsq2gPx3nvx2/LDknAcHT1FKg7U25YvtVdcMjU4U4 VHuoxBCaraFrbfdi7m7GM2PyPDr3Uoc0hXKaCBG37f31N6aUgeXoCqdi+0CYQoe4X7pw C8KQ== X-Gm-Message-State: AOAM5328WS99xo6ndihDGIs4TfeOtd8Dg5sOtOkZzK7HR4v+dPGGnso/ +k7cUO8iSExge/yoMnjltiq2wg== X-Google-Smtp-Source: ABdhPJzCDfyCaOqONShrGzC8VJoQgNBmutXD42q/UwtrqERpH1arTrrensBhgkJDw5zkDOp6xBcjVA== X-Received: by 2002:adf:ba4f:: with SMTP id t15mr4383017wrg.335.1602089086053; Wed, 07 Oct 2020 09:44:46 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id z191sm3332280wme.40.2020.10.07.09.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 09:44:45 -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, linux-s390@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 09/13] PCI: obey iomem restrictions for procfs mmap Date: Wed, 7 Oct 2020 18:44:22 +0200 Message-Id: <20201007164426.1812530-10-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> References: <20201007164426.1812530-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. 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 --- 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)