stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Peter Xu <peterx@redhat.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	David Hildenbrand <david@redhat.com>,
	Yang Shi <shy828301@gmail.com>,
	Konstantin Khlebnikov <khlebnikov@openvz.org>,
	Huang Ying <ying.huang@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>
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	[thread overview]
Message-ID: <20220829105757.352116900@linuxfoundation.org> (raw)
In-Reply-To: <20220829105756.500128871@linuxfoundation.org>

From: Peter Xu <peterx@redhat.com>

[ 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 <peterx@redhat.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Yang Shi <shy828301@gmail.com>
Cc: Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: Huang Ying <ying.huang@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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




  parent reply	other threads:[~2022-08-29 11:10 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-29 10:58 [PATCH 5.10 00/86] 5.10.140-rc1 review Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 01/86] audit: fix potential double free on error path from fsnotify_add_inode_mark Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 02/86] parisc: Fix exception handler for fldw and fstw instructions Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 03/86] kernel/sys_ni: add compat entry for fadvise64_64 Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 04/86] pinctrl: amd: Dont save/restore interrupt status and wake status bits Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 05/86] xfs: prevent a WARN_ONCE() in xfs_ioc_attr_list() Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 06/86] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP* Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 07/86] fs: remove __sync_filesystem Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 08/86] vfs: make sync_filesystem return errors from ->sync_fs Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 09/86] xfs: return errors in xfs_fs_sync_fs Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 10/86] xfs: only bother with sync_filesystem during readonly remount Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 11/86] kernel/sched: Remove dl_boosted flag comment Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 12/86] xfrm: fix refcount leak in __xfrm_policy_check() Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 13/86] xfrm: clone missing x->lastused in xfrm_do_migrate Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 14/86] af_key: Do not call xfrm_probe_algs in parallel Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 15/86] xfrm: policy: fix metadata dst->dev xmit null pointer dereference Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 16/86] NFS: Dont allocate nfs_fattr on the stack in __nfs42_ssc_open() Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 17/86] NFSv4.2 fix problems with __nfs42_ssc_open Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 18/86] SUNRPC: RPC level errors should set task->tk_rpc_status Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 19/86] mm/huge_memory.c: use helper function migration_entry_to_page() Greg Kroah-Hartman
2022-08-29 10:58 ` Greg Kroah-Hartman [this message]
2022-08-29 10:58 ` [PATCH 5.10 21/86] rose: check NULL rose_loopback_neigh->loopback Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 22/86] nfc: pn533: Fix use-after-free bugs caused by pn532_cmd_timeout Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 23/86] ice: xsk: Force rings to be sized to power of 2 Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 24/86] ice: xsk: prohibit usage of non-balanced queue id Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 25/86] net/mlx5e: Properly disable vlan strip on non-UL reps Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 26/86] net: ipa: dont assume SMEM is page-aligned Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 27/86] net: moxa: get rid of asymmetry in DMA mapping/unmapping Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 28/86] bonding: 802.3ad: fix no transmission of LACPDUs Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 29/86] net: ipvtap - add __init/__exit annotations to module init/exit funcs Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 30/86] netfilter: ebtables: reject blobs that dont provide all entry points Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 31/86] bnxt_en: fix NQ resource accounting during vf creation on 57500 chips Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 32/86] netfilter: nft_payload: report ERANGE for too long offset and length Greg Kroah-Hartman
2022-08-29 10:58 ` [PATCH 5.10 33/86] netfilter: nft_payload: do not truncate csum_offset and csum_type Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 34/86] netfilter: nf_tables: do not leave chain stats enabled on error Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 35/86] netfilter: nft_osf: restrict osf to ipv4, ipv6 and inet families Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 36/86] netfilter: nft_tunnel: restrict it to netdev family Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 37/86] netfilter: nftables: remove redundant assignment of variable err Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 38/86] netfilter: nf_tables: consolidate rule verdict trace call Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 39/86] netfilter: nft_cmp: optimize comparison for 16-bytes Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 40/86] netfilter: bitwise: improve error goto labels Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 41/86] netfilter: nf_tables: upfront validation of data via nft_data_init() Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 42/86] netfilter: nf_tables: disallow jump to implicit chain from set element Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 43/86] netfilter: nf_tables: disallow binding to already bound chain Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 44/86] tcp: tweak len/truesize ratio for coalesce candidates Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 45/86] net: Fix data-races around sysctl_[rw]mem(_offset)? Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 46/86] net: Fix data-races around sysctl_[rw]mem_(max|default) Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 47/86] net: Fix data-races around weight_p and dev_weight_[rt]x_bias Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 48/86] net: Fix data-races around netdev_max_backlog Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 49/86] net: Fix data-races around netdev_tstamp_prequeue Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 50/86] ratelimit: Fix data-races in ___ratelimit() Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 51/86] bpf: Folding omem_charge() into sk_storage_charge() Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 52/86] net: Fix data-races around sysctl_optmem_max Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 53/86] net: Fix a data-race around sysctl_tstamp_allow_data Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 54/86] net: Fix a data-race around sysctl_net_busy_poll Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 55/86] net: Fix a data-race around sysctl_net_busy_read Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 56/86] net: Fix a data-race around netdev_budget Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 57/86] net: Fix a data-race around netdev_budget_usecs Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 58/86] net: Fix data-races around sysctl_fb_tunnels_only_for_init_net Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 59/86] net: Fix data-races around sysctl_devconf_inherit_init_net Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 60/86] net: Fix a data-race around sysctl_somaxconn Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 61/86] ixgbe: stop resetting SYSTIME in ixgbe_ptp_start_cyclecounter Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 62/86] rxrpc: Fix locking in rxrpcs sendmsg Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 63/86] ionic: fix up issues with handling EAGAIN on FW cmds Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 64/86] btrfs: fix silent failure when deleting root reference Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 65/86] btrfs: replace: drop assert for suspended replace Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 66/86] btrfs: add info when mount fails due to stale replace target Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 67/86] btrfs: check if root is readonly while setting security xattr Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 68/86] perf/x86/lbr: Enable the branch type for the Arch LBR by default Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 69/86] x86/unwind/orc: Unwind ftrace trampolines with correct ORC entry Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 70/86] x86/bugs: Add "unknown" reporting for MMIO Stale Data Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 71/86] loop: Check for overflow while configuring loop Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 72/86] asm-generic: sections: refactor memory_intersects Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 73/86] s390: fix double free of GS and RI CBs on fork() failure Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 74/86] ACPI: processor: Remove freq Qos request for all CPUs Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 75/86] xen/privcmd: fix error exit of privcmd_ioctl_dm_op() Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 76/86] mm/hugetlb: fix hugetlb not supporting softdirty tracking Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 77/86] Revert "md-raid: destroy the bitmap after destroying the thread" Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 78/86] md: call __md_stop_writes in md_stop Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 79/86] arm64: Fix match_list for erratum 1286807 on Arm Cortex-A76 Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 80/86] Documentation/ABI: Mention retbleed vulnerability info file for sysfs Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 81/86] blk-mq: fix io hung due to missing commit_rqs Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 82/86] perf python: Fix build when PYTHON_CONFIG is user supplied Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 83/86] perf/x86/intel/uncore: Fix broken read_counter() for SNB IMC PMU Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 84/86] scsi: ufs: core: Enable link lost interrupt Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 85/86] scsi: storvsc: Remove WQ_MEM_RECLAIM from storvsc_error_wq Greg Kroah-Hartman
2022-08-29 10:59 ` [PATCH 5.10 86/86] bpf: Dont use tnum_range on array range checking for poke descriptors Greg Kroah-Hartman
2022-08-29 17:19 ` [PATCH 5.10 00/86] 5.10.140-rc1 review Florian Fainelli
2022-08-29 17:56 ` Slade Watkins
2022-08-29 18:41 ` Pavel Machek
2022-08-29 22:19 ` Shuah Khan
2022-08-30  0:47 ` Guenter Roeck
2022-08-30  2:16 ` Daniel Díaz
2022-08-30 10:21 ` Jon Hunter
2022-08-30 10:41 ` Sudip Mukherjee (Codethink)
2022-08-30 11:56 ` Rudi Heitbaum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220829105757.352116900@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=khlebnikov@openvz.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterx@redhat.com \
    --cc=sashal@kernel.org \
    --cc=shy828301@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=vbabka@suse.cz \
    --cc=ying.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).