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=1794064450; b=46c8N46boA1S+Vl4klIPkA9LL4u8R1cDc9sOkdFIJNzEu7sER/8x2zeDAUZG+aXqT8r2 RtlaoUx/K90foG4NjbaoWhSs5r2/kC78J73+taLhbr1TdpLVm820vLUZ4ge5pLZ4gM9f9 8yqbVu5qMvNfle7lj+MNEzwaBXiJm0BBqwiaI6IZD+RiWQTOkmSAh5x7Nsrp7bHJ3jm19 KM1tIrEWgoF3ZnXui/mAMQsf2ih2qUnWNniaE33tdxSc2QU8d9WKd3547nrP5x/j+3kWo hXh3hzIaN6gj82tIkjHcEVfIbec2QmhrW9d0DvS8AP4eUtwzBIQiozTuTbZC93Byq2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794064450; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Tz6gM60bxzPkpwLctg4CgxpiHcWrN847pXZXayGkpiw=; b=mstixpWrsKxA7yhtvPbCosualtaN42kd4YgpmSCWRXdXyOkaQuQAsYUmE07lmhtsPIym 0vHPuTHNKmT4wAfTk4zzYctMNVO4M7lNpAYFDiQ34Y1GcOSgqObGixSakl74M+LCFSeEN 4/NsEcP4w2pS+zaxLcCceUyrfGSe1w04502lf6x/i/0OrNtpZdkCQdkwkE4UcuZA/sr1S ZVfBRAU1X7Qj8hAbcXnZmb6s0N2mE/o8FQJnpE4Ydo1dZL3p2oSTpUhg5f8QBTtNYFVgc cEL45CuD+eiC2vAtC0nPw+GOu3V8x9VuzTiPQJd25nG+rzkW2bFS4NTRCIY/TMtj6Gg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WM+an9Qt; 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 4FE416082BD6; Sat, 7 Nov 2026 15:14:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WM+an9Qt Received: by smtp.kernel.org (Postfix) with ESMTPSA id F213A1F008A5; Sat, 7 Nov 2026 15:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794064450; bh=Tz6gM60bxzPkpwLctg4CgxpiHcWrN847pXZXayGkpiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WM+an9QtahWIlRsJ0iqRb8nyc/FufQZ/tac2zfoC6xKs+2IWUjnr/FGupiEXzS3Wx 9tdahTrh0mmtWypiwNc7d7bn8MTHphRt/GC+5eXzXmdEguzKPWccVPrEtP/AjA/svK 48C17b6vzvOE4bi5ts6xxcL2AL512my/AN52n+yY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qi Xi , Andrew Morton , Zi Yan , Johannes Weiner , Kefeng Wang , Michal Hocko , Nanyong Sun , Suren Baghdasaryan , Vlastimil Babka , Brendan Jackman , Sasha Levin Subject: [PATCH 7.3 0493/1257] mm/page_isolation: fix UBSAN shift-out-of-bounds warning Date: Sat, 7 Nov 2026 08:46:29 -0500 Message-ID: <20261107134953.054089550@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134939.434104957@linuxfoundation.org> References: <20261107134939.434104957@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qi Xi [ Upstream commit eba0e6297edd60a85bc96ff5cfb734d066af62dd ] Patch series "mm/page_isolation: fix UBSAN shift-out-of-bounds in isolate_single_pageblock", v3. Patch 1 fixes a UBSAN shift-out-of-bounds warning in the PageBuddy branch of isolate_single_pageblock() triggered by concurrent buddy allocation. Patch 2 addresses the same class of issue in the PageCompound branch, where racy compound_order() and compound_head() reads could lead to out-of-range shifts or incorrect page skipping. This patch (of 2): A contig-range allocation racing with buddy allocation on the adjacent pageblock can trigger: UBSAN: shift-out-of-bounds in mm/page_isolation.c:393:15 shift exponent -749042176 is negative Call trace: isolate_single_pageblock start_isolate_page_range alloc_contig_frozen_range_noprof alloc_contig_range_noprof isolate_single_pageblock() first calls set_migratetype_isolate() with zone->lock held, which marks the pageblock MIGRATE_ISOLATE and moves any free page straddling the boundary out of the way. Once the lock is dropped, it scans the MAX_ORDER_NR_PAGES-aligned window [start_pfn, boundary_pfn) locklessly, only to skip the free pages already handled above and to detect in-use pages straddling the boundary. Since this scan only reads page state to decide how far to skip and returns -EBUSY on a straddling in-use page, it does not take the lock. The window also covers the adjacent pageblock, whose free pages stay on the normal movable/CMA freelist and can be allocated concurrently. So after the scan observes PageBuddy(page), another CPU can allocate the page, leaving a stale value in page->private that makes "1 << order" shift out of range. Use buddy_order_unsafe() with READ_ONCE to read the order, and validate it is within MAX_PAGE_ORDER before shifting to prevent UBSAN warnings. Since pageblock_isolate_and_move_free_pages() already handles free pages straddling boundary_pfn under zone->lock, bail out with -EBUSY instead of VM_WARN_ON_ONCE() when a PageBuddy page appears to cross the boundary during the lockless scan. Link: https://lore.kernel.org/20260825120549.966271-2-xiqi2@huawei.com Fixes: b2c9e2fbba32 ("mm: make alloc_contig_range work at pageblock granularity") Signed-off-by: Qi Xi Signed-off-by: Andrew Morton Reviewed-by: Zi Yan Cc: Johannes Weiner Cc: Kefeng Wang Cc: Michal Hocko Cc: Nanyong Sun Cc: Suren Baghdasaryan Cc: Vlastimil Babka Cc: Brendan Jackman Cc: Signed-off-by: Sasha Levin --- mm/page_isolation.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/page_isolation.c b/mm/page_isolation.c index e5dfc7bf49446..e4ee998c00f3b 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -388,13 +388,19 @@ static int isolate_single_pageblock(unsigned long boundary_pfn, } if (PageBuddy(page)) { - int order = buddy_order(page); + unsigned int order = buddy_order_unsafe(page); - /* pageblock_isolate_and_move_free_pages() handled this */ - VM_WARN_ON_ONCE(pfn + (1 << order) > boundary_pfn); - - pfn += 1UL << order; - continue; + /* buddy_order_unsafe() is racy. Validate the order before shifting. */ + if (order <= MAX_PAGE_ORDER && + /* + * pageblock_isolate_and_move_free_pages() splits + * cross-boundary PageBuddy, verify it. + */ + pfn + (1UL << order) <= boundary_pfn) { + pfn += 1UL << order; + continue; + } + goto failed; } /* -- 2.53.0