Skip to contentSkip to conversation

find_appropriate_src() BUG also exist in 2.4.24

DISCUSSION zhi wang 4 participants 7 messages Apr 3, 2004 – Apr 5, 2004

Subsystems (2)
lore
Share & tools
lore

zhi wang

author
#0 lore raw
Quoted 5 lines

Still consider a simple SNAT, without CONFIG_IP_NF_NAT_LOCAL selected

[ Client A ] -----> [ Box B ] ----> [ Server C ]
iptalbes -A POSTROUTING -t nat -p udp -j SNAT --to-source B:2000-3000

Quoted 7 lines

when two udp connection built:
ct1: ORIG A.1---> C.1 REPLY C.1 ---> B.2000
ct2: ORIG B.2000 ---> C.2 REPLY C.2 ---> B.2000

then the third will hang on the system

B.2000 ---> C.1

After some email communication with wanght@legend, and cleared my own misunderstander, I agree that this is a bug. The following steps can faithfully hang the linux 2.4.24 machine.

     [1.1.1.2]<--->[1.1.1.1  2.2.2.1] <--->[2.2.2.2]
     iptalbes -A POSTROUTING -t nat -j SNAT --to-source 2.2.2.1:2000-3000

1. Deselect the CONFIG_IP_NF_NAT_LOCAL.
set up the route:
at [1.1.1.2]: ip route add 2.2.2.0/24 via 1.1.1.1 at [2.2.2.2]: ip route add 1.1.1.0/24 via 2.2.2.1 at [1.1.1.1]: echo 1 > /proc/sys/net/ipv4/ip_forward

2. at [2.2.2.2] execute:
nc -l -p 1023
nc -l -p 1024

3. at [1.1.1.2] execute:
nc -n -p 1023 2.2.2.2 1023
at [1.1.1.1], assume port 2000 is used. that is, there is a conntrack:

             {1.1.1.2:1023-->2.2.2.2:1023, 2.2.2.2:1023-->2.2.2.1:2000}

4. at [1.1.1.1] execute:
nc -n -s 2.2.2.1 -p 2000 2.2.2.2 1024
then another conntrack will be created:

             {2.2.2.1:2000-->2.2.2.2:1024,  2.2.2.2:1024-->2.2.2.1:2000}

5. at [1.1.1.1] again execute:
nc -n -s 2.2.2.1 -p 2000 2.2.2.2 1023
Then NF will try to create a conntrack with:

             {2.2.2.1:2000-->2.2.2.2:1023, 2.2.2.2:1023-->2.2.2.1:2000}

This will trigger the dead loop.

Why CONFIG_IP_NF_NAT_LOCAL disabled:
When CONFIG_IP_NF_NAT_LOCAL is enabled, a null binding will be allocated at
LOCAL_OUT hook. While a LOCAL_OUT hook is consided for DNAT, nat will not call find_appropriate_src, and it will try to do implicit source NAT. So, the conntrack will be change to something like {2.2.2.1:2000-->2.2.2.2:1023, 2.2.2.2:1023-->2.2.2.1:2001} before the POSTROUTING hook is called, dead loop will NOT occur. I believe this DNAT identity is the power of CONFIG_IP_NF_NAT_LOCAL. It covers this and the LIST_DELETE bug. Because it is consided as DNAT, the PREROUTING hook will NOT call ip_nat_rule_find in LIST_DELETE bug setup.

Current 2.6 kernel has fixed this bug. It should be used in current 2.4 kernel also.

Some thoughts:
The purpose of find_appropriate_src as stated by the comment in the source code, "If this srcip/proto/src-proto-part is currently mapped,and that same mapping gives a unique tuple within the given range, use that". I am just wondering why we can't be the first to use that mapping, if it is valid within the given range?

=====
--
Regards
Wang, zhi

__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/

#1 lore raw
Quoted 2 lines · zhi wang

Current 2.6 kernel has fixed this bug. It should be used in current 2.4 kernel also.

The fix is included in 2.4-bk, it will be included in 2.4.26 when that is released.

Signature · 1 line
/Martin
#2 lore raw

Hi,

Quoted 6 lines · Martin Josefsson
Quoted 2 lines · zhi wang

Current 2.6 kernel has fixed this bug. It should be used in current 2.4 kernel also.

The fix is included in 2.4-bk, it will be included in 2.4.26 when that is released.

Martin, I think this is a different problem than the LIST_DELETE-related
bug fixed in -bk (and 2.6.5). Are you sure it is solved?

Signature · 2 lines
 Regards,
  Krisztian KOVACS
#3 lore raw
Quoted 4 lines · KOVACS Krisztian

Hi,

Quoted 1 line · Martin Josefsson

On Sat, 2004-04-03 at 04:01, zhi wang wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Current 2.6 kernel has fixed this bug. It should be used in current 2.4 kernel also.

The fix is included in 2.4-bk, it will be included in 2.4.26 when that is released.

Martin, I think this is a different problem than the LIST_DELETE-related
bug fixed in -bk (and 2.6.5). Are you sure it is solved?

No, I should learn to eat breakfast before replying to mail :(

Ignore my reply. Need to get a clue :)

Signature · 1 line
/Martin
author
#4 lore raw

Yes, there are different. This bug is because get_unique_tuple blindly accepts whatever find_appropriate_src returns in 2.4.x. While 2.6.5 has the return tuple checked by ip_nat_used_tuple. You must have know this.:)

__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/

#5 lore raw

Hi,

Quoted 3 lines · zhi wang

Yes, there are different. This bug is because get_unique_tuple blindly accepts whatever find_appropriate_src returns in 2.4.x. While 2.6.5 has the return tuple checked by ip_nat_used_tuple. You must have know this.:)

Indeed. This was the cause that the in_range() fix caused problems in
2.4, and had to be backed out.

Furthermore, I think that find_appropriate_src() is completely useless
in its current form. Note thate src_cmp(), after checking that the source is the same, passes the source in the original direction as the manip-to-be-applied to in_range. However, in case of SNAT, this is the unmodified, original source! I suspect that the destination address in the reply direction should be used instead, since that value is the new value applied by NAT on the matching connection. A more detailed description of the probelem, though somewhat braindump-like, is available at

http://lists.netfilter.org/pipermail/netfilter-devel/2004-March/014418.html

Signature · 2 lines
 Regards,
   Krisztian KOVACS
#6 lore raw
In reply to zhi wang

Hi,

Quoted 3 lines · zhi wang

Yes, there are different. This bug is because get_unique_tuple blindly accepts whatever find_appropriate_src returns in 2.4.x. While 2.6.5 has the return tuple checked by ip_nat_used_tuple. You must have know this.:)

Harald, would it be possible to apply the patch which adds this check
(attached), plus the in_range() fix from pom/broken/74_nat-range-fix.patch to 2.4? They seem to be reliable in 2.6.

Signature · 2 lines
 Regards,
   Krisztian KOVACS
net/ipv4/netfilter/ip_nat_core.c +2 -1
Index: linux-2.4.25/net/ipv4/netfilter/ip_nat_core.c
===================================================================
@@ -420,7 +420,8 @@
 			*tuple = ((struct ip_conntrack_tuple)
 				  { *manip, orig_tuple->dst });
 			DEBUGP("get_unique_tuple: Found current src map\n");
-			return 1;
+			if (!ip_nat_used_tuple(tuple, conntrack))
+				return 1;
 		}
 	}