Re: [PATCH] mm/zsmalloc: fix NULL pointer dereference in get_next_zpdesc

From: Joshua Hahn

Date: Mon Feb 09 2026 - 18:17:28 EST


I just noticed that Minchan wasn't Cc-ed in the patch. Adding him to the
conversation here.

On Mon, 9 Feb 2026 14:50:16 -0800 Joshua Hahn <joshua.hahnjy@xxxxxxxxx> wrote:

> On Mon, 9 Feb 2026 19:32:57 +0000 Michael Fara <mjfara@xxxxxxxxx> wrote:
>
> Hello Michael,
>
> I hope you are doing well! Thank you for the patch. I'm not entirely sure if
> the race condition that you note here is correct, and also if this is the
> right fix.
>
> > get_next_zpdesc() calls get_zspage() which unconditionally dereferences
> > zpdesc->zspage without a NULL check. This causes a kernel oops when
> > zpdesc->zspage has been set to NULL by reset_zpdesc() during a race
> > between zspage destruction and page compaction/migration.

[...snip...]

Should we add a Fixes tag here as well?
> > Signed-off-by: Michael Fara <mjfara@xxxxxxxxx>
> > ---
> > mm/zsmalloc.c | 14 +++++++++++++-
> > 1 file changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> > --- a/mm/zsmalloc.c
> > +++ b/mm/zsmalloc.c
> > @@ -735,7 +735,19 @@ static struct zspage *get_zspage(struct zpdesc *zpdesc)
> >
> > static struct zpdesc *get_next_zpdesc(struct zpdesc *zpdesc)
> > {
> > - struct zspage *zspage = get_zspage(zpdesc);
> > + struct zspage *zspage = zpdesc->zspage;
> > +
> > + /*
> > + * If the backpointer is NULL, this zpdesc was already freed via
> > + * reset_zpdesc() by a racing async_free_zspage() while isolated
> > + * for compaction. See the TODO comment in zs_page_migrate().
> > + */
> > + if (unlikely(!zspage)) {
> > + WARN_ON_ONCE(1);
> > + return NULL;
> > + }
> > +
> > + BUG_ON(zspage->magic != ZSPAGE_MAGIC);
> >
> > if (unlikely(ZsHugePage(zspage)))
> > return NULL;
> > --
> > 2.39.0