From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 DAF43C561F8 for ; Wed, 21 Oct 2020 12:50:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2CE6122249 for ; Wed, 21 Oct 2020 12:50:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Bjric0h8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2CE6122249 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E9E206B005C; Wed, 21 Oct 2020 08:50:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4C906B0062; Wed, 21 Oct 2020 08:50:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEC0E6B0068; Wed, 21 Oct 2020 08:50:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 9ED396B005C for ; Wed, 21 Oct 2020 08:50:33 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3175E84A373E for ; Wed, 21 Oct 2020 12:50:33 +0000 (UTC) X-FDA: 77395916346.20.hate80_1e0126327248 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 12127180C07AF for ; Wed, 21 Oct 2020 12:50:33 +0000 (UTC) X-HE-Tag: hate80_1e0126327248 X-Filterd-Recvd-Size: 6189 Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Wed, 21 Oct 2020 12:50:32 +0000 (UTC) Received: by mail-qv1-f65.google.com with SMTP id w5so970147qvn.12 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=liY4j4yYksgmakD2W2WBb3iSFQlHbYg9360pknlMX6P4Vur/dO8dl/VkKtvIleQkTi EuHYtyt64pu8/DNvfjfZ6AIWGCauc75idcmUN+80mHrV0zevhQUaBNm3R/bD0boH9a+B V6dhsj+0FOsI1EJLHmxBpXKQ1+ITKXoBLIhFqRwVVY9U+xf6CczAOLxGg8aFVd1VwDqH G3MgUMkb7jzYnSIVvZbBnUBxoC3Pg6gA6gmwN19/hIh0Dq4Uf8s83a9l8b9o+YRAeft7 WYKSeAbxSdhMHrLx7s7leP+GEulZZKRks7+CYeheKAb3r48EU323G1pBn7SXVpM2CfvU kNmg== X-Gm-Message-State: AOAM530BXoTiuPtLRZ9nkt0GZGNwHlncc4uy9M8ZQEm4fdPlZJjH9I6H fHycvsMAbifBJE4MU755BCX3AQ== X-Google-Smtp-Source: ABdhPJylgNYamo6kqGCWkyezTruGMIXv95IBuM/bFST1jOCSfo3IMWIRoN2J3LwPyBiAPIKaTroxlw== 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 In-Reply-To: <20201021085655.1192025-13-daniel.vetter@ffwll.ch> Content-Transfer-Encoding: quoted-printable 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: 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. >=20 > Fix this by adding the same iomem_is_exclusive() check we already have > on the sysfs side in pci_mmap_resource(). >=20 > 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=C3=A9r=C3=B4me 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 =3D 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 =3D 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()=20 !!! 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