LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-27-2016, 08:47 AM   #1
sillysrik
LQ Newbie
 
Registered: Jan 2016
Posts: 1

Rep: Reputation: Disabled
Binding twice on the same ip/port pair became success


Hi,

I observed one instance in my program, where 2nd bind on same ip/port pair became success instead of failure.
I have made below set socket options before bind.

Fun1()
{
..........
fd1 = socket (AF_INET, SOCK_DGRAM, 0);
setsockopt(fd1, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof (optval))
then called bind...
}

Fun2()
{
fd2 = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
setsockopt(fd2, SOL_SOCKET, SO_REUSEADDR, (char*)&unOptVal, sizeof(unOptVal)))
then called bind.......
}
i am expecting 2nd bind call to be failed, but it became success.
And output of netstat command displays two instances as below

# netstat -apn |grep -i 9897
udp 0 0 127.0.0.1:9897 0.0.0.0:* 5011/abc.vx
udp 0 0 127.0.0.1:9897 0.0.0.0:* 5011/abc.vx

Please help me understanding this behavior, how data from two different sockets are read?

Thanks,
Srik,
 
Old 01-27-2016, 06:20 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
SO_REUSEADDR.

Don't do that.

Personally, I don't know WHY this is there, as it allows for significant security problems.

The security problem is that two different users can connect to the same port/address and get each others data.

It is intended to allow a server to rebind to a socket in case the previous server has died and the socket is still open until the timeout occurs... Unfortunately, it also allows OTHER servers to also connect.... and leave security problems in its wake.

A user application/server doing this allows multiple users to connect... and the corresponding security failures happen again.

And yes, I got bit by this - fortunately, local user testing identified the problem so I could remove it before a general release happened.

Last edited by jpollard; 01-27-2016 at 06:22 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
binding port mokku Linux - Newbie 4 11-10-2007 06:51 PM
Azureus port binding G00fy Linux - Networking 0 07-18-2006 03:15 AM
error binding address/port blackzone Linux - Networking 1 09-03-2004 03:23 AM
PsyBNC not binding on port 80. Adam15906 Linux - Software 1 06-10-2004 12:24 PM
Socket binding to port problems Xris718 Linux - General 0 07-10-2003 02:04 PM


All times are GMT -5. The time now is 08:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration