Re: [PATCH 4/6] time: Avoid undefined behaviour in timespec64_add_safe()

From: Richard Cochran
Date: Thu Sep 01 2016 - 04:04:38 EST


On Wed, Aug 31, 2016 at 02:50:20PM -0700, John Stultz wrote:
> UBSAN: Undefined behaviour in kernel/time/time.c:783:2
> signed integer overflow:
> 5273 + 9223372036854771711 cannot be represented in type 'long int'

...

> Line 783 is this:
>
> 783 set_normalized_timespec64(&res, lhs.tv_sec + rhs.tv_sec,
> 784 lhs.tv_nsec + rhs.tv_nsec);

...

> Note that this is not currently a huge concern since the kernel should be
> built with -fno-strict-overflow by default, but could be a problem in the
> future, a problem with older compilers, or other compilers than gcc.

Is this really a concern at all? The value 9223372036854771711 is a
huge number of seconds.

Thanks,
Richard