From patchwork Mon Mar 5 19:09:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selva Nair X-Patchwork-Id: 264 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net (Dovecot) with LMTP id MwESHBcxnlrfNwAAIUCqbw for ; Tue, 06 Mar 2018 01:11:35 -0500 Received: from proxy13.mail.ord1d.rsapps.net ([172.30.191.6]) by director9.mail.ord1d.rsapps.net (Dovecot) with LMTP id swzcGxcxnlrzNwAAalYnBA ; Tue, 06 Mar 2018 01:11:35 -0500 Received: from smtp33.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy13.mail.ord1d.rsapps.net with LMTP id AD6hGxcxnlrZGwAAgjf6aA ; Tue, 06 Mar 2018 01:11:35 -0500 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: smtp33.gate.ord1d.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=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Classification-ID: 38b3aab8-2105-11e8-933b-525400041ef2-1-1 Received: from [216.105.38.7] ([216.105.38.7:10435] helo=lists.sourceforge.net) by smtp33.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id FC/D8-18631-7113E9A5; Tue, 06 Mar 2018 01:11:35 -0500 Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1et5nA-000g3o-GM; Tue, 06 Mar 2018 06:09:40 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1et5n8-000g3i-Ru for openvpn-devel@lists.sourceforge.net; Tue, 06 Mar 2018 06:09:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: 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=KuPG5hRpb4c5oTkcJy7PLQcH1vP6nwFRDiPyTKZ4lHM=; b=UAE2vZEeeJyRFsCR1OcIOmuitH VabxOVUZen401iM1ZqyTUkHbe/WO8XHExZUPMdazjfseIIXImX7LHjStyt6bdzoQsoUpvzMn9NSru Du271ELWqBT+4V5oTl3d/9v++xvnBSjPb4ijEnMvnD4JlXLM+WXc7H4ffCngPrff1uaU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: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=KuPG5hRpb4c5oTkcJy7PLQcH1vP6nwFRDiPyTKZ4lHM=; b=LtdDB8A0Icv+KlyMSFV5P63Bgn 3qAI4tPIlxtZqxlZYga16yF6DxXUYC+4jZgAupD5Y+jmiO7BF5ldhsSobm/SaBo8H04oSQ1mz3oz9 iG405I5YKkAlFCEfb+s2GORw96g43fP9b9YgxjbJa0Gyz6jchsyBd4TdB7IIDUpAHdeg=; Received: from sfi-lb-mx.v20.lw.sourceforge.com ([172.30.20.201] helo=mail-it0-f65.google.com) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) id 1et5n7-002Rf6-6q for openvpn-devel@lists.sourceforge.net; Tue, 06 Mar 2018 06:09:38 +0000 Received: by mail-it0-f65.google.com with SMTP id w19so11593854ite.0 for ; Mon, 05 Mar 2018 22:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=KuPG5hRpb4c5oTkcJy7PLQcH1vP6nwFRDiPyTKZ4lHM=; b=n39hq7/IK8hhYuxYfG2rg/UMTheuNEI9xAXZ07xilKPiN86uDD4SJtsC3HSdek3uJl AqG7jmt8WEmiWEqEwU+YlkSEm585/LOarKTsc43AvOZgaWZ+hazAVthJ7HgAqaTO3lQA Q8PQzZxkQ3IBL5MQ3QU/oMO22LHi2xX/voRemE5lj0buU1/ROldG6+YFEwIeSs4c+aJl 66CmMLEPpg5x1eq7VAO8hyKTRCZyToyTIz958fk3VEvsMztxnJA1fUkH+piAbgehi3PW UujOQDnC5Q6TkF+lyuPUEpWavm/XaDB0J3yt+hjlQX4CEHGUbQ1WA2oZvUj0J7vLBfCn 1Dcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KuPG5hRpb4c5oTkcJy7PLQcH1vP6nwFRDiPyTKZ4lHM=; b=AxtbmDJAooc3qK0mRQCDPyISDJZUclYTJoI42HSOi2ZsDSIH+bsg61WbNkH+l5bSEm hE3p+urysEsjJnwEyM1PzdFXub/orfCVoh2Ax22pqqB5/QtVjLR7yWZ3gB4AP2ltMPPG aSws2/k99Lwb0fqatMRoB2vMkonkZJHth5YYA/on9wA+r8TOH1xg3yyp0CrXSJIUJYvA Klj9fi0pEy4jWPqqR1xD5KF2uyQSB/gFZu8bRNF+H4X8H+Q1HKmBkix61L9961X2RwJd I/tixhbGq7r0x3qUbzpT5rd1KG8tJhJwIN1oyWPIKsFSwBcRs7mpt0SxPawYGIORdcP1 L0Dg== X-Gm-Message-State: AElRT7Hy1vxBQScT963bhX0Sa6AtB2zBun/mXuw+47Eg6sJgEfpERmzO udXDvpI3+dFo+AV/VsvJQOkIm+XQ X-Google-Smtp-Source: AG47ELu2LqFs5qd9DZSFjvu+upO6eJXfC0HqGl7hj/b0lOHlR13kGlACRup5s0F+qUZNCob+E9Pclg== X-Received: by 10.36.165.75 with SMTP id w11mr17414477iti.136.1520316571522; Mon, 05 Mar 2018 22:09:31 -0800 (PST) Received: from saturn.home.sansel.ca (CPE40167ea0e1c2-CM788df74daaa0.cpe.net.cable.rogers.com. [99.228.215.92]) by smtp.gmail.com with ESMTPSA id y126sm3196963itc.29.2018.03.05.22.09.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Mar 2018 22:09:30 -0800 (PST) From: selva.nair@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Tue, 6 Mar 2018 01:09:28 -0500 Message-Id: <1520316568-8983-1-git-send-email-selva.nair@gmail.com> X-Mailer: git-send-email 2.1.4 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (selva.nair[at]gmail.com) 3.6 RCVD_IN_PBL RBL: Received via a relay in Spamhaus PBL [99.228.215.92 listed in zen.spamhaus.org] 1.3 RCVD_IN_RP_RNBL RBL: Relay in RNBL, https://senderscore.org/blacklistlookup/ [99.228.215.92 listed in bl.score.senderscore.com] 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1et5n7-002Rf6-6q Subject: [Openvpn-devel] [PATCH] Avoid overflow in wakeup time computation 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 From: Selva Nair Time interval arithmetic can overflow especially when user defined intervals are involved. E.g., see Trac #922. Avoid this by reordering the arithmetic operation in event_timeout_trigger(). Also avoid unnecessary casting of time variable to int. Time until wakeup is now calculated like: time_t wakeup = (last - now) + delay Here delay is of type int, but is +ve by construction. Time backtrack protection in OpenVPN ensures (last - now) <= 0. Then the above expression cannot overflow (provided time_t is at least as large as int). A similar expression in interval.h is also changed. (This patch grew out of patch 168 by Steffan Karger.) Signed-off-by: Selva Nair Acked-by: Steffan Karger --- src/openvpn/interval.c | 8 +++++--- src/openvpn/interval.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/openvpn/interval.c b/src/openvpn/interval.c index 00ee627..b728560 100644 --- a/src/openvpn/interval.c +++ b/src/openvpn/interval.c @@ -51,11 +51,12 @@ event_timeout_trigger(struct event_timeout *et, if (et->defined) { - int wakeup = (int) et->last + et->n - local_now; + time_t wakeup = et->last - local_now + et->n; if (wakeup <= 0) { #if INTERVAL_DEBUG - dmsg(D_INTERVAL, "EVENT event_timeout_trigger (%d) etcr=%d", et->n, et_const_retry); + dmsg(D_INTERVAL, "EVENT event_timeout_trigger (%d) etcr=%d", et->n, + et_const_retry); #endif if (et_const_retry < 0) { @@ -72,7 +73,8 @@ event_timeout_trigger(struct event_timeout *et, if (tv && wakeup < tv->tv_sec) { #if INTERVAL_DEBUG - dmsg(D_INTERVAL, "EVENT event_timeout_wakeup (%d/%d) etcr=%d", wakeup, et->n, et_const_retry); + dmsg(D_INTERVAL, "EVENT event_timeout_wakeup (%d/%d) etcr=%d", + (int) wakeup, et->n, et_const_retry); #endif tv->tv_sec = wakeup; tv->tv_usec = 0; diff --git a/src/openvpn/interval.h b/src/openvpn/interval.h index 826a08b..5623f3a 100644 --- a/src/openvpn/interval.h +++ b/src/openvpn/interval.h @@ -196,7 +196,7 @@ event_timeout_modify_wakeup(struct event_timeout *et, interval_t n) static inline interval_t event_timeout_remaining(struct event_timeout *et) { - return (int) et->last + et->n - now; + return (interval_t) (et->last - now + et->n); } /*