netfilter updates for net (3.4) tree
Subsystems (3)
[email protected]
maintainercover netfilter updates for net (3.4) tree
From: Pablo Neira Ayuso <[email protected]>
Hi David,
The following are five fixes for xt_LOG and the cttimeout infrastructure that got into your tree in the previous development cycle. This contains:
* One fix for missing symbol in xt_LOG reported by Randy Dunlap.
* Fix module dependency between cttimeout and nf_conntrack_proto_* friends from me. Now, we make sure that protocol trackers modules cannot be unloaded if there's any cttimeout object refering to them.
* Fix missing rcu_read_lock section in xt_CT while dereferencing a RCU pointer.
* Fix the assignation of a custom timeout policy for the generic protocol tracker.
* Fix possible inconsistencies in the application of the cttimeout policy by permanently attaching it to the conntrack entry. Before this patch, the timeout policy was attached per packet which may result in applying the timeout policy only in one traffic direction.
You can pull this changes from:
git://1984.lsi.us.es/net master
Thanks!
Pablo Neira Ayuso (5):
netfilter: xt_LOG: use CONFIG_IP6_NF_IPTABLES instead of CONFIG_IPV6
netfilter: cttimeout: fix dependency with l4protocol conntrack module
netfilter: xt_CT: missing rcu_read_lock section in timeout assignment
netfilter: xt_CT: fix assignation of the generic protocol tracker
netfilter: nf_conntrack: permanently attach timeout policy to conntrack
include/net/netfilter/nf_conntrack_l4proto.h | 4 ++ include/net/netfilter/nf_conntrack_timeout.h | 2 +- net/netfilter/nf_conntrack_core.c | 39 ++++++++++++---------- net/netfilter/nf_conntrack_proto.c | 21 ++++++++++++ net/netfilter/nfnetlink_cttimeout.c | 45 +++++++++++++------------ net/netfilter/xt_CT.c | 31 +++++++++++++---- net/netfilter/xt_LOG.c | 12 +++--- 7 files changed, 100 insertions(+), 54 deletions(-)
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 1/5 netfilter: xt_LOG: use CONFIG_IP6_NF_IPTABLES instead of CONFIG_IPV6
From: Pablo Neira Ayuso <[email protected]>
This fixes the following linking error:
xt_LOG.c:(.text+0x789b1): undefined reference to `ip6t_ext_hdr'
ifdefs have to use CONFIG_IP6_NF_IPTABLES instead of CONFIG_IPV6.
--- net/netfilter/xt_LOG.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
net/netfilter/xt_LOG.c +6 -6
@@ -480,7 +480,7 @@ ipt_log_packet(u_int8_t pf,sb_close (m); } -#if IS_ENABLED (CONFIG_IPV6 ) +#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES )/* One level of recursion won't kill us */ static void dump_ipv6_packet(struct sbuff *m, const struct nf_loginfo *info,
@@ -824,7 +824,7 @@ log_tg(struct sk_buff *skb, const struct xt_action_param *par)if (par->family ==NFPROTO_IPV4 )ipt_log_packet (NFPROTO_IPV4 , par->hooknum, skb, par->in, par->out, &li, loginfo->prefix); -#if IS_ENABLED (CONFIG_IPV6 ) +#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES ) else if (par->family == NFPROTO_IPV6) ip6t_log_packet(NFPROTO_IPV6, par->hooknum, skb, par->in, par->out, &li, loginfo->prefix);
@@ -864,7 +864,7 @@ static struct xt_target log_tg_regs[] __read_mostly = { .checkentry = log_tg_check, .me = THIS_MODULE, }, -#if IS_ENABLED (CONFIG_IPV6 ) +#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES ) { .name = "LOG", .family = NFPROTO_IPV6,
@@ -882,7 +882,7 @@ static struct nf_logger ipt_log_logger __read_mostly = { .me = THIS_MODULE, }; -#if IS_ENABLED (CONFIG_IPV6 ) +#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES )static struct nf_logger ip6t_log_logger__read_mostly = { .name ="ip6t_LOG" , .logfn = &ip6t_log_packet,
@@ -899,7 +899,7 @@ static int __init log_tg_init(void)return ret;nf_log_register (NFPROTO_IPV4 , &ipt_log_logger); -#if IS_ENABLED (CONFIG_IPV6 ) +#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES )nf_log_register (NFPROTO_IPV6 , &ip6t_log_logger);#endif return 0 ;
@@ -908,7 +908,7 @@ static int __init log_tg_init(void) static void __exit log_tg_exit(void) {nf_log_unregister (&ipt_log_logger); -#if IS_ENABLED (CONFIG_IPV6 ) +#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES )nf_log_unregister (&ip6t_log_logger);#endif xt_unregister_targets (log_tg_regs,ARRAY_SIZE (log_tg_regs));
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 2/5 netfilter: cttimeout: fix dependency with l4protocol conntrack module
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch introduces nf_conntrack_l4proto_find_get() and nf_conntrack_l4proto_put() to fix module dependencies between timeout objects and l4-protocol conntrack modules.
Thus, we make sure that the module cannot be removed if it is used by any of the cttimeout objects.
--- include/net/netfilter/nf_conntrack_l4proto.h | 4 ++ include/net/netfilter/nf_conntrack_timeout.h | 2 +- net/netfilter/nf_conntrack_proto.c | 21 ++++++++++++ net/netfilter/nfnetlink_cttimeout.c | 45 +++++++++++++------------ net/netfilter/xt_CT.c | 6 ++- 5 files changed, 53 insertions(+), 25 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +4 -0
@@ -118,6 +118,10 @@ extern struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;extern struct nf_conntrack_l4proto *__nf_ct_l4proto_find (u_int16_t l3proto,u_int8_t l4proto); +extern struct nf_conntrack_l4proto * +nf_ct_l4proto_find_get (u_int16_t l3proto,u_int8_t l4proto); +extern void nf_ct_l4proto_put (struct nf_conntrack_l4proto *p); +/* Protocol registration. */ extern int nf_conntrack_l4proto_register (struct nf_conntrack_l4proto *proto);extern void nf_conntrack_l4proto_unregister (struct nf_conntrack_l4proto *proto);
include/net/netfilter/nf_conntrack_timeout.h +1 -1
@@ -15,7 +15,7 @@ struct ctnl_timeout {atomic_t refcnt;char name[CTNL_TIMEOUT_NAME_MAX ];__u16 l3num; -__u8 l4num; +struct nf_conntrack_l4proto *l4proto;char data[0 ]; };
net/netfilter/nf_conntrack_proto.c +21 -0
@@ -127,6 +127,27 @@ void nf_ct_l3proto_module_put(unsigned short l3proto) }EXPORT_SYMBOL_GPL (nf_ct_l3proto_module_put); +struct nf_conntrack_l4proto * +nf_ct_l4proto_find_get (u_int16_t l3num,u_int8_t l4num) +{ +struct nf_conntrack_l4proto *p; + +rcu_read_lock (); + p =__nf_ct_l4proto_find (l3num, l4num); +if (!try_module_get (p->me)) + p = &nf_conntrack_l4proto_generic; +rcu_read_unlock (); + +return p; +} +EXPORT_SYMBOL_GPL (nf_ct_l4proto_find_get); + +void nf_ct_l4proto_put (struct nf_conntrack_l4proto *p) +{ +module_put (p->me); +} +EXPORT_SYMBOL_GPL (nf_ct_l4proto_put); +static int kill_l3proto (struct nf_conn *i,void *data) {return nf_ct_l3num (i) == ((struct nf_conntrack_l3proto *)data)->l3proto;
net/netfilter/nfnetlink_cttimeout.c +23 -22
113 lines not on this page · raw message
net/netfilter/xt_CT.c +4 -2
@@ -16,6 +16,7 @@#include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack_helper.h> #include <net/netfilter/nf_conntrack_ecache.h> +#include <net/netfilter/nf_conntrack_l4proto.h> #include <net/netfilter/nf_conntrack_timeout.h> #include <net/netfilter/nf_conntrack_zones.h>
@@ -243,11 +244,12 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par) info->timeout, timeout->l3num); goto err3; } -if (timeout->l4num != e->ip.proto) { +if (timeout->l4proto->l4proto != e->ip.proto) { ret = -EINVAL ;pr_info ("Timeout policy `%s' can only be " "used by L4 protocol number %d\n" , - info->timeout, timeout->l4num); + info->timeout, + timeout->l4proto->l4proto); goto err3; } timeout_ext = nf_ct_timeout_ext_add(ct, timeout,
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 3/5 netfilter: xt_CT: missing rcu_read_lock section in timeout assignment
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
Fix a dereference to pointer without rcu_read_lock held.
--- net/netfilter/xt_CT.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-)
net/netfilter/xt_CT.c +12 -6
@@ -218,6 +218,7 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)struct ctnl_timeout *timeout;struct nf_conn_timeout *timeout_ext; +rcu_read_lock (); timeout_find_get =rcu_dereference (nf_ct_timeout_find_get_hook);
@@ -228,21 +229,21 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par) ret = -EINVAL ;pr_info ("You cannot use inversion on " "L4 protocol\n" ); - goto err3; + goto err4; } timeout =timeout_find_get (info->timeout);if (timeout ==NULL ) { ret = -ENOENT ;pr_info ("No such timeout policy \"%s\"\n" , info->timeout); - goto err3; + goto err4; }if (timeout->l3num != par->family) { ret = -EINVAL ;pr_info ("Timeout policy `%s' can only be " "used by L3 protocol number %d\n" , info->timeout, timeout->l3num); - goto err3; + goto err4; }if (timeout->l4proto->l4proto != e->ip.proto) { ret = -EINVAL ;
@@ -250,19 +251,20 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)"used by L4 protocol number %d\n" , info->timeout, timeout->l4proto->l4proto); - goto err3; + goto err4; } timeout_ext =nf_ct_timeout_ext_add (ct, timeout,GFP_KERNEL );if (timeout_ext ==NULL ) { ret = -ENOMEM ; - goto err3; + goto err4; } }else { ret = -ENOENT ;pr_info ("Timeout policy base is empty\n" ); - goto err3; + goto err4; } +rcu_read_unlock (); }#endif
@@ -272,6 +274,8 @@ out: info->ct = ct;return 0 ; +err4: +rcu_read_unlock (); err3:nf_conntrack_free (ct); err2:
@@ -313,6 +317,7 @@ static void xt_ct_tg_destroy_v1(const struct xt_tgdtor_param *par)nf_ct_l3proto_module_put (par->family);#ifdef CONFIG_NF_CONNTRACK_TIMEOUT +rcu_read_lock (); timeout_put =rcu_dereference (nf_ct_timeout_put_hook);if (timeout_put) {
@@ -320,6 +325,7 @@ static void xt_ct_tg_destroy_v1(const struct xt_tgdtor_param *par)if (timeout_ext) timeout_put(timeout_ext->timeout); } +rcu_read_unlock ();#endif }nf_ct_put (info->ct);
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 4/5 netfilter: xt_CT: fix assignation of the generic protocol tracker
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
iptables -p all' uses 0 to match all protocols, while the conntrack subsystem uses 255. We still need -p all' to attach the custom timeout policies for the generic protocol tracker.
Moreover, we may use `iptables -p sctp' while the SCTP tracker is not loaded. In that case, we have to default on the generic protocol tracker.
Another possibility is `iptables -p ip' that should be supported as well. This patch makes sure we validate all possible scenarios.
--- net/netfilter/xt_CT.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
net/netfilter/xt_CT.c +8 -1
@@ -14,6 +14,7 @@#include <linux/netfilter/x_tables.h> #include <linux/netfilter/xt_CT.h> #include <net/netfilter/nf_conntrack.h> +#include <net/netfilter/nf_conntrack_l4proto.h> #include <net/netfilter/nf_conntrack_helper.h> #include <net/netfilter/nf_conntrack_ecache.h> #include <net/netfilter/nf_conntrack_l4proto.h>
@@ -224,6 +225,7 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)if (timeout_find_get) {const struct ipt_entry *e = par->entryinfo; +struct nf_conntrack_l4proto *l4proto;if (e->ip.invflags &IPT_INV_PROTO ) { ret = -EINVAL ;
@@ -245,7 +247,12 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par) info->timeout, timeout->l3num); goto err4; } -if (timeout->l4proto->l4proto != e->ip.proto) { +/* Make sure the timeout policy matches any existing +* protocol tracker, otherwise default to generic. +*/ + l4proto =__nf_ct_l4proto_find (par->family, + e->ip.proto); +if (timeout->l4proto->l4proto != l4proto->l4proto) { ret = -EINVAL ; pr_info("Timeout policy `%s' can only be " "used by L4 protocol number %d\n",
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 5/5 netfilter: nf_conntrack: permanently attach timeout policy to conntrack
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
We need to permanently attach the timeout policy to the conntrack, otherwise we may apply the custom timeout policy inconsistently.
Without this patch, the following example:
nfct timeout add test inet icmp timeout 100
iptables -I PREROUTING -t raw -p icmp -s 1.1.1.1 -j CT --timeout test
Will only apply the custom timeout policy to outgoing packets from 1.1.1.1, but not to reply packets from 2.2.2.2 going to 1.1.1.1.
To fix this issue, this patch modifies the current logic to attach the timeout policy when the first packet is seen (which is when the conntrack entry is created). Then, we keep using the attached timeout policy until the conntrack entry is destroyed.
--- net/netfilter/nf_conntrack_core.c | 39 ++++++++++++++++++++---------------- 1 files changed, 22 insertions(+), 17 deletions(-)
net/netfilter/nf_conntrack_core.c +22 -17
@@ -768,8 +768,7 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,struct nf_conntrack_l3proto *l3proto, struct nf_conntrack_l4proto *l4proto, struct sk_buff *skb, - unsigned int dataoff, u32 hash, - unsigned int *timeouts) + unsigned int dataoff, u32 hash) { struct nf_conn *ct;struct nf_conn_help *help;
@@ -777,6 +776,8 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,struct nf_conntrack_ecache *ecache;struct nf_conntrack_expect *exp;u16 zone = tmpl ?nf_ct_zone (tmpl) :NF_CT_DEFAULT_ZONE ; +struct nf_conn_timeout *timeout_ext; +unsigned int *timeouts;if (!nf_ct_invert_tuple (&repl_tuple, tuple, l3proto, l4proto)) {pr_debug ("Can't invert tuple.\n" );
@@ -788,12 +789,21 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,if (IS_ERR (ct))return (struct nf_conntrack_tuple_hash *)ct; + timeout_ext = tmpl ?nf_ct_timeout_find (tmpl) :NULL ; +if (timeout_ext) + timeouts =NF_CT_TIMEOUT_EXT_DATA (timeout_ext); +else + timeouts = l4proto->get_timeouts (net); +if (!l4proto->new (ct, skb, dataoff, timeouts)) {nf_conntrack_free (ct);pr_debug ("init conntrack: can't track with proto module\n" );return NULL ; } +if (timeout_ext) +nf_ct_timeout_ext_add (ct, timeout_ext->timeout,GFP_ATOMIC ); +nf_ct_acct_ext_add (ct,GFP_ATOMIC );nf_ct_tstamp_ext_add (ct,GFP_ATOMIC );
@@ -854,8 +864,7 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl,struct nf_conntrack_l3proto *l3proto, struct nf_conntrack_l4proto *l4proto, int *set_reply, - enum ip_conntrack_info *ctinfo, - unsigned int *timeouts) + enum ip_conntrack_info *ctinfo) { struct nf_conntrack_tuple tuple;struct nf_conntrack_tuple_hash *h;
@@ -875,7 +884,7 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl, h =__nf_conntrack_find_get (net, zone, &tuple, hash);if (!h) { h =init_conntrack (net, tmpl, &tuple, l3proto, l4proto, - skb, dataoff, hash, timeouts); + skb, dataoff, hash);if (!h)return NULL ;if (IS_ERR (h))
@@ -964,19 +973,8 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum, goto out; } -/* Decide what timeout policy we want to apply to this flow. */ -if (tmpl) { - timeout_ext =nf_ct_timeout_find (tmpl); -if (timeout_ext) - timeouts =NF_CT_TIMEOUT_EXT_DATA (timeout_ext); -else - timeouts = l4proto->get_timeouts (net); - }else - timeouts = l4proto->get_timeouts (net); - ct =resolve_normal_ct (net, tmpl, skb, dataoff, pf, protonum, - l3proto, l4proto, &set_reply, &ctinfo, - timeouts); + l3proto, l4proto, &set_reply, &ctinfo);if (!ct) {/* Not valid part of a connection */ NF_CT_STAT_INC_ATOMIC (net, invalid);
@@ -993,6 +991,13 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,NF_CT_ASSERT (skb->nfct); +/* Decide what timeout policy we want to apply to this flow. */ + timeout_ext =nf_ct_timeout_find (ct); +if (timeout_ext) + timeouts =NF_CT_TIMEOUT_EXT_DATA (timeout_ext); +else + timeouts = l4proto->get_timeouts (net); + ret = l4proto->packet (ct, skb, dataoff, ctinfo, pf, hooknum, timeouts);if (ret <=0 ) {/* Invalid: inverse of the return code tells
Signature · 1 line
1.7.2.5
David Miller
maintainerFrom: [email protected]
Date: Fri, 23 Mar 2012 10:34:12 +0100
Quoted 19 lines
* One fix for missing symbol in
xt_LOGreported by Randy Dunlap.* Fix module dependency between cttimeout and nf_conntrack_proto_* friends from me. Now, we make sure that protocol trackers modules cannot be unloaded if there's any cttimeout object refering to them.
* Fix missing
rcu_read_locksection inxt_CTwhile dereferencing a RCU pointer.* Fix the assignation of a custom timeout policy for the generic protocol tracker.
* Fix possible inconsistencies in the application of the cttimeout policy by permanently attaching it to the conntrack entry. Before this patch, the timeout policy was attached per packet which may result in applying the timeout policy only in one traffic direction.
Quoted 3 lines
You can pull this changes from:
git://1984.lsi.us.es/netmaster
Pulled, thanks Pablo.