From patchwork Mon Jun 18 15:22:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 138997 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4081387lji; Mon, 18 Jun 2018 08:23:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLKx/EKLvMH3QWCDeuAkESFv8PVIusEWK4cMuo4OybGRWKjFiyZvUVdGHHM4ORR5gAozJOk X-Received: by 2002:a62:bca:: with SMTP id 71-v6mr13758198pfl.234.1529335393773; Mon, 18 Jun 2018 08:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529335393; cv=none; d=google.com; s=arc-20160816; b=goX7LcjYU0wQ/Xyi1dSBlvV4k7yoWPaAUM8Mz5PjxYbChkl+wA3h9/werXvm57BZU6 3YlerD3kFzvdCInml1/xyKoAUl553MvopirIGaSfpX6qzJ+KWTzc2Mhhw6AR0d9yXyfb E6ruFjP23F1STKoLEqMYXxMrB3rBoNCOLPYWzVF5gpgPgaYkkaGoU792uK/jFBEwuH1/ 7rh7bOfRIkAlrbL1FeHOAdHbCUTkAgnizw8pJIp1w3D3T1PBUNVBtk43HFViP2cH+Dj+ lTWMprUqWs40+ZwU00TUuqM1XUCSr7tkXQ4bXqYzPxV6L8sGftjI/k0aOYtD4MYPTuyv P4bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=MUTUsDONPNiLyr1rsCg/JPmix6WvaCwZyDKH0u3ltU8=; b=rlA4b5nNljgJUA3BPxflDLpEV3GcfUYi2de5NgtQcd1dlTMhmDNTV6wpNhf+jlmukE ca4XR82XgRsqAelxZMVWQUe6O9gXCEWryfQfvzFakGOTjnKI1NXFyFfpmCkXJFie26Zc 2fMF6O8yPDyiBML3GFd9eXS/IWgysqvLsGcYSLforGPHVAnjB4sTbWg16NdwdXj55/xH eZtgb/jaItASwCRUswfi7IZKlVmlFeI5sCikCOP6XQhsD0SjLNx0vl8UF+uI64LADZjX bSQoJYApyrTjIGKXVIa7gFJJmB7alO1slnaeg5pkXuxTT+BioIAHd25UiJ2DFPQUnC9f M2Qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p23-v6si15214643plr.384.2018.06.18.08.23.13; Mon, 18 Jun 2018 08:23:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754940AbeFRPXL (ORCPT + 30 others); Mon, 18 Jun 2018 11:23:11 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:59731 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750910AbeFRPXJ (ORCPT ); Mon, 18 Jun 2018 11:23:09 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0M8iqK-1fNFxj1kUu-00C6RC; Mon, 18 Jun 2018 17:22:47 +0200 From: Arnd Bergmann To: Steffen Klassert , Herbert Xu , "David S. Miller" Cc: y2038@lists.linaro.org, Arnd Bergmann , Florian Westphal , Eric Dumazet , Kirill Tkhai , Lorenzo Colitti , Al Viro , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/3] xfrm: use time64_t for in-kernel timestamps Date: Mon, 18 Jun 2018 17:22:13 +0200 Message-Id: <20180618152242.1566661-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K1:YDM89EYLc97ArtFrjQTZBNvz2IcWh0tqsY+SSdl47X9836aok9V a8FMh1HsyU8JZhh/h9kyhL5vSol5FDtB0FswCmZ3lH72pM7/ckTWMdRSOXD/ysaDTJjo4qE FcxfClAxpiTFc9IIT8oRBpjPZ0l7N4QJAimAxXH/u6AMEcMY6oSIThLmJaWyJtwLNvwWHEW 4fil9jJG8uBYZDibuKNNg== X-UI-Out-Filterresults: notjunk:1; V01:K0:rBt5a3aPgVA=:T4lqh41oShp+kH2mVwezeB uvPeeKtcvyfCXGs6ye2QSXdBAMtWW0mfcrZ+KUkAinOQ+EYUkIjJTGyi7ql08Wl0XRpg5y+l+ gGXmD3wj9bWUGyexbKJ/8h/3rRsAqsICP0qYzSY90N8X+vscxJhwfPeVtfMnEmLB2uL6i4v3L 9u/S2ikNbFvSAa/ApazOwUY9MBDlDHBYm1q/J7cKYAMG7qr4keaBE3bwFU5WLzVfsy7NmSCqF g1ueTk9JEcaiWb9MxvNxgL6igHAO3qEeasJwluQkDlnHTYQTxVLydU+fzvIpj01W7Ni1/WUf7 CE5axfQYCEZLWiY59uZXYUQ1GgSULrmHk/JxTq3Z4m/DiIpIVHiPr3Y12zS+9gi+gAJNEsk1m ZMnaVuUTPTqO409/mIp1/zw2sMvc3docPLiPrdDIjYNieSn4NcdCf5Vt9/rsKwMUqJHoynobs pb1p1q/0gn91oALWwlbH/mjFOrnTKLqKQRm4bpG5Vu5NxxgY9rT3gIi5uxMkQOqZFOXdDLG+W s837/EUzPT0JO7hLlGnG9FiwDnDqFuKgYKKVvSJHVRBxj9CuW9h427CrXsVzPBVjPAr/AxSEu RT50ZKz6jrseP7jlXCFlUvbc1FMCzqND78kkiEj34tFtyJX0d7jkDUY0wXj1q7qbmUkjrps+Q Zf/8okQOU5Ppk+b6BWkPvp6aoKkNBl0jwwuAuJBDLQ2CJG9VCrXt72FzsBWmpDJQFKsw= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The lifetime managment uses '__u64' timestamps on the user space interface, but 'unsigned long' for reading the current time in the kernel with get_seconds(). While this is probably safe beyond y2038, it will still overflow in 2106, and the get_seconds() call is deprecated because fo that. This changes the xfrm time handling to use time64_t consistently, along with reading the time using the safer ktime_get_real_seconds(). It still suffers from problems that can happen from a concurrent settimeofday() call or (to a lesser degree) a leap second update, but since the time stamps are part of the user API, there is nothing we can do to prevent that. Signed-off-by: Arnd Bergmann --- net/xfrm/xfrm_policy.c | 24 ++++++++++++------------ net/xfrm/xfrm_state.c | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) -- 2.9.0 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 5f48251c1319..9f4afca8b4f5 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -182,8 +182,8 @@ static inline unsigned long make_jiffies(long secs) static void xfrm_policy_timer(struct timer_list *t) { struct xfrm_policy *xp = from_timer(xp, t, timer); - unsigned long now = get_seconds(); - long next = LONG_MAX; + time64_t now = ktime_get_real_seconds(); + time64_t next = TIME64_MAX; int warn = 0; int dir; @@ -195,7 +195,7 @@ static void xfrm_policy_timer(struct timer_list *t) dir = xfrm_policy_id2dir(xp->index); if (xp->lft.hard_add_expires_seconds) { - long tmo = xp->lft.hard_add_expires_seconds + + time64_t tmo = xp->lft.hard_add_expires_seconds + xp->curlft.add_time - now; if (tmo <= 0) goto expired; @@ -203,7 +203,7 @@ static void xfrm_policy_timer(struct timer_list *t) next = tmo; } if (xp->lft.hard_use_expires_seconds) { - long tmo = xp->lft.hard_use_expires_seconds + + time64_t tmo = xp->lft.hard_use_expires_seconds + (xp->curlft.use_time ? : xp->curlft.add_time) - now; if (tmo <= 0) goto expired; @@ -211,7 +211,7 @@ static void xfrm_policy_timer(struct timer_list *t) next = tmo; } if (xp->lft.soft_add_expires_seconds) { - long tmo = xp->lft.soft_add_expires_seconds + + time64_t tmo = xp->lft.soft_add_expires_seconds + xp->curlft.add_time - now; if (tmo <= 0) { warn = 1; @@ -221,7 +221,7 @@ static void xfrm_policy_timer(struct timer_list *t) next = tmo; } if (xp->lft.soft_use_expires_seconds) { - long tmo = xp->lft.soft_use_expires_seconds + + time64_t tmo = xp->lft.soft_use_expires_seconds + (xp->curlft.use_time ? : xp->curlft.add_time) - now; if (tmo <= 0) { warn = 1; @@ -233,7 +233,7 @@ static void xfrm_policy_timer(struct timer_list *t) if (warn) km_policy_expired(xp, dir, 0, 0); - if (next != LONG_MAX && + if (next != TIME64_MAX && !mod_timer(&xp->timer, jiffies + make_jiffies(next))) xfrm_pol_hold(xp); @@ -783,7 +783,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl) } policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir, policy->index); hlist_add_head(&policy->byidx, net->xfrm.policy_byidx+idx_hash(net, policy->index)); - policy->curlft.add_time = get_seconds(); + policy->curlft.add_time = ktime_get_real_seconds(); policy->curlft.use_time = 0; if (!mod_timer(&policy->timer, jiffies + HZ)) xfrm_pol_hold(policy); @@ -1268,7 +1268,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol) old_pol = rcu_dereference_protected(sk->sk_policy[dir], lockdep_is_held(&net->xfrm.xfrm_policy_lock)); if (pol) { - pol->curlft.add_time = get_seconds(); + pol->curlft.add_time = ktime_get_real_seconds(); pol->index = xfrm_gen_index(net, XFRM_POLICY_MAX+dir, 0); xfrm_sk_policy_link(pol, dir); } @@ -2234,7 +2234,7 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, } for (i = 0; i < num_pols; i++) - pols[i]->curlft.use_time = get_seconds(); + pols[i]->curlft.use_time = ktime_get_real_seconds(); if (num_xfrms < 0) { /* Prohibit the flow */ @@ -2446,7 +2446,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, return 1; } - pol->curlft.use_time = get_seconds(); + pol->curlft.use_time = ktime_get_real_seconds(); pols[0] = pol; npols++; @@ -2460,7 +2460,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR); return 0; } - pols[1]->curlft.use_time = get_seconds(); + pols[1]->curlft.use_time = ktime_get_real_seconds(); npols++; } } diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index 8308281f3253..1c2b6fdd9518 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -475,8 +475,8 @@ static enum hrtimer_restart xfrm_timer_handler(struct hrtimer *me) { struct tasklet_hrtimer *thr = container_of(me, struct tasklet_hrtimer, timer); struct xfrm_state *x = container_of(thr, struct xfrm_state, mtimer); - unsigned long now = get_seconds(); - long next = LONG_MAX; + time64_t now = ktime_get_real_seconds(); + time64_t next = TIME64_MAX; int warn = 0; int err = 0; @@ -537,7 +537,7 @@ static enum hrtimer_restart xfrm_timer_handler(struct hrtimer *me) if (warn) km_state_expired(x, 0, 0); resched: - if (next != LONG_MAX) { + if (next != TIME64_MAX) { tasklet_hrtimer_start(&x->mtimer, ktime_set(next, 0), HRTIMER_MODE_REL); } @@ -577,7 +577,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net) tasklet_hrtimer_init(&x->mtimer, xfrm_timer_handler, CLOCK_BOOTTIME, HRTIMER_MODE_ABS); timer_setup(&x->rtimer, xfrm_replay_timer_handler, 0); - x->curlft.add_time = get_seconds(); + x->curlft.add_time = ktime_get_real_seconds(); x->lft.soft_byte_limit = XFRM_INF; x->lft.soft_packet_limit = XFRM_INF; x->lft.hard_byte_limit = XFRM_INF; @@ -1571,7 +1571,7 @@ EXPORT_SYMBOL(xfrm_state_update); int xfrm_state_check_expire(struct xfrm_state *x) { if (!x->curlft.use_time) - x->curlft.use_time = get_seconds(); + x->curlft.use_time = ktime_get_real_seconds(); if (x->curlft.bytes >= x->lft.hard_byte_limit || x->curlft.packets >= x->lft.hard_packet_limit) { From patchwork Mon Jun 18 15:22:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 138999 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4081789lji; Mon, 18 Jun 2018 08:23:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL4z57QH889CqOL2uA84nfqivUGBL7gJuURvGs+adOEyl7D/x4c2fH1di5Zt4Wr5yTQXiRt X-Received: by 2002:a62:ea14:: with SMTP id t20-v6mr14114927pfh.117.1529335415267; Mon, 18 Jun 2018 08:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529335415; cv=none; d=google.com; s=arc-20160816; b=NSTimAsymgF1Z4iIupigN7w3FAqHUEF5hso23ZlJjaxqQDt+R/PkqTl4f7E9pe0n4P nj6Y5QcpkOC05Nt+bO1T6ch6v+cojktfz1r94vATt1bpnuTY+4ZRlzYrzi+ygUas5Gn4 hFAGOf4Er9OJwsPR7Z/FO9kVDOmocnsrdIoQ5cA7bXa+rp5qs5AXKTassJJQgyi8FaeO pY0Hi4/CZ3jj69/clS/GnGzmvvQFPNEZR5+AHFSkdEqjEhDigcGRGNuWvnHHrFKb3RYa sFhdvjXPwFU9K3HYpAaRw+8x5N5rpKXb4l8sue6EGjhKq0/NTWZskVzdGIGrqxXCsm7q t8dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=sFAGZ5hkhV9gkcvGYzmgUuFXo55I77Vht2VvpdPlOvo=; b=I313a+1C2jxy2ozMZVgGIzz+q7/9QLOyyuRBeRslPjn378obTe63DHdMSfpmyNhVXt GlsAHhXSMAmo0s5SP4kuKwup3M2PwvxxaB4lcb//yIXwYS4X4I1OGPdJ/M5WaMAqnS/j ++7PLYaBJk9y2QgmQ+zDW7oJ5vb+Nl7nKM59QluXOizzn9E9vl6rAj+PcBMtEUEc2+uv ML1HoEgiWMVR35zpwUlHCVkzmYhNJdO7VN5Lx/M3w4z/Kj+9fud8NxYbrmdKp46O2fUi 0UzN2o/pIMGi0eDGaXzE+SUf4MAEBlzORjeRjdbKrZF1y2kAPemgKixUnkbfGspDL6bO 5Afg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61-v6si15158608pla.92.2018.06.18.08.23.34; Mon, 18 Jun 2018 08:23:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755150AbeFRPXd (ORCPT + 30 others); Mon, 18 Jun 2018 11:23:33 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:56387 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754110AbeFRPXb (ORCPT ); Mon, 18 Jun 2018 11:23:31 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0Lpvbr-1g6Tvv3fKp-00fjAT; Mon, 18 Jun 2018 17:23:09 +0200 From: Arnd Bergmann To: Steffen Klassert , Herbert Xu , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI Cc: y2038@lists.linaro.org, Arnd Bergmann , Alexey Dobriyan , Hans Liljestrand , Kees Cook , "Reshetova, Elena" , Florian Westphal , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/3] ipv6: xfrm: use 64-bit timestamps Date: Mon, 18 Jun 2018 17:22:14 +0200 Message-Id: <20180618152242.1566661-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180618152242.1566661-1-arnd@arndb.de> References: <20180618152242.1566661-1-arnd@arndb.de> X-Provags-ID: V03:K1:MumUtdStB+H7OHowHs5Dcrf+8C5zawBp39altZ0CBRX/P/rSezf /ZYMxO1hj5Enwdvff3psaUnnoPR22wB/9MSlojFjgpihmzsfq3njgQE57C3mWhAUqw6SZXi GTKN4qGBZYyBgk6tFvw94pEsjkHWCNQC0XaVKJD6NMWbqn7cQSR9gd34y3d9SxW9oMh4vb4 hLBQ112szslLAyYfBuAIA== X-UI-Out-Filterresults: notjunk:1; V01:K0:DdqbT/qtOlo=:Jz7ILWoAsbYd7qjuavkI0B wvTMNERisN6+ye9w1Eq0bbuy3wxgXpiErRcoLY1UcF3CG4N7aJefPWLeVnhXacAdH8aQZUss6 5Q1kQ+emx+SX0q+xz+fGmyiRZZvUrQfGnDxPc0yhGmBVVAHWG94QzIZ1r8KBHoEHsdBJXb2rL wTFCp/7YAkR13cOQx1l1Nd7yUuvkH8rshBvNCFA/0uOtxnKgLw+9R4jDgnz9AebeDsgj5Y0IS YOoZO/aJLjTYqU2s90F6jYpjhNhUjy48ILtg63fYCqYmrws/4L6ehEKaerA0p57ofUmnuYFk+ PrUS/7dulARJr26ozgyUpWzSa5snlENtEW7+5cm3LhHQCRsvXIO+o9uD8un6HnsODuCLv+zvc xhpIQzO1dqm1y/PyOaieVomrQe43SlYW8zObFJsow2z2XpQUiYxrXHuBRgyYFpbI3mbpY1ijs WpvGApiUY4e3zrXe8P+e01qZvDrmjRUGZqwGXdEpD97cY6/EH5/rXdsThosxj+TMUMCKp2XlK vra4mLcl0dmdnGZdWzw2WQ4OZn5jnymJ0Eb0lN0wPECHGtPGyqypWE4Pm0cS/AIQNA0CxFct4 m2PviToQL+OI+CA2Y8jxJE07uvgkC8t+lZoVUe45IyCP/pwBUSEFpEWKT76KdRoTHzYgVltYm ekNuyQZ+/j6rWlBHXfxE5RC75CGcp/LVitkeC6h8bmjmjaTi4quc9b3boc0UNFskVijE= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org get_seconds() is deprecated because it can overflow on 32-bit architectures. For the xfrm_state->lastused member, we treat the data as a 64-bit number already, so we just need to use the right accessor that works on both 32-bit and 64-bit machines. Signed-off-by: Arnd Bergmann --- include/net/xfrm.h | 2 +- net/ipv6/xfrm6_mode_ro.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.9.0 diff --git a/include/net/xfrm.h b/include/net/xfrm.h index 557122846e0e..d9031415402f 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h @@ -225,7 +225,7 @@ struct xfrm_state { long saved_tmo; /* Last used time */ - unsigned long lastused; + time64_t lastused; struct page_frag xfrag; diff --git a/net/ipv6/xfrm6_mode_ro.c b/net/ipv6/xfrm6_mode_ro.c index 07d36573f50b..da28e4407b8f 100644 --- a/net/ipv6/xfrm6_mode_ro.c +++ b/net/ipv6/xfrm6_mode_ro.c @@ -55,7 +55,7 @@ static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb) __skb_pull(skb, hdr_len); memmove(ipv6_hdr(skb), iph, hdr_len); - x->lastused = get_seconds(); + x->lastused = ktime_get_real_seconds(); return 0; }