Skip to content

Commit f56ccc3

Browse files
kevinLourencoDevrppt
authored andcommitted
mm/memtest: add underflow detection for size calculation
The computation: end = start + (size - (start_phys_aligned - start_phys)) / incr could theoretically underflow if size < offset, leading to a massive iteration. Add VM_WARN_ON_ONCE() to detect cases where the region size is smaller than the alignment offset. While this should never happen in practice due to memblock guarantees, the warning helps catch potential bugs in early memory initialization code. Suggested-by: Mike Rapoport <rppt@kernel.org> Signed-off-by: Kevin Lourenco <klourencodev@gmail.com> Link: https://patch.msgid.link/20251229161321.9079-1-klourencodev@gmail.com Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
1 parent 58e3e52 commit f56ccc3

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

mm/memtest.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ static void __init memtest(u64 pattern, phys_addr_t start_phys, phys_addr_t size
5050
start_bad = 0;
5151
last_bad = 0;
5252

53+
VM_WARN_ON_ONCE(size < start_phys_aligned - start_phys);
54+
5355
for (p = start; p < end; p++)
5456
WRITE_ONCE(*p, pattern);
5557

0 commit comments

Comments
 (0)