lkml.org 
[lkml]   [1999]   [Feb]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: bind/connect: correct behaviour?
Hi Andi,

you wrote:
> > Obviously the process has just connected to itself
> > on port 515 - though it never did an accept(). Is this to be expected?
> > This is with kernel 2.2.1.
> Yes. The three-way handshake for a listen socket proceeds asynchronous to
> the process. accept only sees connections when they are completely established.

Could you please explain? I see no socket in state listening in the code
I wrote from the inspiration given by Roderich. For me it just looks
like a simultanous open. IMO it's not a good idea to get a socket
connected to itself. Atleast it does not crash the system as it did in
MS Windows.


#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>

int sk;
struct sockaddr_in sin;
int r;

int main(void)
{
sk = socket(AF_INET, SOCK_STREAM, 0);
if ( sk < 0 ) {
perror("socket");
return 1;
}

memset(&sin, 0, sizeof sin);
sin.sin_family = AF_INET;
sin.sin_port = htons(4444);
sin.sin_addr.s_addr = inet_addr("0.0.0.0");
r = bind(sk, (struct sockaddr *)&sin, sizeof sin);
if ( r < 0 ) {
perror("bind");
return 2;
}

system("/bin/bash -c \"netstat -ntua\"");

memset(&sin, 0, sizeof sin);
sin.sin_family = AF_INET;
sin.sin_port = htons(4444);
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
r = connect(sk, (struct sockaddr *)&sin, sizeof sin);
if ( r < 0 ) {
perror("connect");
return 3;
}
system("/bin/bash -c \"netstat -ntua\"");

return 0;
}


The kernel(*) source does state in tcp_input.c:tcp_rcv_state_process:

if(th->ack) {
...
} else {
if(th->syn && !th->rst) {
/* The previous version of the code
* checked for "connecting to self"
* here. that check is done now in
* tcp_connect.
*/

Seems the connect to itself is not what we want but the check fails. I
can not even find the check in tcp_connect. As I far as I understand the
usage of this function it even would not block connects with source
address fake to equal destination.


Malware

(*) source is version 2.2.1-ac5, running is version 2.2.1-ac2

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:50    [W:0.046 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site