svn commit: r360220 - stable/12/lib/libc/sys
Konstantin Belousov
kib at FreeBSD.org
Thu Apr 23 09:48:03 UTC 2020
Author: kib
Date: Thu Apr 23 09:48:02 2020
New Revision: 360220
URL: https://svnweb.freebsd.org/changeset/base/360220
Log:
MFC r359758:
libc: Fix possible overflow in binuptime().
Modified:
stable/12/lib/libc/sys/__vdso_gettimeofday.c
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/lib/libc/sys/__vdso_gettimeofday.c
==============================================================================
--- stable/12/lib/libc/sys/__vdso_gettimeofday.c Thu Apr 23 09:37:22 2020 (r360219)
+++ stable/12/lib/libc/sys/__vdso_gettimeofday.c Thu Apr 23 09:48:02 2020 (r360220)
@@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
#include <sys/time.h>
#include <sys/vdso.h>
#include <errno.h>
+#include <strings.h>
#include <time.h>
#include <machine/atomic.h>
#include "libc_private.h"
@@ -62,7 +63,8 @@ binuptime(struct bintime *bt, struct vdso_timekeep *tk
{
struct vdso_timehands *th;
uint32_t curr, gen;
- u_int delta;
+ uint64_t scale, x;
+ u_int delta, scale_bits;
int error;
do {
@@ -78,7 +80,19 @@ binuptime(struct bintime *bt, struct vdso_timekeep *tk
continue;
if (error != 0)
return (error);
- bintime_addx(bt, th->th_scale * delta);
+ scale = th->th_scale;
+#ifdef _LP64
+ scale_bits = ffsl(scale);
+#else
+ scale_bits = ffsll(scale);
+#endif
+ if (__predict_false(scale_bits + fls(delta) > 63)) {
+ x = (scale >> 32) * delta;
+ scale &= 0xffffffff;
+ bt->sec += x >> 32;
+ bintime_addx(bt, x << 32);
+ }
+ bintime_addx(bt, scale * delta);
if (abs)
bintime_add(bt, &th->th_boottime);
More information about the svn-src-all
mailing list