netfilter -stable 00/02: netfilter -stable fixes
Subsystems (3)
The following two patches fix two bug in netfilter:
- a bug in TCP conntrack sequence tracking when used with NAT helpers that enlarge packets
- a regression in the xt_connlimit match introduced in 2.6.29, causing false negatives
Please apply, thanks.
include/net/netfilter/nf_conntrack.h | 8 +-- include/net/netfilter/nf_nat_helper.h | 4 ++ net/ipv4/netfilter/nf_nat_core.c | 3 + net/ipv4/netfilter/nf_nat_helper.c | 34 +++++++++++----- net/netfilter/nf_conntrack_core.c | 8 ++++ net/netfilter/nf_conntrack_proto_tcp.c | 64 +++++++++++++------------------- net/netfilter/xt_connlimit.c | 10 ++--- 7 files changed, 71 insertions(+), 60 deletions(-)
Jan Engelhardt (1):
netfilter: xt_connlimit: fix regression caused by zero family value
Jozsef Kadlecsik (1):
netfilter: nf_nat: fix NAT issue in 2.6.30.4+
netfilter -stable 01/02: nf_nat: fix NAT issue in 2.6.30.4+
commit eb3336f5b440ae5c15d09abe20d7bdd45a88d157
Author: Jozsef Kadlecsik <[email protected]> Date: Tue Nov 10 10:53:08 2009 +0100
netfilter: nf_nat: fix NAT issue in 2.6.30.4+
Upstream commit f9dd09c7:
Vitezslav Samel discovered that since 2.6.30.4+ active FTP can not work over NAT. The "cause" of the problem was a fix of unacknowledged data detection with NAT (commit a3a9f79e361e864f0e9d75ebe2a0cb43d17c4272). However, actually, that fix uncovered a long standing bug in TCP conntrack:
when NAT was enabled, we simply updated the max of the right edge of the segments we have seen (td_end), by the offset NAT produced with changing IP/port in the data. However, we did not update the other parameter (td_maxend) which is affected by the NAT offset. Thus that could drift away from the correct value and thus resulted breaking active FTP.
The patch below fixes the issue by *not* updating the conntrack parameters from NAT, but instead taking into account the NAT offsets in conntrack in a consistent way. (Updating from NAT would be more harder and expensive because it'd need to re-calculate parameters we already calculated in conntrack.)
include/net/netfilter/nf_conntrack.h +3 -5
@@ -252,11 +252,9 @@ static inline bool nf_ct_kill(struct nf_conn *ct) }/* These are for NAT. Icky. */ -/* Update TCP window tracking data when NAT mangles the packet */ -extern void nf_conntrack_tcp_update (const struct sk_buff *skb, -unsigned int dataoff, -struct nf_conn *ct,int dir, -s16 offset); +extern s16 (*nf_ct_nat_offset)(const struct nf_conn *ct, +enum ip_conntrack_dir dir, +u32 seq);/* Fake conntrack entry for untracked connections */ extern struct nf_conn nf_conntrack_untracked;
include/net/netfilter/nf_nat_helper.h +4 -0
@@ -32,4 +32,8 @@ extern int (*nf_nat_seq_adjust_hook)(struct sk_buff *skb,* to port ct->master->saved_proto. */ extern void nf_nat_follow_master (struct nf_conn *ct,struct nf_conntrack_expect *this); + +extern s16 nf_nat_get_offset (const struct nf_conn *ct, +enum ip_conntrack_dir dir, +u32 seq);#endif
net/ipv4/netfilter/nf_nat_core.c +3 -0
@@ -750,6 +750,8 @@ static int __init nf_nat_init(void)BUG_ON (nfnetlink_parse_nat_setup_hook !=NULL );rcu_assign_pointer (nfnetlink_parse_nat_setup_hook, nfnetlink_parse_nat_setup); +BUG_ON (nf_ct_nat_offset !=NULL ); +rcu_assign_pointer (nf_ct_nat_offset, nf_nat_get_offset);return 0 ; cleanup_extend:
@@ -764,6 +766,7 @@ static void __exit nf_nat_cleanup(void)nf_ct_extend_unregister (&nat_extend);rcu_assign_pointer (nf_nat_seq_adjust_hook,NULL );rcu_assign_pointer (nfnetlink_parse_nat_setup_hook,NULL ); +rcu_assign_pointer (nf_ct_nat_offset,NULL );synchronize_net (); }
net/ipv4/netfilter/nf_nat_helper.c +23 -11
@@ -73,6 +73,28 @@ adjust_tcp_sequence(u32 seq,DUMP_OFFSET (this_way); } +/* Get the offset value, for conntrack */ +s16 nf_nat_get_offset (const struct nf_conn *ct, +enum ip_conntrack_dir dir, +u32 seq) +{ +struct nf_conn_nat *nat =nfct_nat (ct); +struct nf_nat_seq *this_way; +s16 offset; + +if (!nat) +return 0 ; + + this_way = &nat->seq[dir]; +spin_lock_bh (&nf_nat_seqofs_lock); + offset =after (seq, this_way->correction_pos) + ? this_way->offset_after : this_way->offset_before; +spin_unlock_bh (&nf_nat_seqofs_lock); + +return offset; +} +EXPORT_SYMBOL_GPL (nf_nat_get_offset); +/* Frobs data inside this packet, which is linear. */ static void mangle_contents(struct sk_buff *skb, unsigned int dataoff,
@@ -189,11 +211,6 @@ nf_nat_mangle_tcp_packet(struct sk_buff *skb,adjust_tcp_sequence (ntohl (tcph->seq), (int )rep_len - (int )match_len, ct, ctinfo); -/* Tell TCP window tracking about seq change */ -nf_conntrack_tcp_update (skb,ip_hdrlen (skb), - ct,CTINFO2DIR (ctinfo), - (int )rep_len - (int )match_len); -nf_conntrack_event_cache (IPCT_NATSEQADJ , ct); }return 1 ;
@@ -415,12 +432,7 @@ nf_nat_seq_adjust(struct sk_buff *skb, tcph->seq = newseq; tcph->ack_seq = newack; -if (!nf_nat_sack_adjust (skb, tcph, ct, ctinfo)) -return 0 ; - -nf_conntrack_tcp_update (skb,ip_hdrlen (skb), ct, dir, seqoff); - -return 1 ; +return nf_nat_sack_adjust (skb, tcph, ct, ctinfo); }/* Setup NAT on this expected conntrack so it follows master. */
net/netfilter/nf_conntrack_core.c +8 -0
@@ -1296,6 +1296,11 @@ err_stat:return ret; } +s16 (*nf_ct_nat_offset)(const struct nf_conn *ct, +enum ip_conntrack_dir dir, +u32 seq); +EXPORT_SYMBOL_GPL (nf_ct_nat_offset); +int nf_conntrack_init (struct net *net) {int ret;
@@ -1313,6 +1318,9 @@ int nf_conntrack_init(struct net *net)/* For use by REJECT target */ rcu_assign_pointer (ip_ct_attach, nf_conntrack_attach);rcu_assign_pointer (nf_ct_destroy, destroy_conntrack); + +/* Howto get NAT offsets */ +rcu_assign_pointer (nf_ct_nat_offset,NULL ); }return 0 ;
net/netfilter/nf_conntrack_proto_tcp.c +26 -38
103 lines not on this page · raw message
netfilter -stable 02/02: xt_connlimit: fix regression caused by zero family value
In reply to Patrick McHardycommit 4dcaa8fa124a6d8ab0f64dc1c289b13a724f8fc1
Author: Jan Engelhardt <[email protected]> Date: Tue Nov 10 10:53:33 2009 +0100
netfilter: xt_connlimit: fix regression caused by zero family value
Upstream commit 539054a8:
Commit v2.6.28-rc1~717^2~109^2~2 was slightly incomplete; not all instances of par->match->family were changed to par->family.
References: http://bugzilla.netfilter.org/show_bug.cgi?id=610
net/netfilter/xt_connlimit.c +4 -6
@@ -103,7 +103,7 @@ static int count_them(struct xt_connlimit_data *data,const struct nf_conntrack_tuple *tuple, const union nf_inet_addr *addr, const union nf_inet_addr *mask, - const struct xt_match *match) + u_int8_t family) { const struct nf_conntrack_tuple_hash *found;struct xt_connlimit_conn *conn;
@@ -113,8 +113,7 @@ static int count_them(struct xt_connlimit_data *data,bool addit = true;int matches =0 ; - -if (match->family ==NFPROTO_IPV6 ) +if (family ==NFPROTO_IPV6 ) hash = &data->iphash[connlimit_iphash6 (addr, mask)];else hash = &data->iphash[connlimit_iphash (addr->ip & mask->ip)];
@@ -157,8 +156,7 @@ static int count_them(struct xt_connlimit_data *data,continue ; } -if (same_source_net (addr, mask, &conn->tuple.src.u3, - match->family)) +if (same_source_net (addr, mask, &conn->tuple.src.u3, family))/* same source network -> be counted! */ ++matches;nf_ct_put (found_ct);
@@ -207,7 +205,7 @@ connlimit_mt(const struct sk_buff *skb, const struct xt_match_param *par)spin_lock_bh (&info->data->lock); connections =count_them (info->data, tuple_ptr, &addr, - &info->mask, par->match); + &info->mask, par->family);spin_unlock_bh (&info->data->lock);if (connections <0 ) {