Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2386484ioo; Sat, 28 May 2022 12:02:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKfsTBt/GI/wIrSsQRy6XLSZVXUQjjp1jEr6q/efvsuBaShmRuYMowpqnLTfk+P8OMMYc5 X-Received: by 2002:a17:90a:1b09:b0:1e2:754d:aec with SMTP id q9-20020a17090a1b0900b001e2754d0aecmr10864625pjq.171.1653764553688; Sat, 28 May 2022 12:02:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653764553; cv=none; d=google.com; s=arc-20160816; b=jnPITntUO+M9F4+hqDRucBRO0q8+SyxoNnVel24iJQA9H3JasrIQfo8esP+iAPNGGf UXWnPNgakzka3isY9R+rWiv0naFTvQpeGpHBvsDkAg6zn26C3jYKkAtAB/jIDS2o5SaG nVkKNvHgFu5/TEDWye7oAAP8Yp3PBynMXWRYKRXKox8oEB7MEP+DbYC4gMafgv378VZ/ 2jyT38dle7TsDW7bGlU2CcBtw6ETUv0yxJzU5C3lzBFmNFO1a8m3SxIiKsPjXquwQHK7 T66ibEPGxFpsgtjOYIDGvsUbaLpmhF7xFCK7YTVpSaqqTQeXb+QWQpoHJTJBGPY0s3Tn Qelg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zZ9DAhCNK6+O0V4masvprPNhs/nf8Fvi/U/e6pxEsj0=; b=MWTRY6Jq0XF3MzFPJ6opxzmuv8wTz4dtDFST5R/h0nqvqFeoUOk/V4XVTctRya2haG yhQ7g0GWGcmeTHM5qKEaTyAVoKXCQlwJO0G8xu1zvepkAm7gMCjFt1f2ZNLwPsLqc6A8 QarHU6mYWn7ZUDknyYyQUpx5sy4EP7ZZWxeP5k7Vj/l7wU/p3bJ+K7UZALgj51Z9PN1R iTDFAiQqf2tjpTu7e1+uVD1hfxJoWNgA8wrooebEAFnEyLCyTAoT6hWbm3vHaMhRf3MW iYaTL2orNzwkgMyYbNZNsvKyyV5iYLNVZRnqwkcNhmJOtoFE3AgKwKUghStnVQ9A5Jxy bnsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=T4I1s68X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j3-20020a17090276c300b0016206c77292si8634220plt.277.2022.05.28.12.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 12:02:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=T4I1s68X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6924E3B2B6; Sat, 28 May 2022 11:44:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232366AbiEZNiZ (ORCPT + 99 others); Thu, 26 May 2022 09:38:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231466AbiEZNiW (ORCPT ); Thu, 26 May 2022 09:38:22 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A068658E52 for ; Thu, 26 May 2022 06:38:21 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id i27so3003227ejd.9 for ; Thu, 26 May 2022 06:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zZ9DAhCNK6+O0V4masvprPNhs/nf8Fvi/U/e6pxEsj0=; b=T4I1s68XXJRufZfuiZ1VZqCrjcDXks8TmQ8oOs2CAd82x1Ea5MYgXQ/hfb66CkrVKh 5xOeCj8uHt2B+CgY6Q9qIMpIvsttNrIw4aGRB/7PctSnXHNgMY251O68aaf6GrtMnSxw Doy1oSWuSM7cQ7+q6k1B60IEafItMK0tUJHf/44SIx2D66qkNgFXDF6L2grXHIvKPwCO vHXqTLPG6SIeYKbhzT09p+jRk/c2LO6ko+9+u/LDyxvtUREQCd98SebqpPmUHdMuXze2 qXgOaZV4I7bUXjTMWtzpwUa3WnqrYGrGciOuF8smnswGCoeRXOcELI9l1MOExdSN7yj7 tMzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zZ9DAhCNK6+O0V4masvprPNhs/nf8Fvi/U/e6pxEsj0=; b=v44zFuIluDT7iPOD4EvxJyoxDtRa/UGuibtUR6+zoKE42+K0lXfLnR1gTH+QTOeRNP roh54mVlbjZjVLjh2Zb6M79aeY19NZrZmrWxDXibse34UuEe4JQaY8ToQyFNS5EP0eM1 MXIhJSCAWlgaKA5ulBaBOKUfdW+GQknlAsJopoS8KNJxpDshTolbOGhR/7Z7SZhAmELW 1yQwoDkeFuwxLB4nqwCMHJlgvS0IMYg64jYASw2+0+kfrNnmQRFY8/Qu50oH+Y9ieet0 Tp/JO9m9o5yTQuIEp77kIyIlcrTqCVqptT/h219kM/HXlHHxRkBy5O7H+ZlGDRbDo/Ym he0Q== X-Gm-Message-State: AOAM531QVRTpGXlaC7fcl5EStT96DOk3v8xhyK/dLbqLQTKZxtG+QBYT oozoeOXMMaq3Oqh7WXGol+euX5+3alwl7WLCGZGh+ejBvhheGg== X-Received: by 2002:a17:906:9b86:b0:6fe:d37f:b29d with SMTP id dd6-20020a1709069b8600b006fed37fb29dmr19980411ejc.327.1653572300197; Thu, 26 May 2022 06:38:20 -0700 (PDT) MIME-Version: 1.0 References: <20220526113350.30806-1-linmiaohe@huawei.com> In-Reply-To: From: Pasha Tatashin Date: Thu, 26 May 2022 09:37:43 -0400 Message-ID: Subject: Re: [PATCH] mm/page_table_check: fix accessing unmapped ptep To: Matthew Wilcox Cc: Miaohe Lin , Andrew Morton , David Rientjes , linux-mm , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 9:34 AM Matthew Wilcox wrote: > > 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. Right, thank you Matthew. Miaohe, please store the ptep, or maybe drop this patch entirely. Thanks, Pasha