[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1776080.QkHrqEjB74@camazotz>
Date: Fri, 14 Mar 2025 17:12:38 -0500
From: Elizabeth Figura <zfigura@...eweavers.com>
To: shuah@...nel.org, Su Hui <suhui@...china.com>
Cc: Su Hui <suhui@...china.com>, wine-devel@...ehq.org,
linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org,
kernel-janitors@...r.kernel.org
Subject:
Re: [PATCH 2/4] selftests: ntsync: avoid possible overflow in 32-bit machine
On Friday, 14 March 2025 02:14:52 CDT Su Hui wrote:
> 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@...china.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)
>
Reviewed-by: Elizabeth Figura <zfigura@...eweavers.com>
Powered by blists - more mailing lists