]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/zsmalloc: copy KMSAN metadata in zs_page_migrate()
authorShigeru Yoshida <syoshida@redhat.com>
Sat, 21 Mar 2026 13:29:11 +0000 (22:29 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 5 Apr 2026 20:53:34 +0000 (13:53 -0700)
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.

Link: https://lkml.kernel.org/r/20260321132912.93434-1-syoshida@redhat.com
Fixes: afb2d666d025 ("zsmalloc: use copy_page for full page copy")
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/zsmalloc.c

index e7417ece1c12ebe058486ceeb9aa3f265b1e6583..63128ddb79598fe3fff546ee0205e6689b391b3a 100644 (file)
@@ -1753,6 +1753,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;