by BoppreH · 11y ago · 0 comments
This is security critical code, being developed and polished for more than a decade, and the only thing protecting the privacy of millions (billions?) of people. If any public project should have gotten this right, it should be this. Yet it can't.
Is this time to admit we simply can't do manual memory management at this level and move to something else? I know the performance boost is tempting, but I think we can't afford the consequences.
OpenBSD uses a whole lot of C and doesn't tend to have these problems...
I'm not at all sympathetic to calls to ban some programming tool because it's "too hard". Just stop trying to squash harsh criticism as "toxic culture", this is how you imbue in people the importance of being careful with important code. Otherwise, even if they acknowledge that they should be careful, they'll write sloppy code, and it might even become popular, and you might have to support it...
On the other hand, I've also worked on some codebases that were very well-documented with respect to this: every function that either returned a pointer or accepted pointers made it clear if/when they should be freed (and if so, with what function.) One example of that looks like:
void /* OWN */ *some_func(void *a, void /* OWN */ *b, void */* OWN */*c);
And the "/* OWN */" are intended to be read like "const" and "static", so this says the function returns a pointer to an object whose ownership is transferred to the caller, its first parameter does not change owners, the second one does, and the third is a pointer to an array of pointers whose ownership is passed to the function. The accompanying comment then says what function should be used to free the returned pointer, and what function will be used (by other code) to eventually free b and c.https://github.com/rust-lang/rust/issues/6268 https://github.com/rust-lang/rust/issues/6393
Those bugs are 2 years old. And heaven forbid you have &mut self in a object.
#define own
Then you don't need ugly comments... void own *some_func(void *a, void own *b, void * own *c);People have built a clean-slate TLS stack in OCaml and you can read about it on the MirageOS site [1]. There's also a Bitcoin Piñata built using this stack [2].
I'm told the performance is actually pretty good (though there's always room for improvement).
[1] http://openmirage.org/blog/introducing-ocaml-tls
[2] http://amirchaudhry.com/bitcoin-pinata/ and https://news.ycombinator.com/item?id=9027743
What OpenSSL needs to do is to throw away all the extra code that makes it run on a billion obsolete platforms, remove support for things that aren't needed (renegociating encryption algorithms? Really if a client supported it before it can support them now), wrap the internal parts of the library and port it to C++ so that they can use smart pointers, then ban malloc.
Manual memory management isn't dangerous, malloc and low level primitives are (e.g you should never manually append strings, other than in your string library, which should automatically resize the strings as needed).
That is somewhat self-contradictory. Those "low level primitives" are manual memory management, so even by your own admission it is dangerous. Even Wikipedia calls smart pointers "automatic memory management."
We can have a debate about whether RAII is "manual memory management" or not, but it's clearly safer than malloc/free without the inefficiency of garbage collection.
Awful idea. The absolute last thing we want is for memory management to be out of OpenSSL's explicit control (then we would have two audit trails to worry about). Automatic memory management is manual memory management you've outsourced to somebody else.
(By this same argument, you also shouldn't turn on compiler optimizations when you build openssl.)
That was one of the first things the LibreSSL team ripped out.
The memory management will have to be done manually at some point.
(Same for Java, or C#, or what have you, though each connection would probably be in a try/catch so no real harm done, most likely.)
A big difference is that the developer would have made the explicit choice at that point to dereference a pointer know to possibly be null. There's no implicit null (and having to wonder "by hand" for each pointer whether or not it could be null, with the risk that changes in any previous operation make make non-nullable pointers nullable without warning).
> Same for Java, or C#, or what have you
Java and C# also use implicit pervasive nullability, and at least deref'ing a null pointer there is a defined behavior.
It is the result of too many cooks in the kitchen. Some of who in fact are not cooks.
Many people work on manual memory management for a reason http://event.scaladays.org/scaladays-sanfran-2015#!#schedule...
Security is a practice, not a programming language. Anthem uses C# and they are hacked almost every year. https://www.anthemfacts.com/