Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp381451iob; Thu, 28 Apr 2022 04:42:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvypdtK8tA8ggQfr1YDBm3UokPDI9LwVTSqViuaHJrw3+o30AmmAPa97dRqlB88lcI4j74 X-Received: by 2002:a63:844a:0:b0:3ab:1cac:8177 with SMTP id k71-20020a63844a000000b003ab1cac8177mr20064262pgd.107.1651146133838; Thu, 28 Apr 2022 04:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651146133; cv=none; d=google.com; s=arc-20160816; b=qXdJp3GrFBG0E/zetUR8IRr846RT001JObSdj524kYDXLQSfcXJrip3i9QGt3SdJXV Ohkx+3kgXu0Hi5TExpeTYwonkcBY+mieKGd8OtBU0lVuF8C5U6aOlmmFPlQm/GqduKW5 AsLrusEXRgYe8okUSiLnYazgBhAbQVrWOJARdth0CXlc663bTQpemDxrR+dQM9KDESKM KxnFoP11y4HURPhgwTJI3LL01haBHCR9Fkk2g3WfDnH8DBTKVrhrFgDVVhD8DQ5m41m3 RLShu6IByXCdPr2w/GUbpyySZCh/JKX0BOyyS/ynCIItv+H/AeoorZMxeEhrvlzEvQfz WSeg== 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=XxKX4TEF+5lwdOh784Kwa/GN7QrQD4Cx2tXhjaS2tbM=; b=HaGnjEUgYJdHZYlZoF/e27gUvKr0enj2cYmlH0fX6CGwd1b3pyieCiwX4FJsoaHCI5 xZnYgtUAeUMNceezZiAMIjI8eB8ADgFLw43L1EPZqBoliX8865Z6H/CWueDCZl0YOQ1z cgwM10tq/DGxnWMhW5Iv+htOR/Zby20T22iRWUo/Q6xBexlvCrsD7zwpCzecFzcCMWm6 vohI8b36u+7NgomXQDGeEmHcZ2yKY197PlR4zF+FVU6C7/vUveNtCirhVuTWHK5xdQ9T k3P+lES5Rw8HZ8obDp1E/1LYkLwxmFTacNgsAo4N2bY7M7yeYouYKTZh+7UXzk5CSx4W RbVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Pkrfzqxk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nn4-20020a17090b38c400b001cd60242c07si8418410pjb.79.2022.04.28.04.41.57; Thu, 28 Apr 2022 04:42:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Pkrfzqxk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239278AbiD1A5h (ORCPT + 99 others); Wed, 27 Apr 2022 20:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231235AbiD1A5f (ORCPT ); Wed, 27 Apr 2022 20:57:35 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9431161289 for ; Wed, 27 Apr 2022 17:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651107263; x=1682643263; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=mF7e3wMds3iUFV1P2ZkCmb7Bzuyagf/LHBu67W4SX68=; b=PkrfzqxkFncV6KhyUA5dnUrlmL+A1gqG6jyE0H8Tlx5KE2own+NGfgbj oQM6AkgGb16IvfKZmX0XavfDCSG2xl0imzLbCJsMp6myWaOtnOloCYNjW q/rabWQvLbG6IOyZidS1nb8cABPA/eVZrpDnKFoCSS6tr2AOo6SLmiwhv 4MukE65ETO7uhODb7A6Ras3L3kiVKl/S0h1lrqKZLmaCAUZk9FTPVXvKY /xfRy+/x9k7QDogrEo1JZpOJAaPmij7XJ+ZLwM6CT1x7oluMpCHp80H+f IOF7amD/9lmdF7KMYYjW13UkmP/2zbxC0eugyFNK17/3y+/1hEXyxcTuh Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10330"; a="264966700" X-IronPort-AV: E=Sophos;i="5.90,294,1643702400"; d="scan'208";a="264966700" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2022 17:54:23 -0700 X-IronPort-AV: E=Sophos;i="5.90,294,1643702400"; d="scan'208";a="559317565" Received: from fyu1.sc.intel.com ([172.25.103.126]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2022 17:54:22 -0700 Date: Wed, 27 Apr 2022 17:54:57 -0700 From: Fenghua Yu To: Zhangfei Gao Cc: Jean-Philippe Brucker , Jacob Pan , Dave Hansen , Tony Luck , Ashok Raj , Ravi V Shankar , Peter Zijlstra , robin.murphy@arm.com, Dave Hansen , x86 , linux-kernel , iommu , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Josh Poimboeuf , Thomas Gleixner , will@kernel.org Subject: Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit Message-ID: References: <76ec6342-0d7c-7c7b-c132-2892e4048fa1@intel.com> <20220425083444.00af5674@jacob-builder> <51514a02-0de9-2f9e-ec0e-c86e147fa74c@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <51514a02-0de9-2f9e-ec0e-c86e147fa74c@linaro.org> X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Dave and Jean, On Tue, Apr 26, 2022 at 01:04:45PM +0800, Zhangfei Gao wrote: > > > On 2022/4/26 下午12:20, Fenghua Yu wrote: > > Hi, Jean and Zhangfei, > > > > On Mon, Apr 25, 2022 at 05:13:02PM +0100, Jean-Philippe Brucker wrote: > > > Could we move mm_pasid_drop() to __mmdrop() instead of __mmput()? For Arm > > > we do need to hold the mm_count until unbind(), and mmgrab()/mmdrop() is > > > also part of Lu's rework [1]. > > Is this a right fix for the issue? Could you please test it on ARM? > > I don't have an ARM machine. > > > > Thanks. > > > > -Fenghua > > > > From 84aa68f6174439d863c40cdc2db0e1b89d620dd0 Mon Sep 17 00:00:00 2001 > > From: Fenghua Yu > > Date: Fri, 15 Apr 2022 00:51:33 -0700 > > Subject: [PATCH] iommu/sva: Fix PASID use-after-free issue > > > > A PASID might be still used on ARM after it is freed in __mmput(). > > > > process: > > open()->sva_bind()->ioasid_alloc() = N; // Get PASID N for the mm > > exit(); > > exit_mm()->__mmput()->mm_pasid_drop()->mm->pasid = -1; // PASID -1 > > exit_files()->release(dev)->sva_unbind()->use mm->pasid; // Failure > > > > To avoid the use-after-free issue, free the PASID after no device uses it, > > i.e. after all devices are unbound from the mm. > > > > sva_bind()/sva_unbind() call mmgrab()/mmdrop() to track mm->mm_count. > > __mmdrop() is called only after mm->mm_count is zero. So freeing the PASID > > in __mmdrop() guarantees the PASID is safely freed only after no device > > is bound to the mm. > > > > Fixes: 701fac40384f ("iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit") > > > > Reported-by: Zhangfei Gao > > Suggested-by: Jean-Philippe Brucker > > Suggested-by: Jacob Pan > > Signed-off-by: Fenghua Yu > Thanks for the fix. > > Tested-by: Zhangfei Gao > > > > --- > > kernel/fork.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/kernel/fork.c b/kernel/fork.c > > index 9796897560ab..35a3beff140b 100644 > > --- a/kernel/fork.c > > +++ b/kernel/fork.c > > @@ -792,6 +792,7 @@ void __mmdrop(struct mm_struct *mm) > > mmu_notifier_subscriptions_destroy(mm); > > check_mm(mm); > > put_user_ns(mm->user_ns); > > + mm_pasid_drop(mm); > > free_mm(mm); > > } > > EXPORT_SYMBOL_GPL(__mmdrop); > > @@ -1190,7 +1191,6 @@ static inline void __mmput(struct mm_struct *mm) > > } > > if (mm->binfmt) > > module_put(mm->binfmt->module); > > - mm_pasid_drop(mm); > > mmdrop(mm); > > } > Is this patch a good fix? Will you help push the fix into upstream? Thank you very much! -Fenghua