Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Su Hui <suhui@nfschina.com>
To: zfigura@codeweavers.com, shuah@kernel.org
Cc: Su Hui <suhui@nfschina.com>,
	wine-devel@winehq.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH 2/4] selftests: ntsync: avoid possible overflow in 32-bit machine
Date: Fri, 14 Mar 2025 15:14:52 +0800	[thread overview]
Message-ID: <20250314071454.201697-3-suhui@nfschina.com> (raw)
In-Reply-To: <20250314071454.201697-1-suhui@nfschina.com>

When using '-m32' flag  to compile this test with gcc, there are some
errors when running test:

 ntsync.c:785:wake_any:Expected ETIMEDOUT (110) == ret (0)
 ntsync.c:823:wake_any:Expected (1) (1) == __count (0)
 ...
 FAILED: 7 / 11 tests passed.
 Totals: pass:7 fail:4 xfail:0 xpass:0 skip:0 error:0

There is an overflow about 'timeout'. 'timespec->tv_sec' is 4 bytes in
32-bit machine. And 'timeout.tv_sec * 1000000000' causing the overflow
problem, adding a cast to avoid this problem.

Signed-off-by: Su Hui <suhui@nfschina.com>
---
 tools/testing/selftests/drivers/ntsync/ntsync.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c
index bfb6fad653d0..ded83dc58e6b 100644
--- a/tools/testing/selftests/drivers/ntsync/ntsync.c
+++ b/tools/testing/selftests/drivers/ntsync/ntsync.c
@@ -103,7 +103,7 @@ static int wait_objs(int fd, unsigned long request, __u32 count,
 
 	clock_gettime(CLOCK_MONOTONIC, &timeout);
 
-	args.timeout = timeout.tv_sec * 1000000000 + timeout.tv_nsec;
+	args.timeout = (__u64)timeout.tv_sec * 1000000000 + timeout.tv_nsec;
 	args.count = count;
 	args.objs = (uintptr_t)objs;
 	args.owner = owner;
@@ -729,7 +729,7 @@ static __u64 get_abs_timeout(unsigned int ms)
 {
 	struct timespec timeout;
 	clock_gettime(CLOCK_MONOTONIC, &timeout);
-	return (timeout.tv_sec * 1000000000) + timeout.tv_nsec + (ms * 1000000);
+	return ((__u64)timeout.tv_sec * 1000000000) + timeout.tv_nsec + (ms * 1000000);
 }
 
 static int wait_for_thread(pthread_t thread, unsigned int ms)
-- 
2.30.2


  parent reply	other threads:[~2025-03-14  7:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14  7:14 [PATCH 0/4] ntsync: some small fixes for doc and selftests Su Hui
2025-03-14  7:14 ` [PATCH 1/4] selftests: ntsync: fix the wrong condition in wake_all Su Hui
2025-03-14  9:21   ` Dan Carpenter
2025-03-14 22:12   ` Elizabeth Figura
2025-03-14  7:14 ` Su Hui [this message]
2025-03-14 22:12   ` [PATCH 2/4] selftests: ntsync: avoid possible overflow in 32-bit machine Elizabeth Figura
2025-03-14  7:14 ` [PATCH 3/4] selftests: ntsync: update config Su Hui
2025-03-14 22:12   ` Elizabeth Figura

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=20250314071454.201697-3-suhui@nfschina.com \
    --to=suhui@nfschina.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=wine-devel@winehq.org \
    --cc=zfigura@codeweavers.com \
    /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