linux(4): Prevent time_t overflows on i386.

As native i386 time_t is still 32-bit, check that the user-provided 64-bit
tv_sec value fits to the kernel time_t, return EOVERFLOW if not.

MFC after:		2 weeks
This commit is contained in:
Dmitry Chagin 2022-05-08 15:39:09 +03:00
parent 1579b320f1
commit 3dc2a06752

View File

@ -177,6 +177,11 @@ int
linux_to_native_timespec64(struct timespec *ntp, struct l_timespec64 *ltp64)
{
#if defined(__i386__)
/* i386 time_t is still 32-bit */
if (ltp64->tv_sec > INT_MAX || ltp64->tv_sec < INT_MIN)
return (EOVERFLOW);
#endif
/* Zero out the padding in compat mode. */
ntp->tv_nsec = ltp64->tv_nsec & 0xFFFFFFFFUL;
ntp->tv_sec = ltp64->tv_sec;