From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (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 3CD4C3EEAD6 for ; Wed, 20 May 2026 15:00:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=96.67.55.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779289260; cv=none; b=DmakCvl4eF07MdIJhlGOVjFp4U2b0Et/0EJqshJJmpA7R9Q76GY2kwoBfwO3DsTKTa7WlbVlKQ2+zwA2cdguEA40Y+/9LbkNygEnhpLGQhGRI/VN/MN1NLjfWC7/9qUVREV+7p2o0oLxDsZio2cg9khb5A8E/vGgsLRupuKD5vU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779289260; c=relaxed/simple; bh=TIW0YEtE+oYb4M7MMJDqXm72Gm9H3t78Bbk6bOshKpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZYuZq7fzEAtMZPz7yYSbrHMj1ADNMk6USKkpdJGIXVETaLSuPx1vQCiJ1TqDDz+K+0rGbPIEkOjvY2Jr2nmPSiok+KG7wjIrUwHM8bfqqdWN1PgF0EZB9fONEQ2gkp2sZDTg7XwwxzTWkUaI8GEqFJUa+cYn2zvRnZnPBzJigDU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com; spf=pass smtp.mailfrom=surriel.com; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b=JS7U779I; arc=none smtp.client-ip=96.67.55.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=surriel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b="JS7U779I" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=surriel.com ; s=mail; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=LP/AzFvTKoIDyrXjf92uY+voMQvTqKcRBE5XC1e952Y=; b=JS7U779IELjaE2QGCB0k/b0Vx5 QPIc1MtZFEDE+nVd1Y87prVHr2R+SVew+KMU3yQIgfGF6fC8om3IjfKmUYrAtLVxupOX/v5UmJ+pA kqTdyCcjnhGY1PNprycURjqSXYthGmuy6FHwZlh3T0D3y7JxKBdgzftKggPxMHW8kLaQNI0K9yefB phBymDjMe/UEk+hgL5Ht0l+2hDTdBRFVN4PfnWFAqk7oCtRwFD8Ac9+2GS6hW7Vl6NNLr7uRig7wA C/HTbM3dMd5kVrrkov6RAXStqcYpSUTgHzchPOPMgn4gdS99Z92m2VNmbzxNdD43lkF/bbxh71muN 8AqbBAeg==; Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1wPiPM-0000000024Q-3tUc; Wed, 20 May 2026 11:00:28 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, linux-mm@kvack.org, david@kernel.org, willy@infradead.org, surenb@google.com, hannes@cmpxchg.org, ljs@kernel.org, ziy@nvidia.com, usama.arif@linux.dev, fvdl@google.com, Rik van Riel Subject: [RFC PATCH 32/40] mm: debug: prevent infinite recursion in dump_page() with CMA Date: Wed, 20 May 2026 10:59:38 -0400 Message-ID: <20260520150018.2491267-33-riel@surriel.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520150018.2491267-1-riel@surriel.com> References: <20260520150018.2491267-1-riel@surriel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit dump_page() calls is_migrate_cma_folio() which expands to get_pfnblock_migratetype(&folio->page, pfn). That helper resolves the pageblock via pfn_to_pageblock(), and on !CONFIG_SPARSEMEM configurations pfn_to_pageblock() reads page_zone(page) to compute the per-zone pageblock_data offset. When dump_page() is invoked on a page whose zone is not initialised (unavailable PFN ranges, very early boot, or a poisoned struct page), the page_zone() dereference returns garbage and a downstream VM_BUG_ON_PAGE in dump_page()'s own consistency checks fires. The BUG handler then calls dump_page() on the same page, which re-enters the same code path, hits the same BUG, and recurses until the kernel runs out of stack. Guard the is_migrate_cma_folio() call with pfn_valid() and only resolve page_zone() once that has succeeded; only then run zone_spans_pfn() before classifying the page. dump_page() can now safely report on pages without a meaningful zone, and the "CMA" suffix is only printed if the page is genuinely in a CMA pageblock. Found by: dump_page() called from a VM_BUG_ON_PAGE in early boot hitting a page in an unavailable range, recursing until stack exhaustion. Signed-off-by: Rik van Riel Assisted-by: Claude:claude-opus-4.7 syzkaller --- mm/debug.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mm/debug.c b/mm/debug.c index d4542d5d202b..e233520b009c 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -73,6 +73,7 @@ static void __dump_folio(const struct folio *folio, const struct page *page, { struct address_space *mapping = folio_mapping(folio); int mapcount = atomic_read(&page->_mapcount) + 1; + bool cma = false; char *type = ""; if (page_mapcount_is_type(mapcount)) @@ -112,9 +113,24 @@ static void __dump_folio(const struct folio *folio, const struct page *page, * "isolate" again in the meantime, but since we are just dumping the * state for debugging, it should be fine to accept a bit of * inaccuracy here due to racing. + * + * Guard the is_migrate_cma_folio() call with pfn_valid() and + * zone_spans_pfn(). The macro calls get_pfnblock_migratetype() + * which calls get_pfnblock_flags_word() which has a VM_BUG_ON_PAGE + * for !zone_spans_pfn(). If that fires, dump_page() recurses + * infinitely. Call page_zone() only after pfn_valid() to avoid + * dereferencing uninitialized zone data during early boot. */ +#ifdef CONFIG_CMA + if (pfn_valid(pfn)) { + struct zone *zone = page_zone(page); + + if (zone_spans_pfn(zone, pfn)) + cma = is_migrate_cma_folio(folio, pfn); + } +#endif pr_warn("%sflags: %pGp%s\n", type, &folio->flags, - is_migrate_cma_folio(folio, pfn) ? " CMA" : ""); + cma ? " CMA" : ""); if (page_has_type(&folio->page)) pr_warn("page_type: %x(%s)\n", folio->page.page_type >> 24, page_type_name(folio->page.page_type)); -- 2.54.0