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:
* Fix nf_trace in nftables if XT_TRACE=n, from Florian Westphal.
* Don't use the fast payload operation in nf_tables if the length is not power of 2 or it is not aligned, from Nikolay Aleksandrov.
* Fix missing break statement the inet flavour of nft_reject, which results in evaluating IPv4 packets with the IPv6 evaluation routine, from Patrick McHardy.
* Fix wrong kconfig symbol in nft_meta to match the routing realm, from Paul Bolle.
* Allocate the NAT null binding when creating new conntracks via ctnetlink to avoid that several packets race at initializing the the conntrack NAT extension, original patch from Florian Westphal, revisited version from me.
* Fix DNAT handling in the snmp NAT helper, the same handling was being done for SNAT and DNAT and 2.4 already contains that fix, from Francois-Xavier Le Bail.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master
Thanks!
----------------------------------------------------------------
The following changes since commit 20e7c4e80dcd01dad5e6c8b32455228b8fe9c619:
6lowpan: fix lockdep splats (2014-02-10 17:51:29 -0800)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master
for you to fetch changes up to 0eba801b64cc8284d9024c7ece30415a2b981a72:
netfilter: ctnetlink: force null nat binding on insert (2014-02-18 00:13:51 +0100)
----------------------------------------------------------------
FX Le Bail (1):
netfilter: nf_nat_snmp_basic: fix duplicates in if/else branches
Florian Westphal (1):
netfilter: nf_tables: fix nf_trace always-on with XT_TRACE=n
Nikolay Aleksandrov (1):
netfilter: nf_tables: check if payload length is a power of 2
Pablo Neira Ayuso (1):
netfilter: ctnetlink: force null nat binding on insert
Patrick McHardy (1):
netfilter: nft_reject_inet: fix unintended fall-through in switch-statatement
Paul Bolle (1):
netfilter: nft_meta: fix typo "CONFIG_NET_CLS_ROUTE"
include/linux/skbuff.h | 5 ++- net/core/skbuff.c | 3 -- net/ipv4/ip_output.c | 3 -- net/ipv4/netfilter/nf_nat_snmp_basic.c | 4 +-- net/ipv6/ip6_output.c | 3 -- net/netfilter/nf_conntrack_netlink.c | 35 ++++++++------------ net/netfilter/nf_nat_core.c | 56 ++++++++++++++++++++------------ net/netfilter/nft_meta.c | 4 +-- net/netfilter/nft_payload.c | 3 +- net/netfilter/nft_reject_inet.c | 4 +-- 10 files changed, 61 insertions(+), 59 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/6 netfilter: nft_reject_inet: fix unintended fall-through in switch-statatement
From: Patrick McHardy <[email protected]>
For IPv4 packets, we call both IPv4 and IPv6 reject.
--- net/netfilter/nft_reject_inet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_reject_inet.c +2 -2
@@ -21,9 +21,9 @@ static void nft_reject_inet_eval(const struct nft_expr *expr, {switch (pkt->ops->pf) {case NFPROTO_IPV4 : -nft_reject_ipv4_eval (expr, data, pkt); +return nft_reject_ipv4_eval (expr, data, pkt);case NFPROTO_IPV6 : -nft_reject_ipv6_eval (expr, data, pkt); +return nft_reject_ipv6_eval (expr, data, pkt); } }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/6 netfilter: nft_meta: fix typo "CONFIG_NET_CLS_ROUTE"
In reply to Pablo Neira AyusoFrom: Paul Bolle <[email protected]>
There are two checks for CONFIG_NET_CLS_ROUTE, but the corresponding Kconfig symbol was dropped in v2.6.39. Since the code guards access to dst_entry.tclassid it seems CONFIG_IP_ROUTE_CLASSID should be used instead.
--- net/netfilter/nft_meta.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_meta.c +2 -2
@@ -116,7 +116,7 @@ static void nft_meta_get_eval(const struct nft_expr *expr, skb->sk->sk_socket->file->f_cred->fsgid);read_unlock_bh (&skb->sk->sk_callback_lock);break ; -#ifdef CONFIG_NET_CLS_ROUTE +#ifdef CONFIG_IP_ROUTE_CLASSID case NFT_META_RTCLASSID : {const struct dst_entry *dst =skb_dst (skb);
@@ -199,7 +199,7 @@ static int nft_meta_init_validate_get(uint32_t key)case NFT_META_OIFTYPE :case NFT_META_SKUID :case NFT_META_SKGID : -#ifdef CONFIG_NET_CLS_ROUTE +#ifdef CONFIG_IP_ROUTE_CLASSID case NFT_META_RTCLASSID :#endif #ifdef CONFIG_NETWORK_SECMARK
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/6 netfilter: nf_nat_snmp_basic: fix duplicates in if/else branches
In reply to Pablo Neira AyusoFrom: FX Le Bail <[email protected]>
The solution was found by Patrick in 2.4 kernel sources.
--- net/ipv4/netfilter/nf_nat_snmp_basic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nf_nat_snmp_basic.c +2 -2
@@ -1198,8 +1198,8 @@ static int snmp_translate(struct nf_conn *ct, map.to =NOCT1 (&ct->tuplehash[!dir].tuple.dst.u3.ip); }else {/* DNAT replies */ - map.from =NOCT1 (&ct->tuplehash[dir].tuple.src.u3.ip); - map.to =NOCT1 (&ct->tuplehash[!dir].tuple.dst.u3.ip); + map.from =NOCT1 (&ct->tuplehash[!dir].tuple.src.u3.ip); + map.to =NOCT1 (&ct->tuplehash[dir].tuple.dst.u3.ip); }if (map.from == map.to)
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/6 netfilter: nf_tables: fix nf_trace always-on with XT_TRACE=n
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
When using nftables with CONFIG_NETFILTER_XT_TARGET_TRACE=n, we get lots of "TRACE: filter:output:policy:1 IN=..." warnings as several places will leave skb->nf_trace uninitialised.
Unlike iptables tracing functionality is not conditional in nftables, so always copy/zero nf_trace setting when nftables is enabled.
Move this into __nf_copy() helper.
--- include/linux/skbuff.h | 5 ++++- net/core/skbuff.c | 3 --- net/ipv4/ip_output.c | 3 --- net/ipv6/ip6_output.c | 3 --- 4 files changed, 4 insertions(+), 10 deletions(-)
include/linux/skbuff.h +4 -1
@@ -2725,7 +2725,7 @@ static inline void nf_reset(struct sk_buff *skb)static inline void nf_reset_trace (struct sk_buff *skb) { -#if IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TRACE ) +#if IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TRACE ) || defined(CONFIG_NF_TABLES ) skb->nf_trace =0 ;#endif }
@@ -2742,6 +2742,9 @@ static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src) dst->nf_bridge = src->nf_bridge;nf_bridge_get (src->nf_bridge);#endif +#if IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TRACE ) || defined(CONFIG_NF_TABLES ) + dst->nf_trace = src->nf_trace; +#endif }static inline void nf_copy (struct sk_buff *dst,const struct sk_buff *src)
net/core/skbuff.c +0 -3
@@ -707,9 +707,6 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old) new->mark = old->mark; new->skb_iif = old->skb_iif;__nf_copy (new, old); -#if IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TRACE ) - new->nf_trace = old->nf_trace; -#endif #ifdef CONFIG_NET_SCHED new->tc_index = old->tc_index;#ifdef CONFIG_NET_CLS_ACT
net/ipv4/ip_output.c +0 -3
@@ -422,9 +422,6 @@ static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from) to->tc_index = from->tc_index;#endif nf_copy (to, from); -#if IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TRACE ) - to->nf_trace = from->nf_trace; -#endif #if defined(CONFIG_IP_VS ) || defined(CONFIG_IP_VS_MODULE ) to->ipvs_property = from->ipvs_property;#endif
net/ipv6/ip6_output.c +0 -3
@@ -517,9 +517,6 @@ static void ip6_copy_metadata(struct sk_buff *to, struct sk_buff *from) to->tc_index = from->tc_index;#endif nf_copy (to, from); -#if IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TRACE ) - to->nf_trace = from->nf_trace; -#endif skb_copy_secmark (to, from); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/6 netfilter: nf_tables: check if payload length is a power of 2
In reply to Pablo Neira AyusoFrom: Nikolay Aleksandrov <[email protected]>
Add a check if payload's length is a power of 2 when selecting ops. The fast ops were meant for well aligned loads, also this fixes a small bug when using a length of 3 with some offsets which causes only 1 byte to be loaded because the fast ops are chosen.
--- net/netfilter/nft_payload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_payload.c +2 -1
@@ -135,7 +135,8 @@ nft_payload_select_ops(const struct nft_ctx *ctx, if (len == 0 || len > FIELD_SIZEOF(struct nft_data, data))return ERR_PTR (-EINVAL ); -if (len <=4 &&IS_ALIGNED (offset, len) && base !=NFT_PAYLOAD_LL_HEADER ) +if (len <=4 &&is_power_of_2 (len) &&IS_ALIGNED (offset, len) && + base !=NFT_PAYLOAD_LL_HEADER )return &nft_payload_fast_ops;else return &nft_payload_ops;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/6 netfilter: ctnetlink: force null nat binding on insert
In reply to Pablo Neira AyusoQuoting Andrey Vagin:
When a conntrack is created by kernel, it is initialized (sets IPS_{DST,SRC}_NAT_DONE_BIT bits in nf_nat_setup_info) and only then it is added in hashes (__nf_conntrack_hash_insert), so one conntract can't be initialized from a few threads concurrently.
ctnetlink can add an uninitialized conntrack (w/o IPS_{DST,SRC}_NAT_DONE_BIT) in hashes, then a few threads can look up this conntrack and start initialize it concurrently. It's dangerous, because BUG can be triggered from nf_nat_setup_info.
Fix this race by always setting up nat, even if no CTA_NAT_ attribute was requested before inserting the ct into the hash table. In absence of CTA_NAT_ attribute, a null binding is created.
This alters current behaviour: Before this patch, the first packet matching the newly injected conntrack would be run through the nat table since nf_nat_initialized() returns false. IOW, this forces ctnetlink users to specify the desired nat transformation on ct creation time.
Thanks for Florian Westphal, this patch is based on his original patch to address this problem, including this patch description.
--- net/netfilter/nf_conntrack_netlink.c | 35 +++++++++------------ net/netfilter/nf_nat_core.c | 56 +++++++++++++++++++++------------- 2 files changed, 49 insertions(+), 42 deletions(-)
net/netfilter/nf_conntrack_netlink.c +14 -21
@@ -1310,27 +1310,22 @@ ctnetlink_change_status(struct nf_conn *ct, const struct nlattr * const cda[]) }static int -ctnetlink_change_nat (struct nf_conn *ct,const struct nlattr *const cda[]) +ctnetlink_setup_nat (struct nf_conn *ct,const struct nlattr *const cda[]) {#ifdef CONFIG_NF_NAT_NEEDED int ret; -if (cda[CTA_NAT_DST ]) { - ret =ctnetlink_parse_nat_setup (ct, -NF_NAT_MANIP_DST , - cda[CTA_NAT_DST ]); -if (ret <0 ) -return ret; - } -if (cda[CTA_NAT_SRC ]) { - ret =ctnetlink_parse_nat_setup (ct, -NF_NAT_MANIP_SRC , - cda[CTA_NAT_SRC ]); -if (ret <0 ) -return ret; - } -return 0 ; + ret =ctnetlink_parse_nat_setup (ct,NF_NAT_MANIP_DST , + cda[CTA_NAT_DST ]); +if (ret <0 ) +return ret; + + ret =ctnetlink_parse_nat_setup (ct,NF_NAT_MANIP_SRC , + cda[CTA_NAT_SRC ]); +return ret;#else +if (!cda[CTA_NAT_DST ] && !cda[CTA_NAT_SRC ]) +return 0 ;return -EOPNOTSUPP ;#endif }
@@ -1659,11 +1654,9 @@ ctnetlink_create_conntrack(struct net *net, u16 zone, goto err2; } -if (cda[CTA_NAT_SRC ] || cda[CTA_NAT_DST ]) { - err =ctnetlink_change_nat (ct, cda); -if (err <0 ) - goto err2; - } + err =ctnetlink_setup_nat (ct, cda); +if (err <0 ) + goto err2;nf_ct_acct_ext_add (ct,GFP_ATOMIC );nf_ct_tstamp_ext_add (ct,GFP_ATOMIC );
net/netfilter/nf_nat_core.c +35 -21
104 lines not on this page · raw message
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 19 Feb 2014 12:41:36 +0100
Quoted 20 lines
The following patchset contains Netfilter fixes for your net tree, they are:
* Fix
nf_tracein nftables if XT_TRACE=n, from Florian Westphal.* Don't use the fast payload operation in
nf_tablesif the length is not power of 2 or it is not aligned, from Nikolay Aleksandrov.* Fix missing break statement the inet flavour of
nft_reject, which results in evaluating IPv4 packets with the IPv6 evaluation routine, from Patrick McHardy.* Fix wrong kconfig symbol in
nft_metato match the routing realm, from Paul Bolle.* Allocate the NAT null binding when creating new conntracks via ctnetlink to avoid that several packets race at initializing the the conntrack NAT extension, original patch from Florian Westphal, revisited version from me.
Quoted 7 lines
* Fix DNAT handling in the snmp NAT helper, the same handling was being done for SNAT and DNAT and 2.4 already contains that fix, from Francois-Xavier Le Bail.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.gitmaster
Pulled, thanks a lot Pablo.