From: Willy TARREAU <willy@w.ods.org>
To: Michal Schmidt <xschmi00@stud.feec.vutbr.cz>
Cc: Alastair Poole <alastair@unixtrix.com>, linux-kernel@vger.kernel.org
Subject: Re: BUG: Unusual TCP Connect() results.
Date: Sat, 11 Jun 2005 00:26:45 +0200 [thread overview]
Message-ID: <20050610222645.GA1317@pcw.home.local> (raw)
In-Reply-To: <42A9BA87.4010600@stud.feec.vutbr.cz>
Hi,
just tried right here with a simpler prog which only connects to its
previously bound socket (prog at the end).
After the bind(), the socket still does not appear in netstat (normal),
but right after the connect() call, the socket appears as established.
It is documented in RFC793 (p30) as the simultaneous connection initation
from 2 clients, although this mode has never been implemented by any
mainline OS (to my knowledge) as it has no real use and poses security
problems (eases spoofing a lot). Moreover, stateful firewalls don't
support it at all for the same reasons. I think that this mode was
designed for point-to-point connections such as TCP over serial lines
or things like this.
Interestingly, the network capture on the 'lo' interface shows that the
protocol does not even match the case above, as it only shows the standard
SYN-SYN/ACK-ACK mechanism and not the dual, simultaneous one :
$ sudo tcpdump -Svvni lo tcp
tcpdump: listening on lo, link-type EN10MB (Ethernet), capture size 96 bytes
00:04:03.688649 IP (tos 0x0, ttl 64, id 45241, offset 0, flags [DF], length: 60) 127.0.0.1.10000 > 127.0.0.1.10000: S [tcp sum ok] 1675767716:1675767716(0) win 32767 <mss 16396,sackOK,timestamp 2727709 0,nop,wscale 2>
00:04:03.688665 IP (tos 0x0, ttl 64, id 45243, offset 0, flags [DF], length: 60) 127.0.0.1.10000 > 127.0.0.1.10000: S [tcp sum ok] 1675767716:1675767716(0) ack 1675767717 win 32767 <mss 16396,sackOK,timestamp 2727709 2727709,nop,wscale 2>
00:04:03.688693 IP (tos 0x0, ttl 64, id 45245, offset 0, flags [DF], length: 64) 127.0.0.1.10000 > 127.0.0.1.10000: . [tcp sum ok] 1675767717:1675767717(0) ack 1675767717 win 8192 <nop,nop,timestamp 2727709 2727709,nop,nop,sack sack 1 {1675767716:1675767717} >
=> connection is ESTABLISHED
00:04:06.479729 IP (tos 0x0, ttl 64, id 45247, offset 0, flags [DF], length: 52) 127.0.0.1.10000 > 127.0.0.1.10000: F [tcp sum ok] 1675767717:1675767717(0) ack 1675767717 win 8192 <nop,nop,timestamp 2730501 2727709>
00:04:06.479781 IP (tos 0x0, ttl 64, id 45249, offset 0, flags [DF], length: 52) 127.0.0.1.10000 > 127.0.0.1.10000: . [tcp sum ok] 1675767718:1675767718(0) ack 1675767718 win 8192 <nop,nop,timestamp 2730501 2730501>
=> connection is TIME_WAIT.
It's even easier to test with netcat, which produces the same output :
$ nc -s 127.0.0.1 -p 10000 127.0.0.1 10000
It works for any local address bound to any other interface :
$ nc -s 10.0.0.1 -p 10000 10.0.0.1 10000
A test with hping2 between the bind() and connect() calls shows that the
connection is refused. I don't know if there's even a small window during
the connect() call during which external (spoofed) packets could validate
a connection. Even very fast local connections do not manage to steal a
connection in progress. All we can say is that it's very strange...
$ sudo hping2 -c 1 -k -a 10.0.0.1 -s 80 -I lo 10.0.0.1 -p 80 -S -M 12345678
//
$ sudo tcpdump -Svvni lo tcp
tcpdump: listening on lo, link-type EN10MB (Ethernet), capture size 96 bytes
00:16:58.274961 IP (tos 0x0, ttl 64, id 63368, offset 0, flags [none], length:
40) 10.0.0.1.80 > 10.0.0.1.80: S [tcp sum ok] 12345678:12345678(0) win 512
00:16:58.275152 IP (tos 0x0, ttl 64, id 11, offset 0, flags [DF], length: 40) 10.0.0.1.80 > 10.0.0.1.80: R [tcp sum ok] 0:0(0) ack 12345679 win 0
Regards,
Willy
--
// Annex: simple connection program.
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define MY_PORT 10000
int
main(int argc, char *argv[])
{
int fd;
int val;
struct sockaddr_in addr;
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0
|| setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof val) < 0) {
perror("socket()");
return 1;
}
addr.sin_family = AF_INET;
addr.sin_port = htons(MY_PORT);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
memset(addr.sin_zero, 0, sizeof (addr.sin_zero));
if (bind(fd, (struct sockaddr *)&addr, sizeof (addr)) < 0) {
perror("bind()");
return 1;
}
printf("bind ok. Press a key to continue.\n"); getchar();
if (connect(fd, (struct sockaddr *)&addr, sizeof (addr)) < 0) {
perror("connect()");
return 1;
}
printf("connected! Press a key to continue.\n"); getchar();
return 0;
}
next prev parent reply other threads:[~2005-06-10 22:31 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-09 20:51 Alastair Poole
2005-06-10 2:23 ` [OT] " Kyle Moffett
2005-06-10 13:24 ` Alastair Poole
2005-06-10 15:28 ` Michal Schmidt
2005-06-10 16:55 ` Alastair Poole
2005-06-10 16:06 ` Michal Schmidt
2005-06-10 22:26 ` Willy TARREAU [this message]
2005-06-10 22:38 ` Willy Tarreau
2005-06-10 22:42 ` David S. Miller
2005-06-11 6:24 ` Willy TARREAU
[not found] ` <20050611074350.GD28759@alpha.home.local>
2005-06-11 19:32 ` [PATCH] fix small DoS on connect() (was Re: BUG: Unusual TCP Connect() results.) Herbert Xu
2005-06-11 19:51 ` Willy Tarreau
2005-06-12 8:13 ` Herbert Xu
2005-06-12 8:34 ` Willy Tarreau
2005-06-12 10:30 ` Herbert Xu
2005-06-12 11:40 ` Willy Tarreau
2005-06-12 12:06 ` Herbert Xu
2005-06-12 12:22 ` Thomas Graf
2005-06-12 13:16 ` Herbert Xu
2005-06-12 12:32 ` Willy Tarreau
2005-06-12 13:13 ` Herbert Xu
2005-06-12 13:33 ` Herbert Xu
2005-06-12 13:47 ` Willy Tarreau
2005-06-12 13:50 ` Herbert Xu
2005-06-12 14:24 ` Willy Tarreau
2005-06-13 4:48 ` Herbert Xu
2005-06-13 5:21 ` Willy Tarreau
2005-06-13 5:24 ` Herbert Xu
2005-06-13 6:17 ` Willy Tarreau
2005-06-13 7:45 ` Herbert Xu
2005-06-13 8:10 ` Willy Tarreau
2005-06-13 20:57 ` [PATCH] fix small DoS on connect() David S. Miller
2005-06-12 13:36 ` [PATCH] fix small DoS on connect() (was Re: BUG: Unusual TCP Connect() results.) Willy Tarreau
2005-06-12 14:44 ` Thomas Graf
2005-06-12 15:02 ` Willy Tarreau
2005-06-12 17:10 ` Denis Vlasenko
2005-06-12 17:36 ` Willy Tarreau
2005-06-12 17:47 ` Denis Vlasenko
2005-06-12 18:14 ` Willy Tarreau
2005-06-13 2:04 ` Valdis.Kletnieks
2005-06-11 15:34 ` BUG: Unusual TCP Connect() results Alastair Poole
2005-06-11 14:38 ` Willy Tarreau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050610222645.GA1317@pcw.home.local \
--to=willy@w.ods.org \
--cc=alastair@unixtrix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xschmi00@stud.feec.vutbr.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®