From nobody Sun Jun 14 02:36:05 2026 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AE00333730 for ; Mon, 4 May 2026 12:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777899346; cv=none; b=KOfFtAewFLMz9WPn8To5U0rHoOFoMBjcsBZK3QfEFqYfUOs8DQ0ZwE3ueupkK3mWBq7pgP2jR1vj2f71y1XwO25/ZJv9QKM5WXKJOj8bQn0YD8B1/PmotVAPlmV/sjbSlYatQZaWSHSe8iK8vetKNhvSrRYWX+K9x3zsNI258Zg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777899346; c=relaxed/simple; bh=t5OfcCVJYbLenPvZDFNRz9sQX96KmPTLbcL/NKnx1AI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=fsWkqYIBfT62R/GgxFhh5tQl63XDZxiKt0ELzFh67s+IareloKLH/4dl8XTLpltc/kypHOT8M3HO8TIg8idVJNRWTPiepZpD3If/VwRjgtOnxt4BM/wnVqrxJcHhvNyL9IWh+Vyv/1CjZVrDVxGEEewr+9TpDKwXvOd8zDhrT34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=JpNjXDzz; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="JpNjXDzz" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777899342; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xkSPJSdtSlIYcN/7W3fB90ZDg2RbpoO3LlLAO8rSbLw=; b=JpNjXDzzxXd0csPoMAtWz2LjLcw/qa/YsWVq2sPGYE3pYjuCFWfpWtTxkAaZ5Au38h6yZQ Reye66yAvGCgHQJpUKc+V8vWFj+w0syusJLF2nojx6sZaYIJkLrDMNFy6w1djEq4WDFdcf jnM9u/Mc4D3AD1lMfR9xRAJFdzDqtjU= From: "Jose Fernandez (Anthropic)" Date: Mon, 04 May 2026 12:55:17 +0000 Subject: [PATCH] mm: swap_cgroup: fix NULL deref in lookup_swap_cgroup_id on swapless host 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 Message-Id: <20260504-swap-cgroup-fix-7-0-v1-1-f53ff41ee553@linux.dev> X-B4-Tracking: v=1; b=H4sIADSX+GkC/yWMSQ7CMAxFr1J5jUVaRnGVikWSuqmRSCK7BaSqd yeB5fvDW0FJmBRuzQpCL1ZOsUC7a8BPNgZCHgpDZ7qzOZkj6ttm9EHSknHkD17QIA1m9IO7jq0 5QHlmoVL9rP39z7q4B/m5qurCWSV0YqOfapSEA8f90+pMAtv2Bctw2NyXAAAA X-Change-ID: 20260504-swap-cgroup-fix-7-0-ed0fcdb8f103 To: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Hugh Dickins , David Hildenbrand , Barry Song Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kairui Song , stable@vger.kernel.org, syzbot+e12bd9ca48157add237a@syzkaller.appspotmail.com, "Jose Fernandez (Anthropic)" X-Migadu-Flow: FLOW_OUT lookup_swap_cgroup_id() passes swap_cgroup_ctrl[type].map to __swap_cgroup_id_lookup() without checking that the type was ever registered via swap_cgroup_swapon(). On a swapless host every ctrl->map is NULL, so __swap_cgroup_id_lookup() dereferences NULL + a scaled swp_offset(). Since commit bea67dcc5eea ("mm: attempt to batch free swap entries for zap_pte_range()"), zap_pte_range() -> swap_pte_batch() calls lookup_swap_cgroup_id() on any non-present, non-none PTE that decodes as a real swap entry, without first validating it against swap_info[]. A single PTE corrupted into a type-0 swap entry takes the host down at process exit. We hit this in production on a swapless 6.12.58 host: ~1s of "get_swap_device: Bad swap file entry 3f800204222bb" (do_swap_page() being correctly defensive about the same entry) followed by BUG: unable to handle page fault for address: 000003f800204220 RIP: 0010:lookup_swap_cgroup_id+0x2b/0x60 Call Trace: swap_pte_batch+0xbf/0x230 zap_pte_range+0x4c8/0x780 unmap_page_range+0x190/0x3e0 exit_mmap+0xd9/0x3c0 do_exit+0x20c/0x4b0 syzbot has reported the identical stack. The source of the PTE corruption is a separate bug; this change makes the teardown path as robust as the fault path already is. Every other caller of lookup_swap_cgroup_id() is downstream of a get_swap_device() that has already validated the entry, so the new branch is cold. Fixes: bea67dcc5eea ("mm: attempt to batch free swap entries for zap_pte_ra= nge()") Cc: stable@vger.kernel.org Reported-by: syzbot+e12bd9ca48157add237a@syzkaller.appspotmail.com Link: https://lore.kernel.org/r/69859728.050a0220.3b3015.0033.GAE@google.com Assisted-by: Claude:unspecified Signed-off-by: Jose Fernandez (Anthropic) --- mm/swap_cgroup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/swap_cgroup.c b/mm/swap_cgroup.c index de779fed8c210..95c38e54dd587 100644 --- a/mm/swap_cgroup.c +++ b/mm/swap_cgroup.c @@ -124,6 +124,8 @@ unsigned short lookup_swap_cgroup_id(swp_entry_t ent) return 0; =20 ctrl =3D &swap_cgroup_ctrl[swp_type(ent)]; + if (unlikely(!ctrl->map)) + return 0; return __swap_cgroup_id_lookup(ctrl->map, swp_offset(ent)); } =20 --- base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731 change-id: 20260504-swap-cgroup-fix-7-0-ed0fcdb8f103 Best regards, -- =20 Jose Fernandez (Anthropic)