Module Name: src Committed By: nia Date: Tue Oct 27 00:07:18 UTC 2020
Modified Files: src/sys/kern: kern_time.c Log Message: kern_time: prevent the system clock from being set too low or high currently doing this will drive KUBSAN haywire and possibly cause system lock-ups, so more testing should probably be performed before we let the clock be set too many thousands of years into the future. ditto for negative values, which were being passed by chrony for some reason while my internet connection was being unreliable. this also triggered some interesting KUBSAN reports. To generate a diff of this commit: cvs rdiff -u -r1.205 -r1.206 src/sys/kern/kern_time.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_time.c diff -u src/sys/kern/kern_time.c:1.205 src/sys/kern/kern_time.c:1.206 --- src/sys/kern/kern_time.c:1.205 Sat May 23 23:42:43 2020 +++ src/sys/kern/kern_time.c Tue Oct 27 00:07:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_time.c,v 1.205 2020/05/23 23:42:43 ad Exp $ */ +/* $NetBSD: kern_time.c,v 1.206 2020/10/27 00:07:18 nia Exp $ */ /*- * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.205 2020/05/23 23:42:43 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.206 2020/10/27 00:07:18 nia Exp $"); #include <sys/param.h> #include <sys/resourcevar.h> @@ -137,6 +137,13 @@ settime1(struct proc *p, const struct ti { struct timespec delta, now; + /* + * The time being set to an unreasonable value will cause + * unreasonable system behaviour. + */ + if (ts->tv_sec < 0 || ts->tv_sec > (1LL << 36)) + return (EINVAL); + /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */ nanotime(&now); timespecsub(ts, &now, &delta);