Netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi David,
The following patchset contains Netfilter fixes for your net tree, they are:
1) Fix compilation warning in xt_hashlimit on m68k 32-bits, from Geert Uytterhoeven.
2) Fix wrong timeout in set elements added from packet path via nft_dynset, from Anders K. Pedersen.
3) Remove obsolete nf_conntrack_events_retry_timeout sysctl documentation, from Nicolas Dichtel.
4) Ensure proper initialization of log flags via xt_LOG, from Liping Zhang.
5) Missing alias to autoload ipcomp, also from Liping Zhang.
6) Missing NFTA_HASH_OFFSET attribute validation, again from Liping.
7) Wrong integer type in the new nft_parse_u32_check() function, from Dan Carpenter.
8) Another wrong integer type declaration in nft_exthdr_init, also from Dan Carpenter.
9) Fix insufficient mode validation in nft_range.
10) Fix compilation warning in nft_range due to possible uninitialized value, from Arnd Bergmann.
11) Zero nf_hook_ops allocated via xt_hook_alloc() in x_tables to calm down kmemcheck, from Florian Westphal.
12) Schedule gc_worker() to run again if GC_MAX_EVICTS quota is reached, from Nicolas Dichtel.
13) Fix nf_queue() after conversion to single-linked hook list, related to incorrect bypass flag handling and incorrect hook point of reinjection.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit 6d3a4c404648e415e7d96e285d723936d4df7ed0:
strparser: Propagate correct error code in strp_recv() (2016-10-12 01:51:49 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git HEAD
for you to fetch changes up to 7034b566a4e7d550621c2dfafd380b77b3787cd9:
netfilter: fix nf_queue handling (2016-10-20 19:59:59 +0200)
----------------------------------------------------------------
Anders K. Pedersen (1):
netfilter: nft_dynset: fix element timeout for HZ != 1000
Arnd Bergmann (1):
netfilter: nf_tables: avoid uninitialized variable warning
Dan Carpenter (2):
netfilter: nf_tables: underflow in nft_parse_u32_check()
netfilter: nft_exthdr: fix error handling in nft_exthdr_init()
Florian Westphal (1):
netfilter: x_tables: suppress kmemcheck warning
Geert Uytterhoeven (1):
netfilter: xt_hashlimit: Add missing ULL suffixes for 64-bit constants
Liping Zhang (3):
netfilter: xt_NFLOG: fix unexpected truncated packet
netfilter: xt_ipcomp: add "ip[6]t_ipcomp" module alias name
netfilter: nft_hash: add missing NFTA_HASH_OFFSET's nla_policy
Nicolas Dichtel (2):
netfilter: conntrack: remove obsolete sysctl (nf_conntrack_events_retry_timeout)
netfilter: conntrack: restart gc immediately if GC_MAX_EVICTS is reached
Pablo Neira Ayuso (2):
netfilter: nft_range: validate operation netlink attribute
netfilter: fix nf_queue handling
Documentation/networking/nf_conntrack-sysctl.txt | 18 --------- net/netfilter/core.c | 13 ++----- net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_internals.h | 2 +- net/netfilter/nf_queue.c | 48 ++++++++++++++++-------- net/netfilter/nf_tables_api.c | 2 +- net/netfilter/nft_dynset.c | 6 ++- net/netfilter/nft_exthdr.c | 3 +- net/netfilter/nft_hash.c | 1 + net/netfilter/nft_range.c | 26 +++++++++---- net/netfilter/x_tables.c | 2 +- net/netfilter/xt_NFLOG.c | 1 + net/netfilter/xt_hashlimit.c | 4 +- net/netfilter/xt_ipcomp.c | 2 + 14 files changed, 70 insertions(+), 60 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/13 netfilter: xt_hashlimit: Add missing ULL suffixes for 64-bit constants
From: Geert Uytterhoeven <[email protected]>
On 32-bit (e.g. with m68k-linux-gnu-gcc-4.1):
net/netfilter/xt_hashlimit.c: In function ‘user2credits’:
net/netfilter/xt_hashlimit.c:476: warning: integer constant is too large for ‘long’ type
...
net/netfilter/xt_hashlimit.c:478: warning: integer constant is too large for ‘long’ type
...
net/netfilter/xt_hashlimit.c:480: warning: integer constant is too large for ‘long’ type
...
net/netfilter/xt_hashlimit.c: In function ‘rateinfo_recalc’:
net/netfilter/xt_hashlimit.c:513: warning: integer constant is too large for ‘long’ type
--- net/netfilter/xt_hashlimit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/xt_hashlimit.c +2 -2
@@ -431,7 +431,7 @@ static void htable_put(struct xt_hashlimit_htable *hinfo)CREDITS_PER_JIFFY*HZ*60*60*24 < 2^32 ie. */ #define MAX_CPJ_v1 (0xFFFFFFFF / (HZ*60*60*24)) -#define MAX_CPJ (0xFFFFFFFFFFFFFFFF / (HZ*60*60*24)) +#define MAX_CPJ (0xFFFFFFFFFFFFFFFFULL / (HZ*60*60*24))/* Repeated shift and or gives us all 1s, final shift and add 1 gives * us the power of 2 below the theoretical max, so GCC simply does a
@@ -473,7 +473,7 @@ static u64 user2credits(u64 user, int revision)return div64_u64 (user *HZ * CREDITS_PER_JIFFY_v1,XT_HASHLIMIT_SCALE ); }else { -if (user >0xFFFFFFFFFFFFFFFF / (HZ *CREDITS_PER_JIFFY )) +if (user >0xFFFFFFFFFFFFFFFFULL / (HZ *CREDITS_PER_JIFFY ))return div64_u64 (user, XT_HASHLIMIT_SCALE_v2) *HZ *CREDITS_PER_JIFFY ;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/13 netfilter: nft_dynset: fix element timeout for HZ != 1000
In reply to Pablo Neira AyusoFrom: "Anders K. Pedersen" <[email protected]>
With HZ=100 element timeout in dynamic sets (i.e. flow tables) is 10 times higher than configured.
Add proper conversion to/from jiffies, when interacting with userspace.
I tested this on Linux 4.8.1, and it applies cleanly to current nf and nf-next trees.
--- net/netfilter/nft_dynset.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netfilter/nft_dynset.c +4 -2
@@ -158,7 +158,8 @@ static int nft_dynset_init(const struct nft_ctx *ctx,if (tb[NFTA_DYNSET_TIMEOUT ] !=NULL ) {if (!(set->flags &NFT_SET_TIMEOUT ))return -EINVAL ; - timeout =be64_to_cpu (nla_get_be64 (tb[NFTA_DYNSET_TIMEOUT ])); + timeout =msecs_to_jiffies (be64_to_cpu (nla_get_be64 ( + tb[NFTA_DYNSET_TIMEOUT ]))); } priv->sreg_key =nft_parse_register (tb[NFTA_DYNSET_SREG_KEY ]);
@@ -246,7 +247,8 @@ static int nft_dynset_dump(struct sk_buff *skb, const struct nft_expr *expr) goto nla_put_failure;if (nla_put_string (skb,NFTA_DYNSET_SET_NAME , priv->set->name)) goto nla_put_failure; -if (nla_put_be64 (skb,NFTA_DYNSET_TIMEOUT ,cpu_to_be64 (priv->timeout), +if (nla_put_be64 (skb,NFTA_DYNSET_TIMEOUT , +cpu_to_be64 (jiffies_to_msecs (priv->timeout)),NFTA_DYNSET_PAD )) goto nla_put_failure;if (priv->expr &&nft_expr_dump (skb,NFTA_DYNSET_EXPR , priv->expr))
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 3/13 netfilter: conntrack: remove obsolete sysctl (nf_conntrack_events_retry_timeout)
In reply to Pablo Neira AyusoFrom: Nicolas Dichtel <[email protected]>
This entry has been removed in commit 9500507c6138.
--- Documentation/networking/nf_conntrack-sysctl.txt | 18 ------------------ 1 file changed, 18 deletions(-)
Documentation/networking/nf_conntrack-sysctl.txt +0 -18
@@ -33,24 +33,6 @@ nf_conntrack_events - BOOLEAN If this option is enabled, the connection tracking code will provide userspace with connection tracking events via ctnetlink. -nf_conntrack_events_retry_timeout - INTEGER (seconds) - default 15 - - This option is only relevant when "reliable connection tracking - events" are used. Normally, ctnetlink is "lossy", that is, - events are normally dropped when userspace listeners can't keep up. - - Userspace can request "reliable event mode". When this mode is - active, the conntrack will only be destroyed after the event was - delivered. If event delivery fails, the kernel periodically - re-tries to send the event to userspace. - - This is the maximum interval the kernel should use when re-trying - to deliver the destroy event. - - A higher number means there will be fewer delivery retries and it - will take longer for a backlog to be processed. - nf_conntrack_expect_max - INTEGER Maximum size of expectation table. Default value is nf_conntrack_buckets / 256. Minimum is 1.
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 4/13 netfilter: xt_NFLOG: fix unexpected truncated packet
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
Justin and Chris spotted that iptables NFLOG target was broken when they upgraded the kernel to 4.8: "ulogd-2.0.5- IPs are no longer logged" or "results in segfaults in ulogd-2.0.5".
Because "struct nf_loginfo li;" is a local variable, and flags will be filled with garbage value, not inited to zero. So if it contains 0x1, packets will not be logged to the userspace anymore.
--- net/netfilter/xt_NFLOG.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/xt_NFLOG.c +1 -0
@@ -32,6 +32,7 @@ nflog_tg(struct sk_buff *skb, const struct xt_action_param *par) li.u.ulog.copy_len = info->len; li.u.ulog.group = info->group; li.u.ulog.qthreshold = info->threshold; + li.u.ulog.flags =0 ;if (info->flags &XT_NFLOG_F_COPY_LEN ) li.u.ulog.flags |=NF_LOG_F_COPY_LEN ;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 5/13 netfilter: xt_ipcomp: add "ip[6]t_ipcomp" module alias name
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
Otherwise, user cannot add related rules if xt_ipcomp.ko is not loaded:
# iptables -A OUTPUT -p 108 -m ipcomp --ipcompspi 1 iptables: No chain/target/match by that name.
--- net/netfilter/xt_ipcomp.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/xt_ipcomp.c +2 -0
@@ -26,6 +26,8 @@MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Fan Du <[email protected]>" );MODULE_DESCRIPTION ("Xtables: IPv4/6 IPsec-IPComp SPI match" ); +MODULE_ALIAS ("ipt_ipcomp" ); +MODULE_ALIAS ("ip6t_ipcomp" );/* Returns 1 if the spi is matched by the range, 0 otherwise */ static inline bool
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 6/13 netfilter: nft_hash: add missing NFTA_HASH_OFFSET's nla_policy
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
Missing the nla_policy description will also miss the validation check in kernel.
--- net/netfilter/nft_hash.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nft_hash.c +1 -0
@@ -44,6 +44,7 @@ static const struct nla_policy nft_hash_policy[NFTA_HASH_MAX + 1] = { [NFTA_HASH_LEN] = { .type = NLA_U32 }, [NFTA_HASH_MODULUS] = { .type = NLA_U32 }, [NFTA_HASH_SEED] = { .type = NLA_U32 }, + [NFTA_HASH_OFFSET] = { .type = NLA_U32 }, }; static int nft_hash_init(const struct nft_ctx *ctx,
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 7/13 netfilter: nf_tables: underflow in nft_parse_u32_check()
In reply to Pablo Neira AyusoFrom: Dan Carpenter <[email protected]>
We don't want to allow negatives here.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -4423,7 +4423,7 @@ static int nf_tables_check_loops(const struct nft_ctx *ctx,*/ unsigned int nft_parse_u32_check (const struct nlattr *attr,int max,u32 *dest) { -int val; +u32 val; val =ntohl (nla_get_be32 (attr));if (val > max)
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 8/13 netfilter: nft_exthdr: fix error handling in nft_exthdr_init()
In reply to Pablo Neira AyusoFrom: Dan Carpenter <[email protected]>
"err" needs to be signed for the error handling to work.
--- net/netfilter/nft_exthdr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_exthdr.c +2 -1
@@ -59,7 +59,8 @@ static int nft_exthdr_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) {struct nft_exthdr *priv =nft_expr_priv (expr); -u32 offset, len, err; +u32 offset, len; +int err; if (tb[NFTA_EXTHDR_DREG] == NULL || tb[NFTA_EXTHDR_TYPE] == NULL ||
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 9/13 netfilter: nft_range: validate operation netlink attribute
In reply to Pablo Neira AyusoUse nft_parse_u32_check() to make sure we don't get a value over the unsigned 8-bit integer. Moreover, make sure this value doesn't go over the two supported range comparison modes.
--- net/netfilter/nft_range.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
net/netfilter/nft_range.c +15 -1
@@ -59,6 +59,7 @@ static int nft_range_init(const struct nft_ctx *ctx, const struct nft_expr *exprstruct nft_range_expr *priv =nft_expr_priv (expr);struct nft_data_desc desc_from, desc_to;int err; +u32 op; err =nft_data_init (NULL , &priv->data_from,sizeof (priv->data_from), &desc_from, tb[NFTA_RANGE_FROM_DATA ]);
@@ -80,7 +81,20 @@ static int nft_range_init(const struct nft_ctx *ctx, const struct nft_expr *exprif (err <0 ) goto err2; - priv->op =ntohl (nla_get_be32 (tb[NFTA_RANGE_OP ])); + err =nft_parse_u32_check (tb[NFTA_RANGE_OP ],U8_MAX , &op); +if (err <0 ) + goto err2; + +switch (op) { +case NFT_RANGE_EQ : +case NFT_RANGE_NEQ : +break ; +default : + err = -EINVAL ; + goto err2; + } + + priv->op = op; priv->len = desc_from.len;return 0 ; err2:
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 10/13 netfilter: nf_tables: avoid uninitialized variable warning
In reply to Pablo Neira AyusoFrom: Arnd Bergmann <[email protected]>
The newly added nft_range_eval() function handles the two possible nft range operations, but as the compiler warning points out, any unexpected value would lead to the 'mismatch' variable being used without being initialized:
net/netfilter/nft_range.c: In function 'nft_range_eval':net/netfilter/nft_range.c:45:5: error: 'mismatch' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This removes the variable in question and instead moves the condition into the switch itself, which is potentially more efficient than adding a bogus 'default' clause as in my first approach, and is nicer than using the 'uninitialized_var' macro.
--- net/netfilter/nft_range.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
net/netfilter/nft_range.c +4 -6
@@ -28,22 +28,20 @@ static void nft_range_eval(const struct nft_expr *expr, const struct nft_pktinfo *pkt) {const struct nft_range_expr *priv =nft_expr_priv (expr); -bool mismatch;int d1, d2; d1 =memcmp (®s->data[priv->sreg], &priv->data_from, priv->len); d2 =memcmp (®s->data[priv->sreg], &priv->data_to, priv->len);switch (priv->op) {case NFT_RANGE_EQ : - mismatch = (d1 <0 || d2 >0 ); +if (d1 <0 || d2 >0 ) + regs->verdict.code =NFT_BREAK ;break ;case NFT_RANGE_NEQ : - mismatch = (d1 >=0 && d2 <=0 ); +if (d1 >=0 && d2 <=0 ) + regs->verdict.code =NFT_BREAK ;break ; } - -if (mismatch) - regs->verdict.code =NFT_BREAK ; }static const struct nla_policy nft_range_policy[NFTA_RANGE_MAX +1 ] = {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 11/13 netfilter: x_tables: suppress kmemcheck warning
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Markus Trippelsdorf reports:
WARNING: kmemcheck: Caught 64-bit read from uninitialized memory (ffff88001e605480) 4055601e0088ffff000000000000000090686d81ffffffff0000000000000000
u u u u u u u u u u u u u u u u i i i i i i i i u u u u u u u u
^
|RIP: 0010:[<ffffffff8166e561>] [<ffffffff8166e561>] nf_register_net_hook+0x51/0x160 [..]
[<ffffffff8166e561>] nf_register_net_hook+0x51/0x160 [<ffffffff8166eaaf>] nf_register_net_hooks+0x3f/0xa0 [<ffffffff816d6715>] ipt_register_table+0xe5/0x110
[..]
This warning is harmless; we copy 'uninitialized' data from the hook ops but it will not be used.
Long term the structures keeping run-time data should be disentangled from those only containing config-time data (such as where in the list to insert a hook), but thats -next material.
--- net/netfilter/x_tables.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/x_tables.c +1 -1
@@ -1513,7 +1513,7 @@ xt_hook_ops_alloc(const struct xt_table *table, nf_hookfn *fn)if (!num_hooks)return ERR_PTR (-EINVAL ); - ops =kmalloc (sizeof (*ops) * num_hooks,GFP_KERNEL ); + ops =kcalloc (num_hooks,sizeof (*ops),GFP_KERNEL );if (ops ==NULL )return ERR_PTR (-ENOMEM );
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 12/13 netfilter: conntrack: restart gc immediately if GC_MAX_EVICTS is reached
In reply to Pablo Neira AyusoFrom: Nicolas Dichtel <[email protected]>
When the maximum evictions number is reached, do not wait 5 seconds before the next run.
--- net/netfilter/nf_conntrack_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_core.c +1 -1
@@ -983,7 +983,7 @@ static void gc_worker(struct work_struct *work)return ; ratio = scanned ? expired_count *100 / scanned :0 ; -if (ratio >=90 ) +if (ratio >=90 || expired_count ==GC_MAX_EVICTS ) next_run =0 ; gc_work->last_bucket = i;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 13/13 netfilter: fix nf_queue handling
In reply to Pablo Neira Ayusonf_queue handling is broken since e3b37f11e6e4 ("netfilter: replace list_head with single linked list") for two reasons:
1) If the bypass flag is set on, there are no userspace listeners and we still have more hook entries to iterate over, then jump to the next hook. Otherwise accept the packet. On nf_reinject() path, the okfn() needs to be invoked.
2) We should not re-enter the same hook on packet reinjection. If the packet is accepted, we have to skip the current hook from where the packet was enqueued, otherwise the packets gets enqueued over and over again.
This restores the previous list_for_each_entry_continue() behaviour happening from nf_iterate() that was dealing with these two cases. This patch introduces a new nf_queue() wrapper function so this fix becomes simpler.
--- net/netfilter/core.c | 13 +++--------- net/netfilter/nf_internals.h | 2 +- net/netfilter/nf_queue.c | 48 +++++++++++++++++++++++++++++--------------- 3 files changed, 36 insertions(+), 27 deletions(-)
net/netfilter/core.c +3 -10
@@ -361,16 +361,9 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)if (ret ==0 ) ret = -EPERM ; }else if ((verdict &NF_VERDICT_MASK ) ==NF_QUEUE ) { -int err; - -RCU_INIT_POINTER (state->hook_entries, entry); - err =nf_queue (skb, state, verdict >>NF_VERDICT_QBITS ); -if (err <0 ) { -if (err == -ESRCH && - (verdict &NF_VERDICT_FLAG_QUEUE_BYPASS )) - goto next_hook; -kfree_skb (skb); - } + ret =nf_queue (skb, state, &entry, verdict); +if (ret ==1 && entry) + goto next_hook; }return ret; }
net/netfilter/nf_internals.h +1 -1
@@ -18,7 +18,7 @@ unsigned int nf_iterate(struct sk_buff *skb, struct nf_hook_state *state,/* nf_queue.c */ int nf_queue (struct sk_buff *skb,struct nf_hook_state *state, -unsigned int queuenum); +struct nf_hook_entry **entryp,unsigned int verdict);void nf_queue_nf_hook_drop (struct net *net,const struct nf_hook_entry *entry);int __init netfilter_queue_init (void );
net/netfilter/nf_queue.c +32 -16
77 lines not on this page · raw message
Signature · 1 line
2.1.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 21 Oct 2016 12:12:10 +0200
Quoted 2 lines
The following patchset contains Netfilter fixes for your net tree, they are:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks!