Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3052803rwe; Mon, 29 Aug 2022 05:11:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR7FK+XtRXRlNohjElRonWyBupug0M47WckTvVux8TbiEzhn7RnM9W9ncq2oULcfyVAHeqNH X-Received: by 2002:a17:90a:eb0e:b0:1fd:9c70:c2c9 with SMTP id j14-20020a17090aeb0e00b001fd9c70c2c9mr9956617pjz.191.1661775091800; Mon, 29 Aug 2022 05:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775091; cv=none; d=google.com; s=arc-20160816; b=VvrAts7Uz3CC2xz33srxHkTBOIYbcJIUHsBnDdC0y3UWcQIHKC/GRx9MIk1ZZpVVNu 2hc+M+A1N6MXhFqQqNS40P+s6yb/L1GNh9t47RhfhL/GDaf/NN1AQHzo4rIlgdiFhoRn FFeZOsQ1aKoXnHl3ONts8AQO2dg+nfIzWI2jOi+QMXMrkxOiHD90Kdi6XpRyi+CIAELT uEmP+P3ot/BCbvObqmW55X0rxmRyyXn41v8WgM7jnPk0blSI8uOZYhomTMvK70Q3V/C9 ZaadHqehyfPuy2UfustZIezEdV3lvPp9F5u6SaYFQJkGKOznnRYDsOfxzt4vE8UFuVjr L9HA== 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=Mrve422qNOSyXokNgeeZxsV35M4LujR5YCPpnXy8/XU=; b=VKxp25Blw8WERLQzznJGRWo19NSW4WR69Bv7gvDnOIE32fv1Dp8X35k/svcJD54yns OoSo2SDzpni9W4eWwnU/ll3WskkS9BpAF3dgO41+NmE25oCZQULWrNOT7sqY+JfpuNdt pgmVJDm9XQz3Q1OqnB3WL5dQZ/cmx7ahOsqRQlGhVyf+Vhm9UoaUV6TQwZ3U4ebKY25o l0iOxNzWiwodiyUNUclPzhAjBw9An/pQrHyrf2jU08UMAb5XjuO+p+tU0gzaoYATzT8A xNuP3elCTmFHJCn2TMWzDiqccXyRY5udmPUwVIemBHoX+nOldYFo57wP9MNjRR861mcG sJqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nr5a2Vlr; 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 n10-20020a170902f60a00b0016dd4c3c2e2si8884813plg.488.2022.08.29.05.11.20; Mon, 29 Aug 2022 05:11:31 -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=nr5a2Vlr; 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 S231448AbiH2LSB (ORCPT + 99 others); Mon, 29 Aug 2022 07:18:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbiH2LRV (ORCPT ); Mon, 29 Aug 2022 07:17:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE2F96CD0C; Mon, 29 Aug 2022 04:11:36 -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 ams.source.kernel.org (Postfix) with ESMTPS id 5B32FB80F98; Mon, 29 Aug 2022 11:11:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C793BC433C1; Mon, 29 Aug 2022 11:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771491; bh=5fD5YTwbU+0/XNyGqfiaf0hqk11P2yRg5wws2o/JuTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nr5a2VlriWiMhLcR0lwz5uGpKQB3f3hV+0KOddTqoCoCUBQOhuscNjYGo4UtWuV3y KGbCRvpbJajBmwdpXwlKMmcAmzyVHvUlKZK5Chh4QZXHpdGqyOXCGXa93W5IIc7bOW HnpGefKHJ0XZrMNlsCLtZ7vQy7qos4g4XGT9bhdw= 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.19 021/158] mm/smaps: dont access young/dirty bit if pte unpresent Date: Mon, 29 Aug 2022 12:57:51 +0200 Message-Id: <20220829105809.698936822@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@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 2d04e3470d4cd..313788bc0c307 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -525,10 +525,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); @@ -558,8 +560,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