From patchwork Mon Nov 18 21:49:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 179615 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3455707ilf; Mon, 18 Nov 2019 13:50:02 -0800 (PST) X-Google-Smtp-Source: APXvYqy6nAbTPG6aY9cf+TT7moXxTahj0kJRtf+RMNSpF5xf9vKdrawP8cI731BVwyUGHliuFKeT X-Received: by 2002:adf:f18c:: with SMTP id h12mr14024004wro.122.1574113802454; Mon, 18 Nov 2019 13:50:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574113802; cv=none; d=google.com; s=arc-20160816; b=KzfFY0VaSQbbmzfOzJd2JlQw6TS1i2i56D7G8MeLMjNhKkeZrGfa60SuDmkhMyENy0 8s2YllJFnSJbre7g5rWmKprO7j4ltXZXcGVoUK1kz7Pn7vDdIHqRrAvGRwuU0pSNNGqu b5XqaPbC2UFXqGxVJk0py/doEw8n3nUYSAapPsP60xOB6/pkUrjMS+/II27fyKxh9xcb yYRn4UqRK89xZ8zrK9Xdg8wO7rppZysC290bg+lIEeIA9VSnfDYB5cH6u5wVoteUg4k6 nOga4uvZwmNPFVIizkPI3cjGaqDjTNekTUAc/lNvnuautaI2CH5REiW2IAq88c9G2UWh tQhQ== 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; bh=cJdMGzzuf/4dMYkxh7ZkBLCoIaRPjCMHlTSJNnEtUh0=; b=eiAerop4loWUu8hCuOMM1bQgJle1O9MZ9lB3DpltTMfC18gAonDvzzvooJXcpmWYuf 2f5XgglFbqjWeqUJyYkEm/kATO1ISkIbDI7ryV4Cv7P1A4u9RjjxYP9L+wqyjUQgWKWR SNNeR3MXrYsx0kbLsGp7O00Df1fk6WM2u1zSCEUzv9TJ0OgHWDFBKwpmzuALZxlcES3b /M1BynvUtxYEjI+LyRGwSBIAqtp0BjTr2uQDjy43LxRPgzK4D8V1mbJMH2voEr13nPAm Ve/wyesp/9jgsg9pwD/+VUOqAMLAcP2Xdbbvb12O1TahBMNMGVsfB/RckDirX8NH9bjG wk0g== 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 p20si14157879edi.252.2019.11.18.13.50.02; Mon, 18 Nov 2019 13:50:02 -0800 (PST) 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 S1727140AbfKRVuB (ORCPT + 9 others); Mon, 18 Nov 2019 16:50:01 -0500 Received: from correo.us.es ([193.147.175.20]:45714 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727141AbfKRVte (ORCPT ); Mon, 18 Nov 2019 16:49:34 -0500 Received: from antivirus1-rhel7.int (unknown [192.168.2.11]) by mail.us.es (Postfix) with ESMTP id 5D212EB497 for ; Mon, 18 Nov 2019 22:49:31 +0100 (CET) Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id 5060AA7EC8 for ; Mon, 18 Nov 2019 22:49:31 +0100 (CET) Received: by antivirus1-rhel7.int (Postfix, from userid 99) id 44189A7EC2; Mon, 18 Nov 2019 22:49:31 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on antivirus1-rhel7.int X-Spam-Level: X-Spam-Status: No, score=-108.2 required=7.5 tests=ALL_TRUSTED,BAYES_50, SMTPAUTH_US2,USER_IN_WHITELIST autolearn=disabled version=3.4.1 Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id 3753221FE5; Mon, 18 Nov 2019 22:49:26 +0100 (CET) Received: from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int (F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); Mon, 18 Nov 2019 22:49:26 +0100 (CET) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int) Received: from salvia.here (sys.soleta.eu [212.170.55.40]) (Authenticated sender: pneira@us.es) by entrada.int (Postfix) with ESMTPA id 0739542EE38F; Mon, 18 Nov 2019 22:49:25 +0100 (CET) X-SMTPAUTHUS: auth mail.us.es From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Cc: davem@davemloft.net, netdev@vger.kernel.org Subject: [PATCH 08/18] netfilter: nft_meta: use 64-bit time arithmetic Date: Mon, 18 Nov 2019 22:49:04 +0100 Message-Id: <20191118214914.142794-9-pablo@netfilter.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191118214914.142794-1-pablo@netfilter.org> References: <20191118214914.142794-1-pablo@netfilter.org> X-Virus-Scanned: ClamAV using ClamSMTP Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arnd Bergmann On 32-bit architectures, get_seconds() returns an unsigned 32-bit time value, which also matches the type used in the nft_meta code. This will not overflow in year 2038 as a time_t would, but it still suffers from the overflow problem later on in year 2106. Change this instance to use the time64_t type consistently and avoid the deprecated get_seconds(). The nft_meta_weekday() calculation potentially gets a little slower on 32-bit architectures, but now it has the same behavior as on 64-bit architectures and does not overflow. Fixes: 63d10e12b00d ("netfilter: nft_meta: support for time matching") Signed-off-by: Arnd Bergmann Acked-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nft_meta.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.11.0 diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c index 8fd21f436347..8fbea031bd4a 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -33,19 +33,19 @@ static DEFINE_PER_CPU(struct rnd_state, nft_prandom_state); -static u8 nft_meta_weekday(unsigned long secs) +static u8 nft_meta_weekday(time64_t secs) { unsigned int dse; u8 wday; secs -= NFT_META_SECS_PER_MINUTE * sys_tz.tz_minuteswest; - dse = secs / NFT_META_SECS_PER_DAY; + dse = div_u64(secs, NFT_META_SECS_PER_DAY); wday = (4 + dse) % NFT_META_DAYS_PER_WEEK; return wday; } -static u32 nft_meta_hour(unsigned long secs) +static u32 nft_meta_hour(time64_t secs) { struct tm tm; @@ -250,10 +250,10 @@ void nft_meta_get_eval(const struct nft_expr *expr, nft_reg_store64(dest, ktime_get_real_ns()); break; case NFT_META_TIME_DAY: - nft_reg_store8(dest, nft_meta_weekday(get_seconds())); + nft_reg_store8(dest, nft_meta_weekday(ktime_get_real_seconds())); break; case NFT_META_TIME_HOUR: - *dest = nft_meta_hour(get_seconds()); + *dest = nft_meta_hour(ktime_get_real_seconds()); break; default: WARN_ON(1);