Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5229857pxu; Wed, 21 Oct 2020 18:02:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOnz6TLd3lwXkmJNXMLnwL4odbzxtvlnN5HGegQFvA2UdHZ1BjWTyBWewp24N6Xk/ZwGyE X-Received: by 2002:a17:906:6a8b:: with SMTP id p11mr63549ejr.470.1603328520449; Wed, 21 Oct 2020 18:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603328520; cv=none; d=google.com; s=arc-20160816; b=IvkjXc3gi/FPICdkCqvhjKNFamldFXCdobEzzgL8jnodo1yfoEn1LWxEqnpw6Lrbf9 bEFUQXpxehbz+w4IvdpPv6aPKDwNr/ILMiW1K7Tk4e96BiCC/O3BUvZ1Dv1EMJnai6Xb VgeYGSAIQ9dFi8Rkl2zhYbfI97SJLr29izw0HD+f07EgB1H/Sf/baoq0YbZ/tTjE49pK BPrxNg25dvzHK4u+v7AGYioe+gczhav7T/svuDOHbpITr8q5dSfUrFvlHTMcmCbHR6ro LPLI5Nu7Gx+c9F+oZcKIqvMG0BvguLH3nDeoIhsRwKsWnFxLBboHhLm/R4FW6nVXGMZs wZEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=VkhhJyafoy36fds4PnCfWF9LNV9fC1i6gyayD/bdTsE=; b=pegr+7VeH/VVW689Ybm7E2oq5LrN4wMo6BbZMu0M8TFnsTh+lyBWX54bdWXEMHjrIN FrgGb2B3ExJIl3uiUut7VuXhosZuPnkSx8rfC8wbEVnNsNOvlAU70nbztDZx5rYKSnaC irrJ/hK9U4skYSLxVhJpGz+/kpvELCkstJc05W2A81FZKLjkRkEzz3q0VuJ43ATWu0cC c1qvm3nbhy5oWCJyy3g3euezc6SBstrmnCSi82Ja4eo5lNuorAQZxpj+zWP3v6XIwSvX 30f+y013ENfvf5xmCOOgblEcFFp4vNJ7/MJTzSwlCUOJrEcdoJG3jNDUKTuQmDmxT+Yv Mqjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=Bjric0h8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm9si39867edb.76.2020.10.21.18.01.38; Wed, 21 Oct 2020 18:02:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=Bjric0h8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442633AbgJUMue (ORCPT + 99 others); Wed, 21 Oct 2020 08:50:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2442626AbgJUMud (ORCPT ); Wed, 21 Oct 2020 08:50:33 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3DCEC0613D6 for ; Wed, 21 Oct 2020 05:50:32 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id s17so974482qvr.11 for ; Wed, 21 Oct 2020 05:50:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=VkhhJyafoy36fds4PnCfWF9LNV9fC1i6gyayD/bdTsE=; b=Bjric0h8k3E5nVSnyA3y8syn5qJbzN5IRzuOHR0d7uEDz69w1rKEdQtJjX2klnSD2f HQcTpKD5D3V7kWLlToHxrM8UOfbUsM4NGMyxmaL4cJNWPBOlwy7SSVlgAu3fXQNgW/tm E/Z154bHNIDfOdfpW4c0/FAD/DUsAoEBg7tdzOhHMjGwZ1srI5ZzmyHw1kqTbOA20Zsr 6FkTvbFUFtQy26Mpkg7JM8b/jc3WZ4zNCmcMh6GqroRxUEuzzQjwRRq/1rm+GvI0lwIa yqkLIFnQ0gQqj71OpMsdVbj1j0y2lESP0Xm+nHN0pfprmhEnmw6kFUQw4XnnGYDmJyHR D1HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=VkhhJyafoy36fds4PnCfWF9LNV9fC1i6gyayD/bdTsE=; b=bg6QC9Ap4ffsDx3Kwm4OXfzMuCMbwJri3v2vwEtdD5OnfOzYjBm4MXFXJb26o+M3X8 su4Guiop4dLMYob99o7kEWiw20SlMenwt4n7lTrGVp5o1nCOi6v4le7KnF5ig/YcfjqL 1tCUIIXLMDmR5+pSwQ4uPu97i+lbhqcTvuV/5uAKi7pKOTe84NHMcubHa1LLCE1cRyoO wQI1D+acY331Ny+HIgX5JFLxKilJ8uIEb6tN1VetcpKZgLzlFByWld/ZD1eaPUMFAo0P UscVTCCK/9lUIcKU1rd4ezW1ZJAgIQhvfMLGmQwKz0n+OMR0F0pEigL9NsNLTL/VLUEx IBhw== X-Gm-Message-State: AOAM533Xp49HPzDK2iLOG6cWiR8joav2jMSInqn+G6TxlIeaGdybICT3 o066ZS12GmDUT+9cAQRE2jGanQ== X-Received: by 2002:ad4:52c6:: with SMTP id p6mr2781869qvs.38.1603284631882; Wed, 21 Oct 2020 05:50:31 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id r11sm1016060qtw.47.2020.10.21.05.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 05:50:31 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kVDZW-003UAg-0q; Wed, 21 Oct 2020 09:50:30 -0300 Date: Wed, 21 Oct 2020 09:50:30 -0300 From: Jason Gunthorpe To: Daniel Vetter Cc: DRI Development , LKML , 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 , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Jan Kara , Bjorn Helgaas , linux-pci@vger.kernel.org, Daniel Vetter Subject: Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap Message-ID: <20201021125030.GK36674@ziepe.ca> References: <20201021085655.1192025-1-daniel.vetter@ffwll.ch> <20201021085655.1192025-13-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20201021085655.1192025-13-daniel.vetter@ffwll.ch> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 21, 2020 at 10:56:51AM +0200, Daniel Vetter wrote: > 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 Maybe not for fixing in this series, but this access to IORESOURCE_BUSY doesn't have any locking. The write side holds the resource_lock at least.. > ret = pci_mmap_page_range(dev, i, vma, > fpriv->mmap_state, write_combine); At this point the vma isn't linked into the address space, so doesn't this happen? CPU 0 CPU1 mmap_region() vma = vm_area_alloc proc_bus_pci_mmap iomem_is_exclusive pci_mmap_page_range revoke_devmem unmap_mapping_range() // vma is not linked to the address space here, // unmap doesn't find it vma_link() !!! The VMA gets mapped with the revoked PTEs I couldn't find anything that prevents it at least, no mmap_sem on the unmap side, just the i_mmap_lock Not seeing how address space and pre-populating during mmap work together? Did I miss locking someplace? Not something to be fixed for this series, this is clearly an improvement, but seems like another problem to tackle? Jason