zsmalloc: reset compaction source zspage pointer after putback_zspage()
authorSergey Senozhatsky <senozhatsky@chromium.org>
Mon, 17 Apr 2023 13:08:50 +0000 (22:08 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 18 Apr 2023 23:29:42 +0000 (16:29 -0700)
commitf7ddb612568361e04d53fcd984d43d1c32c1294a
treed3e93453b37ba48c5ad598a64d3103b654178920
parent5f300fd59a2ae90b8a7fb5ed3d5fd43768236c38
zsmalloc: reset compaction source zspage pointer after putback_zspage()

The current implementation of the compaction loop fails to set the source
zspage pointer to NULL in all cases, leading to a potential issue where
__zs_compact() could use a stale zspage pointer.  This pointer could even
point to a previously freed zspage, causing unexpected behavior in the
putback_zspage() and migrate_write_unlock() functions after returning from
the compaction loop.

Address the issue by ensuring that the source zspage pointer is always set
to NULL when it should be.

Link: https://lkml.kernel.org/r/20230417130850.1784777-1-senozhatsky@chromium.org
Fixes: 5a845e9f2d66 ("zsmalloc: rework compaction algorithm")
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reported-by: Yu Zhao <yuzhao@google.com>
Tested-by: Yu Zhao <yuzhao@google.com>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/zsmalloc.c