netfilter fixes for 3.6-rc
Subsystems (3)
[email protected]
maintainercover netfilter fixes for 3.6-rc
From: Pablo Neira Ayuso <[email protected]>
Hi David,
The following five patches contain fixes for 3.6-rc, they are:
* Two fixes for message parsing in the SIP conntrack helper, from Patrick McHardy.
* One fix for the SIP helper introduced in the user-space cthelper infrastructure, from Patrick McHardy.
* fix missing appropriate locking while modifying one conntrack entry from the nfqueue integration code, from myself.
* fix possible access to uninitiliazed timer in the nf_conntrack expectation infrastructure, from myself.
You can pull these changes from:
git://1984.lsi.us.es/nf
Thanks!
Pablo Neira Ayuso (2):
netfilter: ctnetlink: fix missing locking while changing conntrack from nfqueue
netfilter: nf_ct_expect: fix possible access to uninitialized timer
Patrick McHardy (3):
netfilter: nf_ct_sip: fix helper name
netfilter: nf_ct_sip: fix IPv6 address parsing
netfilter: nf_nat_sip: fix via header translation with multiple parameters
include/linux/netfilter/nf_conntrack_sip.h | 2 +- net/ipv4/netfilter/nf_nat_sip.c | 9 +-- net/netfilter/nf_conntrack_expect.c | 29 ++------- net/netfilter/nf_conntrack_netlink.c | 7 ++- net/netfilter/nf_conntrack_sip.c | 92 ++++++++++++++++++++++------ 5 files changed, 90 insertions(+), 49 deletions(-)
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 1/5 netfilter: nf_ct_sip: fix helper name
From: Patrick McHardy <[email protected]>
Commit 3a8fc53a (netfilter: nf_ct_helper: allocate 16 bytes for the helper and policy names) introduced a bug in the SIP helper, the helper name is sprinted to the sip_names array instead of instead of into the helper structure. This breaks the helper match and the /proc/net/nf_conntrack_expect output.
--- net/netfilter/nf_conntrack_sip.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/netfilter/nf_conntrack_sip.c +2 -3
@@ -1515,7 +1515,6 @@ static int sip_help_udp(struct sk_buff *skb, unsigned int protoff, }static struct nf_conntrack_helper sip[MAX_PORTS ][4 ]__read_mostly ; -static char sip_names[MAX_PORTS ][4 ][sizeof ("sip-65535" )]__read_mostly ;static const struct nf_conntrack_expect_policy sip_exp_policy[SIP_EXPECT_MAX +1 ] = { [SIP_EXPECT_SIGNALLING ] = {
@@ -1585,9 +1584,9 @@ static int __init nf_conntrack_sip_init(void) sip[i][j].me =THIS_MODULE ;if (ports[i] ==SIP_PORT ) -sprintf (sip_names[i][j],"sip" ); +sprintf (sip[i][j].name,"sip" );else -sprintf (sip_names[i][j],"sip-%u" , i); +sprintf (sip[i][j].name,"sip-%u" , i);pr_debug ("port #%u: %u\n" , i, ports[i]);
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 2/5 netfilter: nf_ct_sip: fix IPv6 address parsing
In reply to [email protected]From: Patrick McHardy <[email protected]>
Within SIP messages IPv6 addresses are enclosed in square brackets in most cases, with the exception of the "received=" header parameter. Currently the helper fails to parse enclosed addresses.
This patch:
- changes the SIP address parsing function to enforce square brackets when required, and accept them when not required but present, as recommended by RFC 5118.
- adds a new SDP address parsing function that never accepts square brackets since SDP doesn't use them.
With these changes, the SIP helper correctly parses all test messages from RFC 5118 (Session Initiation Protocol (SIP) Torture Test Messages for Internet Protocol Version 6 (IPv6)).
--- include/linux/netfilter/nf_conntrack_sip.h | 2 +- net/ipv4/netfilter/nf_nat_sip.c | 4 +- net/netfilter/nf_conntrack_sip.c | 87 ++++++++++++++++++++++------ 3 files changed, 73 insertions(+), 20 deletions(-)
include/linux/netfilter/nf_conntrack_sip.h +1 -1
@@ -164,7 +164,7 @@ extern int ct_sip_parse_address_param(const struct nf_conn *ct, const char *dptr unsigned int dataoff, unsigned int datalen, const char *name, unsigned int *matchoff, unsigned int *matchlen, - union nf_inet_addr *addr); + union nf_inet_addr *addr, bool delim); extern int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr, unsigned int off, unsigned int datalen, const char *name,
net/ipv4/netfilter/nf_nat_sip.c +2 -2
@@ -173,7 +173,7 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, unsigned int dataoff,* the reply. */ if (ct_sip_parse_address_param (ct, *dptr, matchend, *datalen,"maddr=" , &poff, &plen, - &addr) >0 && + &addr, true) >0 && addr.ip == ct->tuplehash[dir].tuple.src.u3.ip && addr.ip != ct->tuplehash[!dir].tuple.dst.u3.ip) { buflen = sprintf(buffer, "%pI4",
@@ -187,7 +187,7 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, unsigned int dataoff,* from which the server received the request. */ if (ct_sip_parse_address_param (ct, *dptr, matchend, *datalen,"received=" , &poff, &plen, - &addr) >0 && + &addr, false) >0 && addr.ip == ct->tuplehash[dir].tuple.dst.u3.ip && addr.ip != ct->tuplehash[!dir].tuple.src.u3.ip) { buflen = sprintf(buffer, "%pI4",
net/netfilter/nf_conntrack_sip.c +70 -17
157 lines not on this page · raw message
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 3/5 netfilter: nf_nat_sip: fix via header translation with multiple parameters
In reply to [email protected]From: Patrick McHardy <[email protected]>
Via-headers are parsed beginning at the first character after the Via-address. When the address is translated first and its length decreases, the offset to start parsing at is incorrect and header parameters might be missed.
Update the offset after translating the Via-address to fix this.
--- net/ipv4/netfilter/nf_nat_sip.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nf_nat_sip.c +3 -2
@@ -148,7 +148,7 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, unsigned int dataoff,if (ct_sip_parse_header_uri (ct, *dptr,NULL , *datalen, hdr,NULL , &matchoff, &matchlen, &addr, &port) >0 ) { -unsigned int matchend, poff, plen, buflen, n; +unsigned int olen, matchend, poff, plen, buflen, n;char buffer[sizeof ("nnn.nnn.nnn.nnn:nnnnn" )];/* We're only interested in headers related to this
@@ -163,11 +163,12 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, unsigned int dataoff, goto next; } + olen = *datalen;if (!map_addr (skb, dataoff, dptr, datalen, matchoff, matchlen, &addr, port))return NF_DROP ; - matchend = matchoff + matchlen; + matchend = matchoff + matchlen + *datalen - olen;/* The maddr= parameter (RFC 2361) specifies where to send * the reply. */
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 4/5 netfilter: ctnetlink: fix missing locking while changing conntrack from nfqueue
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
Since 9cb017665 netfilter: add glue code to integrate nfnetlink_queue and ctnetlink, we can modify the conntrack entry via nfnl_queue. However, the change of the conntrack entry via nfnetlink_queue requires appropriate locking to avoid concurrent updates.
--- net/netfilter/nf_conntrack_netlink.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +6 -1
@@ -1896,10 +1896,15 @@ static int ctnetlink_nfqueue_parse(const struct nlattr *attr, struct nf_conn *ct) { struct nlattr *cda[CTA_MAX+1]; +int ret;nla_parse_nested (cda,CTA_MAX , attr, ct_nla_policy); -return ctnetlink_nfqueue_parse_ct ((const struct nlattr **)cda, ct); +spin_lock_bh (&nf_conntrack_lock); + ret =ctnetlink_nfqueue_parse_ct ((const struct nlattr **)cda, ct); +spin_unlock_bh (&nf_conntrack_lock); + +return ret; } static struct nfq_ct_hook ctnetlink_nfqueue_hook = {
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 5/5 netfilter: nf_ct_expect: fix possible access to uninitialized timer
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
In __nf_ct_expect_check, the function refresh_timer returns 1 if a matching expectation is found and its timer is successfully refreshed. This results in nf_ct_expect_related returning 0. Note that at this point:
- the passed expectation is not inserted in the expectation table and its timer was not initialized, since we have refreshed one matching/existing expectation.
- nf_ct_expect_alloc uses kmem_cache_alloc, so the expectation timer is in some undefined state just after the allocation, until it is appropriately initialized.
This can be a problem for the SIP helper during the expectation addition:
...
if (nf_ct_expect_related(rtp_exp) == 0) {
if (nf_ct_expect_related(rtcp_exp) != 0)
nf_ct_unexpect_related(rtp_exp);...
Note that nf_ct_expect_related(rtp_exp) may return 0 for the timer refresh case that is detailed above. Then, if nf_ct_unexpect_related(rtcp_exp) returns != 0, nf_ct_unexpect_related(rtp_exp) is called, which does:
spin_lock_bh(&nf_conntrack_lock);
if (del_timer(&exp->timeout)) {
nf_ct_unlink_expect(exp);
nf_ct_expect_put(exp); }
spin_unlock_bh(&nf_conntrack_lock);
Note that del_timer always returns false if the timer has been initialized. However, the timer was not initialized since setup_timer was not called, therefore, the expectation timer remains in some undefined state. If I'm not missing anything, this may lead to the removal an unexistent expectation.
To fix this, the optimization that allows refreshing an expectation is removed. Now nf_conntrack_expect_related looks more consistent to me since it always add the expectation in case that it returns success.
Thanks to Patrick McHardy for participating in the discussion of this patch.
I think this may be the source of the problem described by:
http://marc.info/?l=netfilter-devel&m=134073514719421&w=2
--- net/netfilter/nf_conntrack_expect.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-)
net/netfilter/nf_conntrack_expect.c +6 -23
@@ -361,23 +361,6 @@ static void evict_oldest_expect(struct nf_conn *master, } } -static inline int refresh_timer (struct nf_conntrack_expect *i) -{ -struct nf_conn_help *master_help =nfct_help (i->master); -const struct nf_conntrack_expect_policy *p; - -if (!del_timer (&i->timeout)) -return 0 ; - - p = &rcu_dereference_protected ( - master_help->helper, -lockdep_is_held (&nf_conntrack_lock) - )->expect_policy[i->class]; - i->timeout.expires = jiffies + p->timeout *HZ ; -add_timer (&i->timeout); -return 1 ; -} -static inline int __nf_ct_expect_check (struct nf_conntrack_expect *expect) {const struct nf_conntrack_expect_policy *p;
@@ -386,7 +369,7 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect)struct nf_conn_help *master_help =nfct_help (master);struct nf_conntrack_helper *helper;struct net *net =nf_ct_exp_net (expect); -struct hlist_node *n; +struct hlist_node *n, *next;unsigned int h;int ret =1 ;
@@ -395,12 +378,12 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect) goto out; } h =nf_ct_expect_dst_hash (&expect->tuple); -hlist_for_each_entry (i, n, &net->ct.expect_hash[h], hnode) { +hlist_for_each_entry_safe (i, n, next, &net->ct.expect_hash[h], hnode) {if (expect_matches (i, expect)) { -/* Refresh timer: if it's dying, ignore.. */ -if (refresh_timer (i)) { - ret =0 ; - goto out; +if (del_timer (&i->timeout)) { +nf_ct_unlink_expect (i); +nf_ct_expect_put (i); +break ; } }else if (expect_clash (i, expect)) { ret = -EBUSY ;
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: [email protected]
Date: Fri, 17 Aug 2012 16:09:28 +0200
Quoted 11 lines
The following five patches contain fixes for 3.6-rc, they are:
* Two fixes for message parsing in the SIP conntrack helper, from Patrick McHardy.
* One fix for the SIP helper introduced in the user-space cthelper infrastructure, from Patrick McHardy.
* fix missing appropriate locking while modifying one conntrack entry from the nfqueue integration code, from myself.
Quoted 6 lines
* fix possible access to uninitiliazed timer in the
nf_conntrackexpectation infrastructure, from myself.You can pull these changes from:
git://1984.lsi.us.es/nf
Pulled, thanks Pablo.