1. 23 11月, 2009 2 次提交
    • F
      netfilter: xtables: fix conntrack match v1 ipt-save output · 3a042929
      Florian Westphal 提交于
      commit d6d3f08b
      (netfilter: xtables: conntrack match revision 2) does break the
      v1 conntrack match iptables-save output in a subtle way.
      
      Problem is as follows:
      
          up = kmalloc(sizeof(*up), GFP_KERNEL);
      [..]
         /*
          * The strategy here is to minimize the overhead of v1 matching,
          * by prebuilding a v2 struct and putting the pointer into the
          * v1 dataspace.
          */
          memcpy(up, info, offsetof(typeof(*info), state_mask));
      [..]
          *(void **)info  = up;
      
      As the v2 struct pointer is saved in the match data space,
      it clobbers the first structure member (->origsrc_addr).
      
      Because the _v1 match function grabs this pointer and does not actually
      look at the v1 origsrc, run time functionality does not break.
      But iptables -nvL (or iptables-save) cannot know that v1 origsrc_addr
      has been overloaded in this way:
      
      $ iptables -p tcp -A OUTPUT -m conntrack --ctorigsrc 10.0.0.1 -j ACCEPT
      $ iptables-save
      -A OUTPUT -p tcp -m conntrack --ctorigsrc 128.173.134.206 -j ACCEPT
      
      (128.173... is the address to the v2 match structure).
      
      To fix this, we take advantage of the fact that the v1 and v2 structures
      are identical with exception of the last two structure members (u8 in v1,
      u16 in v2).
      
      We extract them as early as possible and prevent the v2 matching function
      from looking at those two members directly.
      
      Previously reported by Michel Messerschmidt via Ben Hutchings, also
      see Debian Bug tracker #556587.
      Signed-off-by: NFlorian Westphal <fw@strlen.de>
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      3a042929
    • P
      netfilter: nf_ct_tcp: improve out-of-sync situation in TCP tracking · c4832c7b
      Pablo Neira Ayuso 提交于
      Without this patch, if we receive a SYN packet from the client while
      the firewall is out-of-sync, we let it go through. Then, if we see
      the SYN/ACK reply coming from the server, we destroy the conntrack
      entry and drop the packet to trigger a new retransmission. Then,
      the retransmision from the client is used to start a new clean
      session.
      
      This patch improves the current handling. Basically, if we see an
      unexpected SYN packet, we annotate the TCP options. Then, if we
      see the reply SYN/ACK, this means that the firewall was indeed
      out-of-sync. Therefore, we set a clean new session from the existing
      entry based on the annotated values.
      
      This patch adds two new 8-bits fields that fit in a 16-bits gap of
      the ip_ct_tcp structure.
      
      This patch is particularly useful for conntrackd since the
      asynchronous nature of the state-synchronization allows to have
      backup nodes that are not perfect copies of the master. This helps
      to improve the recovery under some worst-case scenarios.
      
      I have tested this by creating lots of conntrack entries in wrong
      state:
      
      for ((i=1024;i<65535;i++)); do conntrack -I -p tcp -s 192.168.2.101 -d 192.168.2.2 --sport $i --dport 80 -t 800 --state ESTABLISHED -u ASSURED,SEEN_REPLY; done
      
      Then, I make some TCP connections:
      
      $ echo GET / | nc 192.168.2.2 80
      
      The events show the result:
      
       [UPDATE] tcp      6 60 SYN_RECV src=192.168.2.101 dst=192.168.2.2 sport=33220 dport=80 src=192.168.2.2 dst=192.168.2.101 sport=80 dport=33220 [ASSURED]
       [UPDATE] tcp      6 432000 ESTABLISHED src=192.168.2.101 dst=192.168.2.2 sport=33220 dport=80 src=192.168.2.2 dst=192.168.2.101 sport=80 dport=33220 [ASSURED]
       [UPDATE] tcp      6 120 FIN_WAIT src=192.168.2.101 dst=192.168.2.2 sport=33220 dport=80 src=192.168.2.2 dst=192.168.2.101 sport=80 dport=33220 [ASSURED]
       [UPDATE] tcp      6 30 LAST_ACK src=192.168.2.101 dst=192.168.2.2 sport=33220 dport=80 src=192.168.2.2 dst=192.168.2.101 sport=80 dport=33220 [ASSURED]
       [UPDATE] tcp      6 120 TIME_WAIT src=192.168.2.101 dst=192.168.2.2 sport=33220 dport=80 src=192.168.2.2 dst=192.168.2.101 sport=80 dport=33220 [ASSURED]
      
      and tcpdump shows no retransmissions:
      
      20:47:57.271951 IP 192.168.2.101.33221 > 192.168.2.2.www: S 435402517:435402517(0) win 5840 <mss 1460,sackOK,timestamp 4294961827 0,nop,wscale 6>
      20:47:57.273538 IP 192.168.2.2.www > 192.168.2.101.33221: S 3509927945:3509927945(0) ack 435402518 win 5792 <mss 1460,sackOK,timestamp 235681024 4294961827,nop,wscale 4>
      20:47:57.273608 IP 192.168.2.101.33221 > 192.168.2.2.www: . ack 3509927946 win 92 <nop,nop,timestamp 4294961827 235681024>
      20:47:57.273693 IP 192.168.2.101.33221 > 192.168.2.2.www: P 435402518:435402524(6) ack 3509927946 win 92 <nop,nop,timestamp 4294961827 235681024>
      20:47:57.275492 IP 192.168.2.2.www > 192.168.2.101.33221: . ack 435402524 win 362 <nop,nop,timestamp 235681024 4294961827>
      20:47:57.276492 IP 192.168.2.2.www > 192.168.2.101.33221: P 3509927946:3509928082(136) ack 435402524 win 362 <nop,nop,timestamp 235681025 4294961827>
      20:47:57.276515 IP 192.168.2.101.33221 > 192.168.2.2.www: . ack 3509928082 win 108 <nop,nop,timestamp 4294961828 235681025>
      20:47:57.276521 IP 192.168.2.2.www > 192.168.2.101.33221: F 3509928082:3509928082(0) ack 435402524 win 362 <nop,nop,timestamp 235681025 4294961827>
      20:47:57.277369 IP 192.168.2.101.33221 > 192.168.2.2.www: F 435402524:435402524(0) ack 3509928083 win 108 <nop,nop,timestamp 4294961828 235681025>
      20:47:57.279491 IP 192.168.2.2.www > 192.168.2.101.33221: . ack 435402525 win 362 <nop,nop,timestamp 235681025 4294961828>
      
      I also added a rule to log invalid packets, with no occurrences  :-) .
      Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
      Acked-by: NJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
      Signed-off-by: NPatrick McHardy <kaber@trash.net>
      c4832c7b
  2. 07 11月, 2009 1 次提交
  3. 05 11月, 2009 3 次提交
  4. 29 10月, 2009 34 次提交