Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp1993147lfo; Sat, 28 May 2022 13:01:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBkPh8xD7D2MR4VsDCMfydNR/9HWtElgOduJYwO8jS9BYfT2k3tmz5MivhRFfczDJ5Knr2 X-Received: by 2002:a05:6a00:3495:b0:518:5199:c58a with SMTP id cp21-20020a056a00349500b005185199c58amr44666750pfb.58.1653768089111; Sat, 28 May 2022 13:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653768089; cv=none; d=google.com; s=arc-20160816; b=tv/kQt/yEYYqsdpBptThpNP1JZZTwfaftWU5/YIIjCOkG70o0CaxPd1kuopR7Xy1uN wST0096vOCjeNdwn1mmt7lbS0Uw9mxZEZPy1Lw0PpwuJh9J5aBP1heWh+c82dCBEfO7I 7AoEGAm5shZbBfjH6DQkvnCXi/4tSPb6RHS/3PDbPck805j2q+nz6fVW0gxXtx9xb0qm QsuEUQ1Whjhvdl7EwcO6PSZFWAPqWSxTMG/gY9kSikkpRhyIkMhJFf0jknynCw7e5t64 UGliZ0lFCyeAWgbZggg4k7+7AiTUgo/wuDqOexPO8jpDNQyjt6C1p22fIp4kSt0uboAf 9lvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=uIxK9C61XlALbRdAEap35isITmKB6SHb6MKDHxeJOLA=; b=MAgZ9cXUAwj/MUhdhI6n4yLXs8nwAHtU9OAMNZ1ckmuMI6GXBHqAp/S7G0TieEwpE+ w/30h0NDPzaaOFqRq5WijGjCvxEQUlYW6kHZMsmGvvZ5mEpkNWRZmFcb+YP6lexxOEOZ L9WI3QrWt/ftgHk9agNzxIX72RktG7GIHfdwhQGIEnJTFWd4NVmdwwVaA0a0Eu7EY/Z/ ZPvkxnBfyGKloX0mTN0vzeNhalPHi4nz8ro+DQnT5qnCqaa4szgNcPnTA84lgzt8K6zm s8gLCS/ljwwx2Lx5kiDukThwvRG4yVloKjOCvSVqfGS0kjt1QnEdiQodh10wfZ7eMLcG 8odA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5mVneQRp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d4-20020a17090a498400b001df5bbb50c0si2005526pjh.47.2022.05.28.13.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:01:29 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5mVneQRp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 979722981C; Sat, 28 May 2022 12:19:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240798AbiEZNXc (ORCPT + 99 others); Thu, 26 May 2022 09:23:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233189AbiEZNX3 (ORCPT ); Thu, 26 May 2022 09:23:29 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4856ED809B for ; Thu, 26 May 2022 06:23:28 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id t28so1315087pga.6 for ; Thu, 26 May 2022 06:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=uIxK9C61XlALbRdAEap35isITmKB6SHb6MKDHxeJOLA=; b=5mVneQRp1xgwPMnkJY6c5qQOroCs4jkOmuB9nncRs6fnUnqyrV2qBEWAqFA4BlwtUC tNk4NQJQ9i8iGVyHA9cLgFkJMqkvKyJ+7tO1CIKcgxf5tU/582UcN0Z31SNXHI4JKOI4 pR4tmus62ZuFKjxr716UdilEuC2KqELG5u4EWEA4p767IMO8AU4AQzs3yUsXuAHDg1b7 bCTXKv9Ef3RwWLQqcSeu685UB9RgSlZfZsUgO7EAceXYWWRfWG5BRK22cr9v5bCZLzPS +Y5lMZRxHpza8sCLGVPIm6VIDKfI1QZcgvheff8mw/ARbDc04ty8Y/z+sWrHem30BrPK TFHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=uIxK9C61XlALbRdAEap35isITmKB6SHb6MKDHxeJOLA=; b=a8Mai8IZDXHVuKtZat3PLy/JX2QUBua2RcnPrvsDfsXG+UDQfVYjszfA4h+/ek/m0C QcLx1qSzKtcmLdC4bzElUL/PNUzgcJPOJkM+DcHRGT3Z9zZb5p1+qMtush8MiJpiZ3k0 poOIfq7Tnyle3lTdpbZm5EDJ6oLlZ7MLl440YFuiIhZuWqQlZf9aneKY3Ii0MbPqHttb CWYXH9Hhh+6rj8Aolhdld/+wvj78XLjW5g//EmkMjfb5ktiyspkD7BSFg3PAv9gp5FeU Tl5CSX3ZHB6+4Dy1oKjW7/NKcUB24xhE1PQ6mt9ubNUy4FUfumWRVbkJf6BqSRrrwAm3 VhHA== X-Gm-Message-State: AOAM531P8AsR0Js2mXPuLwMUVItmGyKsr3OeLvPY/iNgZKIan/e45/vI C3djFpaacGCATiES0VsNy3kigQ== X-Received: by 2002:aa7:8d47:0:b0:4f6:a7f9:1ead with SMTP id s7-20020aa78d47000000b004f6a7f91eadmr38855819pfe.42.1653571407802; Thu, 26 May 2022 06:23:27 -0700 (PDT) Received: from [10.5.103.226] ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id v16-20020a17090abb9000b001e09cab8893sm3584055pjr.42.2022.05.26.06.23.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 May 2022 06:23:27 -0700 (PDT) Message-ID: Date: Thu, 26 May 2022 21:23:22 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] mm/page_table_check: fix accessing unmapped ptep Content-Language: en-US To: Pasha Tatashin Cc: Miaohe Lin , Andrew Morton , David Rientjes , linux-mm , LKML References: <20220526113350.30806-1-linmiaohe@huawei.com> <09f38cf3-282a-61fa-9916-057b01b57d30@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 2022/5/26 9:11 PM, Pasha Tatashin wrote: > On Thu, May 26, 2022 at 9:04 AM Qi Zheng wrote: >> >> >> >> On 2022/5/26 7:33 PM, 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. >> >> In the beginning, page_table_check only supported x86_64, so there >> is no problem. But then the commit 3fee229a8eb9 ("riscv/mm: enable >> ARCH_SUPPORTS_PAGE_TABLE_CHECK") added support for riscv-32, it is >> indeed a problem in this case. > > pte_unmap() is needed only with CONFIG_HIGHPTE. I do not see this > config for riskv-32? My bad, but it's better to call pte_unmap() after the check is done. > > Pasha > >> >> So: >> >> Reviewed-by: Qi Zheng >> >>> >>> 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); >>> } >>> } >> >> -- >> Thanks, >> Qi -- Thanks, Qi