From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795560318; b=LN5hi815sZlVm3LNfPP+QsTfYYG6rO6PTh/GLuarDWtbd3fINJL3fnQyYBn0v/te+Ega rmBS3esi6OHTam9IXfWvfhDUDLkXoRnIQXkUDQNpn6FtkxqPY8MO0HNT81C4LnZbmdzwq eOF3bQiBfFeobrfjrtD1pNHBNHhbEiylHU1D+YUogOn1yzsogB3yz0rLHkM+NtITwHs8T /Wty8VLq/IRAWMuqxnrisMStfDpqIRZf791SKHBZPggbjBjwuC+Ed+oV0rwJOQcU7hw9L wxVS95iQnql2N3FWnYj11cqjrU6KkE0aQOg5Xl5hj0H5t4BZvjA2uCxZeM1/tQjOtvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795560318; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=5Okhxl82T594oLxg4Fx99v5/WPZS4+0XSGf6zFY3OZY=; b=Wxkc39HjJY1vHnoIjlkyX64FT5G2oMOHMFkHURGb0BzcVB+IA6ejbzcojVLfCw665SbM lORh5d3ECskyKGh+/hSTKm/DHoJuym0bQuThL+bq9zm7RacwqdOJRF8O8rDUFDsEhSyY6 snbqMbcccCwlqY/lrHpK2f4E2AVkds08tsKPmss4IcMG4/Wu1Q75M7ayd2iHaycIRaRmX vxdo3UF92aDiMZkyP/nwEDIhwu6nHjMy1UBVzyN4J/TMGfxxSlTe+CdDzfrd8whYQy749 TVyBc7RqTKKzbCXY2eTi6AiEC6MaQk4tdp/178+QaqJp1jDEqu0jsalfr4MvtGY5TUg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JZd4JeOO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4CAF606A327 for ; Tue, 24 Nov 2026 22:45:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JZd4JeOO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 959E81F000C0; Tue, 24 Nov 2026 22:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795560318; bh=5Okhxl82T594oLxg4Fx99v5/WPZS4+0XSGf6zFY3OZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JZd4JeOOxI2gDQq+kvFrU2LStscBJ9vc9duYm75qYB3U4Ty9xexLivMzwd+H2JHI7 YCHWFFc8+LSScbV1fe2crJ2lEIarhxvBVy0mRazfbBFeED3iP17DfmZhhi4Ihbd1ZH rDtKbpET2+4p1kakXdADByJj9NSeTAa+gK3UPsTbZwiv8GfBcT3ogM6bdc/Yd8QsR8 8XZs08JOR28b2V/3JzY22PWDho5rJSMer9DSA9Xsb6gBEYA1PtZaR7B7ouAnbxqvB8 5gPUpUtdk9lYFcFHIztjo/fons/miXWbAO0SHR8dF6/3Py6kNJKp6hvq31lujWiFTk pn64MMnh/g8zQ== From: Sasha Levin To: stable@vger.kernel.org Cc: "Gregory Price (Meta)" , "Vlastimil Babka (SUSE)" , Zi Yan , Sasha Levin Subject: [PATCH 5.10.y] mm/page_alloc: snapshot the preferred zone against shrink rebuilds Date: Tue, 24 Nov 2026 17:45:16 -0500 Message-ID: <20261124224433.3116232-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026112443-pentagon-half-0c17@gregkh> References: <2026112443-pentagon-half-0c17@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Gregory Price (Meta)" [ Upstream commit b3e3a760eb68449e2794ef68ab212173d9c3e8c7 ] get_page_from_freelist() and alloc_pages_bulk_noprof() reread ac->preferred_zoneref->zone at every use. Offlining a zone's last block rebuilds the zonelists in place, and the shrunk list's NULL terminator can land on the preferred slot mid-walk: CPU 0 CPU 1 get_page_from_freelist(GFP_KERNEL | __GFP_THISNODE) zone = NORMAL (slot 1) offline_pages() build_all_zonelists() [MOVABLE, NORMAL, NULL] -> [NORMAL, NULL] rmqueue(zonelist_zone(slot 1), zone) zone_statistics(NULL, zone) BUG: kernel NULL pointer dereference, address: 0000000000000060 RIP: 0010:get_page_from_freelist+0x6a5/0x15f0 Call Trace: __alloc_frozen_pages_noprof+0x125/0x330 Read the slot once. Zones are never freed, so a stale zone is safe, and a NULL slot fails the same way as walking off the end. Fixes: 11cd8638c37f ("mm, page_alloc: remove stop_machine from build_all_zonelists") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price (Meta) Reviewed-by: Vlastimil Babka (SUSE) Link: https://patch.msgid.link/20261101021340.2251928-7-gourry@gourry.net Acked-by: Zi Yan Signed-off-by: Vlastimil Babka (SUSE) [ sashal: Dropped the alloc_pages_bulk_noprof() hunks since 5.10 has no bulk allocator, and adjusted context for older get_page_from_freelist() locals and conditions. ] Signed-off-by: Sasha Levin --- mm/page_alloc.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index cb0614988479a..3679a8ec6f8e8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3807,9 +3807,18 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, { struct zoneref *z; struct zone *zone; + struct zone *preferred_zone; struct pglist_data *last_pgdat_dirty_limit = NULL; bool no_fallback; + /* + * A concurrent zonelist rebuild can NULL or replace this slot. Zones + * are never freed, so reading it once keeps a usable zone. + */ + preferred_zone = zonelist_zone(ac->preferred_zoneref); + if (!preferred_zone) + return NULL; + retry: /* * Scan zonelist, looking for a zone with enough free. @@ -3856,7 +3865,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, } if (no_fallback && nr_online_nodes > 1 && - zone != ac->preferred_zoneref->zone) { + zone != preferred_zone) { int local_nid; /* @@ -3864,7 +3873,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, * fragmenting fallbacks. Locality is more important * than fragmentation avoidance. */ - local_nid = zone_to_nid(ac->preferred_zoneref->zone); + local_nid = zone_to_nid(preferred_zone); if (zone_to_nid(zone) != local_nid) { alloc_flags &= ~ALLOC_NOFRAGMENT; goto retry; @@ -3893,7 +3902,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, goto try_this_zone; if (node_reclaim_mode == 0 || - !zone_allows_reclaim(ac->preferred_zoneref->zone, zone)) + !zone_allows_reclaim(preferred_zone, zone)) continue; ret = node_reclaim(zone->zone_pgdat, gfp_mask, order); @@ -3915,7 +3924,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, } try_this_zone: - page = rmqueue(ac->preferred_zoneref->zone, zone, order, + page = rmqueue(preferred_zone, zone, order, gfp_mask, alloc_flags, ac->migratetype); if (page) { prep_new_page(page, order, gfp_mask, alloc_flags); -- 2.53.0