Bug 12754 - Linux bug in _wapi_setsockopt implementation
Summary: Linux bug in _wapi_setsockopt implementation
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-06-19 02:48 UTC by benoit
Modified: 2014-07-29 08:04 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description benoit 2013-06-19 02:48:08 UTC
In the code below (from _wapi_setsockopt  in https://github.com/mono/mono/blob/master/mono/io-layer/sockets.c), tmpval points to a deallocated bufsize int variable and as a result the socket buffer size is sometime set to a random value (we've seen this occurring on latest Ubuntu versions in particular...).


#if defined (__linux__)
	} else if (level == SOL_SOCKET &&
		   (optname == SO_SNDBUF || optname == SO_RCVBUF)) {
		/* According to socket(7) the Linux kernel doubles the
		 * buffer sizes "to allow space for bookkeeping
		 * overhead."
		 */
		int bufsize = *((int *) optval);

		bufsize /= 2;
		tmp_val = &bufsize;
#endif
	}
Comment 1 Narinder 2013-11-07 18:49:55 UTC
Hi,
I have some interest in this bug as I have just reported :
https://bugzilla.xamarin.com/show_bug.cgi?id=16021

However, I am not convinced (although I could be completely wrong ) that the explanation above is correct.

I think when you say "deallocated bufsize int variable" you mean de-referenced ?
If so, then if you look here :

http://linux.die.net/man/2/setsockopt

and here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms740476(v=vs.85).aspx

you'll see that the fourth parameter indeed should be a pointer to the int value not the int value itself, hence the definition of tmp_val looks correct to me.

Rgds
N
Comment 2 Narinder 2013-11-08 14:54:26 UTC
Benoit,

I've just realised what you meant. Sorry for misunderstanding. The variable bufsize is indeed local to the else if {} block. Then attempting to use tmp_val (it's address) in the code that follows the block :

#endif
	}
		
	ret = setsockopt (fd, level, optname, tmp_val, optlen);

is clearly a bug.

Fixing this finally resolves my issue.

Rgds
N
Comment 3 Andres G. Aragoneses 2014-01-02 06:48:43 UTC
The bug was fixed in https://github.com/mono/mono/commit/bbd4ee4181787189fbb1f8ba6364afdd982ae706, can someone mark the bug as RESOLVED->FIXED?