* [PATCH] mm: fix cachestat NULL pgdat dereference on DAX mappings
@ 2026-11-23 3:00 Henry Martin
2026-11-24 2:58 ` sashiko-bot
2026-11-24 12:42 ` Jan Kara
0 siblings, 2 replies; 5+ 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] 5+ 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
2026-11-24 12:42 ` Jan Kara
1 sibling, 0 replies; 5+ 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] 5+ 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
@ 2026-11-24 12:42 ` Jan Kara
2026-11-24 15:58 ` Nhat Pham
1 sibling, 1 reply; 5+ messages in thread
From: Jan Kara @ 2026-11-24 12:42 UTC (permalink / raw)
To: Henry Martin
Cc: Matthew Wilcox, Jan Kara, Andrew Morton, Nhat Pham,
Johannes Weiner, linux-fsdevel, linux-mm, stable
On Mon 23-11-26 11:00:14, Henry Martin wrote:
> 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>
I think that for DAX mappings, cachestat should just return all zeros
because none of the fields really make sense there. There's simply no page
cache for DAX mappings.
Honza
> ---
> 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
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] mm: fix cachestat NULL pgdat dereference on DAX mappings
2026-11-24 12:42 ` Jan Kara
@ 2026-11-24 15:58 ` Nhat Pham
2026-11-25 3:13 ` henry martin
0 siblings, 1 reply; 5+ messages in thread
From: Nhat Pham @ 2026-11-24 15:58 UTC (permalink / raw)
To: Jan Kara
Cc: Henry Martin, Matthew Wilcox, Andrew Morton, Johannes Weiner,
linux-fsdevel, linux-mm, stable
On Tue, Nov 24, 2026 at 5:42 AM Jan Kara <jack@suse.cz> wrote:
>
> On Mon 23-11-26 11:00:14, Henry Martin wrote:
> > 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>
>
> I think that for DAX mappings, cachestat should just return all zeros
> because none of the fields really make sense there. There's simply no page
> cache for DAX mappings.
>
> Honza
+1. This sounds good to me.
Henry, would you mind sending v2 along this line?
(and maybe add some documentation).
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] mm: fix cachestat NULL pgdat dereference on DAX mappings
2026-11-24 15:58 ` Nhat Pham
@ 2026-11-25 3:13 ` henry martin
0 siblings, 0 replies; 5+ messages in thread
From: henry martin @ 2026-11-25 3:13 UTC (permalink / raw)
To: Nhat Pham
Cc: Jan Kara, Matthew Wilcox, Andrew Morton, Johannes Weiner,
linux-fsdevel, linux-mm, stable
> +1. This sounds good to me.
>
> Henry, would you mind sending v2 along this line?
>
> (and maybe add some documentation).
Sure, v2 sent: cachestat() now skips the xarray walk for DAX mappings
and reports all zeros, and the behaviour is documented in the syscall's
kernel-doc.
Link: https://lore.kernel.org/linux-mm/20261125030432.274396-1-bsdhenrymartin@gmail.com/
Thanks,
Henry
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-25 3:13 UTC | newest]
Thread overview: 5+ 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
2026-11-24 12:42 ` Jan Kara
2026-11-24 15:58 ` Nhat Pham
2026-11-25 3:13 ` henry martin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.