* [PATCH] mm/zsmalloc: copy KMSAN metadata in zs_page_migrate()
@ 2026-03-21 13:29 Shigeru Yoshida
2026-03-21 17:48 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Shigeru Yoshida @ 2026-03-21 13:29 UTC (permalink / raw)
To: Minchan Kim, Sergey Senozhatsky, Andrew Morton, Mark-PK Tsai
Cc: Shigeru Yoshida, linux-mm, linux-kernel
zs_page_migrate() uses copy_page() to copy the contents of a zspage
page during migration. However, copy_page() is not instrumented by
KMSAN, so the shadow and origin metadata of the destination page are
not updated.
As a result, subsequent accesses to the migrated page are reported
as use-after-free by KMSAN, despite the data being correctly copied.
Add a kmsan_copy_page_meta() call after copy_page() to propagate the
KMSAN metadata to the new page, matching what copy_highpage() does
internally.
Fixes: afb2d666d025 ("zsmalloc: use copy_page for full page copy")
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
---
mm/zsmalloc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 2c1430bf8d57..79ef9d57f2e1 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1741,6 +1741,7 @@ static int zs_page_migrate(struct page *newpage, struct page *page,
*/
d_addr = kmap_local_zpdesc(newzpdesc);
copy_page(d_addr, s_addr);
+ kmsan_copy_page_meta(zpdesc_page(newzpdesc), zpdesc_page(zpdesc));
kunmap_local(d_addr);
for (addr = s_addr + offset; addr < s_addr + PAGE_SIZE;
--
2.52.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] mm/zsmalloc: copy KMSAN metadata in zs_page_migrate()
2026-03-21 13:29 [PATCH] mm/zsmalloc: copy KMSAN metadata in zs_page_migrate() Shigeru Yoshida
@ 2026-03-21 17:48 ` Andrew Morton
2026-03-22 11:29 ` Shigeru Yoshida
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2026-03-21 17:48 UTC (permalink / raw)
To: Shigeru Yoshida
Cc: Minchan Kim, Sergey Senozhatsky, Mark-PK Tsai, linux-mm,
linux-kernel
On Sat, 21 Mar 2026 22:29:11 +0900 Shigeru Yoshida <syoshida@redhat.com> wrote:
> zs_page_migrate() uses copy_page() to copy the contents of a zspage
> page during migration. However, copy_page() is not instrumented by
> KMSAN, so the shadow and origin metadata of the destination page are
> not updated.
>
> As a result, subsequent accesses to the migrated page are reported
> as use-after-free by KMSAN, despite the data being correctly copied.
>
> Add a kmsan_copy_page_meta() call after copy_page() to propagate the
> KMSAN metadata to the new page, matching what copy_highpage() does
> internally.
>
> Fixes: afb2d666d025 ("zsmalloc: use copy_page for full page copy")
That's three years old. Can anyone suggest why this has only now been
discovered?
>
> ...
>
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -1741,6 +1741,7 @@ static int zs_page_migrate(struct page *newpage, struct page *page,
> */
> d_addr = kmap_local_zpdesc(newzpdesc);
> copy_page(d_addr, s_addr);
> + kmsan_copy_page_meta(zpdesc_page(newzpdesc), zpdesc_page(zpdesc));
> kunmap_local(d_addr);
>
> for (addr = s_addr + offset; addr < s_addr + PAGE_SIZE;
I assume we'll want a cc:stable on this.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] mm/zsmalloc: copy KMSAN metadata in zs_page_migrate()
2026-03-21 17:48 ` Andrew Morton
@ 2026-03-22 11:29 ` Shigeru Yoshida
0 siblings, 0 replies; 3+ messages in thread
From: Shigeru Yoshida @ 2026-03-22 11:29 UTC (permalink / raw)
To: Andrew Morton
Cc: Minchan Kim, Sergey Senozhatsky, Mark-PK Tsai, linux-mm,
linux-kernel
Andrew Morton <akpm@linux-foundation.org> writes:
> On Sat, 21 Mar 2026 22:29:11 +0900 Shigeru Yoshida <syoshida@redhat.com> wrote:
>
>> zs_page_migrate() uses copy_page() to copy the contents of a zspage
>> page during migration. However, copy_page() is not instrumented by
>> KMSAN, so the shadow and origin metadata of the destination page are
>> not updated.
>>
>> As a result, subsequent accesses to the migrated page are reported
>> as use-after-free by KMSAN, despite the data being correctly copied.
>>
>> Add a kmsan_copy_page_meta() call after copy_page() to propagate the
>> KMSAN metadata to the new page, matching what copy_highpage() does
>> internally.
>>
>> Fixes: afb2d666d025 ("zsmalloc: use copy_page for full page copy")
>
> That's three years old. Can anyone suggest why this has only now been
> discovered?
I think it's because KMSAN is clang and x86-64-only, so very few people
run it. Also, this only triggers when compaction actually migrates a
zspage page, which needs significant memory pressure.
Shigeru
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-22 11:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-21 13:29 [PATCH] mm/zsmalloc: copy KMSAN metadata in zs_page_migrate() Shigeru Yoshida
2026-03-21 17:48 ` Andrew Morton
2026-03-22 11:29 ` Shigeru Yoshida
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox