From: Li Wang <li.wang@linux.dev>
To: Wake Liu <wakel@google.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v7 1/2] lib: Fix overflow in backoff polling and timeout multiplication
Date: Mon, 10 Aug 2026 18:02:49 +0800 [thread overview]
Message-ID: <anmhyfuUdUrzQuWY@linux.dev> (raw)
In-Reply-To: <20260810025817.1665141-2-wakel@google.com>
Hi Wake,
This patch is not necessary, the overflow is not reachable in practice.
MAX_DELAY is a compile-time constant <= 30 at all call sites, so
'MAX_DELAY * 1000000' never overflows int. And the backoff would
need tst_delay_ to reach 2^31 (a single ~35 min usleep) to wrap,
which the loop-device probing never approaches regardless of
LTP_TIMEOUT_MUL.
So, I'd prefer to keep the change minimal and apply only v6.
On Mon, Aug 10, 2026 at 02:58:16AM +0000, Wake Liu via ltp wrote:
> Prevent integer overflow in TST_RETRY_FN_EXP_BACKOFF() when the delay
> doubles. By using 'unsigned long long' for delay variables, we ensure
> the doubled delay is safely represented without wrapping to 0 (which
> causes an infinite loop). The loop will naturally terminate when the
> 64-bit delay exceeds 'tst_max_delay_' (capped at UINT_MAX).
>
> Also fix potential overflow in tst_multiply_timeout() when the
> multiplied timeout exceeds UINT_MAX. Perform the calculation in double
> precision and cap the result at UINT_MAX.
>
> Signed-off-by: Wake Liu <wakel@google.com>
> ---
> include/tst_common.h | 4 +++-
> lib/tst_test.c | 11 +++++++++--
> 2 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/include/tst_common.h b/include/tst_common.h
> index e1f7c7907..058060fa4 100644
> --- a/include/tst_common.h
> +++ b/include/tst_common.h
> @@ -26,6 +26,8 @@
> #define LTP_ALIGN(x, a) __LTP_ALIGN_MASK(x, (typeof(x))(a) - 1)
> #define __LTP_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
>
> +unsigned int tst_multiply_timeout(unsigned int timeout);
> +
> /**
> * TST_RETRY_FUNC() - Repeatedly retry a function with an increasing delay.
> * @FUNC - The function which will be retried
> @@ -42,7 +44,7 @@
> TST_RETRY_FN_EXP_BACKOFF(FUNC, ECHCK, 1)
>
> #define TST_RETRY_FN_EXP_BACKOFF(FUNC, ECHCK, MAX_DELAY) \
> -({ unsigned int tst_delay_, tst_max_delay_; \
> +({ unsigned long long tst_delay_, tst_max_delay_; \
> typeof(FUNC) tst_ret_; \
> tst_delay_ = 1; \
> tst_max_delay_ = tst_multiply_timeout(MAX_DELAY * 1000000); \
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 5c3607016..80463e7c6 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1855,10 +1855,17 @@ unsigned int tst_multiply_timeout(unsigned int timeout)
> if (timeout < 1)
> tst_brk(TBROK, "timeout must to be >= 1! (%d)", timeout);
>
> + double t = timeout;
> +
> if (tst_has_slow_kconfig())
> - timeout *= 4;
> + t *= 4;
> +
> + t *= timeout_mul;
> +
> + if (t > (double)UINT_MAX)
> + return UINT_MAX;
>
> - return timeout * timeout_mul;
> + return t;
> }
>
> static void set_overall_timeout(void)
> --
> 2.55.0.654.g21b8a5bc05-goog
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-08-10 10:03 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 15:27 [LTP] [PATCH] lib: Use exponential-backoff polling to wait for loop device nodes Wake Liu via ltp
2026-08-03 16:28 ` [LTP] " linuxtestproject.agent
2026-08-04 1:59 ` [LTP] [PATCH v2] lib: Use backoff " Wake Liu via ltp
2026-08-04 3:58 ` Li Wang
2026-08-04 15:24 ` [LTP] [PATCH v3] " Wake Liu via ltp
2026-08-05 2:24 ` Li Wang
2026-08-05 2:54 ` [LTP] [PATCH v4] " Wake Liu via ltp
2026-08-05 4:09 ` [LTP] " linuxtestproject.agent
2026-08-05 6:53 ` Li Wang
2026-08-05 6:35 ` [LTP] [PATCH v4] " Li Wang
2026-08-05 6:52 ` Andrea Cervesato via ltp
2026-08-05 6:55 ` Andrea Cervesato via ltp
2026-08-05 7:10 ` Li Wang
2026-08-07 10:04 ` [LTP] [PATCH v5] " Wake Liu via ltp
2026-08-07 11:05 ` [LTP] " linuxtestproject.agent
2026-08-07 23:49 ` [LTP] [PATCH v6] " Wake Liu via ltp
2026-08-08 1:32 ` [LTP] " linuxtestproject.agent
2026-08-10 3:55 ` Li Wang
2026-08-10 4:16 ` Wake Liu via ltp
2026-08-10 2:58 ` [LTP] [PATCH v7 0/2] Fix overflow and use backoff polling for loop devices Wake Liu via ltp
2026-08-10 2:58 ` [LTP] [PATCH v7 1/2] lib: Fix overflow in backoff polling and timeout multiplication Wake Liu via ltp
2026-08-10 3:56 ` [LTP] " linuxtestproject.agent
2026-08-10 9:17 ` [LTP] [PATCH v7 1/2] " Andrea Cervesato via ltp
2026-08-10 10:02 ` Li Wang [this message]
2026-08-10 2:58 ` [LTP] [PATCH v7 2/2] lib: Use backoff polling to wait for loop device nodes Wake Liu via ltp
2026-08-10 9:17 ` Andrea Cervesato via ltp
2026-08-10 10:10 ` [LTP] [PATCH v6] " Li Wang
2026-08-10 12:30 ` Wake Liu via ltp
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=anmhyfuUdUrzQuWY@linux.dev \
--to=li.wang@linux.dev \
--cc=ltp@lists.linux.it \
--cc=wakel@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.