Skip to contentSkip to conversation

netfilter: xt_time: reject pre-epoch calendar matching

PATCH In review Ren Wei 4 participants 7 messages Jul 3 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ren Wei

author
#1 lore raw

PATCH 1/1 netfilter: xt_time: reject pre-epoch calendar matching

From: Zhengyang Chen <[email protected]>

When XT_TIME_CONTIGUOUS handles a cross-day daytime range, packets in the post-midnight part of the range are matched against the previous calendar day by subtracting SECONDS_PER_DAY from stamp.

On the first day after the epoch, this backdating can make the signed time64_t stamp negative. localtime_2() and localtime_3() then feed the value into unsigned division helpers and derive wrapped calendar fields. In particular, monthday can become larger than the valid 1..31 range, leading time_mt() to evaluate an out-of-range
1U << current_time.monthday shift.

The date_start/date_stop ABI is unsigned and cannot represent pre-epoch calendar dates. If contiguous matching backdates stamp before the epoch, only rules without weekday and monthday constraints can still be evaluated safely; reject calendar-constrained rules before converting the timestamp to calendar fields.

Fixes 54eb3df3a7d0 ("netfilter: xt_time: add support to ignore day transition")
Assisted-by Codex:gpt-5.4
---
 net/netfilter/xt_time.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/netfilter/xt_time.c +9 -0
index 2065fce8ef81..014561a2ef3f 100644
@@ -220,6 +220,15 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par)
 			stamp -= SECONDS_PER_DAY;
 	}
 
+	/*
+	 * The date_start/date_stop ABI cannot express pre-epoch timestamps.
+	 * If XT_TIME_CONTIGUOUS moves the packet into that range, only rules
+	 * without calendar constraints can still match.
+	 */
+	if (stamp < 0)
+		return info->weekdays_match == XT_TIME_ALL_WEEKDAYS &&
+		       info->monthdays_match == XT_TIME_ALL_MONTHDAYS;
+
 	localtime_2(&current_time, stamp);
 
 	if (!(info->weekdays_match & (1U << current_time.weekday)))
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#2 lore raw
Quoted 19 lines · Ren Wei

From: Zhengyang Chen <[email protected]>

When XT_TIME_CONTIGUOUS handles a cross-day daytime range, packets in the post-midnight part of the range are matched against the previous calendar day by subtracting SECONDS_PER_DAY from stamp.

On the first day after the epoch, this backdating can make the signed time64_t stamp negative. localtime_2() and localtime_3() then feed the value into unsigned division helpers and derive wrapped calendar fields. In particular, monthday can become larger than the valid 1..31 range, leading time_mt() to evaluate an out-of-range
1U << current_time.monthday shift.

The date_start/date_stop ABI is unsigned and cannot represent pre-epoch calendar dates. If contiguous matching backdates stamp before the epoch, only rules without weekday and monthday constraints can still be evaluated safely; reject calendar-constrained rules before converting the timestamp to calendar fields.

Quoted 7 lines
Fixes 54eb3df3a7d0 ("netfilter: xt_time: add support to ignore day transition")
Assisted-by Codex:gpt-5.4
maintainer
#3 lore raw
Quoted 6 lines · Phil Sutter
Quoted 5 lines · Ren Wei

From: Zhengyang Chen <[email protected]>

When XT_TIME_CONTIGUOUS handles a cross-day daytime range, packets in the post-midnight part of the range are matched against the previous calendar day by subtracting SECONDS_PER_DAY from stamp.

This is silly. I'm not sure this is even a bug.
We're in 2026 not 1970. I really don't see why this patch is required.

reviewer
#4 lore raw
Quoted 10 lines · Florian Westphal
Quoted 6 lines · Phil Sutter
Quoted 5 lines · Ren Wei

From: Zhengyang Chen <[email protected]>

When XT_TIME_CONTIGUOUS handles a cross-day daytime range, packets in the post-midnight part of the range are matched against the previous calendar day by subtracting SECONDS_PER_DAY from stamp.

This is silly. I'm not sure this is even a bug.
We're in 2026 not 1970. I really don't see why this patch is required.

I imagined a system with broken BIOS clock which boots at epoch until NTP has fixed it. Then stamp will be close to zero, no?

Cheers, Phil

maintainer
#5 lore raw
Quoted 5 lines · Phil Sutter
Quoted 2 lines

This is silly. I'm not sure this is even a bug.
We're in 2026 not 1970. I really don't see why this patch is required.

I imagined a system with broken BIOS clock which boots at epoch until NTP has fixed it. Then stamp will be close to zero, no?

So what? Rule won't match either way. I wish we could get somehow get rid of xt_time and nft_meta time matching, this was a very bad idea from the start.

reviewer
#6 lore raw
Quoted 10 lines · Florian Westphal
Quoted 5 lines · Phil Sutter
Quoted 2 lines

This is silly. I'm not sure this is even a bug.
We're in 2026 not 1970. I really don't see why this patch is required.

I imagined a system with broken BIOS clock which boots at epoch until NTP has fixed it. Then stamp will be close to zero, no?

So what? Rule won't match either way. I wish we could get somehow get rid of xt_time and nft_meta time matching, this was a very bad idea from the start.

Sure, time-based packet matching won't work on a system with wrong time, but AIUI the patch is merely trying to prevent the unexpectedly large lshift. It seems harmless, though:
- current_time.weekday can't exceed 7, it is assigned the result of a modulo operation
- current_time.monthday is type u8, so worst case the kernel will compute '1U << 255'

Cheers, Phil

#7 lore raw
Quoted 12 lines · Phil Sutter
Quoted 10 lines · Florian Westphal
Quoted 5 lines · Phil Sutter
Quoted 2 lines

This is silly. I'm not sure this is even a bug.
We're in 2026 not 1970. I really don't see why this patch is required.

I imagined a system with broken BIOS clock which boots at epoch until NTP has fixed it. Then stamp will be close to zero, no?

So what? Rule won't match either way. I wish we could get somehow get rid of xt_time and nft_meta time matching, this was a very bad idea from the start.

Quoted 7 lines

Sure, time-based packet matching won't work on a system with wrong time, but AIUI the patch is merely trying to prevent the unexpectedly large lshift. It seems harmless, though:
- current_time.weekday can't exceed 7, it is assigned the result of a modulo operation
- current_time.monthday is type u8, so worst case the kernel will compute '1U << 255'

Maybe it can be added as hardening for nf-next, just for correctness. Remove Fixes: tag. I don't see this as a bug either.