git: 3dc2a06752b5 - main - linux(4): Prevent time_t overflows on i386.

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Sun, 08 May 2022 13:17:10 UTC
The branch main has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=3dc2a06752b593acd1a76e784b169f3d60e81d00

commit 3dc2a06752b593acd1a76e784b169f3d60e81d00
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2022-05-08 12:39:09 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-05-08 12:39:09 +0000

    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
---
 sys/compat/linux/linux_time.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sys/compat/linux/linux_time.c b/sys/compat/linux/linux_time.c
index d4f502eee7c6..0f1af6b3a5cf 100644
--- a/sys/compat/linux/linux_time.c
+++ b/sys/compat/linux/linux_time.c
@@ -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;