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

* Re: [PATCH] mm: fix cachestat NULL pgdat dereference on DAX mappings
  2026-11-23  3:00 [PATCH] mm: fix cachestat NULL pgdat dereference on DAX mappings Henry Martin
@ 2026-11-24  2:58 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-24  2:58 UTC (permalink / raw)
  To: Henry Martin, Matthew Wilcox, Jan Kara, Andrew Morton, Nhat Pham,
	Johannes Weiner
  Cc: linux-mm

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mm: skipped dirty accounting for DAX entries in
  filemap_cachestat()
- [Low] mm: inaccurate commit message claim on PMD-order DAX entry count
--

commit 00a07291e64203188f9848c4b4c587fb6f5215ca
Author: Henry Martin <bsdhenrymartin@gmail.com>

mm: fix cachestat NULL pgdat dereference on DAX mappings

This commit avoids decoding DAX exceptional value entries as workingset
shadows in filemap_cachestat(), counting them as cached pages instead.

> PMD-order entries
> are counted as one page, as value entries carry no order information.

[Severity: Low]
Is this statement in the commit message accurate?

dax_iomap_pmd_fault() and dax_insert_pfn_mkwrite() insert PMD entries with
XA_STATE_ORDER(..., PMD_ORDER), and filemap_cachestat() derives nr_pages
from xas_get_order(&xas) before checking xa_is_value(folio), so PMD-order
DAX entries are counted across all pages they cover.

> diff --git a/mm/filemap.c b/mm/filemap.c
> index dc0ceaa58a0f7..5d12230de32d9 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -4706,6 +4706,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 */

[Severity: Medium]
Does jumping to resched here skip cs->nr_dirty accounting for dirty DAX
entries?

DAX marks dirty exceptional entries with PAGECACHE_TAG_DIRTY in
mapping->i_pages (via dax_insert_entry() and dax_insert_pfn_mkwrite())
until writeback flushes CPU caches.  Because the in-cache path below only
queries &xas and never dereferences folio, guarding the evicted branch
with "if (xa_is_value(folio) && !dax_mapping(mapping))" would avoid
duplicating cs->nr_cache += nr_pages and preserve cs->nr_dirty reporting
via xas_get_mark(&xas, PAGECACHE_TAG_DIRTY).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123030014.3116755-1-bsdhenrymartin@gmail.com?part=1


^ permalink raw reply	[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