From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f98.google.com (mail-yx1-f98.google.com [74.125.224.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 8107E36A02F for ; Mon, 9 Feb 2026 19:36:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.98 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770665788; cv=none; b=MRvKTgVK6DgAHXluyi+BsoONbJzE9WNPNK2prg1ru7ynjqJLeSeUebSE3jbo5FMQqwneBhGNzQSd9Nu8tCZpGAzuVnA0uZDu0G6f5Qt/vu5AAbqlrcA4hpdICSxlVU4HAIxbF2FbHjb4E4j+bU7g8lEBx1AtbW3sYhCMAOax3Zw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770665788; c=relaxed/simple; bh=FgOf4QjL5w1p+Ob8lUKYZ9BDOMDBUEYNFPHwt2eZ9to=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=lDkXRu6vppif7JwY2DTjzC6jEV9zJorPM2eiwHXwEUKfzC6P8UJ7L5PYR2lJhfRoYf/3CPqMWBu+USpDkfGvkRGEQ4vOXKdYF4c3cy9QNw+USDrbJhq/7VpdW7v+wv4A46qVrG5xMo6GNiiCTFAbmGrANJoBbe6wfEAB8Ogc5sk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=com; spf=pass smtp.mailfrom=windowsforum.com; arc=none smtp.client-ip=74.125.224.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=windowsforum.com Received: by mail-yx1-f98.google.com with SMTP id 956f58d0204a3-64ad019bb5eso3059922d50.1 for ; Mon, 09 Feb 2026 11:36:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770665787; x=1771270587; 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=q/dU35L5Z/EBEW2tzbK4y4s54HZVYp85dkZZh1qYy6quh/nOxZ+7rD/a68VVH06MuB XatjonP0fJq5ZEK1bk1Geiqkmsy8aW2EnWoUEeCjvXVOZ/LNP+tgoHqzWt9RMi6hRJVA l1hRIjDW5vNPJDe/J3qIF01DMavjyGC3AAF4FpUsvxyXf4TbAW9lqc9Eh4Gbi2o3YsyO Ml93U/iNOnmBKo0m6sLJJ8ouTH1QbL3xcorzA/W0NdjwhMehR1u8CK8HjYfUCNdQfuEw yQ1rNEyT1QvHQljRwYxqyrA6NXLd57RYzUIZk+VHZUL1QFbaqx9/7VaHAsMZBsjUYcwN xCEQ== X-Forwarded-Encrypted: i=1; AJvYcCVAn0hsSnkffU8QvCsUIjtmyjsSWGJPIB/yWx1DMeFfbZgEPeeWEmKUcQ85nIVjUr9tlbc5I5QsYuMLzp4=@vger.kernel.org X-Gm-Message-State: AOJu0YwR0NDfzywl8rbw/lRqX9E7dlPAn6BWPrx1J6uAiNhQXsBi1hMf OBFZ2spPcMTd2iXFiQ7OsGYYv6vd6Kyi8dFNm7FjpRogws1yu8WGgkuCmjG3Itg3r9WN01G7Wbs mLOqv+e6CtuIqBP4SdqjQ1gtzeuvMHXIGs+fm X-Gm-Gg: AZuq6aIFaVGX6z9hYqoCfZz03QuegW2ZhyHx2M4UOeqoTdgCs2EsPz9alE253CemC3K beZjn9IqXkOL0xMqDAdKU0xFKPcB2XqvXJY6q1c4bfRHxsmkuoeVlU8VZSnHqXG0zGm7V7+MSZD MNU1rfLgeGkKRyBuOdJrlT8Z/oYnj5GzWXYLNp1m5DLHrJzuZHlW7Io+QKppqFriwWXxtzH68Fa EjUxyUtWXAPfW4TuCzElcjijStH73N2IRjm2/4I0jEQYKdHjk2E/AK7IdSBv1cFdNvVn8FjCveV PTd1HXjbYATFats5+zzQGiRS4/+xyg33uhsjJtTVpc4Ee+jpx4IL/9EeZydnaAigCmcigckab/3 klDBQeLIYAEEsXR3OTIg4gkSR2d+YbN3L7PDO42VGq8U= X-Received: by 2002:a05:690e:23c8:b0:646:5127:ad55 with SMTP id 956f58d0204a3-649f21c2cd9mr7136866d50.95.1770665787205; Mon, 09 Feb 2026 11:36:27 -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 956f58d0204a3-649f249e35dsm1086650d50.7.2026.02.09.11.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Feb 2026 11:36:27 -0800 (PST) X-Relaying-Domain: windowsforum.com Received: by windowsforum.com (Postfix, from userid 0) id 177DA2A1C1C; Mon, 09 Feb 2026 19:36:01 +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:36:01 +0000 Message-ID: <20260209193601.64662-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: 8bit 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 = 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 — 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 = 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