From patchwork Fri Jul 27 07:24:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Klassert X-Patchwork-Id: 143014 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp489706ljj; Fri, 27 Jul 2018 00:25:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfmEtjDEgQA1TJH1cutq1DZCAkb8l0HP1fPqAHIEYLNHk7enT83D61kjtNSNuFThUzqNm6F X-Received: by 2002:a17:902:7586:: with SMTP id j6-v6mr4948914pll.295.1532676317409; Fri, 27 Jul 2018 00:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532676317; cv=none; d=google.com; s=arc-20160816; b=U3skDgtljas4TVcVjreo8UpilnXLD6Bpu3U0fW7HCNUAOTVQ18IO12FMMXfclyZCZC JWDynU2dunY9rZbmOACfZ0EJWmAVo+k7KFMWuTvS65Uf4YpZWauzwVFwwLpB5k0OS1jr 8bitEXZgSPD6eIDN+rNlpZysMWRPtq3HBcLIu94+bnGuXlFiR72LjLqPiQXMAp2QZ6Zv JSjr7mzjK1NG+/drWLz0c+1IjjddMpVa/u5z7vIlCi2A+hGImDa2xYvANbWd1j3cE4U1 DyYSjs+NlLJz1LPq39zzvcIfi2m+vlqomGhDAYOCbRsLmob/z9bzmygv+KKR6v4ixkXi WrqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=BThXkgEso/qeH48TcKDJALm8jpU8q1QYhKQVj3AFDRw=; b=HzaSXsPmk2DmKgenlO2XfLHP/qxyLELkHC2+AyQ5d2ndm055mqKosIktayqDa+MsbV BD01szlHSRu6kLboOetqGdLFUmnUj4EIxSDaLjJbfO4DM7NqdZqAkubLK0CoJmK+jSAI 9nPkG2KeLdJitks/s5kTUXIrDRAegaB4C80YCvKTQP8drSuORLvWFKcRWuh/Yc6sa9Vj glPR8cQhIB7Fos1j5S21pJ9/CsSAt2n7MJdQ7sbjeP9xJr8IPvg3TapWHTwAyWT5kuq8 xFiz5W0gSL3t/iuF9CJKBAm5VRY+59bmouFk82UaemZSy8AjUumAEOw7apJ1Dbl2Cnwn VUFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 w13-v6si2913643plp.51.2018.07.27.00.25.17; Fri, 27 Jul 2018 00:25:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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 netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729955AbeG0Ipe (ORCPT + 10 others); Fri, 27 Jul 2018 04:45:34 -0400 Received: from a.mx.secunet.com ([62.96.220.36]:57494 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729547AbeG0Ipd (ORCPT ); Fri, 27 Jul 2018 04:45:33 -0400 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id 0F79A201C8; Fri, 27 Jul 2018 11:24:43 +0200 (CEST) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LawZRS1dVFCj; Fri, 27 Jul 2018 11:24:42 +0200 (CEST) Received: from mail-essen-01.secunet.de (mail-essen-01.secunet.de [10.53.40.204]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 9C405201CA; Fri, 27 Jul 2018 11:24:38 +0200 (CEST) Received: from gauss2.secunet.de (10.182.7.193) by mail-essen-01.secunet.de (10.53.40.204) with Microsoft SMTP Server id 14.3.399.0; Fri, 27 Jul 2018 09:24:53 +0200 Received: by gauss2.secunet.de (Postfix, from userid 1000) id D4DB33182134; Fri, 27 Jul 2018 09:24:52 +0200 (CEST) From: Steffen Klassert To: David Miller CC: Herbert Xu , Steffen Klassert , Subject: [PATCH 07/14] xfrm: use time64_t for in-kernel timestamps Date: Fri, 27 Jul 2018 09:24:42 +0200 Message-ID: <20180727072449.11896-8-steffen.klassert@secunet.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180727072449.11896-1-steffen.klassert@secunet.com> References: <20180727072449.11896-1-steffen.klassert@secunet.com> MIME-Version: 1.0 X-G-Data-MailSecurity-for-Exchange-State: 0 X-G-Data-MailSecurity-for-Exchange-Error: 0 X-G-Data-MailSecurity-for-Exchange-Sender: 23 X-G-Data-MailSecurity-for-Exchange-Server: d65e63f7-5c15-413f-8f63-c0d707471c93 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 X-G-Data-MailSecurity-for-Exchange-Guid: 0C07722A-BC9F-4DD0-9328-1BB034C692CB Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arnd Bergmann 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 Signed-off-by: Steffen Klassert --- net/xfrm/xfrm_policy.c | 24 ++++++++++++------------ net/xfrm/xfrm_state.c | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) -- 2.14.1 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index ef75891450e7..5d2f734f4309 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 */ @@ -2352,7 +2352,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++; @@ -2366,7 +2366,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 c9ffcdfa89f6..27c84e63c7ff 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; @@ -1588,7 +1588,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 Fri Jul 27 07:24:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Klassert X-Patchwork-Id: 143013 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp489474ljj; Fri, 27 Jul 2018 00:25:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcQBGdi+T9EcFqdpnuFK/3q5XwwOkN84ZmiUVYYVur5w8LJ+RobU6mcDhBeHNqsUqci+gJK X-Received: by 2002:a63:81c3:: with SMTP id t186-v6mr5029985pgd.413.1532676303184; Fri, 27 Jul 2018 00:25:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532676303; cv=none; d=google.com; s=arc-20160816; b=QJuphzYsGCc/qfgpYpgemVC3utFPloMWtnwDjexDlcYMPcghD7b2O8dzMtC8JSnWUf CxgX/fcb+EsGD2zhoJJiOBRLkI7wTC/8dwliAbCoK2hcEyydO9B6hkjWrRyDovdgEc/q MrB1fL/zKGwiIQmxVklI+iaIMiVVGwmudbPhk8nCaa6/n2o+daZWYIxi/c98k60u5cRd xKauQBuRXDuR5AEfVKPLZOc/1hCclSya81xtiT6ddKfyMA6gQoa/hyrQdX3mgY87SbBh QoFjMRX3+YBRrENzXv/0gRGgDwN+umapFFYv9X3+YE3qS6zuOSWvqixN/Nq7PX2B5A4V Nsgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=mIxUwJ0KcCOTT/+cs+HG9VOuvjWMcFZJs4/2P8Muya4=; b=mNGIrrwbXMj8KKCivAZXVHJq6QUPIT1/TjnEn8qNIbCrOGUvz0f69f4gTQcEshfKNG aOpJ2pcYrlrRCmzok3ud50SBhhYpFCnGbe8+qQYltwM8v/MoOWvOKEZz9lR2NF95TMMc ek9u5upa98GhvaUfs0aqk2gJlVdCPzpZwaOzHJkrof9zDVt9nMvmVNQkPF8O4Bv+TkaH XuzB5mOcsbKgNoMV2IJ4TcOvtUSnkQ3MWN/exU242PSt/U+VEWkOmAGW/URmCTG2Aggv pGmEJyI7v1MmHtsotODyJnRfN7O6R8/olWeOeV3CdXCbHpn5wv1quRN+o39UBs96lWUN jYLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 w13-v6si2913643plp.51.2018.07.27.00.25.02; Fri, 27 Jul 2018 00:25:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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 netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730189AbeG0Ipf (ORCPT + 10 others); Fri, 27 Jul 2018 04:45:35 -0400 Received: from a.mx.secunet.com ([62.96.220.36]:57462 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729483AbeG0Ipc (ORCPT ); Fri, 27 Jul 2018 04:45:32 -0400 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id CEF52201BF; Fri, 27 Jul 2018 11:24:41 +0200 (CEST) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zMNYOW7dcp83; Fri, 27 Jul 2018 11:24:40 +0200 (CEST) Received: from mail-essen-01.secunet.de (mail-essen-01.secunet.de [10.53.40.204]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 97A0A201C6; Fri, 27 Jul 2018 11:24:38 +0200 (CEST) Received: from gauss2.secunet.de (10.182.7.193) by mail-essen-01.secunet.de (10.53.40.204) with Microsoft SMTP Server id 14.3.399.0; Fri, 27 Jul 2018 09:24:53 +0200 Received: by gauss2.secunet.de (Postfix, from userid 1000) id D893C3182135; Fri, 27 Jul 2018 09:24:52 +0200 (CEST) From: Steffen Klassert To: David Miller CC: Herbert Xu , Steffen Klassert , Subject: [PATCH 08/14] ipv6: xfrm: use 64-bit timestamps Date: Fri, 27 Jul 2018 09:24:43 +0200 Message-ID: <20180727072449.11896-9-steffen.klassert@secunet.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180727072449.11896-1-steffen.klassert@secunet.com> References: <20180727072449.11896-1-steffen.klassert@secunet.com> MIME-Version: 1.0 X-G-Data-MailSecurity-for-Exchange-State: 0 X-G-Data-MailSecurity-for-Exchange-Error: 0 X-G-Data-MailSecurity-for-Exchange-Sender: 23 X-G-Data-MailSecurity-for-Exchange-Server: d65e63f7-5c15-413f-8f63-c0d707471c93 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 X-G-Data-MailSecurity-for-Exchange-Guid: 27B7980B-3CF0-46EC-8682-AAB8E922935F Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arnd Bergmann 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 Signed-off-by: Steffen Klassert --- include/net/xfrm.h | 2 +- net/ipv6/xfrm6_mode_ro.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.14.1 diff --git a/include/net/xfrm.h b/include/net/xfrm.h index a5378613a49c..1350e2cf0749 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; }