From patchwork Wed Jul 11 10:19: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: 141715 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp104114ljj; Wed, 11 Jul 2018 03:20:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeYh3Vr/V8Glj2uq8MLgk3tybY5pqU6VagLhgulopUiu1hBf7OiHDjTYp3+6MZtWPY00azO X-Received: by 2002:a17:902:2006:: with SMTP id n6-v6mr27946102pla.325.1531304404934; Wed, 11 Jul 2018 03:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531304404; cv=none; d=google.com; s=arc-20160816; b=JjdgT93S/RZevByTgNFgeIyXnsh0NpjRJ+AVFOwX76wUc/rcNuPKUKUOkZ44wjsL/l YTTjwJ4kBsiEG1PrwLUf6n1M/T0fNNVRauopsQ35SSZ4VmDjH4wwzYLdC4PVz++o6IC3 upoRX8eYm/IgJeoMG8iWGw3th+4dyO3TuZFX0uQ1wMNTIH2mhjyQm546acipikVNwIvU 0PWOnFLNXkpAJjFE8xWb8Wm5sv5/iQHCw+Fwvmk+TOEBk8jUglKEwmtuhevd7a6z624Q it5sKUVF0s1OS472PdfWZ2mZ5XoxmwrkzZuTziv0NrpWapAod+4LIgCX6SBDdWAecMAt G0Zg== 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=HoikzrYIQ/jJ5yVtMZcYs8UiPGf+kS1Xqnx0JaR0lEs=; b=DQigSl50fJLe3f9gkRxrNBT5XL8y4+vJHhtd9DdR9oWTDav/tuLrziVHo1PcMZVz8d niQ5oG52v8h2fJ14FZVc+u7H+F40Du6ijX/bNXXFlSG38xmDb9EMhu1pup3BonECDgmN viDDRC8zHe2rRpAuUCwLBsC2d+zQNWn4hUyqlx6oBNj7gQdnPzyOyPLp9ZeCsQU2nwXa Ym0w6HK8KQ5DWT1lqGN02LevSaPhH0/s6dk7cNDvNbbG3Z5T+hebW6fBhoVnC6HZEkTF sPZg/SKhGHA9CtPk9XfhtSf5gvWJ6TDsKbqb6sI1emzZiRtxAvasFdpaWFgf5vgwDF4o ABAw== 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 s64-v6si17989417pgs.499.2018.07.11.03.20.04; Wed, 11 Jul 2018 03:20:04 -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 S1732465AbeGKKXi (ORCPT + 23 others); Wed, 11 Jul 2018 06:23:38 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:54235 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726463AbeGKKXi (ORCPT ); Wed, 11 Jul 2018 06:23:38 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.129]) with ESMTPA (Nemesis) id 0MSmNI-1fTGac3xZM-00RdNd; Wed, 11 Jul 2018 12:19:47 +0200 From: Arnd Bergmann To: Steffen Klassert , Herbert Xu , "David S. Miller" Cc: Arnd Bergmann , Florian Westphal , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] [RESEND, net-next] xfrm: use time64_t for in-kernel timestamps Date: Wed, 11 Jul 2018 12:19:13 +0200 Message-Id: <20180711101941.4039411-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K1:eDumljfDIEgHVihgCRbl9UVrxtg59JBdT0VLc0Ob8CtDSEf/hf4 0BN3jxW5YxWEec1341SDa9cl2klFVSSgSYuuYo8jihvqqj9VuxnxrJ8zs3XozBdrp4E3h3e QcyWuXz/pKyDvDqrw1hNeSixNwjREna8gU09GIEM3iCGLOJGWfiEmiwmMy6U6cJH2AtjKq4 Ua3y8oIvg6NxfU7AsGUWg== X-UI-Out-Filterresults: notjunk:1; V01:K0:kj5RcVlUw28=:mIcs7d2odMq/VxSBLsiOvr 6JwCHasJeR1geWlq7+pcob9cIPn3OGH2a4fcdeRhIb8Hpp/vcD0NaF/XXE+OJoOeU4b4pwYlY j1mLi0n5W2PzmBNzH+6SdPaI7Ucnv9fA21LG8UkjBsz67p27POmw7jmR02536pY1Ux4KT/wFH r18HqTtAopKpltgK+Za/kMQFQUf5gwJxsuzrb++CgiqHfFpCKymUOXhbASxxR5dnCezQ5OcTR OFfnw8c1/+dhpJVBSsQbEeNue8Xfl+ZALsDuz3bwOY2doTmT4eXrCbsOhj1wrTsRF13kRJlyN SD65Z8dsRl9dAamBtIT64MRKQWe9Wx9DoGS3c4RmyDg51iV2oo2R7puorRvv/84Y2UfOMY61H dRA6k9ZsZbQMLdBxmjff3r7zWioSMb6+l/scVCjftpEOObv2/nUBIPbPkXPFnRerZoIIEF3qM fDjmEH9q0kb+rVLTjr9nYFYZEuaCyowDuMqqXVtOsCst839xUct5CHqJ4bVtgGEW2Nc1Rkxio zlFqM7urZ/WJgwmBXGC05PPrieW7R87qs2jtMXqWYihhY+yU07P2mLqZsJAvUm5Bkd7KYp+t2 wh8lxh6inMLE5NKoINK38U2yqUh1C+CaAAll49YIXQSTxzQ/8S1VUcDqsHkXudw8hOwOdvcXN z9wktGXKugmIfMcY7rp3VJ3uRZdchN9CvYCEwsfXz7FcnmhrU7EVrGMxwpBxc3j4cMf0= 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 7338610d7b8f..9dbbb0d3771b 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -189,8 +189,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; @@ -202,7 +202,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; @@ -210,7 +210,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; @@ -218,7 +218,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; @@ -228,7 +228,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; @@ -240,7 +240,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); @@ -791,7 +791,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); @@ -1282,7 +1282,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); } @@ -2132,7 +2132,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 */ @@ -2355,7 +2355,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++; @@ -2369,7 +2369,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 e04a510ec992..7efc299fba56 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; @@ -1579,7 +1579,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 Wed Jul 11 10:19: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: 141716 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp104532ljj; Wed, 11 Jul 2018 03:20:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdOvbt0eV1t2Ik+J0qDaeBu5c3LMZXl5b4wUMxhHAosU1Ttn11jnmkcqnIIIPAG2AYpAmpa X-Received: by 2002:a63:c312:: with SMTP id c18-v6mr19879457pgd.449.1531304432121; Wed, 11 Jul 2018 03:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531304432; cv=none; d=google.com; s=arc-20160816; b=GIzd66O0yHbEziMFm8gAFBOWfa/3/O5usVEMUcGvNCrYpunJzGNa5GfbQ/g6upAtzI cATxn4xmaoeiMVgwZqeswX495yYVGE0bZMmXP2aDaIe/RhrG+3RjtLvTFJ3Mh9fshAgJ 8OBhrOp1lA0bgCzEkbQaDf2puoD0rutLHKAR+Y6ZGBC13zGzyvvaCpEHgzF08G209b6V NHPx/FYMtvUtFXOLP3pIqWhdeXQuYcehIkSWIGXtK3HE9kZ6RffhVwHrxQF/u9DVp0NI kJWWtQKuz0HSnL76uLzlmCLdrEDoXdgqtjsxvO7NGNTEplsuGNfINuFeRF3leRA6UYGg oJdg== 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=1yHpwg71uPzYAl4G2h44xEqqE2Imo+uqZwHdooY7DZs=; b=dYNu+QuljAgTsILHCy43utcX0jZuDC/1aJb2+IRFoECe6AZan0RR8suM8YRYWlX3Le ANkUqNsGIKKuGWYSbH1JFWmdoCZFDA1vlKA07APyu/YPDBoGEsdyNZ4ooc5998crV6xX Q50NXOU5twziQaHi31fYObznNF2CCg0YLtWaRd4D5V15yNR5DZOBchgODIWV0XZxC12r kG3epZE3+EowUplh+MY1nuaOLx40vfTR8s0pfJ7jf/GMuJYk0mFbPOTwJ2j9Qd4dcCQQ 1TVvLPxjnaqjBcqiTGk4ZjOeTfGEYnf5TUpszepH7zcsi2SlWj06Kt/8YUzqmkQvhMLl Y9Wg== 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 r25-v6si18010840pge.104.2018.07.11.03.20.31; Wed, 11 Jul 2018 03:20:32 -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 S1732521AbeGKKYG (ORCPT + 23 others); Wed, 11 Jul 2018 06:24:06 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:40601 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732499AbeGKKYF (ORCPT ); Wed, 11 Jul 2018 06:24:05 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.129]) with ESMTPA (Nemesis) id 0Lnopk-1gIpVx2qO8-00fwBt; Wed, 11 Jul 2018 12:20:17 +0200 From: Arnd Bergmann To: Steffen Klassert , Herbert Xu , "David S. Miller" Cc: Arnd Bergmann , Alexey Kuznetsov , Hideaki YOSHIFUJI , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] [RESEND, net-next] ipv6: xfrm: use 64-bit timestamps Date: Wed, 11 Jul 2018 12:19:14 +0200 Message-Id: <20180711101941.4039411-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180711101941.4039411-1-arnd@arndb.de> References: <20180711101941.4039411-1-arnd@arndb.de> X-Provags-ID: V03:K1:oPTogUBpFHn0fyK8ppcY26kg3RNuctUI+j2Z/4enDutxGpW9bSv MISQcAq/LbXnIPpjHy94HA/Hu9VlP6e585Z4JCtAJD4PaIlhr2Z8WOborRNrFjA7FT2v8TP 9om3d0nYNXsdokWvm33H04GUI1ZIQ3SJUwrUVP1HtQ/U8QR2PhqzVjEQm6wcO4cVfaVrBty nMkcZtC+iHoSPsPTWR2lQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:E7NASbAE02s=:gQJKalm6BOP3IqAvN8tsF9 AhKkb4S+54c/yaarIDeD2I7emUBuosxh8hW1HB8uigzJFmK9/fBeFA5ZrSzcg82oO3VxEP7w0 4EQa4dy2lNp8HUspUN3SFYLTzh3xGvj16sM5hHHF+CAOvN1/kYwz0GCSoO2obWCC4ZNDnw83e 8FQmgU7f6fmovRC/P5i41RE2fw/08LQSmCNn+rqO1G5kh9fM8+0LCrLEwuVFv9X4YQgMpbnm9 Ru8VxnIZEuV4T732SKAGnKvEHPvikgfPe91IKb3J/DusXTH201EVIoziWS9BBiApUEteXr0xL bzxBlnFc4VBPKST5RZ4+cv/lJ59nVgdFBa57ngdAqKrx8HDdVfZR3yLZCblOxZbWw1QVvalvG mxi+5nz1LDHQlNsQNg4HKwKXb500gLtf6fnjdW8tpTn3bivq7xPVC+/NU4FwBgovi3DBExvx/ Tmn+bW2GWEOGuCRkrJMSljlYcLaYkHpcbEMQIVx0PCrlWd+ZZGB9KJsnfZpcmiTZBmZ1cmZyJ sQks/MiJSvdMK2yKR9+PRx07jIh5y7Ym31nfm0+SNCUfqZdSOhIQEyNLLTVt+u5WemRoBN8nL LynxuhUFVdBkmhKMXOM8z1z7H9W6+YVhoidttMWMHbp65gX8S3PvKb8a6U9+y3BlIXty3QDFD UQTkVxlgDrqeyiEAcLqUf7HJ6WF3LJQrlo07kx7AJnoaw3qlOqBbT0scssYHglwCAYic= 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 51cc475b87e0..d704b662a94b 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h @@ -227,7 +227,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; }