@@ -2779,6 +2779,27 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
2779
2779
return 0 ;
2780
2780
}
2781
2781
2782
+ static int nf_msecs_to_jiffies64 (const struct nlattr * nla , u64 * result )
2783
+ {
2784
+ u64 ms = be64_to_cpu (nla_get_be64 (nla ));
2785
+ u64 max = (u64 )(~((u64 )0 ));
2786
+
2787
+ max = div_u64 (max , NSEC_PER_MSEC );
2788
+ if (ms >= max )
2789
+ return - ERANGE ;
2790
+
2791
+ ms *= NSEC_PER_MSEC ;
2792
+ * result = nsecs_to_jiffies64 (ms );
2793
+ return 0 ;
2794
+ }
2795
+
2796
+ static u64 nf_jiffies64_to_msecs (u64 input )
2797
+ {
2798
+ u64 ms = jiffies64_to_nsecs (input );
2799
+
2800
+ return cpu_to_be64 (div_u64 (ms , NSEC_PER_MSEC ));
2801
+ }
2802
+
2782
2803
static int nf_tables_fill_set (struct sk_buff * skb , const struct nft_ctx * ctx ,
2783
2804
const struct nft_set * set , u16 event , u16 flags )
2784
2805
{
@@ -2826,7 +2847,7 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
2826
2847
2827
2848
if (set -> timeout &&
2828
2849
nla_put_be64 (skb , NFTA_SET_TIMEOUT ,
2829
- cpu_to_be64 ( jiffies_to_msecs ( set -> timeout ) ),
2850
+ nf_jiffies64_to_msecs ( set -> timeout ),
2830
2851
NFTA_SET_PAD ))
2831
2852
goto nla_put_failure ;
2832
2853
if (set -> gc_int &&
@@ -3122,8 +3143,10 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
3122
3143
if (nla [NFTA_SET_TIMEOUT ] != NULL ) {
3123
3144
if (!(flags & NFT_SET_TIMEOUT ))
3124
3145
return - EINVAL ;
3125
- timeout = msecs_to_jiffies (be64_to_cpu (nla_get_be64 (
3126
- nla [NFTA_SET_TIMEOUT ])));
3146
+
3147
+ err = nf_msecs_to_jiffies64 (nla [NFTA_SET_TIMEOUT ], & timeout );
3148
+ if (err )
3149
+ return err ;
3127
3150
}
3128
3151
gc_int = 0 ;
3129
3152
if (nla [NFTA_SET_GC_INTERVAL ] != NULL ) {
@@ -3387,8 +3410,8 @@ const struct nft_set_ext_type nft_set_ext_types[] = {
3387
3410
.align = __alignof__(u64 ),
3388
3411
},
3389
3412
[NFT_SET_EXT_EXPIRATION ] = {
3390
- .len = sizeof (unsigned long ),
3391
- .align = __alignof__(unsigned long ),
3413
+ .len = sizeof (u64 ),
3414
+ .align = __alignof__(u64 ),
3392
3415
},
3393
3416
[NFT_SET_EXT_USERDATA ] = {
3394
3417
.len = sizeof (struct nft_userdata ),
@@ -3481,22 +3504,21 @@ static int nf_tables_fill_setelem(struct sk_buff *skb,
3481
3504
3482
3505
if (nft_set_ext_exists (ext , NFT_SET_EXT_TIMEOUT ) &&
3483
3506
nla_put_be64 (skb , NFTA_SET_ELEM_TIMEOUT ,
3484
- cpu_to_be64 (jiffies_to_msecs (
3485
- * nft_set_ext_timeout (ext ))),
3507
+ nf_jiffies64_to_msecs (* nft_set_ext_timeout (ext )),
3486
3508
NFTA_SET_ELEM_PAD ))
3487
3509
goto nla_put_failure ;
3488
3510
3489
3511
if (nft_set_ext_exists (ext , NFT_SET_EXT_EXPIRATION )) {
3490
- unsigned long expires , now = jiffies ;
3512
+ u64 expires , now = get_jiffies_64 () ;
3491
3513
3492
3514
expires = * nft_set_ext_expiration (ext );
3493
- if (time_before (now , expires ))
3515
+ if (time_before64 (now , expires ))
3494
3516
expires -= now ;
3495
3517
else
3496
3518
expires = 0 ;
3497
3519
3498
3520
if (nla_put_be64 (skb , NFTA_SET_ELEM_EXPIRATION ,
3499
- cpu_to_be64 ( jiffies_to_msecs ( expires ) ),
3521
+ nf_jiffies64_to_msecs ( expires ),
3500
3522
NFTA_SET_ELEM_PAD ))
3501
3523
goto nla_put_failure ;
3502
3524
}
@@ -3871,7 +3893,7 @@ void *nft_set_elem_init(const struct nft_set *set,
3871
3893
memcpy (nft_set_ext_data (ext ), data , set -> dlen );
3872
3894
if (nft_set_ext_exists (ext , NFT_SET_EXT_EXPIRATION ))
3873
3895
* nft_set_ext_expiration (ext ) =
3874
- jiffies + timeout ;
3896
+ get_jiffies_64 () + timeout ;
3875
3897
if (nft_set_ext_exists (ext , NFT_SET_EXT_TIMEOUT ))
3876
3898
* nft_set_ext_timeout (ext ) = timeout ;
3877
3899
@@ -3958,8 +3980,10 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
3958
3980
if (nla [NFTA_SET_ELEM_TIMEOUT ] != NULL ) {
3959
3981
if (!(set -> flags & NFT_SET_TIMEOUT ))
3960
3982
return - EINVAL ;
3961
- timeout = msecs_to_jiffies (be64_to_cpu (nla_get_be64 (
3962
- nla [NFTA_SET_ELEM_TIMEOUT ])));
3983
+ err = nf_msecs_to_jiffies64 (nla [NFTA_SET_ELEM_TIMEOUT ],
3984
+ & timeout );
3985
+ if (err )
3986
+ return err ;
3963
3987
} else if (set -> flags & NFT_SET_TIMEOUT ) {
3964
3988
timeout = set -> timeout ;
3965
3989
}
0 commit comments