Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp656025ioo; Thu, 26 May 2022 11:27:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwp4XMNF8dmKdjr+TCExrbjCxFmtH4sMdqbIzg4mxHHC6nKBtMeA03ljCavURTvcd/JGXFl X-Received: by 2002:a17:90a:600f:b0:1e0:cc4f:b72d with SMTP id y15-20020a17090a600f00b001e0cc4fb72dmr3929083pji.56.1653589676736; Thu, 26 May 2022 11:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653589676; cv=none; d=google.com; s=arc-20160816; b=WV2RDoWamkcVUznWUwB3S+5dFqydpuNtS4RDpHZhEo02rB65R1zLatfRcLmygV4AdR 4Gd24O8OcgtFYGhqwCtRwsi69ExYrLebkyQklJ30TUZ31eHw0ophkr222cR+DlacsR3g Aoiy3QB9NhSfXPWlXNJY4moOUhR+kNMAbWs9nNY9OlqAlx/oannyOKWXPr20OGr431Sr DqWHbQSK6BdafetAwuNFKJuYYDOfmAmp1SiYbjRHI13YYFY60bNsNsmWCqnFc2EgP/x3 KgNXeghNMBGRyQATOI/Lf/kte1/ZShHCQEfDBIqsuUrJ5bxUlW3mgUEh7tiyMNoP/O+4 OCxQ== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SlbzwgeVcIbkiDLid8eYrVjR73Fsp4oET2KHh+9DwAY=; b=uW07vpt0JBgzmp2G0WNEBSTjOC+SKIQLj4jdvkPYvfdgCoj7uPTnJSLVo1mcd+LSd3 HSVpAtP7qe76QVfy/yCVE3dGdSI4VkLEU3Tw0+cgi2xnniInugtwXAJEuyagNb0ZKyOL oL3iY51Oh8fzJBVINorNT9yusflpQY5FKOe/Pe76Oj85plNcq805piNOx5J91sUSNeg7 rbKzzQlvmdvxsRf70tc9Ga2oy9OYdprO4FQIO4TzY0kHzQ+pqeMaaWGsVIvs5feonRHU JWnbrV5dH5qtJSOp3DB0L/dgmC7huHtNh0ZSdfCve6pS8smJ2T62RyUThXet4NelGnpg XlOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HC5DPeqs; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5-20020a17090a74c500b001e02916daccsi2963532pjl.32.2022.05.26.11.27.44; Thu, 26 May 2022 11:27:56 -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=@infradead.org header.s=casper.20170209 header.b=HC5DPeqs; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347616AbiEZNfK (ORCPT + 99 others); Thu, 26 May 2022 09:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347650AbiEZNew (ORCPT ); Thu, 26 May 2022 09:34:52 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09063DFF69 for ; Thu, 26 May 2022 06:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=SlbzwgeVcIbkiDLid8eYrVjR73Fsp4oET2KHh+9DwAY=; b=HC5DPeqs8vrqrrDyfcDTUyvArs MLHy0inxmzbEGqRQQpStnYry1aptGoD6Hm3nq9gM8X5GxKptCCA8dhZ/4jzrYDBO21d5HB4xQLsVV qlKKntVjewPTgGS8TwQLS7eqJS5mNhMyllcsnKuPUAGqXZQBowB1Es3yBi4ninf2bo3JtjQIrLs4U 2O3evDVyqbJIbenC2u1ExWO29id/sftoUY6ZiC8oRdPt83irlDxlFVQO/4Oc9a1aZPzc8gVNIv1Nb I83hEqExyoiwTzAPI+EeEKEt+im338CLoQpC9RnsGe4+iygXY/r5iL719YLV1cU35RjtMgCkvkZfn vlZjPGew==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nuDdB-001HHa-6e; Thu, 26 May 2022 13:34:25 +0000 Date: Thu, 26 May 2022 14:34:25 +0100 From: Matthew Wilcox To: Miaohe Lin Cc: akpm@linux-foundation.org, pasha.tatashin@soleen.com, rientjes@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/page_table_check: fix accessing unmapped ptep Message-ID: References: <20220526113350.30806-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220526113350.30806-1-linmiaohe@huawei.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On Thu, May 26, 2022 at 07:33:50PM +0800, Miaohe Lin wrote: > ptep is unmapped too early, so ptep will be accessed while it's unmapped. > Fix it by deferring pte_unmap() until page table checking is done. > > Fixes: 80110bbfbba6 ("mm/page_table_check: check entries at pmd levels") > Signed-off-by: Miaohe Lin > --- > mm/page_table_check.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/page_table_check.c b/mm/page_table_check.c > index 3692bea2ea2c..971c3129b0e3 100644 > --- a/mm/page_table_check.c > +++ b/mm/page_table_check.c > @@ -234,11 +234,11 @@ void __page_table_check_pte_clear_range(struct mm_struct *mm, > pte_t *ptep = pte_offset_map(&pmd, addr); > unsigned long i; > > - pte_unmap(ptep); > for (i = 0; i < PTRS_PER_PTE; i++) { > __page_table_check_pte_clear(mm, addr, *ptep); > addr += PAGE_SIZE; > ptep++; > } > + pte_unmap(ptep); But ptep was mutated in the loop. So surely this needs to be: pte_unmap(ptep - PTRS_PER_PTE); or you'll be unmapping the wrong page.