netfilter: xt_time: reject pre-epoch calendar matching
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
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.
--- net/netfilter/xt_time.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/netfilter/xt_time.c +9 -0
@@ -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 (¤t_time, stamp);if (!(info->weekdays_match & (1U << current_time.weekday)))
Signature · 1 line
2.43.0
Quoted 19 lines · Ren Wei
From: Zhengyang Chen <[email protected]>
When
XT_TIME_CONTIGUOUShandles a cross-day daytime range, packets in the post-midnight part of the range are matched against the previous calendar day by subtractingSECONDS_PER_DAYfrom stamp.On the first day after the epoch, this backdating can make the signed
time64_tstamp negative.localtime_2()andlocaltime_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, leadingtime_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")Reported-by Yuan Tan <[email protected]>Reported-by Xin Liu <[email protected]>Assisted-by Codex:gpt-5.4Signed-off-by Zhengyang Chen <[email protected]>Reviewed-by Ren Wei <[email protected]>
Florian Westphal
maintainerQuoted 6 lines · Phil Sutter
Quoted 5 lines · Ren Wei
From: Zhengyang Chen <[email protected]>
When
XT_TIME_CONTIGUOUShandles a cross-day daytime range, packets in the post-midnight part of the range are matched against the previous calendar day by subtractingSECONDS_PER_DAYfrom 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.
Phil Sutter
reviewerQuoted 10 lines · Florian Westphal
Quoted 6 lines · Phil Sutter
Quoted 5 lines · Ren Wei
From: Zhengyang Chen <[email protected]>
When
XT_TIME_CONTIGUOUShandles a cross-day daytime range, packets in the post-midnight part of the range are matched against the previous calendar day by subtractingSECONDS_PER_DAYfrom 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
Florian Westphal
maintainerQuoted 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.
Phil Sutter
reviewerQuoted 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_timeandnft_metatime 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
Pablo Neira Ayuso
maintainerQuoted 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_timeandnft_metatime 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.