From patchwork Thu Jan 23 02:10:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13947901 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 DA8DFC02181 for ; Thu, 23 Jan 2025 02:16:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4143B6B0083; Wed, 22 Jan 2025 21:16:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 39D8C6B0085; Wed, 22 Jan 2025 21:16:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23DC56B0088; Wed, 22 Jan 2025 21:16:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 047B86B0083 for ; Wed, 22 Jan 2025 21:16:02 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 996C746DA9 for ; Thu, 23 Jan 2025 02:16:02 +0000 (UTC) X-FDA: 83037101364.04.9A63EA4 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf30.hostedemail.com (Postfix) with ESMTP id AA29E80013 for ; Thu, 23 Jan 2025 02:15:59 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737598561; 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; bh=yVXHh4VIWZnZxklfskhGEX/pGlm0qLK3TIN/iZLbHfk=; b=vUnP6ibbk2XLBivSl+68QFrwU9eTuX9+NiPoSuFp2+9VYRpSBc25Z8qxa3JBeBN2xh4Nlu fvNq1KGAJBG5QGo+kGh5vVwEamo9JBEMPJ6YBPcwMhKxvmslsgDrSCZMzZiMWtECWxx3Np ocuhnqx+M42qQZ8WCZzP6ONhysPNRRU= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737598561; a=rsa-sha256; cv=none; b=iJQOAnBomMUPwQob7loX5db4MyhFzIRGchf5qIwLnlqZaHLEXVRob7DLoOdX5cGoL2L5BR Gn4SjmMAw2XxMTaXeXVajCtr31llYs2aitLPlN0D8rG7ETNiOCqaLG/l5xE7VTDED8RdMd KeTKizCDXjJGGYUA5f+MtHPLllpmqvM= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Ydkwz182gz1V5Qy; Thu, 23 Jan 2025 10:12:35 +0800 (CST) Received: from kwepemg200013.china.huawei.com (unknown [7.202.181.64]) by mail.maildlp.com (Postfix) with ESMTPS id BA6921A016C; Thu, 23 Jan 2025 10:15:55 +0800 (CST) Received: from huawei.com (10.175.113.32) by kwepemg200013.china.huawei.com (7.202.181.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 23 Jan 2025 10:15:54 +0800 From: Liu Shixin To: Andrew Morton , Kefeng Wang , Kemeng Shi , Baolin Wang , Mel Gorman , David Hildenbrand , Matthew Wilcox , Nanyong Sun CC: , , Liu Shixin Subject: [PATCH] mm/compaction: fix UBSAN shift-out-of-bounds warning Date: Thu, 23 Jan 2025 10:10:29 +0800 Message-ID: <20250123021029.2826736-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemg200013.china.huawei.com (7.202.181.64) X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: AA29E80013 X-Stat-Signature: qsgjxu4mrwkmp61wnbesrngq94rw449g X-HE-Tag: 1737598559-487950 X-HE-Meta: U2FsdGVkX1+EaL1q5HAJ18tiGUX/z0y6tTsXprc0AGcwLl/pE0ZSpKCKk4DTmWmlqO8qmf4rSVSFsXGS7bMVqRYd/BvjHDbsLf1BljmnnzC4LVIhAO/kie+gtNFQQB+26do+AM84xf9Oh6b+0sYU9TOAFtHVEi/FYHjGZStXBivTzWuEpwSInE4olWhLmcXFx8iqsHeDAHs4LU4U8BSRKXKpk07poaaEZuIOL0XQYVH5MGdExXzgnpo1QFcpHcp0WlQ0iefcqfD43Yklz4/Ce5HtNOwSTHpmiCFAAHtP35RKUO41//j+sznEmK/kXxSaspNaP+GX58vvp2JJHDi1Ia13S8nSSqE0uZ6lGmIk4lNwLSEmVCeKuCn2DyHcTzmNm992blczQx/kHv/3mmquncGE4Bv0qnaSUAUxxcDS+y/s3MJBWmOtv8K42mEdAzdW5w9wBKC76l/sk6xrYlKACtw4ISygDEIz26gqQuaMaNeNgwyUTc6g79d1iifnNdACKYuVL+dp6uFOcHbXV7sEU6GOJDvAkN9K4jfJS6TC0KuElrMmNhNrdbcWiBYA5sMcdfVbM0qWHEFrGV5P/eI5XBBV1OOJ3+/dWPe+79WvqKmDk68kZNsxW3sXT6FeSBKst2/h5fEZCaYoyZATR6XoYXOraAc/hG/Nwi2UirLoDvyraG/8SOBpwUzQADuT5ykrzCdOeiCj0vF+ms67kihhCGr34DNV0GUesK/ZgP9oTv93AXkmHhDMrCbS2t9dMTnyAKRj+pTsJPfMXq797t96RwvYFbTxoT992cIO0yUfYGxdyppTsglnqw2XCnHdBBojnmpBm1uniK1sEkJTBiJMAH7mdeZLL0oGNZ5A+sRPJcN7HFSSIGB9kZAN0RyeZcyNPsc6rChbtihpuriMFmUuax83VqDi2hmpreo0LIc++8moryHZ0hlQZocuapRiFVdH9CetcWZRQVrhWQcxe0H XhyMdTCa 7FqHGGsQT1NEfuLVt1gOQJTw8PwN40rtjcKaWT/UrA38mJouOWnfkNF+mxn2qQAcD4KAUzDnO8n4CEKL3OckNjXxCD2L+eBWKHMzSf7k+BqGke2VhOFOPuvE/4pp2dA0NscfB2TGuuGKeu+0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.003065, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: syzkaller reported a UBSAN shift-out-of-bounds warning of (1UL << order) in isolate_freepages_block(). The bogus compound_order can be any value because it is union with flags. Add back the MAX_PAGE_ORDER check to fix the warning. Fixes: 3da0272a4c7d ("mm/compaction: correctly return failure with bogus compound_order in strict mode") Signed-off-by: Liu Shixin Reviewed-by: Kemeng Shi Acked-by: David Hildenbrand --- mm/compaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index a2b16b08cbbff..384e4672998e5 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -630,7 +630,8 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, if (PageCompound(page)) { const unsigned int order = compound_order(page); - if (blockpfn + (1UL << order) <= end_pfn) { + if ((order <= MAX_PAGE_ORDER) && + (blockpfn + (1UL << order) <= end_pfn)) { blockpfn += (1UL << order) - 1; page += (1UL << order) - 1; nr_scanned += (1UL << order) - 1;