Skip to content

Commit 5b94b2b

Browse files
committed
Merge git://blackhole.kfki.hu/nf
Jozsef Kadlecsik says: ==================== ipset patches for nf - Check hook mask for unsupported hooks instead of supported ones in xt_set. (Serhey Popovych). - List/save just timing out entries with "timeout 1" instead of "timeout 0": zero timeout value means permanent entries. When restoring the elements, we'd add non-timing out entries. Fixes netfilter bugzilla id #1258. - Limit max timeout value to (UINT_MAX >> 1)/MSEC_PER_SEC due to the negative value condition in msecs_to_jiffies(). msecs_to_jiffies() should be revised: if one wants to set the timeout above 2147483, msecs_to_jiffies() sets the value to 4294967. (Reported by Maxim Masiutin). - Forbid family for hash:mac sets in the kernel module: ipset userspace tool enforces it but third party tools could create sets with this parameter. Such sets then cannot be listed/saved with ipset itself. (Florent Fourcot) ==================== Signed-off-by: Pablo Neira Ayuso <[email protected]>
2 parents 11ff728 + cbdebe4 commit 5b94b2b

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

include/linux/netfilter/ipset/ip_set_timeout.h

Lines changed: 14 additions & 6 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
@@ -65,8 +67,14 @@ ip_set_timeout_set(unsigned long *timeout, u32 value)
6567
static inline u32
6668
ip_set_timeout_get(const unsigned long *timeout)
6769
{
68-
return *timeout == IPSET_ELEM_PERMANENT ? 0 :
69-
jiffies_to_msecs(*timeout - jiffies)/MSEC_PER_SEC;
70+
u32 t;
71+
72+
if (*timeout == IPSET_ELEM_PERMANENT)
73+
return 0;
74+
75+
t = jiffies_to_msecs(*timeout - jiffies)/MSEC_PER_SEC;
76+
/* Zero value in userspace means no timeout */
77+
return t == 0 ? 1 : t;
7078
}
7179

7280
#endif /* __KERNEL__ */

net/netfilter/ipset/ip_set_hash_gen.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,10 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set,
12341234
pr_debug("Create set %s with family %s\n",
12351235
set->name, set->family == NFPROTO_IPV4 ? "inet" : "inet6");
12361236

1237-
#ifndef IP_SET_PROTO_UNDEF
1237+
#ifdef IP_SET_PROTO_UNDEF
1238+
if (set->family != NFPROTO_UNSPEC)
1239+
return -IPSET_ERR_INVALID_FAMILY;
1240+
#else
12381241
if (!(set->family == NFPROTO_IPV4 || set->family == NFPROTO_IPV6))
12391242
return -IPSET_ERR_INVALID_FAMILY;
12401243
#endif

net/netfilter/xt_set.c

Lines changed: 5 additions & 5 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)
@@ -470,7 +470,7 @@ set_target_v3_checkentry(const struct xt_tgchk_param *par)
470470
}
471471
if (((info->flags & IPSET_FLAG_MAP_SKBPRIO) |
472472
(info->flags & IPSET_FLAG_MAP_SKBQUEUE)) &&
473-
!(par->hook_mask & (1 << NF_INET_FORWARD |
473+
(par->hook_mask & ~(1 << NF_INET_FORWARD |
474474
1 << NF_INET_LOCAL_OUT |
475475
1 << NF_INET_POST_ROUTING))) {
476476
pr_info_ratelimited("mapping of prio or/and queue is allowed only from OUTPUT/FORWARD/POSTROUTING chains\n");

0 commit comments

Comments
 (0)