From patchwork Mon Sep 21 14:40:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Grishenko X-Patchwork-Id: 1468 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id GFLSJ0tIaV8QXQAAIUCqbw (envelope-from ) for ; Mon, 21 Sep 2020 20:41:47 -0400 Received: from proxy18.mail.iad3b.rsapps.net ([172.31.255.6]) by director10.mail.ord1d.rsapps.net with LMTP id 4NSbJ0tIaV9CWQAApN4f7A (envelope-from ) for ; Mon, 21 Sep 2020 20:41:47 -0400 Received: from smtp23.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 ON8wIUtIaV9jZgAA3NpJmQ (envelope-from ) for ; Mon, 21 Sep 2020 20:41:47 -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: smtp23.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: 648fcb36-fc6c-11ea-bd89-525400aa5716-1-1 Received: from [216.105.38.7] ([216.105.38.7:44646] helo=lists.sourceforge.net) by smtp23.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 99/C7-02158-A48496F5; Mon, 21 Sep 2020 20:41:46 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kKWMC-0003WA-BU; Tue, 22 Sep 2020 00:40:32 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKWM8-0003Vd-3N for openvpn-devel@lists.sourceforge.net; Tue, 22 Sep 2020 00:40:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lxccLRQT9/naCtZuHD1tNHh40YVBV1Nuvs8c9Tksszo=; b=EM2QyoZE8KnanC1QMjAXDYolb8 x+dhzpdAqKCb56umFlN9nYiNFwDthHoxDryvH7MpPAjQRlbCBPlKYxuq8sT7HIeywLiKG55XqrWRo mrw7S+jWfGLgFerLdOwPGxwkaJU9rDjK81p+Iz7H4d4fHk4vy3j47JV1nuBWhW+y66/c=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=lxccLRQT9/naCtZuHD1tNHh40YVBV1Nuvs8c9Tksszo=; b=cbXfiT5u4zvmGJA7qUEkrfWh5n bnCc7GKu2h+SEtUdAuYYq7sfCIhPNyTJTzvlwXn+NasT33j4XeWpYvOvjvFhxURcsZ3srIkz3v/z3 nGGmIx0BKDSiTk5s34fyphR9j4vUm8e99Ej9M7JJMFVmr3/iG7ERXr78gvsAwsBU/GTI=; Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kKWLx-002bK7-6g for openvpn-devel@lists.sourceforge.net; Tue, 22 Sep 2020 00:40:27 +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 forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id E0ADA2E1551 for ; Tue, 22 Sep 2020 03:40:09 +0300 (MSK) Received: from iva8-88b7aa9dc799.qloud-c.yandex.net (iva8-88b7aa9dc799.qloud-c.yandex.net [2a02:6b8:c0c:77a0:0:640:88b7:aa9d]) by iva8-d077482f1536.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id jwMlyFg3NK-e9vigcp1; Tue, 22 Sep 2020 03:40:09 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1600735209; bh=lxccLRQT9/naCtZuHD1tNHh40YVBV1Nuvs8c9Tksszo=; h=Message-Id:Date:Subject:To:From; b=R351neh9R/Z6T8wj8F44VNbZZB0FJVzo2arhNypaPuXvoF+4eFg3wRwu7gTGUJrkF YsSxCgIzUlv9310jAas8JsdaMgkJnS/fXhA2vrbqA44DcRvSqeSFL/1aSWA/HciakQ 2x9ODw+sXhme0lckhG+A0xY8bKRuInoMPYlwPTQA= Received: from 37.9.85.33-iva.dhcp.yndx.net (37.9.85.33-iva.dhcp.yndx.net [37.9.85.33]) by iva8-88b7aa9dc799.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id eBgQQ5S47x-e9nS2wcE; Tue, 22 Sep 2020 03:40:09 +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 05:40:05 +0500 Message-Id: <20200922004005.10268-1-themiron@yandex-team.ru> X-Mailer: git-send-email 2.17.1 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_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: 1kKWLx-002bK7-6g Subject: [Openvpn-devel] [PATCH] Fix update_time() and openvpn_gettimeofday() 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 100ns, 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, to fix their coexistance update_time() must update "now_usec" as well, calling just update_now() is not enough. Signed-off-by: Vladislav Grishenko --- src/openvpn/otime.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/openvpn/otime.h b/src/openvpn/otime.h index a6f7ec25..fab4575c 100644 --- a/src/openvpn/otime.h +++ b/src/openvpn/otime.h @@ -78,13 +78,9 @@ openvpn_gettimeofday(struct timeval *tv, void *tz) static inline void update_time(void) { -#ifdef _WIN32 - /* on _WIN32, gettimeofday is faster than time(NULL) */ + /* can't use time(NULL), now_usec needs to be updated */ struct timeval tv; openvpn_gettimeofday(&tv, NULL); -#else - update_now(time(NULL)); -#endif } #else /* !TIME_BACKTRACK_PROTECTION */