Skip to contentSkip to conversation

Transparent web proxiing stops working in linux-2.4.22

DISCUSSION Raivis Bucis 3 participants 5 messages Sep 2, 2003 – Sep 5, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Transparent web proxiing stops working in linux-2.4.22 because of the following patch:

@@ -1446,8 +1446,8 @@
getorigdst(struct sock *sk, int optval, void *user, int *len) {
struct ip_conntrack_tuple_hash *h;
- struct ip_conntrack_tuple tuple = { { sk->rcv_saddr, { sk->sport } },
- { sk->daddr, { sk->dport },
+ struct ip_conntrack_tuple tuple = { { sk->rcv_saddr, { .tcp = { sk->sport }
} },
+ { sk->daddr, { .tcp = { sk->dport } },
IPPROTO_TCP } };

It comes from
http://lists.netfilter.org/pipermail/netfilter-devel/2003-May/011460.html

It doesn't zero all of the tuple contents before assigning, and this way 3rd and 4th bytes of tuple.src.all contain garbage, and ip_conntrack_find_get is not able to find correct conntrack because of that.

So instead of fixing getorigdst for big endian architectures, it brakes even the little endian ones.

Raivis Bucis

#1 lore raw
Quoted 2 lines · Raivis Bucis

Transparent web proxiing stops working in linux-2.4.22 because of the following patch:

I've added your bug report to bugzilla.netfilter.org - It has been assigned #126

Quoted 3 lines

It doesn't zero all of the tuple contents before assigning, and this way 3rd and 4th bytes of tuple.src.all contain garbage, and ip_conntrack_find_get is not able to find correct conntrack because of that.

I'll write up a patch to fix this issue later today.

Quoted 2 lines

So instead of fixing getorigdst for big endian architectures, it brakes even the little endian ones.

:(

Quoted 1 line

Raivis Bucis

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#2 lore raw
In reply to Raivis Bucis
Quoted 6 lines · Raivis Bucis

It doesn't zero all of the tuple contents before assigning, and this way 3rd and 4th bytes of tuple.src.all contain garbage, and ip_conntrack_find_get is not able to find correct conntrack because of that.

So instead of fixing getorigdst for big endian architectures, it brakes even the little endian ones.

Can you please test the following (proposed) patch and report back if it fixes your problems?

If you could post your comments to the correspoinding bugzilla entry
(https://bugzilla.netfilter.org/cgi-bin/bugzilla/show_bug.cgi?id=126),
it would make my work easier. Otherwise, just send an email reply.

net/ipv4/netfilter/ip_conntrack_core.c +5 -3
diff -Nru --exclude .depend --exclude '*.o' --exclude '*.ko' --exclude '*.ver' --exclude '.*.flags' --exclude '*.orig' --exclude '*.rej' --exclude '*.cmd' --exclude '*.mod.c' --exclude '*~' linux-2.4.22-plain/net/ipv4/netfilter/ip_conntrack_core.c linux-2.4.22-getorig/net/ipv4/netfilter/ip_conntrack_core.c
@@ -1303,9 +1303,11 @@
 getorigdst(struct sock *sk, int optval, void *user, int *len)
 {
 	struct ip_conntrack_tuple_hash *h;
-	struct ip_conntrack_tuple tuple = { { sk->rcv_saddr, { .tcp = { sk->sport } } },
-					    { sk->daddr, { .tcp = { sk->dport } },
-					      IPPROTO_TCP } };
+	struct ip_conntrack_tuple tuple;
+
+	memset(&tuple, 0, sizeof(tuple));
+	tuple = { { sk->rcv_saddr, { .tcp = { sk->sport } } },
+		  { sk->daddr, { .tcp = { sk->dport } }, IPPROTO_TCP } };
 
 	/* We only do TCP at the moment: is there a better way? */
 	if (strcmp(sk->prot->name, "TCP") != 0) {
Quoted 1 line

Raivis Bucis

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#3 lore raw

net/ipv4/netfilter/ip_conntrack_core.c line 1310

Quoted 5 lines · Harald Welte
net/ipv4/netfilter/ip_conntrack_core.c +5 -0
+	struct ip_conntrack_tuple tuple;
+
+	memset(&tuple, 0, sizeof(tuple));
+	tuple = { { sk->rcv_saddr, { .tcp = { sk->sport } } },
+		  { sk->daddr, { .tcp = { sk->dport } }, IPPROTO_TCP } };

This construct looks dangerous to me, relying on the compiler to optimize the assignment in order to fix the bug..

The above is in principle semantically equivalent to

struct ip_conntract_tuple tuple;

memset(&tuple, 0, sizeof(tuple));

   {
      struct ip_conntrac_tuple newtuple = { { sk->rcv_saddr, {
		  .tcp = { sk->sport } } },
                  { sk->daddr, { .tcp = { sk->dport } }, IPPROTO_TCP } };
      tuple = newtuple;

}

Which obviously still has the bug..

Regards
Henrik

#4 lore raw
Quoted 10 lines · Henrik Nordstrom

Review

Quoted 5 lines · Harald Welte
(quoted diff) +5 -0
+	struct ip_conntrack_tuple tuple;
+
+	memset(&tuple, 0, sizeof(tuple));
+	tuple = { { sk->rcv_saddr, { .tcp = { sk->sport } } },
+		  { sk->daddr, { .tcp = { sk->dport } }, IPPROTO_TCP } };

This construct looks dangerous to me, relying on the compiler to optimize the assignment in order to fix the bug..

You are right. Thanks for pointing this out.

This new patch should be a much cleaner solution:

include/linux/netfilter_ipv4/ip_conntrack_tuple.h +8 -0
diff -Nru --exclude .depend --exclude '*.o' --exclude '*.ko' --exclude '*.ver' --exclude '.*.flags' --exclude '*.orig' --exclude '*.rej' --exclude '*.cmd' --exclude '*.mod.c' --exclude '*~' linux-2.4.22-plain/include/linux/netfilter_ipv4/ip_conntrack_tuple.h linux-2.4.22-getorig/include/linux/netfilter_ipv4/ip_conntrack_tuple.h
@@ -62,6 +62,14 @@
 	} dst;
 };
 
+/* This is optimized opposed to a memset of the whole structure.  Everything we
+ * really care about is the  source/destination unions */
+#define IP_CT_TUPLE_BLANK(tuple) 				\
+	do {							\
+		tuple->src.u.all = 0;				\
+		tuple->dst.u.all = 0;				\
+	} while (0)
+
 enum ip_conntrack_dir
 {
 	IP_CT_DIR_ORIGINAL,
net/ipv4/netfilter/ip_conntrack_core.c +8 -3
diff -Nru --exclude .depend --exclude '*.o' --exclude '*.ko' --exclude '*.ver' --exclude '.*.flags' --exclude '*.orig' --exclude '*.rej' --exclude '*.cmd' --exclude '*.mod.c' --exclude '*~' linux-2.4.22-plain/net/ipv4/netfilter/ip_conntrack_core.c linux-2.4.22-getorig/net/ipv4/netfilter/ip_conntrack_core.c
@@ -1303,9 +1303,14 @@
 getorigdst(struct sock *sk, int optval, void *user, int *len)
 {
 	struct ip_conntrack_tuple_hash *h;
-	struct ip_conntrack_tuple tuple = { { sk->rcv_saddr, { .tcp = { sk->sport } } },
-					    { sk->daddr, { .tcp = { sk->dport } },
-					      IPPROTO_TCP } };
+	struct ip_conntrack_tuple tuple;
+
+	IP_CT_TUPLE_BLANK(&tuple);
+	tuple.src.ip = sk->rcv_saddr;
+	tuple.src.u.tcp.port = sk->sport;
+	tuple.dst.ip = sk->daddr;
+	tuple.dst.u.tcp.port = sk->dport;
+	tuple.dst.protonum = IPPROTO_TCP;
 
 	/* We only do TCP at the moment: is there a better way? */
 	if (strcmp(sk->prot->name, "TCP") != 0) {
Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie