From owner-svn-src-all@freebsd.org Thu Apr 9 23:22:36 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1C4842AA77E; Thu, 9 Apr 2020 23:22:36 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48yxy373yyz4QkV; Thu, 9 Apr 2020 23:22:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EDE6C1CBBB; Thu, 9 Apr 2020 23:22:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 039NMZXB075799; Thu, 9 Apr 2020 23:22:35 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 039NMZ4Q075798; Thu, 9 Apr 2020 23:22:35 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202004092322.039NMZ4Q075798@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 9 Apr 2020 23:22:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359758 - head/lib/libc/sys X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/lib/libc/sys X-SVN-Commit-Revision: 359758 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Apr 2020 23:22:36 -0000 Author: kib Date: Thu Apr 9 23:22:35 2020 New Revision: 359758 URL: https://svnweb.freebsd.org/changeset/base/359758 Log: libc: Fix possible overflow in binuptime(). This is an application of the kernel overflow fix from r357948 to userspace, based on the algorithm developed by Bruce Evans. To keep the ABI of the vds_timekeep stable, instead of adding the large_delta member, MSB of both multipliers are added to quickly estimate the overflow. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Modified: head/lib/libc/sys/__vdso_gettimeofday.c Modified: head/lib/libc/sys/__vdso_gettimeofday.c ============================================================================== --- head/lib/libc/sys/__vdso_gettimeofday.c Thu Apr 9 23:11:19 2020 (r359757) +++ head/lib/libc/sys/__vdso_gettimeofday.c Thu Apr 9 23:22:35 2020 (r359758) @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #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);