From patchwork Thu Nov 19 14:41:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11917871 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 92074C63697 for ; Thu, 19 Nov 2020 15:03:32 +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 000A120867 for ; Thu, 19 Nov 2020 15:03:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MhRs13HP"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="d+2XVLWr"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="lhtA9EHT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 000A120867 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=REFjMEWsSAB8XVaDGKcVix9zoY7KmWsuGWic1hFBbhg=; b=MhRs13HPO420zRf5TtkZRUNGq jYwaA6a+eljohnTcxuyiTEDrXieC2xauUwjSf3w6uT7QZ9lBhr5OEHyz0qr9wBV0fibFxF4hSxNvo jdRPAwU9r6tvGXn7poZVEpFFpE+Am9JvLhYL7o+PRg9jDJfFUxogqJqi7dlGNOrXE0bJ1i+/Ffuqh 0wTtx61wIeWpwufMXQSKTQSArjsVJUmd3oGkPd1mlJk8dXmaAzXWW0o9oy84h81g6+UNOv2A90qet 0Y0cmzwMcb6nlNGl4lEfQbcip9qBOj6pD5PGbL+amtYCi9PG3tfCVFONf8U84l7cWGLHeBP0LjJsV 6H3T0igRQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kflRo-0008SH-4e; Thu, 19 Nov 2020 15:02:08 +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 1kflRZ-0008K3-IJ for linux-arm-kernel@merlin.infradead.org; Thu, 19 Nov 2020 15:01:53 +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=r9CpIi9VXsG+zuZeNFc6wtzpnBA/KWk/gpfUTZT1Zjk=; b=d+2XVLWr4PI7dUbmyCiP7dco8g s45XmyStTLsBbEbu+GhymxoGXfKczvxx063xkLq0DH0JlK09T3SsBrr0j7+w16MVsc8p7NvdJyC8D 7AMEREzvmSXIB4r12I4LRQ3XFEKVxvMKeZ+Kr423D0k8FhBtM42n3IXj3jB/ag+4dRAzWzdBDSQND 3rnt6wEPjGs8N29ncWT4b/jpxdIZVaSd4Tnw3fHrYTSSKQrA0qgixvR9OT+mF529kIK/EC2n0PAqk 36n3xIp89DPnCrdWksC00g75F2o/AnBDku65l7eKw5s8HKBWJSqrji4nAVUou6RcmWtSflKhNmCD3 71rQ3gEw==; Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfl8U-0000Dj-O6 for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 14:42:15 +0000 Received: by mail-wm1-x341.google.com with SMTP id p22so7424495wmg.3 for ; Thu, 19 Nov 2020 06:42:07 -0800 (PST) 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=r9CpIi9VXsG+zuZeNFc6wtzpnBA/KWk/gpfUTZT1Zjk=; b=lhtA9EHTSs14S/lWfBd1cIy0B+1WAFjZ2wwrxe0xfxaPFoO4tE/BV8FsM/+QBdNKSb qaDof6bo+sV1dmoR3pr9L3cROFnjeyDX7YUhLjLaTr5vvJuZGC/AQ8qhGDGYOPWuK2ES DXV+m9I+q0gCIequCxlA9xJnLLr4u+Z/5Mgjs= 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=r9CpIi9VXsG+zuZeNFc6wtzpnBA/KWk/gpfUTZT1Zjk=; b=Q+qg8LiMrcagI1V8KTx0AGprTtCW6em186HG0ifjcSbGCUqW/CWLdRsY7jXERXQXPH s2+b2mKkdAwK1VyRZkA5LsRLGaD3OwTtEQ+FtfUQ721ySx5hJbRVNTPwNUWnwgExs/R6 4rUT7cqbEuZNH1Y4j6Qsik4X37aSMGrzl41WdxZUsLwpnjZlKJBRqibC2UWxqy7qIAwf VsXcROPoaDEYRGCuren3jMFq2i/bFdpo2vNynflOZWSs7wau4KcNZSADSQq8F6islKqa 652OkV7Zeow3hAQMVL+VVSoyL9bNfdu0UWjvWf7YTD1YqSndT9f7k80JRjqcQv5EBcGb q1JA== X-Gm-Message-State: AOAM532DOjT35E/NTjcK5yUH1Kme2rZzrlX2hvuDgk340CwEveTvzpIt XR1EhNxTZbBM7OA7Jp8ZZjgCAg== X-Google-Smtp-Source: ABdhPJwmTNYcq6djsIakV7SIgJh96B+fhnfkl7M76m7WAG1RYZMmoYFSDpdjObIHYtpegBgvRnmxPg== X-Received: by 2002:a05:600c:288:: with SMTP id 8mr4943834wmk.106.1605796926931; Thu, 19 Nov 2020 06:42:06 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id x63sm51292wmb.48.2020.11.19.06.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 06:42:06 -0800 (PST) From: Daniel Vetter To: DRI Development , LKML Subject: [PATCH v6 10/17] vfio/type1: Mark follow_pfn as unsafe Date: Thu, 19 Nov 2020 15:41:39 +0100 Message-Id: <20201119144146.1045202-11-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201119144146.1045202-1-daniel.vetter@ffwll.ch> References: <20201119144146.1045202-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-20201119_144211_462054_7E2D9D5C X-CRM114-Status: GOOD ( 18.75 ) 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-samsung-soc@vger.kernel.org, Jan Kara , Kees Cook , kvm@vger.kernel.org, Jason Gunthorpe , Daniel Vetter , Cornelia Huck , Alex Williamson , linux-mm@kvack.org, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , 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 The code seems to stuff these pfns into iommu pts (or something like that, I didn't follow), but there's no mmu_notifier to ensure that access is synchronized with pte updates. Hence mark these as unsafe. This means that with CONFIG_STRICT_FOLLOW_PFN, these will be rejected. Real fix is to wire up an mmu_notifier ... somehow. Probably means any invalidate is a fatal fault for this vfio device, but then this shouldn't ever happen if userspace is reasonable. 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: Alex Williamson Cc: Cornelia Huck Cc: kvm@vger.kernel.org Signed-off-by: Daniel Vetter --- drivers/vfio/vfio_iommu_type1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 67e827638995..10170723bb58 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -421,7 +421,7 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm, { int ret; - ret = follow_pfn(vma, vaddr, pfn); + ret = unsafe_follow_pfn(vma, vaddr, pfn); if (ret) { bool unlocked = false; @@ -435,7 +435,7 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm, if (ret) return ret; - ret = follow_pfn(vma, vaddr, pfn); + ret = unsafe_follow_pfn(vma, vaddr, pfn); } return ret;