All of lore.kernel.org
 help / color / mirror / Atom feed
* TCP Connection tracking and SYN/ACK/PSH
@ 2005-04-17 10:37 NIIBE Yutaka
  2005-04-18  1:34 ` Henrik Nordstrom
  0 siblings, 1 reply; 9+ messages in thread
From: NIIBE Yutaka @ 2005-04-17 10:37 UTC (permalink / raw)
  To: netfilter-devel; +Cc: ukai

I got a problem with netfilter connection tracking for TCP.
Kernel version is 2.6.9 (of Debian sarge).

Linux 2.6 cannot connect to (a version of) MELCO Wireless Print
Server.  It is because MELCO Wireless Print Server responds SYN/ACK/PSH, 
when it gets SYN.  And Linux connection tracking for TCP cannot handle
SYN/ACK/PSH.

I found that there is a discussion about SYN/ACK/PSH:
http://www.linuxforum.com/forums/index.php?s=6af41cf69e81a2cde189f6b7168ed535&showtopic=137778&st=0&#entry600234

It seems that it is same issue.

I attach (formatted) output of tcpdump at the end of this message.
Please note the packets with flags SP and ack.

The model of MELCO Wireless Print Server was:
-------------------------------
Server Name    :  WS-363251
Server Model   :  LPV2-WS11GC
F/W Version    :  0.10
-------------------------------

The iptables were:
-------------------------------
# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     icmp --  anywhere             anywhere            icmp echo-reply 
ACCEPT     icmp --  anywhere             anywhere            icmp destination-unreachable 
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request 
ACCEPT     icmp --  anywhere             anywhere            icmp time-exceeded 
ACCEPT     udp  --  anywhere             anywhere            udp spt:netbios-ns dpts:1024:65535 

Chain FORWARD (policy DROP)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
-------------------------------

I think that the protocol stack of MELCO Wireless Print Server is
broken or at least, unusual.  But following patch fixes this issue...

--- net/ipv4/netfilter/ip_conntrack_proto_tcp.c~	2004-10-19 06:55:29.000000000 +0900
+++ net/ipv4/netfilter/ip_conntrack_proto_tcp.c	2005-04-17 18:06:10.000000000 +0900
@@ -754,6 +754,7 @@ static u8 tcp_valid_flags[(TH_FIN|TH_SYN
 {
 	[TH_SYN]			= 1,
 	[TH_SYN|TH_ACK]			= 1,
+	[TH_SYN|TH_PUSH|TH_ACK]		= 1,
 	[TH_RST]			= 1,
 	[TH_RST|TH_ACK]			= 1,
 	[TH_RST|TH_ACK|TH_PUSH]		= 1,
------------

Here is the output of tcpdump, 192.168.2.5 is Linux box,
192.168.2.70 is MELCO server.
-------------------------------
16:55:10.649183 IP (tos 0x10, ttl  64, id 26625, offset 0,
		flags [DF], length: 60)
	192.168.2.5.34139 > 192.168.2.70.telnet:
	S [tcp sum ok] 1185703014:1185703014(0) win 5840
	<mss 1460,sackOK,timestamp 277089383 0,nop,wscale 2>
16:55:10.657457 IP (tos 0x0, ttl  30, id 5214, offset 0,
		flags [none], length: 44)
	192.168.2.70.telnet > 192.168.2.5.34139:
	SP [tcp sum ok] 8419755:8419755(0) ack 1185703015 win 1024 <mss 1024>
16:55:11.829212 IP (tos 0x0, ttl  30, id 5215, offset 0,
		flags [none], length: 44)
	192.168.2.70.telnet > 192.168.2.5.34139:
	SP [tcp sum ok] 8419755:8419755(0) ack 1185703015 win 1024 <mss 1024>
16:55:13.648646 IP (tos 0x10, ttl  64, id 26627, offset 0,
		flags [DF], length: 60)
	192.168.2.5.34139 > 192.168.2.70.telnet:
	S [tcp sum ok] 1185703014:1185703014(0) win 5840
	<mss 1460,sackOK,timestamp 277092383 0,nop,wscale 2>
16:55:13.655225 IP (tos 0x0, ttl  30, id 5216, offset 0,
		flags [none], length: 40)
	192.168.2.70.telnet > 192.168.2.5.34139:
	. [tcp sum ok] 1:1(0) ack 1 win 1024
16:55:13.836717 IP (tos 0x0, ttl  30, id 5217, offset 0,
		flags [none], length: 44)
	192.168.2.70.telnet > 192.168.2.5.34139:
	SP [tcp sum ok] 8419755:8419755(0) ack 1185703015 win 1024 <mss 1024>
16:55:15.839199 IP (tos 0x0, ttl  30, id 5218, offset 0,
		flags [none], length: 44)
	192.168.2.70.telnet > 192.168.2.5.34139:
	SP [tcp sum ok] 8419755:8419755(0) ack 1185703015 win 1024 <mss 1024>
16:55:19.647731 IP (tos 0x10, ttl  64, id 26629, offset 0,
		flags [DF], length: 60)
	192.168.2.5.34139 > 192.168.2.70.telnet:
	S [tcp sum ok] 1185703014:1185703014(0) win 5840
	<mss 1460,sackOK,timestamp 277098383 0,nop,wscale 2>
16:55:19.655215 IP (tos 0x0, ttl  30, id 5220, offset 0,
		flags [none], length: 40)
	192.168.2.70.telnet > 192.168.2.5.34139:
	. [tcp sum ok] 1:1(0) ack 1 win 1024
16:55:19.837037 IP (tos 0x0, ttl  30, id 5222, offset 0,
		flags [none], length: 44)
	192.168.2.70.telnet > 192.168.2.5.34139:
	SP [tcp sum ok] 8419755:8419755(0) ack 1185703015 win 1024 <mss 1024>
16:55:27.830395 IP (tos 0x0, ttl  30, id 5228, offset 0,
		flags [none], length: 44)
	192.168.2.70.telnet > 192.168.2.5.34139:
	SP [tcp sum ok] 8419755:8419755(0) ack 1185703015 win 1024 <mss 1024>
16:55:31.645907 IP (tos 0x10, ttl  64, id 26631, offset 0,
		flags [DF], length: 60)
	192.168.2.5.34139 > 192.168.2.70.telnet:
	S [tcp sum ok] 1185703014:1185703014(0) win 5840
	<mss 1460,sackOK,timestamp 277110383 0,nop,wscale 2>
16:55:31.657868 IP (tos 0x0, ttl  30, id 5231, offset 0,
		flags [none], length: 40)
	192.168.2.70.telnet > 192.168.2.5.34139:
	. [tcp sum ok] 1:1(0) ack 1 win 1024
16:55:43.834948 IP (tos 0x0, ttl  30, id 5239, offset 0,
		flags [none], length: 44)
	192.168.2.70.telnet > 192.168.2.5.34139:
	SP [tcp sum ok] 8419755:8419755(0) ack 1185703015 win 1024 <mss 1024>
-------------------------------
-- 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: TCP Connection tracking and SYN/ACK/PSH
  2005-04-17 10:37 TCP Connection tracking and SYN/ACK/PSH NIIBE Yutaka
@ 2005-04-18  1:34 ` Henrik Nordstrom
  2005-04-18 23:06   ` Phil Oester
  2005-04-20  1:30   ` Tim Burress
  0 siblings, 2 replies; 9+ messages in thread
From: Henrik Nordstrom @ 2005-04-18  1:34 UTC (permalink / raw)
  To: NIIBE Yutaka; +Cc: netfilter-devel, ukai

On Sun, 17 Apr 2005, NIIBE Yutaka wrote:

> Linux 2.6 cannot connect to (a version of) MELCO Wireless Print
> Server.  It is because MELCO Wireless Print Server responds SYN/ACK/PSH,
> when it gets SYN.  And Linux connection tracking for TCP cannot handle
> SYN/ACK/PSH.

Just a small note to support this: SYN+ACK+PSH is a perfectly valid flags 
combination, even more so if there actually is data enclosed in the 
SYN+ACK (which is valid, only a little odd).

There is not really any good reason why conntrack should care in detail 
about the PSH flag. Most if not all valid flag combinations are good both 
with and without PSH (even SYN).

Regards
Henrik

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: TCP Connection tracking and SYN/ACK/PSH
  2005-04-18  1:34 ` Henrik Nordstrom
@ 2005-04-18 23:06   ` Phil Oester
  2005-04-20  1:30   ` Tim Burress
  1 sibling, 0 replies; 9+ messages in thread
From: Phil Oester @ 2005-04-18 23:06 UTC (permalink / raw)
  To: Henrik Nordstrom; +Cc: netfilter-devel, NIIBE Yutaka, ukai

On Mon, Apr 18, 2005 at 03:34:41AM +0200, Henrik Nordstrom wrote:
> Just a small note to support this: SYN+ACK+PSH is a perfectly valid flags 
> combination, even more so if there actually is data enclosed in the 
> SYN+ACK (which is valid, only a little odd).
> 
> There is not really any good reason why conntrack should care in detail 
> about the PSH flag. Most if not all valid flag combinations are good both 
> with and without PSH (even SYN).

Given that nmap's Xmas tree scan uses an invalid PSH flag combination to scan
for open ports, I'd suggest conntrack should care about the flag.

While the particular combination being seen here is likely always harmless,
perhaps netfilter should only allow RFC-defined handshakes as a general
rule.

Phil

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: TCP Connection tracking and SYN/ACK/PSH
  2005-04-18  1:34 ` Henrik Nordstrom
  2005-04-18 23:06   ` Phil Oester
@ 2005-04-20  1:30   ` Tim Burress
  2005-04-20  7:02     ` Re[2]: " Maciej Soltysiak
  2005-04-20  7:42     ` Henrik Nordstrom
  1 sibling, 2 replies; 9+ messages in thread
From: Tim Burress @ 2005-04-20  1:30 UTC (permalink / raw)
  To: Henrik Nordstrom; +Cc: netfilter-devel, NIIBE Yutaka, ukai

Henrik Nordstrom wrote:

> Just a small note to support this: SYN+ACK+PSH is a perfectly valid 
> flags combination, even more so if there actually is data enclosed in 
> the SYN+ACK (which is valid, only a little odd).
>
> There is not really any good reason why conntrack should care in 
> detail about the PSH flag. Most if not all valid flag combinations are 
> good both with and without PSH (even SYN).

We recently had a similar issue, and initially I thought it was overly 
paranoid for Netfilter to mark these segments invalid, but after some 
digging I've changed my mind. The problem is that, even though there is 
no statement in the standards classifying SYN/ACK/PSH itself as invalid, 
the operation that PSH demands -- immediate transmission to the 
application -- is explicitly forbidden during the handshake [RFC 793, 
pg. 30]. In any other protocol, a request to perform a prohibited 
operation would, I think, be considered invalid, so in the end I think 
Netfilter is doing the right thing, inconvenient as it may be for a few 
devices.

In our case the device was a Panasonic WJ-NT104 interface/server for 
network cameras. Apparently there is an embedded TCP/IP stack making the 
rounds in Japan that sets the PSH flag on *every* segment. Panasonic's 
technical support have not yet replied to queries about the issue, but 
we're hoping they will issue a firmware upgrade to fix the problem. In 
the meantime, we modified our rules to allow INVALID traffic to/from the 
device. Obviously it's not ideal, but it gets the job done. If Panasonic 
is unable/unwilling to fix the TCP behavior, we would probably patch 
Netfilter to clear the PSH flag when it occurs in combination with SYN. 
That way we could accept the traffic without allowing invalid segments 
through to hosts on the other side.

Tim

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re[2]: TCP Connection tracking and SYN/ACK/PSH
  2005-04-20  1:30   ` Tim Burress
@ 2005-04-20  7:02     ` Maciej Soltysiak
  2005-04-20  7:42     ` Henrik Nordstrom
  1 sibling, 0 replies; 9+ messages in thread
From: Maciej Soltysiak @ 2005-04-20  7:02 UTC (permalink / raw)
  To: netfilter-devel

Hello Tim,

Wednesday, April 20, 2005, 3:30:31 AM, you wrote:
> the meantime, we modified our rules to allow INVALID traffic to/from the
> device. Obviously it's not ideal, but it gets the job done. If Panasonic
> is unable/unwilling to fix the TCP behavior, we would probably patch
> Netfilter to clear the PSH flag when it occurs in combination with SYN.
I guess this is material for a FAQ item...
And maybe for the INCOMPATIBILITIES file that sits around in /iptables

> Tim
Maciej

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: TCP Connection tracking and SYN/ACK/PSH
  2005-04-20  1:30   ` Tim Burress
  2005-04-20  7:02     ` Re[2]: " Maciej Soltysiak
@ 2005-04-20  7:42     ` Henrik Nordstrom
  2005-04-22  9:38       ` Tim Burress
  1 sibling, 1 reply; 9+ messages in thread
From: Henrik Nordstrom @ 2005-04-20  7:42 UTC (permalink / raw)
  To: Tim Burress; +Cc: netfilter-devel, NIIBE Yutaka, ukai

On Wed, 20 Apr 2005, Tim Burress wrote:

> explicitly forbidden during the handshake [RFC 793, pg. 30]. In any other 
> protocol, a request to perform a prohibited operation would, I think, be 
> considered invalid, so in the end I think Netfilter is doing the right thing, 
> inconvenient as it may be for a few devices.

I am of a slightly different opinion. These segments is not invalid (only 
odd) and won't cause any disturbance to the TCP protocol as long as the 
standard on how to process received segments is followed.

I am of the opinion that as long as the traffic is not explicitly 
violating the protocol conntrack should track it. Stricter checking 
belongs in a separate match such as unclean if desired imho.

Regards
Henrik

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: TCP Connection tracking and SYN/ACK/PSH
  2005-04-20  7:42     ` Henrik Nordstrom
@ 2005-04-22  9:38       ` Tim Burress
  2005-04-22 13:45         ` Jozsef Kadlecsik
  0 siblings, 1 reply; 9+ messages in thread
From: Tim Burress @ 2005-04-22  9:38 UTC (permalink / raw)
  To: Henrik Nordstrom; +Cc: netfilter-devel, NIIBE Yutaka, ukai

Hello!

Henrik Nordstrom wrote:

> On Wed, 20 Apr 2005, Tim Burress wrote:
>
>> explicitly forbidden during the handshake [RFC 793, pg. 30]. In any 
>> other protocol, a request to perform a prohibited operation would, I 
>> think, be considered invalid, so in the end I think Netfilter is 
>> doing the right thing, inconvenient as it may be for a few devices.
>
>
> I am of a slightly different opinion. These segments is not invalid 
> (only odd) and won't cause any disturbance to the TCP protocol as long 
> as the standard on how to process received segments is followed.
>
> I am of the opinion that as long as the traffic is not explicitly 
> violating the protocol conntrack should track it. Stricter checking 
> belongs in a separate match such as unclean if desired imho.

I think the segments are invalid (or at least in-something), but I agree 
with your second point. Since PSH has no bearing on TCP connection 
state, it seems like it might be better to treat PSH the same way as ECE 
and CWR, and have conntrack ignore it. Other layers could then decide 
whether to accept or drop combinations like SYN+ACK+PSH depending on how 
strictly they want to enforce protocol conventions in the firewall. It's 
not so much a question of whether the segments are valid or not as 
whether strict protocol enforcement (beyond what is needed for 
connection tracking) is really conntrack's job. And since I didn't 
design it, I'm not sure!

Tim

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: TCP Connection tracking and SYN/ACK/PSH
  2005-04-22  9:38       ` Tim Burress
@ 2005-04-22 13:45         ` Jozsef Kadlecsik
  2005-04-22 15:34           ` Patrick McHardy
  0 siblings, 1 reply; 9+ messages in thread
From: Jozsef Kadlecsik @ 2005-04-22 13:45 UTC (permalink / raw)
  To: Tim Burress
  Cc: ukai, netfilter-devel, NIIBE Yutaka, Henrik Nordstrom,
	Patrick McHardy

Hi,

On Fri, 22 Apr 2005, Tim Burress wrote:

> I think the segments are invalid (or at least in-something), but I agree
> with your second point. Since PSH has no bearing on TCP connection
> state, it seems like it might be better to treat PSH the same way as ECE
> and CWR, and have conntrack ignore it. Other layers could then decide
> whether to accept or drop combinations like SYN+ACK+PSH depending on how
> strictly they want to enforce protocol conventions in the firewall. It's
> not so much a question of whether the segments are valid or not as
> whether strict protocol enforcement (beyond what is needed for
> connection tracking) is really conntrack's job. And since I didn't
> design it, I'm not sure!

The sole task of conntrack is to keep track of the connections :-),
however it may flag packets as invalid (or even drop directly) in order to
preserve its sanity. It should not protect the communicating parties from
sending illegal packets, as far as the packets can be tracked. Such
protection should be configured in the raw/filter tables.

Patrick, could you submit NIIBE Yutaka's patch, which started this thread?

Best regards,
Jozsef
-
E-mail  : kadlec@blackhole.kfki.hu, kadlec@sunserv.kfki.hu
PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
          H-1525 Budapest 114, POB. 49, Hungary

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: TCP Connection tracking and SYN/ACK/PSH
  2005-04-22 13:45         ` Jozsef Kadlecsik
@ 2005-04-22 15:34           ` Patrick McHardy
  0 siblings, 0 replies; 9+ messages in thread
From: Patrick McHardy @ 2005-04-22 15:34 UTC (permalink / raw)
  To: Jozsef Kadlecsik
  Cc: ukai, Tim Burress, netfilter-devel, NIIBE Yutaka,
	Henrik Nordstrom

Jozsef Kadlecsik wrote:
> Patrick, could you submit NIIBE Yutaka's patch, which started this thread?

Sure, I'll pass it on to Dave this weekend.

Regards
Patrick

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-04-22 15:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-17 10:37 TCP Connection tracking and SYN/ACK/PSH NIIBE Yutaka
2005-04-18  1:34 ` Henrik Nordstrom
2005-04-18 23:06   ` Phil Oester
2005-04-20  1:30   ` Tim Burress
2005-04-20  7:02     ` Re[2]: " Maciej Soltysiak
2005-04-20  7:42     ` Henrik Nordstrom
2005-04-22  9:38       ` Tim Burress
2005-04-22 13:45         ` Jozsef Kadlecsik
2005-04-22 15:34           ` Patrick McHardy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.