Skip to content

Commit 30a2e10

Browse files
author
Jozsef Kadlecsik
committed
netfilter: ipset: Limit max timeout value
Due to the negative value condition in msecs_to_jiffies(), the real max possible timeout value must be set to (UINT_MAX >> 1)/MSEC_PER_SEC. Neutron Soutmun proposed the proper fix, but an insufficient one was applied, see https://patchwork.ozlabs.org/patch/400405/. Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
1 parent bd975e6 commit 30a2e10

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎include/linux/netfilter/ipset/ip_set_timeout.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
/* Set is defined with timeout support: timeout value may be 0 */
2424
#define IPSET_NO_TIMEOUT UINT_MAX
2525

26+
/* Max timeout value, see msecs_to_jiffies() in jiffies.h */
27+
#define IPSET_MAX_TIMEOUT (UINT_MAX >> 1)/MSEC_PER_SEC
28+
2629
#define ip_set_adt_opt_timeout(opt, set) \
2730
((opt)->ext.timeout != IPSET_NO_TIMEOUT ? (opt)->ext.timeout : (set)->timeout)
2831

@@ -32,11 +35,10 @@ ip_set_timeout_uget(struct nlattr *tb)
3235
unsigned int timeout = ip_set_get_h32(tb);
3336

3437
/* Normalize to fit into jiffies */
35-
if (timeout > UINT_MAX/MSEC_PER_SEC)
36-
timeout = UINT_MAX/MSEC_PER_SEC;
38+
if (timeout > IPSET_MAX_TIMEOUT)
39+
timeout = IPSET_MAX_TIMEOUT;
3740

38-
/* Userspace supplied TIMEOUT parameter: adjust crazy size */
39-
return timeout == IPSET_NO_TIMEOUT ? IPSET_NO_TIMEOUT - 1 : timeout;
41+
return timeout;
4042
}
4143

4244
static inline bool

‎net/netfilter/xt_set.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ set_target_v2(struct sk_buff *skb, const struct xt_action_param *par)
372372

373373
/* Normalize to fit into jiffies */
374374
if (add_opt.ext.timeout != IPSET_NO_TIMEOUT &&
375-
add_opt.ext.timeout > UINT_MAX / MSEC_PER_SEC)
376-
add_opt.ext.timeout = UINT_MAX / MSEC_PER_SEC;
375+
add_opt.ext.timeout > IPSET_MAX_TIMEOUT)
376+
add_opt.ext.timeout = IPSET_MAX_TIMEOUT;
377377
if (info->add_set.index != IPSET_INVALID_ID)
378378
ip_set_add(info->add_set.index, skb, par, &add_opt);
379379
if (info->del_set.index != IPSET_INVALID_ID)
@@ -407,8 +407,8 @@ set_target_v3(struct sk_buff *skb, const struct xt_action_param *par)
407407

408408
/* Normalize to fit into jiffies */
409409
if (add_opt.ext.timeout != IPSET_NO_TIMEOUT &&
410-
add_opt.ext.timeout > UINT_MAX / MSEC_PER_SEC)
411-
add_opt.ext.timeout = UINT_MAX / MSEC_PER_SEC;
410+
add_opt.ext.timeout > IPSET_MAX_TIMEOUT)
411+
add_opt.ext.timeout = IPSET_MAX_TIMEOUT;
412412
if (info->add_set.index != IPSET_INVALID_ID)
413413
ip_set_add(info->add_set.index, skb, par, &add_opt);
414414
if (info->del_set.index != IPSET_INVALID_ID)

0 commit comments

Comments
 (0)