From patchwork Tue Dec 10 09:34:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13901107 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 037A3E7717F for ; Tue, 10 Dec 2024 09:34:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 882796B0158; Tue, 10 Dec 2024 04:34:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8329C6B015A; Tue, 10 Dec 2024 04:34:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 660966B015B; Tue, 10 Dec 2024 04:34:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 44CD86B0158 for ; Tue, 10 Dec 2024 04:34:46 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BC869C0656 for ; Tue, 10 Dec 2024 09:34:45 +0000 (UTC) X-FDA: 82878539100.12.56AF409 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 42AA580012 for ; Tue, 10 Dec 2024 09:34:02 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FchMyA5L; spf=pass (imf02.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733823261; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=aJTE5aAWIDEa6vwoKjHOaUlIQUcp6L018sbCgFuL3Us=; b=N8ZSRTHIySnmeqjD/UUJoM8frSQJ2Q54xAkG4S1XXjbfAdR+Tz2dwKk38F3kMDpShg5tle r64utgY3vZ3JLKjAqvxQ9fgd8BMAhXDpB2oQqZQ6Lv27ei8fkg438AXxbW7miFzTLeY0Kh kmfn6dXpVNGBzXkY1Dney+TrQlRBpKQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733823261; a=rsa-sha256; cv=none; b=y/JfxSEJYtKjF81yHRANxIz85nTj1/fD8huToVbghaagt/xzeVQ/HxBaFX2bsiwwXk1iKE n1xvU9nb8M/5v1k3FtW7XnaGs06X1rfEeCuv2LWW3/ieRk0uufEEjcYW2nEhhyPj7M1p4n HqMhB0nhE1852/drHCDpqlQmCIG++XQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FchMyA5L; spf=pass (imf02.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733823282; 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=aJTE5aAWIDEa6vwoKjHOaUlIQUcp6L018sbCgFuL3Us=; b=FchMyA5L03ajh6XRg2ptrVre0dixAOcjki3ggQZfwi091wLx4O3W5bsarQJZ4vkX1xY6JS 0ZN9BbrbARQhf+MXaKRebPLUJ1+2IBMPD/zez/slBGmnfD55AfeCFCA+Rgaxman+YKxgn6 ERHUbWJYgQnbP3T6/hAXtiqtsVNMPho= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-chz_tKvpMeOH_dcVFfg_iA-1; Tue, 10 Dec 2024 04:34:41 -0500 X-MC-Unique: chz_tKvpMeOH_dcVFfg_iA-1 X-Mimecast-MFC-AGG-ID: chz_tKvpMeOH_dcVFfg_iA Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-434f15c1c8fso14544965e9.2 for ; Tue, 10 Dec 2024 01:34:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823280; x=1734428080; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aJTE5aAWIDEa6vwoKjHOaUlIQUcp6L018sbCgFuL3Us=; b=HVUERRW8+IO5GstOPxvD6E5+icswvaT3RAhqSZGc9rnjXZi9a7/8THk87I71f0+f/W 3fS6LQlizU1RsV9Hi+yZdxkJSyKj19VeVNMLczKU03nFUhtyZAs+kNGq70nbHWpH3GBA MmrsRCU0cUcgjRI5CaKzeCNc3kzilnUqItuDXKSpstSsASS2g6kW7IbbxtnT4Xe16DYr VvYDQjTC//t1iGM294gNDVGXzTi1Q3rOsyGERb+FivXmz7DEwoIs8yjATvVU/xY14xzp SP6XaWZzyHpw4+9ao2LsXs1PEZqWd9Bj8veHz/Ol7OPxvQJ1I+FdGhzYeRc6njNFlepm HrzA== X-Gm-Message-State: AOJu0Yxbknca7IJxGW3LkHsV7hanAjBERg9GADelCUaC2ALHktEA9+Jo riRriu4RbuD8kJdaotaSEhXu8aab/IINzEs0pkfn+z+I/LfB1t5YDc9cW1qjs1stU/tXWK8LO7l NaJ/UWoGPayrJhzBLIEIU8A3Y6shWgLPIFCmekpHHFSfOO9cqazbOlslT X-Gm-Gg: ASbGncunSoBWwzatbqQphgSE7jLH8fdyThchuw8+3Hqq1IL4MhP3Vw5bjbw2MYCsLuG aoCfSlHp4Hn7hUvEeurkQKCplcbOORXFCc5hAIjNAISnqKCWFPChiB6SPXPexjAQir5wRvLbJdV 4s5zFbrZ5nYBeJk+DIlUoOnFyp5P04N/zXCr5b2RPdwjICQaIRFll6Smri8a6n7LpL51jvXT6YQ zjzBJPJjrYLzXIPAY+QG8/wpaMEWy0cKNv5FZxHTS4HdH1D7Dauho3PqH/hpAia8r0XLAO/hPQg u+riCkUf1I86TfRtUl3skBPsfLE1vazGNjOJGcY= X-Received: by 2002:a05:600c:46c6:b0:434:fddf:5c13 with SMTP id 5b1f17b1804b1-434fff4b38bmr31213425e9.14.1733823280334; Tue, 10 Dec 2024 01:34:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiSIcThERj1j+yIda8YMpOdaSblizl8osiTYt8iJ3IApoHVuyuGpAwgTEfZiyREhYWF3Jphg== X-Received: by 2002:a05:600c:46c6:b0:434:fddf:5c13 with SMTP id 5b1f17b1804b1-434fff4b38bmr31213175e9.14.1733823279931; Tue, 10 Dec 2024 01:34:39 -0800 (PST) Received: from localhost (p200300cbc723b8009a604b4649f987f3.dip0.t-ipconnect.de. [2003:cb:c723:b800:9a60:4b46:49f9:87f3]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-434faeda409sm54729765e9.7.2024.12.10.01.34.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Dec 2024 01:34:39 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Vlastimil Babka , Andrew Morton , Johannes Weiner , Zi Yan , Yu Zhao , stable@vger.kernel.org Subject: [PATCH v1] mm/page_alloc: don't call pfn_to_page() on possibly non-existent PFN in split_large_buddy() Date: Tue, 10 Dec 2024 10:34:37 +0100 Message-ID: <20241210093437.174413-1-david@redhat.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: o8Jz8g_ShEglf6cozD6sRro2iicnv7_OBPWPIgQce5M_1733823280 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: 42AA580012 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 8z7m8yj17c8r3fa7xxfah7q7tw1z7kow X-HE-Tag: 1733823242-163458 X-HE-Meta: U2FsdGVkX1/P9Ujc5XGt4pl0/LbPZy1OxQt6pzSJgBxkXfZahzhSRrNJIMcCTiJ7v2jKGWJ1A33QDiD7u57DSdtQfFRLBsmuqmdjpOiZ8avag9yg/YbbcqjUjOm60O2/LMRXmpq20Ur3/lxTctTg3Z54HSF4O+GRPYqarKVcugaTD/C4r/epi6Y80M2COqz6NQPDfLcbZrkEXVC9ttSu9jqPIsHQHHg2QsSmDat/WqdTxOC23WCqCZ7FurJi6HEV7YXk8ekEujRzh4XLVwcV042/ubvVM9gY2Q4J6N0n7WKSi6SUVTv9AyfWwj1BQgycld+bcU6uk/Y5kv8wDkyRlti4Helz8zCDh0FmMyKolsocEqgI4KFxNiVWqB5Vu/W5MHHcwtO9Gv5/FZLbGezzeMsBuaJUn+FczrvJ87DANJPtONIJZ2ml7q2s0KcxK4p/0+DPOKTeE3xrQYQ77upO094udQFCR+KHt5s/an8R922PscD1VPvKujiAIFE8jGB+rhdL4QhAlJTqk5i69F2s8dl8plKv5JsVL6wyLu5k7j4HSUiGONK2Hilq3p5mFqf3XMZahgjk7DHAzkGGCFGXTWU+KwhZK57d7kFpU4vWjKnequhHtYKeTWywkCinsUUPhvsWrE/thQXNDfDdvNFDxNtliBo8n3qeJtATvW+xSAGH1SIHDskmkPW+kspUPRizUpdCKUQMBDch0uIPJdl/mzNs+4UHroB0g6899w5S98bzCeJrujipSsuXdoTMM8vI03uqyuNT3POSl2m5z5kKVbz1J8JVZOtg5VK3HjgZn6Hzt/mQakQ/SIb1I2Yfs55wZFFPLXZXLYoho64/AMk7Er6JlCSTXF4krcnzQ4ubIAvCRp9M2ORdXG6h4zTa/3cbOrFRBpfm5/greZMV5G6oTkA4UFYKX8qQvLGujFfTr/uwltL7NXbTfGfoMGckNTq0VhOh+dNzyPdmMGAoxXJ JJiVt1Qg C+wnY4BqT9xleUS01XqeJzVYQvisMz1dx1vSfssrO+Epe1nJw2ah7Wyv/YzBbqaVPgNUoNphnXtsjDT05rL+/hcaeOBdEgXX6v1lwHSgA2sIPB7343pOtbZxC1Lc6KDbQWT1nAhruLd5OeqOzAtd5K+BqRNgAeE03/qnlHhgUoDnbWAjjW95Sh2dkHxY8ZOwpQhqsWTTzB9Ddbit/bjyFwBF52M19ROZlNMAg7nYnomqhjFlDawu3HjLlPDU/UeY8OAaQ6/4PqaTmrkUp3JN2cUevxLth1D9E4OUuVMkidEcyNvK55gRjIkZ0t+tn8pjB1mIs0XeE9sgY4SjKJ4vPS0wKql/ODI/mTXkxJOzevNLeFRmcpmMG/ppS/qTOqLfUJhJSgWKXS9+fzValJdKQPrXXa46hyShNpns7zP2Sh/6rK3P6iyBuQnbkYbkKWoskOEsvq21x0brta04KdqV909lGzIeREmP6rUuadB0UCMNCJIU21JCD7Kre/SWCwv+03n0i0q726leVzFJbSPN4bIF8XN1TRZt7KqwC1eWJQCaCn2J6n9A5ItJDzL4y1GeuwYmB+TIQMPE2+cFyU8srrqoNwgkvp+oI1ex1SsbvktN1/2M+J9EE8+XirzWXEVYbcjGi2Zp3xDw6Y8DnrISwYedKurhWbYDRkPat 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: In split_large_buddy(), we might call pfn_to_page() on a PFN that might not exist. In corner cases, such as when freeing the highest pageblock in the last memory section, this could result with CONFIG_SPARSEMEM && !CONFIG_SPARSEMEM_EXTREME in __pfn_to_section() returning NULL and and __section_mem_map_addr() dereferencing that NULL pointer. Let's fix it, and avoid doing a pfn_to_page() call for the first iteration, where we already have the page. So far this was found by code inspection, but let's just CC stable as the fix is easy. Fixes: fd919a85cd55 ("mm: page_isolation: prepare for hygienic freelists") Reported-by: Vlastimil Babka Closes: https://lkml.kernel.org/r/e1a898ba-a717-4d20-9144-29df1a6c8813@suse.cz Cc: Andrew Morton Cc: Johannes Weiner Cc: Zi Yan Cc: Yu Zhao Cc: Signed-off-by: David Hildenbrand Reviewed-by: Vlastimil Babka Reviewed-by: Zi Yan Acked-by: Johannes Weiner --- mm/page_alloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 48a291c485df4..a52c6022c65cb 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1238,13 +1238,15 @@ static void split_large_buddy(struct zone *zone, struct page *page, if (order > pageblock_order) order = pageblock_order; - while (pfn != end) { + do { int mt = get_pfnblock_migratetype(page, pfn); __free_one_page(page, pfn, zone, order, mt, fpi); pfn += 1 << order; + if (pfn == end) + break; page = pfn_to_page(pfn); - } + } while (1); } static void free_one_page(struct zone *zone, struct page *page,