Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1435340lql; Tue, 12 Mar 2024 18:29:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV/XbaTN945b9rz6KNuxImloDuyz3Ip8YSk7ED4w26qksytyHOwTEY1r0UVzFlVfs+QcDbZWzOd6RLZ6a2beq5rf08zXTa/hBqbFyO7eg== X-Google-Smtp-Source: AGHT+IHLVHIBQZ7VhrC/RY9vt99OXca7ayGDYUUDA8C3w7j7eg7D4JwbEbs3+ZgpFK9DBcLIBlks X-Received: by 2002:a05:620a:1193:b0:788:32c4:7d05 with SMTP id b19-20020a05620a119300b0078832c47d05mr11840240qkk.17.1710293379596; Tue, 12 Mar 2024 18:29:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710293379; cv=pass; d=google.com; s=arc-20160816; b=zL+Ak0lesndEeK+8frh7i0r3+R1QocFLLqSH7rlUGzbtUsSltSg+Fv71tgr+aRpeNI VbOyIfbT7Lo9O8Tz+N885Ve2T/677A3iFaQZgGRSfz39xVU3NMBZrJMzwxBDYRYJPZJq UA2O9g+2HoZQcBp4lDj+DrsMLq4qyK5vz6D9CRslou1IBDaZZHIcDRq1McB5cQ/4zndZ rB+ELAnSvaPBXMsCXMJQd4n3WReAig/GZmOu0wh+XSIjhw/JgeogCFz8QrrcS+McATL7 kplc4RlZ2zCWUhoUA6tVJHN7moQsezTzt63Y9UDZ21g0t7LSZe2KpTnzPRAA9cxv7nh3 sf0w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=KJPnevTrjXiGP64+GxnJxbFIjEKKfG0Sz5sPcVm9+iU=; fh=fcD19hXSFGUnjNvjXuo5CWHUlWeTjvAdIZ3yBUGWUAQ=; b=vwY4ia7lCIVYdaUDXSif5/GV6qWDG98H6IWhOMqh+Wft29hpFtoMOXAXn1ylBJaYe2 Ttonb81jP4bY2O5jxXQGy/zaMVBJmSTTQFPZU8gujtxvFj2S4MD1urUwasUY8xDhs6jP LmK0oAOdX7cCQ94WdwfJJv/9Y+D2ieAR5gGwrHnraui+D7l68mRRqMhbTH82588gvJ27 KTbxmLRCwHWeVPKwNkcWhOH32WeSSWGrAmobpjbkNVI9o5P5Le3l14yIWYIBlrwyPB6g m6h1NEOkV7+au5KoUjbVlfwkZePm34Dbv7UjhsvptA9hsz0TknqqIUhTrd1p/Vfozd+8 jEfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-101016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101016-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id vw16-20020a05620a565000b007882d72663bsi8629362qkn.659.2024.03.12.18.29.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 18:29:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-101016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101016-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 527431C21373 for ; Wed, 13 Mar 2024 01:29:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53D08BA2B; Wed, 13 Mar 2024 01:29:33 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC350B652 for ; Wed, 13 Mar 2024 01:29:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710293372; cv=none; b=i90FSQ/L4GRQeOMGUx7WBvvPqNfVd1c1pzqEUPA1KRTn9qATUL3WdBAmCvVMYw0Hw7k4jYDWepIDwh/xC4mbWOqpvrGzYEss4Hqrgfpv8IPTV+ZQGhXpD2vVW/CtRGzzOMm8chMJmpve9FwFYyXDB2I1xDmb/qH7MGM3z/CISGo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710293372; c=relaxed/simple; bh=UJlpHkjPoNvC6jxkYpAzHDrDK0oNnOtTFuq6EhLz/48=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=XLfysyIZssQs5AK9r4l4dZmzJ3wG3KqrP4PYIDSq6e/oBEY36V1yhb2HDlctgNIyeHisy33Ba0S07T4SWLS/f+fZZ95TXgCJVdDJ8W6kvVdFZ5wLjyL/qJ3ehBqcQ/bjQxD8L1YsQtaZB01JA3Ytbt0E9lzwXcIc9eWimLS5l1I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4TvXt75qYSzXj3j; Wed, 13 Mar 2024 09:26:55 +0800 (CST) Received: from kwepemm600020.china.huawei.com (unknown [7.193.23.147]) by mail.maildlp.com (Postfix) with ESMTPS id 3C9FF18007B; Wed, 13 Mar 2024 09:29:21 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 13 Mar 2024 09:29:20 +0800 From: Peng Zhang To: , CC: , , , , , , , , , , Subject: [PATCH] filemap: replace pte_offset_map() with pte_offset_map_nolock() Date: Wed, 13 Mar 2024 09:29:13 +0800 Message-ID: <20240313012913.2395414-1-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600020.china.huawei.com (7.193.23.147) From: ZhangPeng The vmf->ptl in filemap_fault_recheck_pte_none() is still set from handle_pte_fault(). But at the same time, we did a pte_unmap(vmf->pte). After a pte_unmap(vmf->pte) unmap and rcu_read_unlock(), the page table may be racily changed and vmf->ptl maybe fails to protect the actual page table. Fix this by replacing pte_offset_map() with pte_offset_map_nolock(). Fixes: 58f327f2ce80 ("filemap: avoid unnecessary major faults in filemap_fault()") Suggested-by: David Hildenbrand Signed-off-by: ZhangPeng --- mm/filemap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 31ab455c4537..222adac7c9c5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3207,7 +3207,8 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf) if (!(vmf->flags & FAULT_FLAG_ORIG_PTE_VALID)) return 0; - ptep = pte_offset_map(vmf->pmd, vmf->address); + ptep = pte_offset_map_nolock(vma->vm_mm, vmf->pmd, vmf->address, + &vmf->ptl); if (unlikely(!ptep)) return VM_FAULT_NOPAGE; -- 2.25.1