From nobody Tue Feb 10 06:04:28 2026 Received: from mail-qv1-f98.google.com (mail-qv1-f98.google.com [209.85.219.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 5EB8C413245 for ; Mon, 9 Feb 2026 19:37:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770665832; cv=none; b=EoVxUv/h8pz53xKoS4PM/Xud+rywDhefZqXmNqBw/ezbJSpMm6y4im5pCKDDrYu1G6C1bzAZZQS5rLvX7KEQTO2DAuwIHslTIpbBRoHLZrD27lg7SKy5I3sS2gCFxpzT9GJkuiWX27348kgAq3x/+xqWCBcV2ONCGUg4XKxpXD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770665832; c=relaxed/simple; bh=FgOf4QjL5w1p+Ob8lUKYZ9BDOMDBUEYNFPHwt2eZ9to=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=WVfFn3H4eD/H4XUU8KEHP1L0nqMYhkwTjDU7i5MMckxp8Y3CcSPFzGdKyfz4Nvbwop0diQbjD/ie9n454xdA5e/VnoZR9QBDTdhUJkw+eaefWgTXoqAB9vzWHUfbqggf2X5eBKsQ6NB7enqFKY2H/hkbrwOgiqxyDUSZJnW18nE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windowsforum.com; spf=pass smtp.mailfrom=windowsforum.com; dkim=pass (1024-bit key) header.d=windowsforum.com header.i=@windowsforum.com header.b=ZsSyXW81; arc=none smtp.client-ip=209.85.219.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windowsforum.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=windowsforum.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=windowsforum.com header.i=@windowsforum.com header.b="ZsSyXW81" Received: by mail-qv1-f98.google.com with SMTP id 6a1803df08f44-8947404b367so54368256d6.3 for ; Mon, 09 Feb 2026 11:37:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windowsforum.com; s=google; t=1770665831; x=1771270631; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0sq/5z8N2ft1xcm3cuopTwCMdowyLeWdG7JWXwBlvJo=; b=ZsSyXW81yklsrytL8VR1aXBb46eJguYYE3ql32/+Yesd5KkYN7MnYe5BdYXa2vHUd1 7CoZ3LXhHp7fOqwu622Lgkb57cwooZrPWeyRu4/7HRaRYhP7dM3Pf5rZm8Vbe8XcwTDG mbwGySCT93Z1Bl3Q1GrlMJ6nkWX+erth0lRLI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770665831; x=1771270631; 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=LQubkwtKhu1GZ2k9OUfUb9vyr4isQP1Qsf6XVVJEHUX6zNYOF2zACViabtdxoXY3Av ljda6AQ1byJFIeWLo3kI6eo2VMTqbvE59qfXUteg8lZtv5ibmhfN6t4SQR2Gva1RfT62 RmtwmJlhEU9DhQk425wPWP9IEZw/FfYfIqRJphMBrbMlq1GPMoFQAnJbvfvVf+4Px+M0 flP4H66ZYa8fwmsLTPqBhwu19Hdni20plCLLWJYLKcolA6O5YvTN7RipK2zMCN8MQzrb 6MJ+mnvu8d0+EF26VIYMdWze8nnUBqRSllw6PnWArGqEitJbxGpXqslXCYelQy5AsYlD fgSg== X-Forwarded-Encrypted: i=1; AJvYcCWOqEACKurgmGmkEUtR+BW0IBZDes6DLTpzm5Oqv5pmRFm1b1p/Kw/2ge5ZMeARQFVsbmsQ5qEpQzh4xqc=@vger.kernel.org X-Gm-Message-State: AOJu0YyhpMY0WPX7dFz0NgSNZWUPMlwkFlga38s74gUsl8fJw6Y/dgCM OYvDhpQJcXWTb4yecBLQMtm1coarVKjJ56FtUFZSsmBM3nLxzXBKODfV4BSEgjo7Tmv0KWC/D3d ySTg/1ZTlzILn9wIbQYSEqzWhKSPEDHqDozAQ X-Gm-Gg: AZuq6aJVKulbK36uv8XgeH6YzdiYOE0A8f8Itwki6bcquGAPHJ2bP6ZeLPFNPBWUILr MjA6wN/+CR4m8C09iYuFD3jBMgb5ykMr/fr42dHTtxzRY40oA22Rt/8rcqfl26Jh+T2uPpxQYlc TLbXA+T+E4kZ0vOPCQtjD/w3iKX12uG3rL2CgMaldxWQ+wMTe+MGj6DAMQ2LdQeqwmXOgexyoR3 eFqV5ZlYpLACtdVZS6Ani6ClxYe5PmqK+Cfj5H4Gn7l+5BC4rDjRQz4uz6t40JZWPVTL1pDJISj tHInz4ZsC7U/SHmOB4cMXYZudeUVNnEb5WCV3ox2JZzzkZ8SGWzxZwPqHYoiW8Az57b37blB4kM UijjRisCDi5sN1ALa9U33fOo2THSLP4Xl2EAuX05VMfzn1IK6dX6Sh7U9a5yS X-Received: by 2002:a05:6214:487:b0:894:7051:2681 with SMTP id 6a1803df08f44-8953cb8126emr197913306d6.51.1770665831084; Mon, 09 Feb 2026 11:37:11 -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 6a1803df08f44-8953bf38308sm18101146d6.8.2026.02.09.11.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Feb 2026 11:37:11 -0800 (PST) X-Relaying-Domain: windowsforum.com Received: by windowsforum.com (Postfix, from userid 0) id E30A82A1C20; Mon, 09 Feb 2026 19:37:08 +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:37:08 +0000 Message-ID: <20260209193708.69454-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