Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3075749rwe; Mon, 29 Aug 2022 05:32:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR727M4QMcYDUC5VqekCOfxSfBNkHtE0R7vHfYq6pBWTJIZIsewjGlGiNNp+OwpKI04Y9A4a X-Received: by 2002:a17:90b:1bca:b0:1fb:7eaf:8955 with SMTP id oa10-20020a17090b1bca00b001fb7eaf8955mr18612006pjb.37.1661776358024; Mon, 29 Aug 2022 05:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661776358; cv=none; d=google.com; s=arc-20160816; b=fX7lMidT/X5J6U4xbgmljLQpOGZ8ackMbi/hEEzvZ9ytcZ930ZTOouiHywVb5c3Iux VkD96gXQB4IuVkOmu802+QJSCWvDkIpykCOxPtC3IOeRt+NSVuPqCCGl8+kItfb2TvWb spfWglDr0S6l1ZP48IKiUkWQZ3hlXe13YLWD2sKa4SQe20XEjGwV3hWY2oM5ctLjJYI8 pxPyzNim5LGcMJ8Rnh0zTOHyrgXAgc6HPPYjGkM+TAFqvTrCI6bigN+zLiMgCtK33Pko 5TQzXoG/fOhOV6spwp+3Qtwd8FT7bNqLcBrCJ+2rn9dcXH9SfmWtXWgEVIgwa2vaJ4/x aCEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kYQZlPlZbwBpr3HlkJTg+bIGUKv1HE42GDnWA/8m4ls=; b=UvAFxD+qsFu6C8xgBqktkf1I9sK4EDGkFO373jZ+8QPbBfnroG0/qbUWNl9khuoaAA IY2ATlL/WQsutEw7XWMx3F0WdyS40gjh6VFPeML0mxLIDy0r+XooT6nNepk62det9dLg B1CCSyUn/NmCUX3GVrSk77aImG/o5+UGEKzPA7J1iWRaNaEq2lf5i67w0BWszEdPXuY8 EhR6xy9/WvZVvgFSbBZuc3EzCp4DWMrjKomxdH572gwqnSQ15dQHEfKIG1SB5Q7DJSBp N0qRlIhFFxRDCeP3nwxUmvpdvYe/czOGZGyw3UzIM3+YTjsRy5shQKT5lQm3CVkg8F5B KBCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GYBQnLmd; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jc13-20020a17090325cd00b00170a468c50dsi8476050plb.275.2022.08.29.05.32.25; Mon, 29 Aug 2022 05:32:38 -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=@linuxfoundation.org header.s=korg header.b=GYBQnLmd; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230124AbiH2LKd (ORCPT + 99 others); Mon, 29 Aug 2022 07:10:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbiH2LJk (ORCPT ); Mon, 29 Aug 2022 07:09:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59DE67148; Mon, 29 Aug 2022 04:06:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 77E01611B0; Mon, 29 Aug 2022 11:04:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8454EC433D6; Mon, 29 Aug 2022 11:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771092; bh=d3HKlBsXcLeK4mkuebyAltdj5guPsJxMc7cwL4yHCM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GYBQnLmd9ECJk9L3lFMFg63vkBhJvRoWSMPl203CEuYzZP3YXFA/hZrSs178VfJ3k Wig+qsc0y4YuGjyqJxj47noYMN6Xm4Al3DAvPUnHcakUu8EyE2GYH0BMXhYI7tliIC TtLNHB6JGguXlfTOF3f8FVseAVz8aoVL/riKhahg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Xu , Vlastimil Babka , David Hildenbrand , Yang Shi , Konstantin Khlebnikov , Huang Ying , Andrew Morton , Sasha Levin Subject: [PATCH 5.10 20/86] mm/smaps: dont access young/dirty bit if pte unpresent Date: Mon, 29 Aug 2022 12:58:46 +0200 Message-Id: <20220829105757.352116900@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105756.500128871@linuxfoundation.org> References: <20220829105756.500128871@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 From: Peter Xu [ Upstream commit efd4149342db2df41b1bbe68972ead853b30e444 ] These bits should only be valid when the ptes are present. Introducing two booleans for it and set it to false when !pte_present() for both pte and pmd accountings. The bug is found during code reading and no real world issue reported, but logically such an error can cause incorrect readings for either smaps or smaps_rollup output on quite a few fields. For example, it could cause over-estimate on values like Shared_Dirty, Private_Dirty, Referenced. Or it could also cause under-estimate on values like LazyFree, Shared_Clean, Private_Clean. Link: https://lkml.kernel.org/r/20220805160003.58929-1-peterx@redhat.com Fixes: b1d4d9e0cbd0 ("proc/smaps: carefully handle migration entries") Fixes: c94b6923fa0a ("/proc/PID/smaps: Add PMD migration entry parsing") Signed-off-by: Peter Xu Reviewed-by: Vlastimil Babka Reviewed-by: David Hildenbrand Reviewed-by: Yang Shi Cc: Konstantin Khlebnikov Cc: Huang Ying Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- fs/proc/task_mmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index ba98371e9d164..ef18f0d71b11b 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -503,10 +503,12 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, struct vm_area_struct *vma = walk->vma; bool locked = !!(vma->vm_flags & VM_LOCKED); struct page *page = NULL; - bool migration = false; + bool migration = false, young = false, dirty = false; if (pte_present(*pte)) { page = vm_normal_page(vma, addr, *pte); + young = pte_young(*pte); + dirty = pte_dirty(*pte); } else if (is_swap_pte(*pte)) { swp_entry_t swpent = pte_to_swp_entry(*pte); @@ -540,8 +542,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, if (!page) return; - smaps_account(mss, page, false, pte_young(*pte), pte_dirty(*pte), - locked, migration); + smaps_account(mss, page, false, young, dirty, locked, migration); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE -- 2.35.1