🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17532

Re: [PATCH net-next 05/13] netfilter: xt_time: fix monthday computation for dates past 2039

#17532
From: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 00:22
131 lines
12491 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch fixes a real, user-visible correctness bug: `-m time
  --monthdays` rules give wrong results once the clock reaches…
- [Low] The commit message has three inaccuracies, and it understates the
  impact.
- [Low] After the patch, some comments and state in
  net/netfilter/xt_time.c still describe the removed table-based date…

--

netfilter: xt_time: fix monthday computation for dates past 2039

This patch replaces the days_since_epoch[] table walk in localtime_3()
with time64_to_tm(). This keeps r->monthday and r->month in range for
dates from 2040-01-01 on. The lookup tables and the 2039 limit are
removed, which also shrinks the xt_time object.

> iocaltime_3() derives the year from days_since_epoch[], which only has
> entries up to 2039. For any date from 2040-01-01 on, the lookup stays on
> the 2039 entry, so the day-of-year offset is 365 or more. That value is
> used to compute r->monthday, which ends up larger than 31 (32 on
> 2040-01-01, and it wraps in the u8 later in the year).

[ ... ]

> Only the real-time clock reaches localtime_3(), so this is not
> triggerable before the clock passes 2040-01-01 UTC.

[Severity: Low]
This isn't a bug, but there's a typo: iocaltime_3() should be
localtime_3().

Is the "2040-01-01 UTC" part accurate when XT_TIME_LOCAL_TZ is set?
time_mt() adjusts the stamp before it calls localtime_3():

    if (info->flags & XT_TIME_LOCAL_TZ)
        /* Adjust for local timezone */
        stamp -= 60 * sys_tz.tz_minuteswest;

For timezones east of UTC, tz_minuteswest is negative, so stamp moves
forward. do_sys_settimeofday64() accepts tz_minuteswest down to -15*60.
That means the old code could produce a bad monthday up to 15 hours
before 2040-01-01 UTC.

Could the message also say what the out-of-range monthday leads to?
time_mt() uses it as a shift count:

    if (!(info->monthdays_match & (1U << current_time.monthday)))

With the old code, a monthday of 32 or more makes this shift undefined
behaviour, and the rule silently fails to match. Once the u8 wraps back
into 1-31 later in 2040, rules match on the wrong days.

> Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

[Severity: Low]
Should this have a Fixes: tag? The days_since_epoch[] table and
DSE_FIRST = 2039 came in with the original match:

Fixes: ee4411a1b1e0 ("[NETFILTER]: x_tables: add xt_time match")

Without the tag, stable backporters could read this as only the size
cleanup suggested by the bloat-o-meter numbers.

> diff --git a/net/netfilter/xt_time.c b/net/netfilter/xt_time.c
> index 2065fce8ef81b..f0c4c1d1bc4a0 100644
> --- a/net/netfilter/xt_time.c
> +++ b/net/netfilter/xt_time.c

[ ... ]

> @@ -102,51 +71,12 @@ static inline void localtime_2(struct xtm *r, time64_t time)
>
>  static void localtime_3(struct xtm *r, time64_t time)
>  {
> -	unsigned int year, i, w = r->dse;
> -

[ ... ]

> +	time64_to_tm(time, 0, &tm);
>
> -	r->month    = i + 1;
> +	r->monthday = tm.tm_mday;	/* 1-31 */
> +	r->month    = tm.tm_mon + 1;	/* 1-12 */
>  }

[Severity: Low]
This isn't a bug, but localtime_3() now works only from time and no
longer reads r->dse. Are some comments and struct xtm now out of date?

The file header still credits dietlibc:

 *	It is using some modified code from dietlibc (localtime() function)
 *	that you can find at https://www.fefe.de/dietlibc/

The table walk removed here was the last of that code.

The comment in localtime_2() still says it computes monthday:

	/*
	 * Here comes the rest (weekday, monthday). First, divide the SSTE
	 * by seconds-per-day to get the number of _days_ since the epoch.
	 */

It now computes only dse and weekday.

struct xtm also keeps this field:

	unsigned int dse;

It used to carry days-since-epoch from localtime_2() to localtime_3().
Now it is only read inside localtime_2(). Could this lead readers to
think localtime_3() depends on localtime_2() running first?

There is also a small side effect. Weekday comes from the unsigned
div_u64() in localtime_2(). Monthday comes from the signed,
floor-corrected division in time64_to_tm(). The two only differ for a
negative stamp. That needs a time within the first day of 1970, plus
either the XT_TIME_CONTIGUOUS one-day subtraction or a timezone west of
UTC.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116001612.2806263-2-pablo%40netfilter.org
Technical Details
Message-ID: <179487496872.3136.7616374385796675511@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364852-linux-kernel-netdev=dewy.ru
References: <20261116001612.2806263-6-pablo@netfilter.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364852-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 05/13] netfilter: xt_time: fix monthday
 computation for dates past 2039
Date: Tue, 17 Nov 2026 00:22:48 +0000
Organization: Usenet Network
Message-ID: <179487496872.3136.7616374385796675511@kernel.org>
References: <20261116001612.2806263-6-pablo@netfilter.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2202409"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:s+FS2+65DfhcYfhQLqs7MILRhso= sha256:+ptr13p9RJB/5u8GhShalAoAlXx3HMlXKYB3FWcqtls=
	sha1:3FZllsC8dojywwezRATcb340Gt0= sha256:nki/EfUI691i1qxlfCsM1d7sIQSjWACRZR70Tb9Hlvc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id AE63C114DDD; Tue, 17 Nov 2026 03:23:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id jy5Fg083Q-8G;
	Tue, 17 Nov 2026 03:23:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-364852-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 28954114DD8; Tue, 17 Nov 2026 03:22:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 9822D600C80; Tue, 17 Nov 2026 00:22:51 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794874970;
	b=ubtkFlutbDZQxv1v5TIFTULXRCYAtrG4AqJ+cNVKCVRfawyNcg5DC5LWh37Yk4qbwXrA
	 P3/VB/Hmj/n1d1QJQEpzgCBMe5HyJfkeu1+P153m2JXAa7bhJ2W30QSASqG+HHtXQg/t8
	 PrSiJt/z0UlIpFwUUN4m3nu8mw1t0SSloDr4pCwpxewa5YIWu7qHZ4uCY5ZexwzuhSc+J
	 7fUDmNJBOXNe/F0HwNH0u0hJYhzLsbUVO33y72UL8fuMF4VyxGbHwl7X7uuhtkfKDj0e9
	 8ORaufwrbW9UzzK5k9uK4QQNCpVBYGsm0wckO0SuoMwPZXVXiF9yPRnTWBUGWVfGeVw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794874970;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=vmRR9pCJ/Q25C5FM/CDfQ6SI3FAF+xqbBv++EEr+IWE=;
	b=btAqO7q2yJ2cz7wmzQzIxJUolzZIkltVgFsyIW03DKw4GFWTHHAPdbQfD4UESmiqmp8P
	 Qg7iWcJt/cKlqCTioZh1J1Ba32Q8hCgwB1wCL6vd6tTkAPMHtnbdOq4/HEsaz24zL8Tc7
	 cep+kOJ7v2s0G0sk0diwvnIjnRXblDDrHCASKXJp61AO552UuRrR02KPxt5xLXKwX82x9
	 jHFMloGoADMbVYYXrkz6ADYA1PcF8Uj1jxx6Q3qklZHD7Q1QZyCZ8ImKUs7W2nWA6lf2N
	 LRykZk8WpayeBYa4cWt2EAQjlp3um1IN/iNI4toUgtvMUgXqO/eLWqKP5LEPFbVFumA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iqDQKVNq;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B0CAA606A330;
	Tue, 17 Nov 2026 00:22:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iqDQKVNq
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794874969;
	b=5YLiODoeUnyGhAWqc6+84H1I2q+oiQxLWIg21uVtiay3NuJNn2qSbp3MgS141B64fdeI
	 81q4BTcJ5L1n6ygTo7gpqM0YGW3NWSOfuxxqEr2SvOi/SQKHk9di2sIll7+0mIRoZTBre
	 +cXgXwz2B8VZ9IuS5GX27vi05kN3f1cpaqOgVC01xAKXS35H8+c5yF9aTgpF3HmfvzUXs
	 rKyBDq418hQRSK8VVawb7PyuxsrEV8iXZRwOoqz8ff0v+a2QDyGuPx3JJXCFyF6qUkDxU
	 uTMpTM2Zphz5cRh0W/p/ctPls/9clZ97nqfqFrUCN0lRLf6NQtskQ8hglkG/i9wK5pw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794874969;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=vmRR9pCJ/Q25C5FM/CDfQ6SI3FAF+xqbBv++EEr+IWE=;
	b=R/olmVg6f/R/njnim+zjsBQBOHjQd/STYAorxFj5UG29f+EH3O2MXcsGOXByRM2YHXk0
	 WGRaQsdgHfpDTIzQBJkttzD5NvrLe7FLfjCh+3nDKeUNlNd2uWpJo/ulCyVA/K2QEgOnW
	 pC7Qgz+rVQ0pA7hxYAYYR0jTdQVLIctbLCHixcLPJ4sqgEyqg/Ktf6vXhC79xIl/e5xyd
	 lMkPkZ8//TNTB2VUmpE53MVe/R5JLQ4uYFrZ+f73xoqmspwRbuXuz/a0zOx/NqqiTvLLe
	 5KtJjw1jQaZZRWwe126nu2xl4yMkXBtddJkFCeJxuTiCMWmZRcxwqAL5Nz60p+dtPDQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iqDQKVNq;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D20D9606A33A;
	Tue, 17 Nov 2026 00:22:49 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B6231F000C8;
	Tue, 17 Nov 2026 00:22:49 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794874969;
	bh=vmRR9pCJ/Q25C5FM/CDfQ6SI3FAF+xqbBv++EEr+IWE=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=iqDQKVNq/zZNeT6IpOsl0PaZP9fKrFrMhzoNIdMYHVjcJexJqRSIeACtrYKnRRyWM
	 PJGnts5zVBCmK1LKnTViIYzv5zp934rj2x8chmq4mHtD/TMHiKZ7wHXlP2nMiOEU3V
	 6AGkGoxaDfOnyOYF3LedOba0nkrUrd5xUex0hB57efqvE7rRwHDyuzCvoVHoqNPjwI
	 YeSIAWh/ksWOUr1Q9eCggelkBMNBzFyd9EYwvIIEmvXRAWt1rNXukB/Ozw1QgxdWSB
	 VKB8P2oWJL19w7LftiGeZeSTyXtQ6BmkvXVi/XqNiStoZyEnPjkRUrOcfafzUCc9BZ
	 QGPd/+G6BD15g==
X-Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
 netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
 edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
X-In-Reply-To: <20261116001612.2806263-6-pablo@netfilter.org>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list