Bogus buffer length check in linux-2.6.11 read()
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · linux-os
The attached file shows that the kernel thinks it's doing something helpful by checking the length of the input buffer for a
read(). It will return "Bad Address" until the length is 1632 bytes. Apparently the kernel thinks 1632 is a good length!
Likely because only 1632 bytes of memory is accessible after the start of the buf buffer, and trying to read in more than that results in copy_to_user failing to write some data.
Quoted 6 lines
Did anybody consider the overhead necessary to do this and the fact that the kernel has no way of knowing if the pointer to the buffer is valid until it actually does the write. What was wrong with
copy_to_user()? Why is there the additional bogus check?
What additional check?
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/
Quoted 10 lines · Robert Hancock
Quoted 6 lines · linux-os
The attached file shows that the kernel thinks it's doing something helpful by checking the length of the input buffer for a
read(). It will return "Bad Address" until the length is 1632 bytes. Apparently the kernel thinks 1632 is a good length!Likely because only 1632 bytes of memory is accessible after the start of the buf buffer, and trying to read in more than that results in
copy_to_userfailing to write some data.
There was NO DATA read or written! The read() call returns immediately without reading anything. Look at the code, assume nothing. This is a blocking read from standard-input.
Quoted 9 lines
Quoted 6 lines
Did anybody consider the overhead necessary to do this and the fact that the kernel has no way of knowing if the pointer to the buffer is valid until it actually does the write. What was wrong with
copy_to_user()? Why is there the additional bogus check?What additional check?
Somebody added some very dumb check of the input value of a read() length that occurs before anything is actually read.
Previously, a read(), which is a kernel write to user-data space, would seg-fault if the read exceeded the data-space that had been mapped. It is done by the CPU, it generates a trap. The performance cost, when done by the CPU, if the data doesn't exceed bounds, is zero. Now, there is a beginning check (a wrong check BTW), in software, before the data is even obtained from the device.
Quoted 11 lines
Signature · 9 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 22 lines · linux-os
I don't know how much more precise I could have been. I show the code that will cause the observed condition. I explain that this condition is new, that it doesn't correspond to the previous behavior.
Never before was some buffer checked for length before some data was written to it. The EFAULT is supposed to occur IFF a write attempt occurs outside the caller's accessible address space. This used to be done by hardware during the write to user-space. This had zero impact upon performance. Now there is some software added that adds CPU cycles, subtracts performance, and cannot possibly do anything useful.
Also, the code was written to show the problem. The code is not designed to be an example of good coding practice.
The actual problem observed with the new kernel was when some legacy code used
gets()instead offgets(). The call returned immediately with an EFAULT because the 'C' runtime library put some value that the kernel didn't 'like' (4096 bytes) in the subsequent read.
Quoted 7 lines
This is code for which there are no sources available and it is required to be used, cannot be replaced, cannot be thrown away and costs about US$ 10,000 from a company that is no longer in business.
Somebody's arbitrary and capricious addition of spook code destroyed an application's functionality.
It appears this was added by the patch shown here:
http://lwn.net/Articles/122581/
The reason given was that if the read or write doesn't use all of the available space due to end-of-file, etc. the remaining part of the buffer given by the user is not checked for accessibility, thereby hiding bugs. It makes little sense for an app to do a read or write with a buffer larger than the space that they've actually allocated.
I can see how this might be a problem when using gets, since there is no way to know how big the buffer that has been allocated by the application is.
Note that access_ok only does a rudimentary check to determine if the address might be a valid user-space address, it does not check every page to determine if it is accessible or not like verify_area did (and copy_to/from_user does).
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/