Re: [PATCH v2 net 2/2] selftests: ptp: add a regression test for the frequency adjustment overflow
From: Simon Horman
Date: Mon Jul 27 2026 - 07:32:59 EST
On Tue, Jul 21, 2026 at 01:42:56AM +0000, Deep Shah wrote:
> testptp's -f option stores the requested adjustment as an int ppb and
> converts it to scaled ppm, so it cannot express the 64-bit scaled-ppm
> values needed to overflow scaled_ppm_to_ppb() and bypass the max_adj
> check enforced by ptp_clock_adjtime().
>
> Add a small test that crafts struct timex.freq directly and verifies that
> an overflowing frequency adjustment is rejected with -ERANGE. The test
> skips when no frequency-adjustable PTP device is available.
>
> Signed-off-by: Deep Shah <deepshah146@xxxxxxxxx>
...
> diff --git a/tools/testing/selftests/ptp/ptp_freq_overflow.c b/tools/testing/selftests/ptp/ptp_freq_overflow.c
...
> + /*
> + * (1 + 147573952589676412) * 125 == 2^64 + 9, which overflows s64 in
> + * scaled_ppm_to_ppb() and wraps the result to a ppb of 0. A kernel
> + * that does not detect the overflow lets this absurd frequency past
> + * the max_adj check; a fixed kernel rejects it with -ERANGE.
> + */
> + tx.modes = ADJ_FREQUENCY;
> +#if __SIZEOF_LONG__ >= 8
> + tx.freq = 147573952589676412L;
> +#endif
Thanks for the update here.
But unfortunately sashiko.dev still flags a problem.
"Will this preprocessor condition cause a false test failure on 32-bit
architectures configured with 64-bit time types (such as x32 or y2038
compliant systems)?
"On those architectures, the runtime check earlier in main() passes because
sizeof(tx.freq) is 8. However, __SIZEOF_LONG__ evaluates to 4, which causes
the preprocessor to skip the assignment of tx.freq.
"This leaves tx.freq as 0, allowing clock_adjtime() to successfully apply
a zero adjustment instead of rejecting the call with -ERANGE, which triggers
a test failure.
I wonder if dropping the #if/#endif would address that concern.