From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (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 6F5C21B87C3 for ; Fri, 24 Jan 2025 10:07:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737713271; cv=none; b=nCJZiabE7uoLzNY12OQ8ZqqU8+iN+yA4Wu8Ka54vqTF51uxmU2k5VwMN7ZseL3dhu8+A6D29mS46b7N5Nyx10L+FvzSE0cWSEFn6BGF70JtHHdiWd+goN5MkW/4J9eWHUYh2QEcZOOIbVVwE0GKiYJqoCi1+n0VzUqqwVXnanBU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737713271; c=relaxed/simple; bh=HkGijxFbcVXEb1+QAohcYGm/TmQhl/OQVcHRniZ0ups=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MDeMuvzmUvjuJS0jLIWxBWbTT7GOTljPIz0Q4+EA7Nmu7sLRnsQUGtJz9DLoBpG/JL+En1+Fi+80+HxX9MXX6OiMDSB5WBJ1oNBJ2bSqpXbtV/plOsQDnF95Pp2NlPBnjvtTI0xg+lKV61APH09GBLS0pMtgP35i/JF4X9HYGwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ty9eLZ+d; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ty9eLZ+d" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1737713258; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=N1cSa6vH9o3QeSLYJ5bFyY0urrbFDp3kXf3Zs30pDLg=; b=ty9eLZ+dW9rE8Zb1GQ+dgOjpO2rDDvOvs1tmBMdipsK2TEnc8Rdlk0LZLqvCOdRrzOaJDR8i2eI6QBO/cctH5IhJUNpgkehnYkWHO9ZIHd+/U/ksQa0vt98sJHJKWYPn+mOpvE+iXTlaC7b1hi9s4XHRi9MYfHEOAT6r4aDZswc= Received: from 30.32.95.77(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WOEB2EB_1737713256 cluster:ay36) by smtp.aliyun-inc.com; Fri, 24 Jan 2025 18:07:37 +0800 Message-ID: Date: Fri, 24 Jan 2025 18:07:35 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/compaction: fix UBSAN shift-out-of-bounds warning To: Liu Shixin , Andrew Morton , Kefeng Wang , Kemeng Shi , Mel Gorman , David Hildenbrand , Matthew Wilcox , Nanyong Sun , Vlastimil Babka Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20250123021029.2826736-1-liushixin2@huawei.com> From: Baolin Wang In-Reply-To: <20250123021029.2826736-1-liushixin2@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2025/1/23 10:10, Liu Shixin wrote: > 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 > --- LGTM. And I remember Vlastimil had the same concern before[1]. Reviewed-by: Baolin Wang [1] https://lore.kernel.org/all/6b055821-ce14-4a6d-959c-25ade4a9bfd7@suse.cz/ > 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;