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:
1) Fix accidental 3-times le/be conversion for 64-bits in nft_byteorder, from Florian Westphal.
2) Get rid of defensive cidr = 0 check in the ipset hash:netiface set type which doesn't allow valid 0.0.0.0/0 elements, also from Florian.
3) Relocate #endif in nft_ct counter support, this doesn't have any relation with labels.
4) Fix TCPMSS target for IPv6 when skb has CHECKSUM_COMPLETE, from Eric Dumazet.
5) Fix netdevice notifier leak from the error path of nf_tables_netdev.
6) Safe conntrack hashtable resizing by introducing a global lock and synchronize all buckets to avoid going over the maximum number of preemption levels, from Sasha Levin.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit f1640c3ddeec12804bc9a21feee85fc15aca95f6:
bgmac: fix a missing check for build_skb (2016-01-13 00:24:14 -0500)
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 b16c29191dc89bd877af99a7b04ce4866728a3e0:
netfilter: nf_conntrack: use safer way to lock all buckets (2016-01-20 14:15:31 +0100)
----------------------------------------------------------------
Eric Dumazet (1):
netfilter: xt_TCPMSS: handle CHECKSUM_COMPLETE in tcpmss_tg6()
Florian Westphal (2):
netfilter: nft_byteorder: avoid unneeded le/be conversion steps
netfilter: ipset: allow a 0 netmask with hash_netiface type
Pablo Neira Ayuso (2):
netfilter: nft_ct: keep counters away from CONFIG_NF_CONNTRACK_LABELS
netfilter: nf_tables_netdev: fix error path in module initialization
Sasha Levin (1):
netfilter: nf_conntrack: use safer way to lock all buckets
include/net/netfilter/nf_conntrack_core.h | 8 +++---- net/netfilter/ipset/ip_set_hash_netiface.c | 4 ---- net/netfilter/nf_conntrack_core.c | 38 ++++++++++++++++++++++-------- net/netfilter/nf_conntrack_helper.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 2 +- net/netfilter/nf_tables_netdev.c | 8 +++---- net/netfilter/nfnetlink_cttimeout.c | 4 ++-- net/netfilter/nft_byteorder.c | 6 ++--- net/netfilter/nft_ct.c | 2 +- net/netfilter/xt_TCPMSS.c | 9 +++++-- 10 files changed, 49 insertions(+), 34 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/6 netfilter: nft_byteorder: avoid unneeded le/be conversion steps
From: Florian Westphal <[email protected]>
David points out that we to three le/be conversions instead of just one. Doesn't matter on x86_64 w. gcc, but other architectures might be less lucky.
Since it also simplifies code just follow his advice.
--- net/netfilter/nft_byteorder.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/netfilter/nft_byteorder.c +2 -4
@@ -46,16 +46,14 @@ static void nft_byteorder_eval(const struct nft_expr *expr,switch (priv->op) {case NFT_BYTEORDER_NTOH :for (i =0 ; i < priv->len /8 ; i++) { - src64 =get_unaligned_be64 (&src[i]); - src64 =be64_to_cpu ((__force __be64 )src64); + src64 =get_unaligned ((u64 *)&src[i]);put_unaligned_be64 (src64, &dst[i]); }break ;case NFT_BYTEORDER_HTON :for (i =0 ; i < priv->len /8 ; i++) { src64 =get_unaligned_be64 (&src[i]); - src64 = (__force u64 )cpu_to_be64 (src64); -put_unaligned_be64 (src64, &dst[i]); +put_unaligned (src64, (u64 *)&dst[i]); }break ; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/6 netfilter: ipset: allow a 0 netmask with hash_netiface type
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Jozsef says:
The correct behaviour is that if we have ipset create test1 hash:net,iface
ipset add test1 0.0.0.0/0,eth0
iptables -A INPUT -m set --match-set test1 src,src
then the rule should match for any traffic coming in through eth0.
This removes the -EINVAL runtime test to make matching work in case packet arrived via the specified interface.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1297092
--- net/netfilter/ipset/ip_set_hash_netiface.c | 4 ---- 1 file changed, 4 deletions(-)
net/netfilter/ipset/ip_set_hash_netiface.c +0 -4
@@ -164,8 +164,6 @@ hash_netiface4_kadt(struct ip_set *set, const struct sk_buff *skb, };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); -if (e.cidr ==0 ) -return -EINVAL ;if (adt ==IPSET_TEST ) e.cidr =HOST_MASK ;
@@ -377,8 +375,6 @@ hash_netiface6_kadt(struct ip_set *set, const struct sk_buff *skb, };struct ip_set_ext ext =IP_SET_INIT_KEXT (skb, opt, set); -if (e.cidr ==0 ) -return -EINVAL ;if (adt ==IPSET_TEST ) e.cidr =HOST_MASK ;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 3/6 netfilter: nft_ct: keep counters away from CONFIG_NF_CONNTRACK_LABELS
In reply to Pablo Neira AyusoThis is accidental, they don't depend on the label infrastructure.
--- net/netfilter/nft_ct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_ct.c +1 -1
@@ -127,6 +127,7 @@ static void nft_ct_get_eval(const struct nft_expr *expr, NF_CT_LABELS_MAX_SIZE - size); return; } +#endif case NFT_CT_BYTES :/* fallthrough */ case NFT_CT_PKTS : {const struct nf_conn_acct *acct =nf_conn_acct_find (ct);
@@ -138,7 +139,6 @@ static void nft_ct_get_eval(const struct nft_expr *expr,memcpy (dest, &count,sizeof (count));return ; } -#endif default :break ; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 4/6 netfilter: xt_TCPMSS: handle CHECKSUM_COMPLETE in tcpmss_tg6()
In reply to Pablo Neira AyusoFrom: Eric Dumazet <[email protected]>
In case MSS option is added in TCP options, skb length increases by 4. IPv6 needs to update skb->csum if skb has CHECKSUM_COMPLETE, otherwise kernel complains loudly in netdev_rx_csum_fault() with a stack dump.
--- net/netfilter/xt_TCPMSS.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/netfilter/xt_TCPMSS.c +7 -2
@@ -228,7 +228,7 @@ tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par) {struct ipv6hdr *ipv6h =ipv6_hdr (skb);u8 nexthdr; -__be16 frag_off; +__be16 frag_off, oldlen, newlen;int tcphoff;int ret;
@@ -244,7 +244,12 @@ tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par)return NF_DROP ;if (ret >0 ) { ipv6h =ipv6_hdr (skb); - ipv6h->payload_len =htons (ntohs (ipv6h->payload_len) + ret); + oldlen = ipv6h->payload_len; + newlen =htons (ntohs (oldlen) + ret); +if (skb->ip_summed ==CHECKSUM_COMPLETE ) + skb->csum =csum_add (csum_sub (skb->csum, oldlen), + newlen); + ipv6h->payload_len = newlen; }return XT_CONTINUE ; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 5/6 netfilter: nf_tables_netdev: fix error path in module initialization
In reply to Pablo Neira AyusoUnregister the chain type and return error, otherwise this leaks the subscription to the netdevice notifier call chain.
--- net/netfilter/nf_tables_netdev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_netdev.c +4 -4
@@ -224,12 +224,12 @@ static int __init nf_tables_netdev_init(void)nft_register_chain_type (&nft_filter_chain_netdev); ret =register_pernet_subsys (&nf_tables_netdev_net_ops); -if (ret <0 ) +if (ret <0 ) {nft_unregister_chain_type (&nft_filter_chain_netdev); - +return ret; + }register_netdevice_notifier (&nf_tables_netdev_notifier); - -return ret; +return 0 ; } static void __exit nf_tables_netdev_exit(void)
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 6/6 netfilter: nf_conntrack: use safer way to lock all buckets
In reply to Pablo Neira AyusoFrom: Sasha Levin <[email protected]>
When we need to lock all buckets in the connection hashtable we'd attempt to lock 1024 spinlocks, which is way more preemption levels than supported by the kernel. Furthermore, this behavior was hidden by checking if lockdep is enabled, and if it was - use only 8 buckets(!).
Fix this by using a global lock and synchronize all buckets on it when we need to lock them all. This is pretty heavyweight, but is only done when we need to resize the hashtable, and that doesn't happen often enough (or at all).
--- include/net/netfilter/nf_conntrack_core.h | 8 +++---- net/netfilter/nf_conntrack_core.c | 38 +++++++++++++++++++++++-------- net/netfilter/nf_conntrack_helper.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 2 +- net/netfilter/nfnetlink_cttimeout.c | 4 ++-- 5 files changed, 35 insertions(+), 19 deletions(-)
include/net/netfilter/nf_conntrack_core.h +3 -5
@@ -79,12 +79,10 @@ print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,const struct nf_conntrack_l3proto *l3proto, const struct nf_conntrack_l4proto *proto); -#ifdef CONFIG_LOCKDEP -# define CONNTRACK_LOCKS 8 -#else -# define CONNTRACK_LOCKS 1024 -#endif +#define CONNTRACK_LOCKS 1024 +extern spinlock_t nf_conntrack_locks[CONNTRACK_LOCKS ]; +void nf_conntrack_lock (spinlock_t *lock);extern spinlock_t nf_conntrack_expect_lock;
net/netfilter/nf_conntrack_core.c +28 -10
@@ -66,6 +66,21 @@ EXPORT_SYMBOL_GPL(nf_conntrack_locks);__cacheline_aligned_in_smp DEFINE_SPINLOCK (nf_conntrack_expect_lock );EXPORT_SYMBOL_GPL (nf_conntrack_expect_lock); +static __read_mostly spinlock_t nf_conntrack_locks_all_lock; +static __read_mostly bool nf_conntrack_locks_all; + +void nf_conntrack_lock (spinlock_t *lock)__acquires (lock) +{ +spin_lock (lock); +while (unlikely (nf_conntrack_locks_all)) { +spin_unlock (lock); +spin_lock (&nf_conntrack_locks_all_lock); +spin_unlock (&nf_conntrack_locks_all_lock); +spin_lock (lock); + } +} +EXPORT_SYMBOL_GPL (nf_conntrack_lock); +static void nf_conntrack_double_unlock (unsigned int h1,unsigned int h2) { h1 %=CONNTRACK_LOCKS ;
@@ -82,12 +97,12 @@ static bool nf_conntrack_double_lock(struct net *net, unsigned int h1, h1 %=CONNTRACK_LOCKS ; h2 %=CONNTRACK_LOCKS ;if (h1 <= h2) { -spin_lock (&nf_conntrack_locks[h1]); +nf_conntrack_lock (&nf_conntrack_locks[h1]);if (h1 != h2)spin_lock_nested (&nf_conntrack_locks[h2],SINGLE_DEPTH_NESTING ); }else { -spin_lock (&nf_conntrack_locks[h2]); +nf_conntrack_lock (&nf_conntrack_locks[h2]);spin_lock_nested (&nf_conntrack_locks[h1],SINGLE_DEPTH_NESTING ); }
@@ -102,16 +117,19 @@ static void nf_conntrack_all_lock(void) {int i; -for (i =0 ; i <CONNTRACK_LOCKS ; i++) -spin_lock_nested (&nf_conntrack_locks[i], i); +spin_lock (&nf_conntrack_locks_all_lock); + nf_conntrack_locks_all = true; + +for (i =0 ; i <CONNTRACK_LOCKS ; i++) { +spin_lock (&nf_conntrack_locks[i]); +spin_unlock (&nf_conntrack_locks[i]); + } }static void nf_conntrack_all_unlock (void ) { -int i; - -for (i =0 ; i <CONNTRACK_LOCKS ; i++) -spin_unlock (&nf_conntrack_locks[i]); + nf_conntrack_locks_all = false; +spin_unlock (&nf_conntrack_locks_all_lock); }unsigned int nf_conntrack_htable_size__read_mostly ;
@@ -757,7 +775,7 @@ restart: hash =hash_bucket (_hash, net);for (; i < net->ct.htable_size; i++) { lockp = &nf_conntrack_locks[hash %CONNTRACK_LOCKS ]; -spin_lock (lockp); +nf_conntrack_lock (lockp);if (read_seqcount_retry (&net->ct.generation, sequence)) {spin_unlock (lockp); goto restart;
@@ -1382,7 +1400,7 @@ get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data),for (; *bucket < net->ct.htable_size; (*bucket)++) { lockp = &nf_conntrack_locks[*bucket %CONNTRACK_LOCKS ];local_bh_disable (); -spin_lock (lockp); +nf_conntrack_lock (lockp);if (*bucket < net->ct.htable_size) {hlist_nulls_for_each_entry (h, n, &net->ct.hash[*bucket], hnnode) {if (NF_CT_DIRECTION (h) !=IP_CT_DIR_ORIGINAL )
net/netfilter/nf_conntrack_helper.c +1 -1
@@ -425,7 +425,7 @@ static void __nf_conntrack_helper_unregister(struct nf_conntrack_helper *me, }local_bh_disable ();for (i =0 ; i < net->ct.htable_size; i++) { -spin_lock (&nf_conntrack_locks[i %CONNTRACK_LOCKS ]); +nf_conntrack_lock (&nf_conntrack_locks[i %CONNTRACK_LOCKS ]);if (i < net->ct.htable_size) {hlist_nulls_for_each_entry (h, nn, &net->ct.hash[i], hnnode)unhelp (h, me);
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -840,7 +840,7 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)for (; cb->args[0 ] < net->ct.htable_size; cb->args[0 ]++) { restart: lockp = &nf_conntrack_locks[cb->args[0 ] %CONNTRACK_LOCKS ]; -spin_lock (lockp); +nf_conntrack_lock (lockp);if (cb->args[0 ] >= net->ct.htable_size) {spin_unlock (lockp); goto out;
net/netfilter/nfnetlink_cttimeout.c +2 -2
@@ -307,12 +307,12 @@ static void ctnl_untimeout(struct net *net, struct ctnl_timeout *timeout)local_bh_disable ();for (i =0 ; i < net->ct.htable_size; i++) { -spin_lock (&nf_conntrack_locks[i %CONNTRACK_LOCKS ]); +nf_conntrack_lock (&nf_conntrack_locks[i %CONNTRACK_LOCKS ]);if (i < net->ct.htable_size) {hlist_nulls_for_each_entry (h, nn, &net->ct.hash[i], hnnode)untimeout (h, timeout); } -spin_unlock (&nf_conntrack_locks[i %CONNTRACK_LOCKS ]); +nf_conntrack_lock (&nf_conntrack_locks[i %CONNTRACK_LOCKS ]); }local_bh_enable (); }
Signature · 1 line
2.1.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 20 Jan 2016 18:03:58 +0100
Quoted 17 lines
The following patchset contains Netfilter fixes for your net tree, they are:
1) Fix accidental 3-times le/be conversion for 64-bits in
nft_byteorder, from Florian Westphal.2) Get rid of defensive cidr = 0 check in the ipset hash:netiface set type which doesn't allow valid 0.0.0.0/0 elements, also from Florian.
3) Relocate #endif in
nft_ctcounter support, this doesn't have any relation with labels.4) Fix TCPMSS target for IPv6 when skb has
CHECKSUM_COMPLETE, from Eric Dumazet.5) Fix netdevice notifier leak from the error path of
nf_tables_netdev.
Quoted 7 lines
6) Safe conntrack hashtable resizing by introducing a global lock and synchronize all buckets to avoid going over the maximum number of preemption levels, from Sasha Levin.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks Pablo.