From patchwork Sun Nov 17 05:52:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13877792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEB48D68BE2 for ; Sun, 17 Nov 2024 05:52:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1E4E6B00AC; Sun, 17 Nov 2024 00:52:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DA7BC6B00B2; Sun, 17 Nov 2024 00:52:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C481B6B00BF; Sun, 17 Nov 2024 00:52:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A1F1C6B00AC for ; Sun, 17 Nov 2024 00:52:53 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F0A26A0121 for ; Sun, 17 Nov 2024 05:52:52 +0000 (UTC) X-FDA: 82794516756.26.AD32622 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf06.hostedemail.com (Postfix) with ESMTP id AA4CA180004 for ; Sun, 17 Nov 2024 05:52:17 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZqgPBW2m; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of kees@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731822706; a=rsa-sha256; cv=none; b=SC74CD8QlootPZ690T2Re/Sc9XXXN3rsHLAiidpmpjv2mAk6wFsVz3ZlgKH5G0wJUeyo2F 3ya/Xyc6BuQ76qjP78ZxgpI/ck7Aj9zNfLmdJIIKis1+NIx83fSqJkUE8pHRjiB/JEdMHf 7AT/BNwFgwiA13nPIp9udRl6Jcce9/k= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZqgPBW2m; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of kees@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731822706; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=LQ+Z2PjuefANkEz+AbE3t6Kt7Kte/bhhv9BkP+BaSjk=; b=a734vbtrmikWac/S7eFQjzFqSgYMWPlygTbYDwuFLRIBKl3aC5Ldu4zUaG9VjvDNM4f7OS ZfzO1RWzgsMO1ZIb19yyEjOdDWHDAj3qxRYQ5fQUQLbXemi2i78lUy9xQIqyyuajjuUfnc TEocYdGDGk3es0dvRmM5r8h/kxdUhTY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 3DD57A4028D; Sun, 17 Nov 2024 05:50:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37BDBC4CECD; Sun, 17 Nov 2024 05:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731822768; bh=lJF35G3iawF9neNf2TiAhh320szRAcoG/yrAEvImh9A=; h=From:To:Cc:Subject:Date:From; b=ZqgPBW2mUQKQGrZWQMHb6934mIVxGzPX+/a7Kzuaman5pmp2OSbEDIb7FgOHi+yvD zQdSozklXiiyqzXw7LQZ0L5fX/Tqa4XTjRFTzlT3uq0cVrmpYTVLv5Pdd/E1d8w6ZI pPLSqXOFlZ1GBvP4x95j+ETDMoM04chyg3D911AOGK+cAhlGPnitf1KFESlovvqF/x kclMhk/Zz8x5y6m0I5TiYCyhCjrYUQNz6wBvIWh2ln8WK6VkuNthxiW3eJK6+dwXzj aguKJAWzFl8grh4Lqv+lWQoE4R8VrqHH0rciiRarfadGoVDBO6ixusUxs9D7NsKT+2 5/hO6rkVB9s2w== From: Kees Cook To: Matthew Wilcox Cc: Kees Cook , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] mm: Handle compound pages better in __dump_page() Date: Sat, 16 Nov 2024 21:52:44 -0800 Message-Id: <20241117055243.work.907-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2294; i=kees@kernel.org; h=from:subject:message-id; bh=lJF35G3iawF9neNf2TiAhh320szRAcoG/yrAEvImh9A=; b=owGbwMvMwCVmps19z/KJym7G02pJDOmWLavfcJ7v+JuzaofVtBfmuo+sN4iHNB68t/Xnm8lbv MuebzLa3VHKwiDGxSArpsgSZOce5+Lxtj3cfa4izBxWJpAhDFycAjAR/0uMDGvPNcsunP17/sPA CRMeVFmoFsdvO3whYNaxMA8pKaf+jRcZGV6ycHHYFThYlu06KB2fsOX78ykx+68UNn1/8jHoWPg zUz4A X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspam-User: X-Rspamd-Queue-Id: AA4CA180004 X-Rspamd-Server: rspam11 X-Stat-Signature: f4qaid9qj9zspdb3f186cpmnftscpwo8 X-HE-Tag: 1731822737-496725 X-HE-Meta: U2FsdGVkX19p6zoBNpxqR18mcmvCVlXpCCGqYTcU119OYGYnw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jxbVgYzhFUdPnvdZ5AS8WUsEx2pA07F5wKRYSLvjVz7LOsWGP1bnju9zzbZOIe8OGJ3gyjX2K34gU3QGJzDbEX7vGnqEoUqo4MpPsDMwIWWMIlm5mXm5pzQmV9Lxowwd8n67O/iLP+V8E0tp65zUtaj4RQW0II36rRz3J1D1WF59wWobF7RC322O2Ji/zySIksy55Ju1ijT4Gol5olUHoiOCSZaTc27xGVLXy/BbDO0miKpClfTXcbo7sGfU6QpayQOkAFN0+rAVYGqAjOmr1Vk7pCEuSisXzGYaxuKFoElwcLHyZU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: GCC 15's -Warray-bounds reports: In function 'page_fixed_fake_head', inlined from '_compound_head' at ../include/linux/page-flags.h:251:24, inlined from '__dump_page' at ../mm/debug.c:123:11: ../include/asm-generic/rwonce.h:44:26: warning: array subscript 9 is outside array bounds of 'struct page[1]' [-Warray-bounds=] (Not noted in this warning is that the code passes through page_folio() _Generic macro.) It may not be that "precise" is always 1 page, so accessing "page[1]" in either page_folio() or folio_test_large() may cause problems. Instead, explicitly make precise 2 pages. Just open-coding page_folio() isn't sufficient to avoid the warning[1]. Link: https://lore.kernel.org/r/ZkN0aSE9zAB5aXvM@casper.infradead.org [1] Signed-off-by: Kees Cook --- Cc: Matthew Wilcox Cc: Andrew Morton Cc: linux-mm@kvack.org --- mm/debug.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/debug.c b/mm/debug.c index aa57d3ffd4ed..7ea396e8c143 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -123,15 +123,15 @@ static void __dump_folio(struct folio *folio, struct page *page, static void __dump_page(const struct page *page) { struct folio *foliop, folio; - struct page precise; + struct page precise[2] = { }; unsigned long pfn = page_to_pfn(page); unsigned long idx, nr_pages = 1; int loops = 5; again: - memcpy(&precise, page, sizeof(*page)); - foliop = page_folio(&precise); - if (foliop == (struct folio *)&precise) { + memcpy(&precise[0], page, sizeof(*page)); + foliop = page_folio(&precise[0]); + if (foliop == (struct folio *)&precise[0]) { idx = 0; if (!folio_test_large(foliop)) goto dump; @@ -150,13 +150,13 @@ static void __dump_page(const struct page *page) if (loops-- > 0) goto again; pr_warn("page does not match folio\n"); - precise.compound_head &= ~1UL; - foliop = (struct folio *)&precise; + precise[0].compound_head &= ~1UL; + foliop = (struct folio *)&precise[0]; idx = 0; } dump: - __dump_folio(foliop, &precise, pfn, idx); + __dump_folio(foliop, &precise[0], pfn, idx); } void dump_page(const struct page *page, const char *reason)