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 156C93A7F4A for ; Thu, 30 Apr 2026 20:22:55 +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=1777580580; cv=none; b=YgIQt9of1yU+c+pZ2Ai7TqNl3pR2SXUEJKM9zfyyigUzggZ2VgogNF5wJ6EC+zqm8rPLQUevdVOPkE2U3iukbxg6OKk2+GiA/RXJ3eWGAxRGE0hDAMFYvAX5d1EgL7FJxyCrHiTg1nvM3/LgXvGWAgFs9epHYNYnoHAfEvfruTs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777580580; c=relaxed/simple; bh=/vmWw03dvJKPnt1PqZxUrItsWPzZBKEXVlQp7Hi4aWM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KTVY/OfQcZEjDhW7AMnVAVoVAbSIQM4CGYfScoLClPXgyZb3xIgQWEY5Y7+6HxNVKpwH95GIfYYMhuCSzJXl+4U1cmKNMJBjpfv8N7o2MR3JoHjgjXPRzS9D/Ok+vqVknYOmOqtfJFxrrDVceaPBw6Gjyn7vCJ9jRCf9r+L4OWw= 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=TeC3RpUV; 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="TeC3RpUV" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=surriel.com ; s=mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=VMo4rj3YcXawZoSW/XqvtDg1E9Hlqa5dFOb9KR5T/oE=; b=TeC3RpUVM1TFbTegpmOO5ftiVM nLmJvwOQD+U1KjTxeI0x7cIKd5e9uKdQCu5C78Mixj7HUuqiOtdYOAi6RfOkhEZ1H8fPpsQkGF0b2 mmywS1a4lapRBtOGw4G2NUtdS3qGh+LA+aNmP1ieEOdVmIM0c1gdScO+5TrSW8i6bUygJtgNiJtVF KWUUc1YzQmsZyIPXPTWDjneDlqgMkizyCDYI84wGnQy5E0qprnyoYeqcF4pcdxCo0V+Wk1GjfC/8t +3ZB8iK6ibRC2Fyul6C+W+UOcEB8b3GyfP95gBrb5RvPYg6Gjw+hT50K5yBgmwFh8tjsIOAPUsKxr UPOxlsbw==; 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 1wIXuD-000000001R0-1oJj; Thu, 30 Apr 2026 16:22:41 -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, Rik van Riel , Rik van Riel Subject: [RFC PATCH 39/45] mm: debug: prevent infinite recursion in dump_page() with CMA Date: Thu, 30 Apr 2026 16:21:08 -0400 Message-ID: <20260430202233.111010-40-riel@surriel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260430202233.111010-1-riel@surriel.com> References: <20260430202233.111010-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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Rik van Riel dump_page() calls is_migrate_cma_folio() which calls get_pfnblock_migratetype() which calls get_pfnblock_flags_word() which has a VM_BUG_ON_PAGE for !zone_spans_pfn(zone, pfn). If that VM_BUG_ON_PAGE fires (e.g. dumping a page in an unavailable range, or a page that hasn't yet been initialized), the BUG handler itself calls dump_page() — which calls is_migrate_cma_folio() — which fires the same VM_BUG_ON_PAGE. Infinite recursion until the kernel runs out of stack. Guard the CMA check with pfn_valid() and zone_spans_pfn() so dump_page() can safely report on pages that don't have a meaningful zone. 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.52.0