From nobody Tue Feb 10 18:36:23 2026 Received: from mail-dl1-f98.google.com (mail-dl1-f98.google.com [74.125.82.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68A5039E6F1 for ; Mon, 9 Feb 2026 19:33:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770665581; cv=none; b=jsK0Rfc7EVipMOTAqPhnAUJcrDEMeT3bFPxRGt0XXVdUFeniT/C0C9stBknbHlL+PjcHAD/3FA1FlSTWVcFDMpoJoRnZl2yzztda13KyW6B3e1usm3ospSzGA/cq1LO7BeRAVGt4WKokxPFS9JNMF3yUIhTu2EhX+HCWirSON3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770665581; c=relaxed/simple; bh=FgOf4QjL5w1p+Ob8lUKYZ9BDOMDBUEYNFPHwt2eZ9to=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=q4XgqufG0ypcIUwsxee0M4B49kN4WlBNQaLFZ72+Q1HpCHL8fmyT2jNjG4g54QG9ATyBNH9WmOWhsx+I6LpseZ6WaZv7khC/4+zgV/OtsfJgRgJ5QdgdBnIv6KQYZOazP/PL7YtV8kgbuoZsQyjDlG3drnhROgaqry1c+183ZYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=windowsforum.com; arc=none smtp.client-ip=74.125.82.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=windowsforum.com Received: by mail-dl1-f98.google.com with SMTP id a92af1059eb24-126ea4b77adso5213185c88.1 for ; Mon, 09 Feb 2026 11:33:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770665580; x=1771270380; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0sq/5z8N2ft1xcm3cuopTwCMdowyLeWdG7JWXwBlvJo=; b=hxGztmmaZvbpZfB/b3EqXtGksprizxTUuuGVYl7Ok5uoID11nKZ6g0s4jGd5JH6e/I KmjjlBFLZadLIyXU3k792TeZG+iG2Rk3ew6U5i3xLHbdIF/hK6wKwnb132bvhH+T0iig i+OxaatjxGZNiqJSDYVCscWHcQlVJqLFdeIUu6ELreqZ68eRfl2soiWOM7Xec/GrCy5n HLFTfQMmNY2ND7wvewqLIUqLMTJSepnzufxDjLCBkcYJ0XTdZfx71wh/KjJtnVa2uHBr XvD9JMu4RMpNVDeVyEqIt3+PdQp8Ky8s5/5q8AQOeQYDvXyv36r7hGkUHR4p2W0CEfaP ZbMA== X-Forwarded-Encrypted: i=1; AJvYcCV4Zl2gEhQgnUYAgeSGcsWvRWHwJFh09ZKmYfmMRnS9Za0JYq8JZKomDRsdTnD4Lxj/4y1tkcw0CbFJSXA=@vger.kernel.org X-Gm-Message-State: AOJu0YygEQuSsdfW/VSPHZ9hre7/DWvfbKpIKT2hfb3C0B9IuecfIH7d qtwpQL2FvigMoMfyV5sUBJ4VvfGAlNvC3IBQaStp7UOPTLn9UGegqjWBO0gMfC+kCLXLhF0xw4m M2g138Ytiykd4seICbAVFosmFJo0uWt6UmkDT X-Gm-Gg: AZuq6aLxz5Jt/9gXC6UM3Wbb20ThvwwJ8UY87BL/Pjrf/NKfJIQiM+TnCQISd5yGLZu 4TjL528zSgglEYC3Y1F7o44gbKh0J5c6TDjJzvCZ+GfMncFMLCulYA2wP8BUIlk2X1ygpS/QELq 1aLVgqzOf/2Yzh/sFnyn4BxAOkXTtqMxKTRP6ZOELAGWsimURSY4paLiyh52Wm93F2JMQbWUpGT 1cikmgYs/bHmbJEziuZdJFa3ZXcpLpgTPGDe4e3JUd111zeCspueBNaqgEiNyddDD7Xxciy5mYE K7QeCXNVdEVw1fampzeuaT5Iib4dZEqVnlnTqhtEpVPI3b3Mqj5YuUbU+Odb71LMuYuVGDkFIGO pnkqhsay/HyCbNDKEqncI75O6fd8= X-Received: by 2002:a05:7300:fb86:b0:2ba:7a5f:9e5b with SMTP id 5a478bee46e88-2ba7a5fa59bmr845438eec.35.1770665580381; Mon, 09 Feb 2026 11:33:00 -0800 (PST) Received: from windowsforum.com (116.9.196.104.bc.googleusercontent.com. [104.196.9.116]) by smtp-relay.gmail.com with ESMTPS id 5a478bee46e88-2b855c8014fsm1831790eec.7.2026.02.09.11.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Feb 2026 11:33:00 -0800 (PST) X-Relaying-Domain: windowsforum.com Received: by windowsforum.com (Postfix, from userid 0) id AEB2D2A1C1F; Mon, 09 Feb 2026 19:32:57 +0000 (UTC) From: Michael Fara To: senozhatsky@chromium.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, mjfara@gmail.com Subject: [PATCH] mm/zsmalloc: fix NULL pointer dereference in get_next_zpdesc Date: Mon, 9 Feb 2026 19:32:57 +0000 Message-ID: <20260209193257.60393-1-mjfara@gmail.com> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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. The race window is documented in a TODO comment in zs_page_migrate(): "nothing prevents a zspage from getting destroyed while it is isolated for migration, as the page lock is temporarily dropped after zs_page_isolate() succeeded" The sequence is: 1. Compaction calls zs_page_isolate() on a zpdesc, then drops its page lock. 2. Concurrently, async_free_zspage() or free_zspage() destroys the zspage, calling reset_zpdesc() which sets zpdesc->zspage =3D NULL. 3. A subsequent zs_free() path calls trylock_zspage(), which iterates zpdescs via get_next_zpdesc(). get_zspage() dereferences the now- NULL backpointer, causing: BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:free_zspage+0x26/0x100 Call Trace: zs_free+0xf4/0x110 zswap_entry_free+0x7e/0x160 The migration side already has a NULL guard (zs_page_migrate line 1675: "if (!zpdesc->zspage) return 0;"), but get_next_zpdesc() lacks the same protection. Fix this by reading zpdesc->zspage directly in get_next_zpdesc() instead of going through get_zspage(), and returning NULL when the backpointer is NULL. This stops iteration safely =E2=80=94 the caller treats it as the end of the page chain. Signed-off-by: Michael Fara --- 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 =3D get_zspage(zpdesc); + struct zspage *zspage =3D 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 !=3D ZSPAGE_MAGIC); if (unlikely(ZsHugePage(zspage))) return NULL; -- 2.39.0