Netfilter fixes for net
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi David,
The following patchset contains Netfilter fixes for your net tree, they are rather small patches but fixing several outstanding bugs in nf_conntrack and nf_tables, as well as minor problems with missing SYNPROXY header uapi installation:
1) Oneliner not to leak conntrack kmemcache on module removal, this problem was introduced in the previous merge window, patch from Florian Westphal.
2) Two fixes for insufficient ruleset loop validation, one due to incorrect flag check in nf_tables_bind_set() and another related to silly wrong generation mask logic from the walk path, from Liping Zhang.
3) Fix double-free of anonymous sets on error, this fix simplifies the code to let the abort path take care of releasing the set object, also from Liping Zhang.
4) The introduction of helper function for transactions broke the skip inactive rules logic from the nft_do_chain(), again from Liping Zhang.
5) Two patches to install uapi xt_SYNPROXY.h header and calm down kbuild robot due to missing #include <linux/types.h>.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit 61e0979a497b07f5a82f3050e37ecc7093e2971d:
Merge branch 'ovs-notifications' (2016-06-14 22:21:45 -0700)
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 1463847e93fe693e89c52b03ab4ede6800d717c1:
netfilter: xt_SYNPROXY: include missing <linux/types.h> (2016-06-17 13:47:40 +0200)
----------------------------------------------------------------
Florian Westphal (1):
netfilter: conntrack: destroy kmemcache on module removal
Liping Zhang (3):
netfilter: nf_tables: fix wrong check of NFT_SET_MAP in nf_tables_bind_set
netfilter: nf_tables: fix wrong destroy anonymous sets if binding fails
netfilter: nf_tables: fix a wrong check to skip the inactive rules
Pablo Neira Ayuso (3):
netfilter: nf_tables: reject loops from set element jump to chain
netfilter: xt_SYNPROXY: add missing header to Kbuild
netfilter: xt_SYNPROXY: include missing <linux/types.h>
include/net/netfilter/nf_tables.h | 1 + include/uapi/linux/netfilter/Kbuild | 1 + include/uapi/linux/netfilter/xt_SYNPROXY.h | 2 ++ net/netfilter/nf_conntrack_core.c | 2 ++ net/netfilter/nf_tables_api.c | 24 +++++++++++------------- net/netfilter/nf_tables_core.c | 2 +- net/netfilter/nft_hash.c | 3 +-- net/netfilter/nft_rbtree.c | 3 +-- 8 files changed, 20 insertions(+), 18 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/7 netfilter: conntrack: destroy kmemcache on module removal
From: Florian Westphal <[email protected]>
I forgot to move the kmem_cache_destroy into the exit path.
--- net/netfilter/nf_conntrack_core.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nf_conntrack_core.c +2 -0
@@ -1544,6 +1544,8 @@ void nf_conntrack_cleanup_end(void)nf_conntrack_tstamp_fini ();nf_conntrack_acct_fini ();nf_conntrack_expect_fini (); + +kmem_cache_destroy (nf_conntrack_cachep); }/*
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/7 netfilter: nf_tables: fix wrong check of NFT_SET_MAP in nf_tables_bind_set
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
We should check "i" is used as a dictionary or not, "binding" is already checked before.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -2946,7 +2946,7 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,* jumps are already validated for that chain. */ list_for_each_entry (i, &set->bindings, list) { -if (binding->flags &NFT_SET_MAP && +if (i->flags &NFT_SET_MAP && i->chain == binding->chain) goto bind; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 3/7 netfilter: nf_tables: reject loops from set element jump to chain
In reply to Pablo Neira AyusoLiping Zhang says:
"Users may add such a wrong nft rules successfully, which will cause an endless jump loop:
# nft add rule filter test tcp dport vmap {1: jump test}This is because before we commit, the element in the current anonymous set is inactive, so osp->walk will skip this element and miss the validate check."
To resolve this problem, this patch passes the generation mask to the walk function through the iter container structure depending on the code path:
1) If we're dumping the elements, then we have to check if the element is active in the current generation. Thus, we check for the current bit in the genmask.
2) If we're checking for loops, then we have to check if the element is active in the next generation, as we're in the middle of a transaction. Thus, we check for the next bit in the genmask.
Based on original patch from Liping Zhang.
--- include/net/netfilter/nf_tables.h | 1 + net/netfilter/nf_tables_api.c | 15 +++++++++------ net/netfilter/nft_hash.c | 3 +-- net/netfilter/nft_rbtree.c | 3 +-- 4 files changed, 12 insertions(+), 10 deletions(-)
include/net/netfilter/nf_tables.h +1 -0
@@ -167,6 +167,7 @@ struct nft_set_elem {struct nft_set ;struct nft_set_iter { +u8 genmask;unsigned int count;unsigned int skip;int err;
net/netfilter/nf_tables_api.c +9 -6
@@ -2951,6 +2951,7 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set, goto bind; } + iter.genmask =nft_genmask_next (ctx->net); iter.skip =0 ; iter.count =0 ; iter.err =0 ;
@@ -3192,12 +3193,13 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)if (nest ==NULL ) goto nla_put_failure; - args.cb = cb; - args.skb = skb; - args.iter.skip = cb->args[0 ]; - args.iter.count =0 ; - args.iter.err =0 ; - args.iter.fn = nf_tables_dump_setelem; + args.cb = cb; + args.skb = skb; + args.iter.genmask =nft_genmask_cur (ctx.net); + args.iter.skip = cb->args[0 ]; + args.iter.count =0 ; + args.iter.err =0 ; + args.iter.fn = nf_tables_dump_setelem; set->ops->walk (&ctx, set, &args.iter);nla_nest_end (skb, nest);
@@ -4284,6 +4286,7 @@ static int nf_tables_check_loops(const struct nft_ctx *ctx, binding->chain != chain)continue ; + iter.genmask =nft_genmask_next (ctx->net); iter.skip =0 ; iter.count =0 ; iter.err =0 ;
net/netfilter/nft_hash.c +1 -2
@@ -189,7 +189,6 @@ static void nft_hash_walk(const struct nft_ctx *ctx, const struct nft_set *set,struct nft_hash_elem *he;struct rhashtable_iter hti;struct nft_set_elem elem; -u8 genmask =nft_genmask_cur (read_pnet (&set->pnet));int err; err =rhashtable_walk_init (&priv->ht, &hti,GFP_KERNEL );
@@ -218,7 +217,7 @@ static void nft_hash_walk(const struct nft_ctx *ctx, const struct nft_set *set, goto cont;if (nft_set_elem_expired (&he->ext)) goto cont; -if (!nft_set_elem_active (&he->ext, genmask)) +if (!nft_set_elem_active (&he->ext, iter->genmask)) goto cont; elem.priv = he;
net/netfilter/nft_rbtree.c +1 -2
@@ -211,7 +211,6 @@ static void nft_rbtree_walk(const struct nft_ctx *ctx,struct nft_rbtree_elem *rbe;struct nft_set_elem elem;struct rb_node *node; -u8 genmask =nft_genmask_cur (read_pnet (&set->pnet));spin_lock_bh (&nft_rbtree_lock);for (node =rb_first (&priv->root); node !=NULL ; node =rb_next (node)) {
@@ -219,7 +218,7 @@ static void nft_rbtree_walk(const struct nft_ctx *ctx,if (iter->count < iter->skip) goto cont; -if (!nft_set_elem_active (&rbe->ext, genmask)) +if (!nft_set_elem_active (&rbe->ext, iter->genmask)) goto cont; elem.priv = rbe;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 4/7 netfilter: nf_tables: fix wrong destroy anonymous sets if binding fails
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
When we add a nft rule like follows:
# nft add rule filter test tcp dport vmap {1: jump test}
-ELOOP error will be returned, and the anonymous set will be
destroyed.But after that, nf_tables_abort will also try to remove the element and destroy the set, which was already destroyed and freed.
If we add a nft wrong rule, nft_tables_abort will do the cleanup work rightly, so nf_tables_set_destroy call here is redundant and wrong, remove it.
--- net/netfilter/nf_tables_api.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
net/netfilter/nf_tables_api.c +1 -6
@@ -2958,13 +2958,8 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set, iter.fn = nf_tables_bind_check_setelem; set->ops->walk (ctx, set, &iter); -if (iter.err <0 ) { -/* Destroy anonymous sets if binding fails */ -if (set->flags &NFT_SET_ANONYMOUS ) -nf_tables_set_destroy (ctx, set); - +if (iter.err <0 )return iter.err; - } } bind: binding->chain = ctx->chain;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 5/7 netfilter: nf_tables: fix a wrong check to skip the inactive rules
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
nft_genmask_cur has already done left-shift operator on the gencursor, so there's no need to do left-shift operator on it again.
--- net/netfilter/nf_tables_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_core.c +1 -1
@@ -143,7 +143,7 @@ next_rule:list_for_each_entry_continue_rcu (rule, &chain->rules, list) {/* This rule is not active, skip. */ -if (unlikely (rule->genmask & (1 << gencursor))) +if (unlikely (rule->genmask & gencursor))continue ; rulenum++;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 6/7 netfilter: xt_SYNPROXY: add missing header to Kbuild
In reply to Pablo Neira AyusoMatt Whitlock says:
Without this line, the file xt_SYNPROXY.h does not get installed in /usr/include/linux/netfilter/, and thus user-space programs cannot make use of it.
--- include/uapi/linux/netfilter/Kbuild | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/netfilter/Kbuild +1 -0
@@ -33,6 +33,7 @@ header-y += xt_NFLOG.h header-y += xt_NFQUEUE.h header-y += xt_RATEEST.h header-y += xt_SECMARK.h +header-y += xt_SYNPROXY.h header-y += xt_TCPMSS.h header-y += xt_TCPOPTSTRIP.h header-y += xt_TEE.h
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 7/7 netfilter: xt_SYNPROXY: include missing <linux/types.h>
In reply to Pablo Neira Ayuso./usr/include/linux/netfilter/xt_SYNPROXY.h:11: found __[us]{8,16,32,64} type without #include <linux/types.h>
--- include/uapi/linux/netfilter/xt_SYNPROXY.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/netfilter/xt_SYNPROXY.h +2 -0
@@ -1,6 +1,8 @@#ifndef _XT_SYNPROXY_H#define _XT_SYNPROXY_H +#include <linux/types.h> +#define XT_SYNPROXY_OPT_MSS 0x01#define XT_SYNPROXY_OPT_WSCALE 0x02#define XT_SYNPROXY_OPT_SACK_PERM 0x04
Signature · 1 line
2.1.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 17 Jun 2016 20:25:12 +0200
Quoted 4 lines
The following patchset contains Netfilter fixes for your net tree, they are rather small patches but fixing several outstanding bugs in
nf_conntrackandnf_tables, as well as minor problems with missing SYNPROXY header uapi installation:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks Pablo.