Skip to content

Commit 6408c40

Browse files
arndbummakynes
authored andcommitted
netfilter: nft_meta: use 64-bit time arithmetic
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: 63d10e1 ("netfilter: nft_meta: support for time matching") Signed-off-by: Arnd Bergmann <[email protected]> Acked-by: Phil Sutter <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent fcbad82 commit 6408c40

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

net/netfilter/nft_meta.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@
3333

3434
static DEFINE_PER_CPU(struct rnd_state, nft_prandom_state);
3535

36-
static u8 nft_meta_weekday(unsigned long secs)
36+
static u8 nft_meta_weekday(time64_t secs)
3737
{
3838
unsigned int dse;
3939
u8 wday;
4040

4141
secs -= NFT_META_SECS_PER_MINUTE * sys_tz.tz_minuteswest;
42-
dse = secs / NFT_META_SECS_PER_DAY;
42+
dse = div_u64(secs, NFT_META_SECS_PER_DAY);
4343
wday = (4 + dse) % NFT_META_DAYS_PER_WEEK;
4444

4545
return wday;
4646
}
4747

48-
static u32 nft_meta_hour(unsigned long secs)
48+
static u32 nft_meta_hour(time64_t secs)
4949
{
5050
struct tm tm;
5151

@@ -250,10 +250,10 @@ void nft_meta_get_eval(const struct nft_expr *expr,
250250
nft_reg_store64(dest, ktime_get_real_ns());
251251
break;
252252
case NFT_META_TIME_DAY:
253-
nft_reg_store8(dest, nft_meta_weekday(get_seconds()));
253+
nft_reg_store8(dest, nft_meta_weekday(ktime_get_real_seconds()));
254254
break;
255255
case NFT_META_TIME_HOUR:
256-
*dest = nft_meta_hour(get_seconds());
256+
*dest = nft_meta_hour(ktime_get_real_seconds());
257257
break;
258258
default:
259259
WARN_ON(1);

0 commit comments

Comments
 (0)