linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: klourencodev@gmail.com
To: linux-mm@kvack.org
Cc: rppt@kernel.org, Kevin Lourenco <klourencodev@gmail.com>
Subject: [PATCH v2] mm/memtest: add underflow detection for size calculation
Date: Mon, 29 Dec 2025 17:13:21 +0100	[thread overview]
Message-ID: <20251229161321.9079-1-klourencodev@gmail.com> (raw)
In-Reply-To: <CAFveykPnTH456rMSRgpDO7VyN2EdP6eOq3pKUBCDdQa1kAJ4AQ@mail.gmail.com>

From: Kevin Lourenco <klourencodev@gmail.com>

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>
---
 mm/memtest.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/memtest.c b/mm/memtest.c
index c2c609c39119..bac195e6077a 100644
--- a/mm/memtest.c
+++ b/mm/memtest.c
@@ -46,6 +46,7 @@ static void __init memtest(u64 pattern, phys_addr_t start_phys, phys_addr_t size
 
 	start_phys_aligned = ALIGN(start_phys, incr);
 	start = __va(start_phys_aligned);
+	VM_WARN_ON_ONCE(size < start_phys_aligned - start_phys);
 	end = start + (size - (start_phys_aligned - start_phys)) / incr;
 	start_bad = 0;
 	last_bad = 0;
-- 
2.47.3



  reply	other threads:[~2025-12-29 16:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-20 15:10 [PATCH] mm/memtest: prevent arithmetic underflow in end pointer calculation klourencodev
2025-12-28 19:56 ` Mike Rapoport
2025-12-29 15:47   ` Kevin Lourenco
2025-12-29 16:13     ` klourencodev [this message]
2025-12-30 13:36       ` [PATCH v2] mm/memtest: add underflow detection for size calculation Mike Rapoport

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251229161321.9079-1-klourencodev@gmail.com \
    --to=klourencodev@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox