mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chaithanya Lagisetty <nagachaithanya9911@gmail.com>
To: pbonzini@redhat.com, seanjc@google.com
Cc: shuah@kernel.org, kvm@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	nagachaithanya9911@gmail.com
Subject: [PATCH] KVM: selftests: Fix the never-true negative UFFD delay check
Date: Mon,  7 Sep 2026 04:52:46 +0000	[thread overview]
Message-ID: <20260907045246.3783304-1-nagachaithanya9911@gmail.com> (raw)

demand_paging_test parses the -d option with strtoul() and then asserts
that the result is not negative:

	p.uffd_delay = strtoul(optarg, NULL, 0);
	TEST_ASSERT(p.uffd_delay >= 0, "A negative UFFD delay is not supported.");

p.uffd_delay is a useconds_t, which is an unsigned type, so the comparison
is always true and the assertion can never fire. GCC points this out with
-Wtype-limits, which is enabled by -Wextra.

As a result, "-d -1" is accepted and converted to a very large unsigned
delay, causing each demand paging fault to sleep for an unexpectedly long
time in usleep() instead of rejecting the argument up front. The return
value of strtoul() is not validated either, so a non-numeric argument
such as "-d abc" is silently treated as a zero delay.

Use atoi_non_negative() instead. It rejects negative values, unparsable
input, and trailing garbage. It is already used a few lines below for -v,
and hexadecimal input keeps working because atoi_paranoid() also passes a
base of 0 to strtol().

Fixes: 0119cb365c93 ("KVM: selftests: Add configurable demand paging delay")
Signed-off-by: Chaithanya Lagisetty <nagachaithanya9911@gmail.com>
---
 tools/testing/selftests/kvm/demand_paging_test.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index f8b3d0b68830..619a0b2be45c 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -297,8 +297,7 @@ int main(int argc, char *argv[])
 			p.single_uffd = true;
 			break;
 		case 'd':
-			p.uffd_delay = strtoul(optarg, NULL, 0);
-			TEST_ASSERT(p.uffd_delay >= 0, "A negative UFFD delay is not supported.");
+			p.uffd_delay = atoi_non_negative("UFFD delay", optarg);
 			break;
 		case 'b':
 			guest_percpu_mem_size = parse_size(optarg);
-- 
2.43.0


             reply	other threads:[~2026-09-07  4:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07  4:52 Chaithanya Lagisetty [this message]
2026-09-09 16:39 ` Gautam Menghani
2026-09-21 14:05 ` Sean Christopherson

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=20260907045246.3783304-1-nagachaithanya9911@gmail.com \
    --to=nagachaithanya9911@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@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

all inboxes | Powered by JetHome®