linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/compaction: fix UBSAN shift-out-of-bounds warning
@ 2025-01-23  2:10 Liu Shixin
  2025-01-23  6:19 ` Kemeng Shi
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Liu Shixin @ 2025-01-23  2:10 UTC (permalink / raw)
  To: Andrew Morton, Kefeng Wang, Kemeng Shi, Baolin Wang, Mel Gorman,
	David Hildenbrand, Matthew Wilcox, Nanyong Sun
  Cc: linux-mm, linux-kernel, Liu Shixin

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 <liushixin2@huawei.com>
---
 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;
-- 
2.34.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-01-26  2:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-23  2:10 [PATCH] mm/compaction: fix UBSAN shift-out-of-bounds warning Liu Shixin
2025-01-23  6:19 ` Kemeng Shi
2025-01-23  9:19 ` David Hildenbrand
2025-01-23  9:42 ` Oscar Salvador
2025-01-24  6:20 ` Andrew Morton
2025-01-24  9:05   ` David Hildenbrand
2025-01-26  2:05   ` Liu Shixin
2025-01-24 10:07 ` Baolin Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox