From nobody Mon Feb 07 18:04:22 2022 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 5F05F195905F for ; Mon, 7 Feb 2022 18:04:22 +0000 (UTC) (envelope-from bugzilla-noreply@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JsvD60rvVz4bDk for ; Mon, 7 Feb 2022 18:04:22 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F36AF237A for ; Mon, 7 Feb 2022 18:04:21 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 217I4La0095856 for ; Mon, 7 Feb 2022 18:04:21 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 217I4LaE095855 for bugs@FreeBSD.org; Mon, 7 Feb 2022 18:04:21 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 261781] VDSO time calculation integer overflow Date: Mon, 07 Feb 2022 18:04:22 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: jarek@jpelczar.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644257062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DkWXHkgiM0tK3VL4c2zL9tx7qrhztLF5uTa+NCEzLL0=; b=Ro74Vpm8jznEQhs7ADP0E1BWmbQWNlQebtoYiRTnG+YnYAXp7dGo/9WgHwO+tzgRnolTEs 42M1IAEMMsofcrgJe0DNuIdLLp9+ZtmBY23zMKMZ8nUuhvfz165SOVuBE4R9w7Js9AId+e wbmJ/gsi2icDYHFpClaOVJ4CIxuynV8AINGyXl6eP9f3VWgzzS3F3SA8WxoBphU837mFWI mGexJjYcvdnrMV7QgTMdxRDYSzMs5ogs3ucXXOydPOVX/xuSORUrTZyai9z3aRz6hCzGtp DfWwwJ6HgeJ7aHxrXwC+iiA0ZjwDbfWNOIJezg8D2I+p/w4kPZtEph4ZjaXuxA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644257062; a=rsa-sha256; cv=none; b=VgAcNW3DYufVut4UHKR2UQMmE80f5pce/WVq+YH9LFCCjucd1HDdtjNG7KCyzH9fyal4zr G5j52DQ6TqPw8E2CCvMMfsNLteSkBHXrO+ehhtRJ8cxXz6rJQnOreF3V6tHdtEYb87+I/K J4PAOaZVEEeS/hxYk47WmbYn2Vkzo7DC3ca+kMhfXXVnq4x4bJtgGqUNF7o0m1T36YHWJ0 Y87ayUjHEtC+YkkM+BRDzBV/JDlOYOXqZ6MGOIubK6PvtnNRSLngO52lNC7zbNraF6AP81 Mspb0NC2dAVheT4ZvWFRnFIE27DiAlYlhX7z4Q+ZagcjIqc5MA8eosXAXrJ18w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D261781 Bug ID: 261781 Summary: VDSO time calculation integer overflow Product: Base System Version: CURRENT Hardware: arm OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: jarek@jpelczar.com I have been tinkering with clock subsystem for more or less tickless based approach. I am not sure whether calculation in "lib/libc/sys/__vdso_gettimeofday.c" for "binuptime" function is correct. Currently the code looks like this: scale =3D th->th_scale; #ifdef _LP64 scale_bits =3D ffsl(scale); #else scale_bits =3D ffsll(scale); #endif if (__predict_false(scale_bits + fls(delta) > 63)) { x =3D (scale >> 32) * delta; scale &=3D 0xffffffff; bt->sec +=3D x >> 32; bintime_addx(bt, x << 32); } Example outputs from two time points (time is measured by ARM Generic Timer, but that's just 64bit counter masked to 32bits): th->th_boottime =3D 1640852968.ff886104742783f9=20 timecounter delta =3D 29015463=20 th->th_scale =3D 295147905178=20 th->th_offset_count =3D 539967626=20 bintime_addx(bt, scale * delta =3D 0x76D8EB0A9A877676) =3D> 9.4522dbb32c111= 955 th->th_boottime =3D 1640852968.ff886104742783f9=20 timecounter delta =3D 64100295=20 th->th_scale =3D 295147905178=20 th->th_offset_count =3D 539967626=20 bintime_addx(bt, scale * delta) =3D> 8.d4d7f89392515095 Multiplication of scale and delta will overflow 64 bits.=20 I am not sure whether the scale_bits should rather be calculated by flsl/fl= sll to detect the overflow. --=20 You are receiving this mail because: You are the assignee for the bug.=