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

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:

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;
Comment 1 Narinder 2013-11-07 18:49:55 UTC
I have some interest in this bug as I have just reported :

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 :


and here:


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.

Comment 2 Narinder 2013-11-08 14:54:26 UTC

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 :

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

is clearly a bug.

Fixing this finally resolves my issue.

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?