From patchwork Tue Sep 22 02:21:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Grishenko X-Patchwork-Id: 1469 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id EP+ZH8rsaV8mFQAAIUCqbw (envelope-from ) for ; Tue, 22 Sep 2020 08:23:38 -0400 Received: from proxy18.mail.iad3b.rsapps.net ([172.31.255.6]) by director11.mail.ord1d.rsapps.net with LMTP id SNRuH8rsaV8rDgAAvGGmqA (envelope-from ) for ; Tue, 22 Sep 2020 08:23:38 -0400 Received: from smtp10.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy18.mail.iad3b.rsapps.net with LMTPS id UGgRGMrsaV/tVgAA3NpJmQ (envelope-from ) for ; Tue, 22 Sep 2020 08:23:38 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp10.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=yandex-team.ru; dmarc=fail (p=none; dis=none) header.from=yandex-team.ru X-Suspicious-Flag: YES X-Classification-ID: 70a10b94-fcce-11ea-b778-52540055034d-1-1 Received: from [216.105.38.7] ([216.105.38.7:56344] helo=lists.sourceforge.net) by smtp10.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id E0/E4-00711-9CCE96F5; Tue, 22 Sep 2020 08:23:37 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kKhJM-0001aT-DU; Tue, 22 Sep 2020 12:22:20 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKhJK-0001a9-Vt for openvpn-devel@lists.sourceforge.net; Tue, 22 Sep 2020 12:22:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:To: From:Sender:Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=mwlxaqAF0Ae5fCjaGYVXu0YrYFbDoHJWMx7pg3R2jQ4=; b=T3l+11SJMidBQPLW3Ot4UrGB9b 8v6MXTAjAdS2nidn99mSBtRwUl+RVRGvTkZLI5nHVxHF1OxwihrToxgatOUVAAdbgT2IntXljAeGB cb8diak1whVwvkIQnwMQpcNCBt+Xvad0zZXdp8EuQt9hS85402CvoUEcfCF00i56Gark=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=mwlxaqAF0Ae5fCjaGYVXu0YrYFbDoHJWMx7pg3R2jQ4=; b=Wv9N/qwkClLb2VjXTcgNr7pTCw PGbywPvxZT0YTa+VwNIJmDmm+imZdBG+Sz4CQhWcZSHY+4n2d6FZNtfBbIIZ1gYUoom5GRibVuSVY Qds37qmAp6+rs71xKUjXlGO6XQXVKRSQXKWw1PN48TMscWlXEQReRyHEdoZJI3Uo3Dcg=; Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kKhJ2-003AVH-Ck for openvpn-devel@lists.sourceforge.net; Tue, 22 Sep 2020 12:22:18 +0000 Received: from iva8-d077482f1536.qloud-c.yandex.net (iva8-d077482f1536.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:2f26:0:640:d077:482f]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 0BC282E1554 for ; Tue, 22 Sep 2020 15:21:43 +0300 (MSK) Received: from iva4-7c3d9abce76c.qloud-c.yandex.net (iva4-7c3d9abce76c.qloud-c.yandex.net [2a02:6b8:c0c:4e8e:0:640:7c3d:9abc]) by iva8-d077482f1536.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id z7QVVDdUow-LfvKwZ8r; Tue, 22 Sep 2020 15:21:42 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1600777302; bh=mwlxaqAF0Ae5fCjaGYVXu0YrYFbDoHJWMx7pg3R2jQ4=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From; b=OMAOO011FxsgGmrRuzR0O1rdozk3l2SAPLuxqS2+mY53ENqCP7x8fL2ukS7z8xsRI v/agDYGxAmSrIUdhoWX5EC2HinM5wAVT3DLJuj4GkgKlQQ+b+8/Il+xEpZNNrPcEOK EkIzhSHXJZeNSmIqdpmlO9fbdOiPFBlSknT/nyBY= Received: from unknown (unknown [95.108.219.45]) by iva4-7c3d9abce76c.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6sgTdLkirC-LflqKv1M; Tue, 22 Sep 2020 15:21:41 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) From: Vladislav Grishenko To: openvpn-devel@lists.sourceforge.net Date: Tue, 22 Sep 2020 17:21:34 +0500 Message-Id: <20200922122134.12634-1-themiron@yandex-team.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <75c379c2-35da-da12-d21f-44b1d6b1065b@rfc2549.org> References: <75c379c2-35da-da12-d21f-44b1d6b1065b@rfc2549.org> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: yandex-team.ru] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1kKhJ2-003AVH-Ck Subject: [Openvpn-devel] [PATCH v2] Fix update_time() and openvpn_gettimeofday() coexistance X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox With TIME_BACKTRACK_PROTECTION defined, openvpn_gettimeofday() uses and updates global variable "now_usec" along with "now" only if current time is ahead of the previsouly stored, taking nanoseconds into account. But, update_time() function updates only "now" leaving "now_usec" as is with any previously value stored. This breaks both update_time() and openvpn_gettimeofday() results and leads to time jumps in the future within one second, can affect shaper and user timers. 100.900 openvpn_gettimeofday(): now set to 100s, now_usec set to 900ns, stored time is 100.900 101.300 update_time(): now set to 101s, but now_usec is not updated and still 900ns, stored time jumps to the future 101.900 101.600 openvpn_gettimeofday(): current time 101.600 is in the past relatively stored time 101.900, now & now_usec variables are not updated, returned time 101.900 is still and again incorrect 102.100 openvpn_gettimeofday(): current time 102.100 is no longer in the past relatively stored time 101.900, so now & now_usec get updated with wrong time delta from previous openvpn_gettimeofday() call or now/now_usec math Since update_time() and openvpn_gettimeofday() calls are mixed in runtime, there're two ways to fix their coexistance: * either fix update_time() to always update "now_usec" for example by moving update_time() to gettimeofday(). Unfortunately, it may bring performance penalty depending on Arch/OS and vuruallized/hw environmant according the tests on various Linux, FreeBSD and MacOS versions. * or, for now, allow update_time() to break "now_usec" value, since it's used directly only in time ajusting and always invalidate it in openvpn_gettimeofday() w/o checking the previous and possibly obsolete value with no performance changes against the current implementation. This patch implements the second way. Signed-off-by: Vladislav Grishenko --- src/openvpn/otime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openvpn/otime.c b/src/openvpn/otime.c index 640168a9..d27d1f9d 100644 --- a/src/openvpn/otime.c +++ b/src/openvpn/otime.c @@ -73,7 +73,7 @@ update_now_usec(struct timeval *tv) { const time_t last = now; update_now(tv->tv_sec); - if (now > last || (now == last && tv->tv_usec > now_usec)) + if (now >= last) { now_usec = tv->tv_usec; }