Netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi David,
This is a large batch of Netfilter fixes for net, they are:
1) Three patches to fix NAT conversion to rhashtable: Switch to rhlist structure that allows to have several objects with the same key. Moreover, fix wrong comparison logic in nf_nat_bysource_cmp() as this is expecting a return value similar to memcmp(). Change location of the nat_bysource field in the nf_conn structure to avoid zeroing this as it breaks interaction with SLAB_DESTROY_BY_RCU and lead us to crashes. From Florian Westphal.
2) Don't allow malformed fragments go through in IPv6, drop them, otherwise we hit GPF, patch from Florian Westphal.
3) Fix crash if attributes are missing in nft_range, from Liping Zhang.
4) Fix arptables 32-bits userspace 64-bits kernel compat, from Hongxu Jia.
5) Two patches from David Ahern to fix netfilter interaction with vrf. From David Ahern.
6) Fix element timeout calculation in nf_tables, we take milliseconds from userspace, but we use jiffies from kernelspace. Patch from Anders K. Pedersen.
7) Missing validation length netlink attribute for nft_hash, from Laura Garcia.
8) Fix nf_conntrack_helper documentation, we don't default to off anymore for a bit of time so let's get this in sync with the code.
I know is late but I think these are important, specifically the NAT bits, as they are mostly addressing fallout from recent changes. I also read there are chances to have -rc8, if that is the case, that would also give us a bit more time to test this.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit b6e01232e25629907df9db19f25da7d4e8f5b589:
net/mlx4_en: Free netdev resources under state lock (2016-11-23 20:18:36 -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 17a49cd549d9dc8707dc9262210166455c612dde:
netfilter: arp_tables: fix invoking 32bit "iptable -P INPUT ACCEPT" failed in 64bit kernel (2016-11-30 20:50:23 +0100)
----------------------------------------------------------------
Anders K. Pedersen (1):
netfilter: nf_tables: fix inconsistent element expiration calculation
David Ahern (2):
netfilter: Update ip_route_me_harder to consider L3 domain
netfilter: Update nf_send_reset6 to consider L3 domain
Florian Westphal (5):
netfilter: fix nf_conntrack_helper documentation
netfilter: nat: fix cmp return value
netfilter: nat: switch to new rhlist interface
netfilter: nat: fix crash when conntrack entry is re-used
netfilter: ipv6: nf_defrag: drop mangled skb on ream error
Hongxu Jia (1):
netfilter: arp_tables: fix invoking 32bit "iptable -P INPUT ACCEPT" failed in 64bit kernel
Laura Garcia Liebana (1):
netfilter: nft_hash: validate maximum value of u32 netlink hash attribute
Liping Zhang (1):
netfilter: nft_range: add the missing NULL pointer check
Documentation/networking/nf_conntrack-sysctl.txt | 7 +++- include/net/netfilter/nf_conntrack.h | 6 +-- include/net/netfilter/nf_tables.h | 2 +- net/ipv4/netfilter.c | 5 ++- net/ipv4/netfilter/arp_tables.c | 4 +- net/ipv6/netfilter/nf_conntrack_reasm.c | 4 +- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 2 +- net/ipv6/netfilter/nf_reject_ipv6.c | 1 + net/netfilter/nf_nat_core.c | 49 +++++++++++++++--------- net/netfilter/nf_tables_api.c | 14 ++++--- net/netfilter/nft_hash.c | 7 +++- net/netfilter/nft_range.c | 6 +++ 12 files changed, 69 insertions(+), 38 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/11 netfilter: Update ip_route_me_harder to consider L3 domain
From: David Ahern <[email protected]>
ip_route_me_harder is not considering the L3 domain and sending lookups to the wrong table. For example consider the following output rule:
iptables -I OUTPUT -p tcp --dport 12345 -j REJECT --reject-with tcp-reset
using perf to analyze lookups via the fib_table_lookup tracepoint shows:
vrf-test 1187 [001] 46887.295927: fib:fib_table_lookup: table 255 oif 0 iif 0 src 0.0.0.0 dst 10.100.1.254 tos 0 scope 0 flags 0
ffffffff8143922c perf_trace_fib_table_lookup ([kernel.kallsyms])
ffffffff81493aac fib_table_lookup ([kernel.kallsyms])
ffffffff8148dda3 __inet_dev_addr_type ([kernel.kallsyms])
ffffffff8148ddf6 inet_addr_type ([kernel.kallsyms])
ffffffff8149e344 ip_route_me_harder ([kernel.kallsyms])
and
vrf-test 1187 [001] 46887.295933: fib:fib_table_lookup: table 255 oif 0 iif 1 src 10.100.1.254 dst 10.100.1.2 tos 0 scope 0 flags
ffffffff8143922c perf_trace_fib_table_lookup ([kernel.kallsyms])
ffffffff81493aac fib_table_lookup ([kernel.kallsyms])
ffffffff814998ff fib4_rule_action ([kernel.kallsyms])
ffffffff81437f35 fib_rules_lookup ([kernel.kallsyms])
ffffffff81499758 __fib_lookup ([kernel.kallsyms])
ffffffff8144f010 fib_lookup.constprop.34 ([kernel.kallsyms])
ffffffff8144f759 __ip_route_output_key_hash ([kernel.kallsyms])
ffffffff8144fc6a ip_route_output_flow ([kernel.kallsyms])
ffffffff8149e39b ip_route_me_harder ([kernel.kallsyms])In both cases the lookups are directed to table 255 rather than the table associated with the device via the L3 domain. Update both lookups to pull the L3 domain from the dst currently attached to the skb.
--- net/ipv4/netfilter.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/netfilter.c +4 -1
@@ -24,10 +24,11 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_tstruct flowi4 fl4 = {};__be32 saddr = iph->saddr;__u8 flags = skb->sk ?inet_sk_flowi_flags (skb->sk) :0 ; +struct net_device *dev =skb_dst (skb)->dev;unsigned int hh_len;if (addr_type ==RTN_UNSPEC ) - addr_type =inet_addr_type (net, saddr); + addr_type =inet_addr_type_dev_table (net, dev, saddr);if (addr_type ==RTN_LOCAL || addr_type ==RTN_UNICAST ) flags |=FLOWI_FLAG_ANYSRC ;else
@@ -40,6 +41,8 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t fl4.saddr = saddr; fl4.flowi4_tos =RT_TOS (iph->tos); fl4.flowi4_oif = skb->sk ? skb->sk->sk_bound_dev_if :0 ; +if (!fl4.flowi4_oif) + fl4.flowi4_oif =l3mdev_master_ifindex (dev); fl4.flowi4_mark = skb->mark; fl4.flowi4_flags = flags; rt =ip_route_output_key (net, &fl4);
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/11 netfilter: Update nf_send_reset6 to consider L3 domain
In reply to Pablo Neira AyusoFrom: David Ahern <[email protected]>
nf_send_reset6 is not considering the L3 domain and lookups are sent to the wrong table. For example consider the following output rule:
ip6tables -A OUTPUT -p tcp --dport 12345 -j REJECT --reject-with tcp-reset
using perf to analyze lookups via the fib6_table_lookup tracepoint shows:
swapper 0 [001] 248.787816: fib6:fib6_table_lookup: table 255 oif 0 iif 1 src 2100:1::3 dst 2100:1:
ffffffff81439cdc perf_trace_fib6_table_lookup ([kernel.kallsyms])
ffffffff814c1ce3 trace_fib6_table_lookup ([kernel.kallsyms])
ffffffff814c3e89 ip6_pol_route ([kernel.kallsyms])
ffffffff814c40d5 ip6_pol_route_output ([kernel.kallsyms])
ffffffff814e7b6f fib6_rule_action ([kernel.kallsyms])
ffffffff81437f60 fib_rules_lookup ([kernel.kallsyms])
ffffffff814e7c79 fib6_rule_lookup ([kernel.kallsyms])
ffffffff814c2541 ip6_route_output_flags ([kernel.kallsyms])
528 nf_send_reset6 ([nf_reject_ipv6])The lookup is directed to table 255 rather than the table associated with the device via the L3 domain. Update nf_send_reset6 to pull the L3 domain from the dst currently attached to the skb.
--- net/ipv6/netfilter/nf_reject_ipv6.c | 1 + 1 file changed, 1 insertion(+)
net/ipv6/netfilter/nf_reject_ipv6.c +1 -0
@@ -156,6 +156,7 @@ void nf_send_reset6(struct net *net, struct sk_buff *oldskb, int hook) fl6.daddr = oip6h->saddr; fl6.fl6_sport = otcph->dest; fl6.fl6_dport = otcph->source; + fl6.flowi6_oif =l3mdev_master_ifindex (skb_dst (oldskb)->dev);security_skb_classify_flow (oldskb,flowi6_to_flowi (&fl6)); dst =ip6_route_output (net,NULL , &fl6);if (dst->error) {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 3/11 netfilter: fix nf_conntrack_helper documentation
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Since kernel 4.7 this defaults to off.
--- Documentation/networking/nf_conntrack-sysctl.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Documentation/networking/nf_conntrack-sysctl.txt +5 -2
@@ -62,10 +62,13 @@ nf_conntrack_generic_timeout - INTEGER (seconds) protocols. nf_conntrack_helper - BOOLEAN - 0 - disabled - not 0 - enabled (default) + 0 - disabled (default) + not 0 - enabled Enable automatic conntrack helper assignment. + If disabled it is required to set up iptables rules to assign + helpers to connections. See the CT target description in the + iptables-extensions(8) man page for further information. nf_conntrack_icmp_timeout - INTEGER (seconds) default 30
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 4/11 netfilter: nft_hash: validate maximum value of u32 netlink hash attribute
In reply to Pablo Neira AyusoFrom: Laura Garcia Liebana <[email protected]>
Use the function nft_parse_u32_check() to fetch the value and validate the u32 attribute into the hash len u8 field.
This patch revisits 4da449ae1df9 ("netfilter: nft_exthdr: Add size check on u8 nft_exthdr attributes").
--- net/netfilter/nft_hash.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/netfilter/nft_hash.c +5 -2
@@ -53,6 +53,7 @@ static int nft_hash_init(const struct nft_ctx *ctx, {struct nft_hash *priv =nft_expr_priv (expr);u32 len; +int err; if (!tb[NFTA_HASH_SREG] || !tb[NFTA_HASH_DREG] ||
@@ -67,8 +68,10 @@ static int nft_hash_init(const struct nft_ctx *ctx, priv->sreg =nft_parse_register (tb[NFTA_HASH_SREG ]); priv->dreg =nft_parse_register (tb[NFTA_HASH_DREG ]); - len =ntohl (nla_get_be32 (tb[NFTA_HASH_LEN ])); -if (len ==0 || len >U8_MAX ) + err =nft_parse_u32_check (tb[NFTA_HASH_LEN ],U8_MAX , &len); +if (err <0 ) +return err; +if (len ==0 )return -ERANGE ; priv->len = len;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 5/11 netfilter: nat: fix cmp return value
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
The comparator works like memcmp, i.e. 0 means objects are equal. In other words, when objects are distinct they are treated as identical, when they are distinct they are allegedly the same.
The first case is rare (distinct objects are unlikely to get hashed to same bucket).
The second case results in unneeded port conflict resolutions attempts.
--- net/netfilter/nf_nat_core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/netfilter/nf_nat_core.c +6 -3
@@ -193,9 +193,12 @@ static int nf_nat_bysource_cmp(struct rhashtable_compare_arg *arg,const struct nf_nat_conn_key *key = arg->key;const struct nf_conn *ct = obj; -return same_src (ct, key->tuple) && -net_eq (nf_ct_net (ct), key->net) && -nf_ct_zone_equal (ct, key->zone,IP_CT_DIR_ORIGINAL ); +if (!same_src (ct, key->tuple) || + !net_eq (nf_ct_net (ct), key->net) || + !nf_ct_zone_equal (ct, key->zone,IP_CT_DIR_ORIGINAL )) +return 1 ; + +return 0 ; }static struct rhashtable_params nf_nat_bysource_params = {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 6/11 netfilter: nat: switch to new rhlist interface
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
I got offlist bug report about failing connections and high cpu usage. This happens because we hit 'elasticity' checks in rhashtable that refuses bucket list exceeding 16 entries.
The nat bysrc hash unfortunately needs to insert distinct objects that share same key and are identical (have same source tuple), this cannot be avoided.
Switch to the rhlist interface which is designed for this.
The nulls_base is removed here, I don't think its needed:
A (unlikely) false positive results in unneeded port clash resolution, a false negative results in packet drop during conntrack confirmation, when we try to insert the duplicate into main conntrack hash table.
Tested by adding multiple ip addresses to host, then adding iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
... and then creating multiple connections, from same source port but different addresses:
for i in $(seq 2000 2032);do nc -p 1234 192.168.7.1 $i > /dev/null & done
(all of these then get hashed to same bysource slot)
Then, to test that nat conflict resultion is working:
nc -s 10.0.0.1 -p 1234 192.168.7.1 2000
nc -s 10.0.0.2 -p 1234 192.168.7.1 2000
tcp .. src=10.0.0.1 dst=192.168.7.1 sport=1234 dport=2000 src=192.168.7.1 dst=192.168.7.10 sport=2000 dport=1024 [ASSURED] tcp .. src=10.0.0.2 dst=192.168.7.1 sport=1234 dport=2000 src=192.168.7.1 dst=192.168.7.10 sport=2000 dport=1025 [ASSURED] tcp .. src=192.168.7.10 dst=192.168.7.1 sport=1234 dport=2000 src=192.168.7.1 dst=192.168.7.10 sport=2000 dport=1234 [ASSURED] tcp .. src=192.168.7.10 dst=192.168.7.1 sport=1234 dport=2001 src=192.168.7.1 dst=192.168.7.10 sport=2001 dport=1234 [ASSURED]
[..]
-> nat altered source ports to 1024 and 1025, respectively. This can also be confirmed on destination host which shows
ESTAB 0 0 192.168.7.1:2000 192.168.7.10:1024 ESTAB 0 0 192.168.7.1:2000 192.168.7.10:1025 ESTAB 0 0 192.168.7.1:2000 192.168.7.10:1234
--- include/net/netfilter/nf_conntrack.h | 2 +- net/netfilter/nf_nat_core.c | 40 +++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 17 deletions(-)
include/net/netfilter/nf_conntrack.h +1 -1
@@ -118,7 +118,7 @@ struct nf_conn {struct nf_ct_ext *ext;#if IS_ENABLED (CONFIG_NF_NAT ) -struct rhash_head nat_bysource; +struct rhlist_head nat_bysource;#endif /* Storage reserved for other modules, must be the last member */ union nf_conntrack_proto proto;
net/netfilter/nf_nat_core.c +24 -16
@@ -42,7 +42,7 @@ struct nf_nat_conn_key {const struct nf_conntrack_zone *zone; }; -static struct rhashtable nf_nat_bysource_table; +static struct rhltable nf_nat_bysource_table;inline const struct nf_nat_l3proto *__nf_nat_l3proto_find (u8 family)
@@ -207,7 +207,6 @@ static struct rhashtable_params nf_nat_bysource_params = { .obj_cmpfn = nf_nat_bysource_cmp, .nelem_hint = 256, .min_size = 1024, - .nulls_base = (1U << RHT_BASE_SHIFT), };/* Only called for SRC manip */
@@ -226,12 +225,15 @@ find_appropriate_src(struct net *net, .tuple = tuple, .zone = zone }; +struct rhlist_head *hl; - ct =rhashtable_lookup_fast (&nf_nat_bysource_table, &key, - nf_nat_bysource_params); -if (!ct) + hl =rhltable_lookup (&nf_nat_bysource_table, &key, + nf_nat_bysource_params); +if (!hl)return 0 ; + ct =container_of (hl,typeof (*ct), nat_bysource); +nf_ct_invert_tuplepr (result, &ct->tuplehash[IP_CT_DIR_REPLY ].tuple); result->dst = tuple->dst;
@@ -449,11 +451,17 @@ nf_nat_setup_info(struct nf_conn *ct, }if (maniptype ==NF_NAT_MANIP_SRC ) { +struct nf_nat_conn_key key = { + .net =nf_ct_net (ct), + .tuple = &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple, + .zone =nf_ct_zone (ct), + };int err; - err =rhashtable_insert_fast (&nf_nat_bysource_table, - &ct->nat_bysource, - nf_nat_bysource_params); + err =rhltable_insert_key (&nf_nat_bysource_table, + &key, + &ct->nat_bysource, + nf_nat_bysource_params);if (err)return NF_DROP ; }
@@ -570,8 +578,8 @@ static int nf_nat_proto_clean(struct nf_conn *ct, void *data)* will delete entry from already-freed table. */ ct->status &= ~IPS_NAT_DONE_MASK ; -rhashtable_remove_fast (&nf_nat_bysource_table, &ct->nat_bysource, - nf_nat_bysource_params); +rhltable_remove (&nf_nat_bysource_table, &ct->nat_bysource, + nf_nat_bysource_params);/* don't delete conntrack. Although that would make things a lot * simpler, we'd end up flushing all conntracks on nat rmmod.
@@ -701,8 +709,8 @@ static void nf_nat_cleanup_conntrack(struct nf_conn *ct)if (!nat)return ; -rhashtable_remove_fast (&nf_nat_bysource_table, &ct->nat_bysource, - nf_nat_bysource_params); +rhltable_remove (&nf_nat_bysource_table, &ct->nat_bysource, + nf_nat_bysource_params); }static struct nf_ct_ext_type nat_extend__read_mostly = {
@@ -837,13 +845,13 @@ static int __init nf_nat_init(void) {int ret; - ret =rhashtable_init (&nf_nat_bysource_table, &nf_nat_bysource_params); + ret =rhltable_init (&nf_nat_bysource_table, &nf_nat_bysource_params);if (ret)return ret; ret =nf_ct_extend_register (&nat_extend);if (ret <0 ) { -rhashtable_destroy (&nf_nat_bysource_table); +rhltable_destroy (&nf_nat_bysource_table);printk (KERN_ERR "nf_nat_core: Unable to register extension\n" );return ret; }
@@ -867,7 +875,7 @@ static int __init nf_nat_init(void)return 0 ; cleanup_extend: -rhashtable_destroy (&nf_nat_bysource_table); +rhltable_destroy (&nf_nat_bysource_table);nf_ct_extend_unregister (&nat_extend);return ret; }
@@ -886,7 +894,7 @@ static void __exit nf_nat_cleanup(void)for (i =0 ; i <NFPROTO_NUMPROTO ; i++)kfree (nf_nat_l4protos[i]); -rhashtable_destroy (&nf_nat_bysource_table); +rhltable_destroy (&nf_nat_bysource_table); }MODULE_LICENSE ("GPL" );
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 7/11 netfilter: nf_tables: fix inconsistent element expiration calculation
In reply to Pablo Neira AyusoFrom: "Anders K. Pedersen" <[email protected]>
As Liping Zhang reports, after commit a8b1e36d0d1d ("netfilter: nft_dynset:
fix element timeout for HZ != 1000"), priv->timeout was stored in jiffies, while set->timeout was stored in milliseconds. This is inconsistent and incorrect.
Firstly, we already call msecs_to_jiffies in nft_set_elem_init, so priv->timeout will be converted to jiffies twice.
Secondly, if the user did not specify the NFTA_DYNSET_TIMEOUT attr, set->timeout will be used, but we forget to call msecs_to_jiffies when do update elements.
Fix this by using jiffies internally for traditional sets and doing the conversions to/from msec when interacting with userspace - as dynset already does.
This is preferable to doing the conversions, when elements are inserted or updated, because this can happen very frequently on busy dynsets.
--- include/net/netfilter/nf_tables.h | 2 +- net/netfilter/nf_tables_api.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
@@ -313,7 +313,7 @@ void nft_unregister_set(struct nft_set_ops *ops);* @size: maximum set size * @nelems: number of elements * @ndeact: number of deactivated elements queued for removal -* @timeout: default timeout value in msecs +* @timeout: default timeout value in jiffies * @gc_int: garbage collection interval in msecs * @policy: set parameterization (see enum nft_set_policies) * @udlen: user data length
net/netfilter/nf_tables_api.c +9 -5
@@ -2570,7 +2570,8 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx, }if (set->timeout && -nla_put_be64 (skb,NFTA_SET_TIMEOUT ,cpu_to_be64 (set->timeout), +nla_put_be64 (skb,NFTA_SET_TIMEOUT , +cpu_to_be64 (jiffies_to_msecs (set->timeout)),NFTA_SET_PAD )) goto nla_put_failure; if (set->gc_int &&
@@ -2859,7 +2860,8 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,if (nla[NFTA_SET_TIMEOUT ] !=NULL ) {if (!(flags &NFT_SET_TIMEOUT ))return -EINVAL ; - timeout =be64_to_cpu (nla_get_be64 (nla[NFTA_SET_TIMEOUT ])); + timeout =msecs_to_jiffies (be64_to_cpu (nla_get_be64 ( + nla[NFTA_SET_TIMEOUT ]))); } gc_int =0 ;if (nla[NFTA_SET_GC_INTERVAL ] !=NULL ) {
@@ -3178,7 +3180,8 @@ static int nf_tables_fill_setelem(struct sk_buff *skb,if (nft_set_ext_exists (ext,NFT_SET_EXT_TIMEOUT ) &&nla_put_be64 (skb,NFTA_SET_ELEM_TIMEOUT , -cpu_to_be64 (*nft_set_ext_timeout (ext)), +cpu_to_be64 (jiffies_to_msecs ( + *nft_set_ext_timeout (ext))),NFTA_SET_ELEM_PAD )) goto nla_put_failure;
@@ -3447,7 +3450,7 @@ void *nft_set_elem_init(const struct nft_set *set,memcpy (nft_set_ext_data (ext), data, set->dlen);if (nft_set_ext_exists (ext,NFT_SET_EXT_EXPIRATION )) *nft_set_ext_expiration (ext) = - jiffies +msecs_to_jiffies (timeout); + jiffies + timeout;if (nft_set_ext_exists (ext,NFT_SET_EXT_TIMEOUT )) *nft_set_ext_timeout (ext) = timeout;
@@ -3535,7 +3538,8 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,if (nla[NFTA_SET_ELEM_TIMEOUT ] !=NULL ) {if (!(set->flags &NFT_SET_TIMEOUT ))return -EINVAL ; - timeout =be64_to_cpu (nla_get_be64 (nla[NFTA_SET_ELEM_TIMEOUT ])); + timeout =msecs_to_jiffies (be64_to_cpu (nla_get_be64 ( + nla[NFTA_SET_ELEM_TIMEOUT ]))); }else if (set->flags &NFT_SET_TIMEOUT ) { timeout = set->timeout; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 8/11 netfilter: nft_range: add the missing NULL pointer check
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
Otherwise, kernel panic will happen if the user does not specify the related attributes.
--- net/netfilter/nft_range.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/nft_range.c +6 -0
@@ -59,6 +59,12 @@ static int nft_range_init(const struct nft_ctx *ctx, const struct nft_expr *exprint err;u32 op; +if (!tb[NFTA_RANGE_SREG ] || + !tb[NFTA_RANGE_OP ] || + !tb[NFTA_RANGE_FROM_DATA ] || + !tb[NFTA_RANGE_TO_DATA ]) +return -EINVAL ; + err =nft_data_init (NULL , &priv->data_from,sizeof (priv->data_from), &desc_from, tb[NFTA_RANGE_FROM_DATA ]);if (err <0 )
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 9/11 netfilter: nat: fix crash when conntrack entry is re-used
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Stas Nichiporovich reports oops in nf_nat_bysource_cmp(), trying to access nf_conn struct at address 0xffffffffffffff50.
This is the result of fetching a null rhash list (struct embedded at offset 176; 0 - 176 gets us ...fff50).
The problem is that conntrack entries are allocated from a SLAB_DESTROY_BY_RCU cache, i.e. entries can be free'd and reused on another cpu while nf nat bysource hash access the same conntrack entry.
Freeing is fine (we hold rcu read lock); zeroing rhlist_head isn't.
-> Move the rhlist struct outside of the memset()-inited area.
--- include/net/netfilter/nf_conntrack.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/net/netfilter/nf_conntrack.h +3 -3
@@ -100,6 +100,9 @@ struct nf_conn {possible_net_t ct_net; +#if IS_ENABLED (CONFIG_NF_NAT ) +struct rhlist_head nat_bysource; +#endif /* all members below initialized via memset */ u8 __nfct_init_offset[0 ];
@@ -117,9 +120,6 @@ struct nf_conn {/* Extensions */ struct nf_ct_ext *ext; -#if IS_ENABLED (CONFIG_NF_NAT ) -struct rhlist_head nat_bysource; -#endif /* Storage reserved for other modules, must be the last member */ union nf_conntrack_proto proto; };
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 10/11 netfilter: ipv6: nf_defrag: drop mangled skb on ream error
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Dmitry Vyukov reported GPF in network stack that Andrey traced down to negative nh offset in nf_ct_frag6_queue().
Problem is that all network headers before fragment header are pulled. Normal ipv6 reassembly will drop the skb when errors occur further down the line.
netfilter doesn't do this, and instead passed the original fragment along. That was also fine back when netfilter ipv6 defrag worked with cloned fragments, as the original, pristine fragment was passed on.
So we either have to undo the pull op, or discard such fragments. Since they're malformed after all (e.g. overlapping fragment) it seems preferrable to just drop them.
Same for temporary errors -- it doesn't make sense to accept (and perhaps forward!) only some fragments of same datagram.
--- net/ipv6/netfilter/nf_conntrack_reasm.c | 4 ++-- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
net/ipv6/netfilter/nf_conntrack_reasm.c +2 -2
@@ -576,11 +576,11 @@ int nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 user)/* Jumbo payload inhibits frag. header */ if (ipv6_hdr (skb)->payload_len ==0 ) {pr_debug ("payload len = 0\n" ); -return -EINVAL ; +return 0 ; }if (find_prev_fhdr (skb, &prevhdr, &nhoff, &fhoff) <0 ) -return -EINVAL ; +return 0 ;if (!pskb_may_pull (skb, fhoff +sizeof (*fhdr)))return -ENOMEM ;
net/ipv6/netfilter/nf_defrag_ipv6_hooks.c +1 -1
@@ -69,7 +69,7 @@ static unsigned int ipv6_defrag(void *priv,if (err == -EINPROGRESS )return NF_STOLEN ; -return NF_ACCEPT ; +return err ==0 ?NF_ACCEPT :NF_DROP ; }static struct nf_hook_ops ipv6_defrag_ops[] = {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 11/11 netfilter: arp_tables: fix invoking 32bit "iptable -P INPUT ACCEPT" failed in 64bit kernel
In reply to Pablo Neira AyusoFrom: Hongxu Jia <[email protected]>
Since 09d9686047db ("netfilter: x_tables: do compat validation via translate_table"), it used compatr structure to assign newinfo structure. In translate_compat_table of ip_tables.c and ip6_tables.c, it used compatr->hook_entry to replace info->hook_entry and compatr->underflow to replace info->underflow, but not do the same replacement in arp_tables.c.
It caused invoking 32-bit "arptbale -P INPUT ACCEPT" failed in 64bit kernel.
--------------------------------------
root@qemux86-64:~# arptables -P INPUT ACCEPT root@qemux86-64:~# arptables -P INPUT ACCEPT ERROR: Policy for `INPUT' offset 448 != underflow 0 arptables: Incompatible with this kernel --------------------------------------
--- net/ipv4/netfilter/arp_tables.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/arp_tables.c +2 -2
@@ -1201,8 +1201,8 @@ static int translate_compat_table(struct xt_table_info **pinfo, newinfo->number = compatr->num_entries;for (i =0 ; i <NF_ARP_NUMHOOKS ; i++) { - newinfo->hook_entry[i] = info->hook_entry[i]; - newinfo->underflow[i] = info->underflow[i]; + newinfo->hook_entry[i] = compatr->hook_entry[i]; + newinfo->underflow[i] = compatr->underflow[i]; } entry1 = newinfo->entries; pos = entry1;
Signature · 1 line
2.1.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 30 Nov 2016 22:57:14 +0100
Quoted 1 line
This is a large batch of Netfilter fixes for net, they are:
...
Quoted 8 lines
I know is late but I think these are important, specifically the NAT bits, as they are mostly addressing fallout from recent changes. I also read there are chances to have -rc8, if that is the case, that would also give us a bit more time to test this.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks Pablo.