Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: fix cachestat NULL pgdat dereference on DAX mappings
@ 2026-11-23  3:00 Henry Martin
  2026-11-24  2:58 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Henry Martin @ 2026-11-23  3:00 UTC (permalink / raw)
  To: Matthew Wilcox, Jan Kara, Andrew Morton, Nhat Pham,
	Johannes Weiner
  Cc: linux-fsdevel, linux-mm, Henry Martin, stable

filemap_cachestat() treats every xarray value entry as a workingset
shadow.  On DAX mappings, value entries are DAX exceptional entries:
same value bit, different bit layout (flags in the low bits, pfn
above).  Decoded as a shadow, a DAX entry yields a bogus node id;
NODE_DATA() for it can be NULL, and lru_gen_test_recent() then
dereferences it:

  Oops: general protection fault
  RIP: 0010:lru_gen_test_recent+0xde/0x300
  Call Trace:
   workingset_test_recent
   filemap_cachestat
   __x64_sys_cachestat

Any writable file on a DAX mount triggers this once an mmap write
fault has populated entries.

DAX entries track present pages, not evicted folios.  Count them as
cached and skip the workingset decode, mirroring the dax_mapping()
split in the invalidation paths in mm/truncate.c.  PMD-order entries
are counted as one page, as value entries carry no order information.

This issue was discovered by Tencent CodeBuddy Security.
Cc: stable@vger.kernel.org
Fixes: cf264e1329fb ("cachestat: implement cachestat syscall")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 mm/filemap.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/mm/filemap.c b/mm/filemap.c
index a1b2ca5b933c..caad0adde792 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -4694,6 +4694,16 @@ static void filemap_cachestat(struct address_space *mapping,
 			void *shadow = (void *)folio;
 			bool workingset; /* not used */
 
+			/*
+			 * DAX exceptional entries track present pages, not
+			 * evicted folios.  They must not be decoded as
+			 * workingset shadows.
+			 */
+			if (dax_mapping(mapping)) {
+				cs->nr_cache += nr_pages;
+				goto resched;
+			}
+
 			cs->nr_evicted += nr_pages;
 
 #ifdef CONFIG_SWAP /* implies CONFIG_MMU */
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-24  2:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  3:00 [PATCH] mm: fix cachestat NULL pgdat dereference on DAX mappings Henry Martin
2026-11-24  2:58 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox