From patchwork Fri Oct 30 10:08:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11869193 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 C0E0DC4363A for ; Fri, 30 Oct 2020 10:32:49 +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 00E6520704 for ; Fri, 30 Oct 2020 10:32:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uUV1Y/P8"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ng5clHOb"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="ddb3ur1/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 00E6520704 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=4bxRLH39vsEeMRkeU05rWK6nR33FOtgdfWINaYEiv2U=; b=uUV1Y/P8zceb/uzb4/YPymfWl t+3lWdmXTizvwnqBj17+eA084mvY42YTgL6wbnGUIshGdA1j67MdbTsoJSluy8RKTTtc7muzhTVoL xdxFZ6n2hkKAGknDYK5LMsBXZNKYnksPjeiJgJWCZYyfDlTLJlp3jRZjyv4YQtK+qSH4b1jiqFqT+ 1utBFV8c7AEC+Gc4OPMidFnIb9Zn6oLs5RU+AYVwyxLrJMNA5r+VBUbyh1uqAi168l9pi5pcZZKkT dXr5rfYOGawRR7Tz+c2haNejVOd4uzii53Z5edLI6U0Tde4lWqvwufs/tDmqZoFTh04rxboT0HrDu lflOYpkWw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYRhY-0007FT-Ce; Fri, 30 Oct 2020 10:32: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 1kYRhF-00070v-Fh for linux-arm-kernel@merlin.infradead.org; Fri, 30 Oct 2020 10:31:49 +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=oGBzVmmcnUwoCpcjwMRu//j69ndtXtCP0NS2ElhXzwU=; b=ng5clHOb++4BOjAdpDnuF6ws92 0yfIaipnHdq+iXgP50Zqf2D3TSoO1a48HkA8TeiOn/cw43Mry9t4Tpg/GEIHqs1hCX37em+K74QSD o1UiE2VCf8bQ3nWReAktiDwtSgxKirTy5HN7bwoUJ8asrBQQsJcMlYG0HtlKYJiKKKams7q/ky//b ZD9EWkeucrQo0ATb8f/aY29/m5SLmnCL/ytYhmQwRKiCksQ6UnWxRsHS/4+r+mTB6YSlaThxzoF+o EYpPZPxCrrJmTx0m84lpFdChVhKq/TnVkBLvlaANakFE6ZYo5+LFOhY0aUTFnz1Batg98ljl23BNp mCHhVp6A==; Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYRL3-0007rR-V1 for linux-arm-kernel@lists.infradead.org; Fri, 30 Oct 2020 10:08:58 +0000 Received: by mail-wm1-x343.google.com with SMTP id k18so2388246wmj.5 for ; Fri, 30 Oct 2020 03:08:53 -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=oGBzVmmcnUwoCpcjwMRu//j69ndtXtCP0NS2ElhXzwU=; b=ddb3ur1/6UNkfQr4L91EGkmgAJ2WFlh64b3krQrxHdXICPqGD1U7KSjV8mliOcYT2T IQK1rF0Fay6IRnqi6Z1rjQW4mkT8UrxQsAja5X4I4Zb0BD7E8rZgI9L3j1sWoJXQiFP2 XQzGN/xa46QCrVP1PNnx5Jw7AGsn+9JT27UuU= 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=oGBzVmmcnUwoCpcjwMRu//j69ndtXtCP0NS2ElhXzwU=; b=IHD4mdQK1fJ2RS4PB5XKsCUx1uTO7NFH1LF8JCFIbArpTfQeJ7LXPzBqmmZIwxQhZ7 bsAELH26rKVLr7dYRdxok/3sgjX3gJUIK9J04FwF4AGJnIB3eakW49rEtiiuWnx+hhKF 5jVqGGdJJoIPHfBFjM6nKyK21Vkj+gGKI9d6nU+O69afGtWP/DM7OuSPLSbmBeuwX034 ANJ61pWR1lDgPJiKU79t6EAfZGpzwssHvvmBuJvMCtFecDtJiluPkWeoWUej7sTayy5C mWGQ4bXrePIbQsFDoQG3LYBTIqvAuqhvJsV2jeICsZZyTY0pwTAtP2Ct/wXpvhD4Hnxj lopQ== X-Gm-Message-State: AOAM533SRiZG3x4u5HovDvU0a+NVda1MjM6bUAPlwrK7Pb6upG50+eb2 Jmo8VZ6gfsBswhQv/MtMlUa9Bw== X-Google-Smtp-Source: ABdhPJwf6UH/CcQRHOKUtt59ycYpiu3snU7M2hjeYaaPa8vODJopyC6lafOLMLKP7+MR3NDzcDgM5Q== X-Received: by 2002:a7b:c309:: with SMTP id k9mr1632728wmj.125.1604052532224; Fri, 30 Oct 2020 03:08:52 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 03:08:51 -0700 (PDT) From: Daniel Vetter To: DRI Development , LKML Subject: [PATCH v5 10/15] vfio/type1: Mark follow_pfn as unsafe Date: Fri, 30 Oct 2020 11:08:10 +0100 Message-Id: <20201030100815.2269-11-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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201030_100854_299928_11618E1B X-CRM114-Status: GOOD ( 18.49 ) 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 bb2684cc245e..eccfee900033 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;