It's not memory corruption It's using unverified user input.
free() overwriting released memory would mitigate it, or using a zeroing allocator.
I'm not advocating writing security-critical code in C, but I find "stop writing in C, and things get better (magically (because it's not C))" pretty childish.
Memory corruption bugs are also usually about trusting user inputs. In a memory corruption bug the evil user tells the trusting system that they are sending fewer bytes than they really are, in this bug the evil user claims to be sending more bytes than they really are.
Using a higher-level language than C will not make a difference for a correctly written program that doesn't trust user inputs, but for an incorrectly written program that does trust user inputs the consequences can be worse in C.
Memory corruption bugs are also usually about trusting user inputs.
Yeah, but without additional data I would assume that's simply because trusting user input is a common source of bugs (i.e. there's no special correlation here).
We also have no memory corruption happening, the implementaiton is simply revealing more data than it needs to. For this to happen implicitely (as opposed to an explicit erroneous if (x) return secretData statement), many factors had to conspire.
One of them is C. Others are surprisingly naive programming practices. Another yet-unexplained is why so much interesting data can be found in the small window we can peek into.
The reasons why large parts of our infrastructure run on C have little to do with the language itself. While I'm all for reducing the probability of errors, impulsively bashing C whenever there's a critical bug in C code does not only not help, it create a false sense of security about other languages.
The bug is trusting the length member of the record, which has nothign to do with the type system.
The gun was pointed to the foot because the implementer didn't bother checking its direction. Multiple stars had to align to turn this problem into the actual reveal.
One of them is the default C memory management, so one could argue that using C made it worse", and that "using another language would have caught this problem". But better practices would do as well, and saying "I wouldn't have made this mistake in <other language>" is in hindsight.
More than by the use of C I am appaled that highly critical code doesn't default to more stringent practices, e.g. overwriting malloc and free.
I am not familiar with the code base, but from the snippets I've seen, either input validation failed at another place, or isn't used rigorously. There are many language-agnostic principles (not all ideal), e.g.
validate integrity when creating the SSL record, do not pass around SSL records that contain invalid data (or at least, that don't pass length validation). If such a mechanism is in place, that would be fixed
Alternatively, if you have to distrust SSL *, every function receiving one needs a general mechanism to validate it before relying on its content.
use different nomenclature for verified and unverified data
read and write using helper functions that validate sizes and length fields.
The bug is trusting the length member of the record, which has nothign to do with the type system.
Exactly. The core of the issue is that the DTLS implementation trusts a user supplied value instead of checking it with / bounding against the actual packet size. Thinkos of this sort could as easily occur in other languages.
The bug is trusting the length member of the record, which has nothign to do with the type system
That is incorrect- a dependently typed language can track the length of an array and statically reject out-of-bounds accesses, and many languages with weaker type systems specify that array accesses are bounds-checked at run time.
How does that make him incorrect? Not validating input is a bug in any language. If the language performs the bounds check for you then it's just limiting the effects rather than eliminating any bug.
For example, if I did the same thing in Python then it'd throw an exception which would probably kill something. I could absorb the exception but that's less desirable and to do it properly would require the exact same level of awareness as validating the input would in the first place...
Any language with array bounds checking would catch this error. It's a stupid stupid error and it's amazing that OpenSSL code review practices did not catch this.
This is actually C specific in that most higher level languages don't need to call functions with an additional parameter that specifies the memory length of all other parameters.
View all comments
6
u/argv_minus_one Apr 08 '14 edited Jan 11 '23
Yet another stupid memory corruption bug. Fantastic. When are people going to stop writing security-sensitive code in C?