r/programming • • Apr 09 '14

Theo de Raadt: "OpenSSL has exploit mitigation countermeasures to make sure it's exploitable"

[deleted] — view deleted post

2.0k Upvotes

661 comments sorted by

View all comments

Show parent comment

408

u/Aethec Apr 09 '14

Theo de Raadt says the memory allocation and release methods on modern systems would've prevented the "Heartbleed" flaw, but OpenSSL explicitly chose to override these methods because some time ago on some operating systems performance wasn't very good. Also, they didn't test the code without this override, so they couldn't remove it once it wasn't needed any more.
Now, a significant portion of Internet servers have to revoke their private keys and regenerate new ones, as well as assume that all user passwords may have been compromised... because the OpenSSL guys "optimized" the code years ago.

22

u/adrianmonk Apr 09 '14 edited Apr 09 '14

How would these have prevented the heartbleed flaw? In not seeing it. The flaw is caused by trusting an external source to tell you how big of a size argument to pass to memcpy() (and malloc()).

EDIT: OK, they're talking about guard pages. Guard pages would use the MMU to detect when something is reading or writing in a place where it shouldn't be.

40

u/Aethec Apr 09 '14

Because the memory accessed by that flaw is often memory that was freed before, so there's an opportunity to prevent the program from accessing it since it shouldn't do so.

20

u/Beaverman Apr 09 '14

In case someone isn't fluent in C and memory management. If you try to read, write, or copy memory that your process doesn't own then most operating systems will terminate your program to protect the integrity of the memory.

The "hearthbleed" bug was caused by the program being allowed to copy memory which was already freed by the program, since some abstraction layer actually didn't free it, but cached it itself.

That's how i understand it, i might have misunderstood something.

16

u/[deleted] Apr 09 '14

It doesn't work like that.

Program gets terminated because you are reading memory which is not backed by storage. Typically there is no way you can address "memory that your process doesn't own", let alone read or write it.

15

u/Beaverman Apr 09 '14

Now we are getting into the whole Physical VS virtual memory i feel. But if i malloc and get a pointer to 0xDEADBEEF i can read from however big i chose to get. If i then free that memory, i still the memory still contains the data it contained just a second ago, the OS just flags it as not mine anymore. If i now try to read it i get terminated with a segfault, even though the memory is still physically there.

→ More replies (2)

6

u/adrianmonk Apr 09 '14

copy memory which was already freed by the program

No, the memory wasn't necessarily freed. The only properties we can confidently state about memory is:

  • It's adjacent to the memory that should have been read.
  • It's readable.
→ More replies (6)

2

u/cparen Apr 10 '14

Spot on, but you should add that the caching leads to order-of-magnitude improvements in performance.

The criticism is that most systems now include both caching and security enhancements. By using their own allocator, OpenSSL doesn't get the advantage of the security enhancements.

5

u/adrianmonk Apr 09 '14

That's not quite what guard pages do. And they are talking about setting MALLOC_OPTIONS=G.

→ More replies (2)

49

u/obsa Apr 09 '14

You don't get to put quotes around optimized. It was a legitmate optimization at the time. Whether or not it should have been done, or if it could have been done better, is a different debate entirely.

19

u/Gloinson Apr 09 '14 edited Apr 10 '14

No it wasn't. OpenBSD malloc may be bad, ugly and slow, but computers have been fast enough for more than a decade. It has been for a long time the greater goal to make them more secure ... which is incidentally the goal of OpenBSD.

It is somewhat of a unfunny joke that they did wrap malloc especially because of OpenBSDs mallocs being so slow and thereby undermined the focus on security in that OS. They could have reengineered the code to use less malloc/free (pointed out by Fefe on his blog) ... but anybody who ever looked into OpenSSL code knows that it is ... difficult, to say the least.

Edit: I relied for the italic part on Fefe. Either I misread him from the beginning or he toned down his article on that point.

→ More replies (6)

0

u/[deleted] Apr 09 '14

[deleted] — view deleted comment

120

u/matthieum Apr 09 '14

It's a difficult point to make though, let's not forget that not so long ago websites shunned https because it was too slow compared to http. Therefore without performance there was no security.

49

u/ggtsu_00 Apr 09 '14

Not entirely. OpenSSL wasn't always openly accepted. Many years ago, most server operators wouldn't even bother to put any encryption security on the their servers because of performance concerns. At that time, decrypting and encrypting every packet coming to and from the server could greatly decrease the amount traffic the server could handle. It still does to this day but server costs have gone down to where this is no longer a major concern. Making TLS efficient really helped its adoption where as before, many sites that required encryption often relied on non-standard custom built poorly implemented client side security modules as ActiveX plugins built specifically for IE.

11

u/chromic Apr 09 '14

Sadly, that isn't true. If you released a "god crypto library" that had a 100% guarantee of correctness, but ran 100 times slower than OpenSSL, very few would use it in production.

At best it's used to test against, and even then a bug like heartbleed in OpenSSL would go unnoticed since it behaved nearly correct for average use.

4

u/foldl Apr 09 '14

That's not entirely true. There isn't much value in a 100% secure library which isn't fast enough to be usable. Without looking at the performance data they based their decision on, we can't really judge whether or not it was appropriate. It's much too easy to criticize these sorts of implementation decisions in retrospect. The fact is that this has been part of an extremely well-known open source code base for years and no-one has complained about it until now, with the benefit of hindsight.

5

u/Aethec Apr 09 '14

I get to put quotes because making the code faster but less readable isn't necessarily an improvement, especially in a library that needs to be understandable because of its importance.

→ More replies (1)
→ More replies (3)

0

u/[deleted] Apr 09 '14

[deleted] — view deleted comment

51

u/SquareWheel Apr 09 '14

It wasn't premature, though. They considered it a problem at the time and wrote a "fix" for it.

79

u/chengiz Apr 09 '14

The problem here is that it's fucking OpenSSL. Performance should be secondary to security. If you're running a numerical math library and profiled it and found some malloc implementations to be slow, by all means roll out your own memory managers that work consistently everywhere. But you're OpenSSL. You should think about this a hundred times. A thousand times. Theo de Raadt is correct - this is not a responsible team.

63

u/Plorkyeran Apr 09 '14

Performance is actually very important for OpenSSL, and is one of the reasons why Chrome is considering switching to it from NSS. It doesn't do any good to have a correct crypto implementation that's so slow that people don't use it (and the performance overhead was for a long time a common argument against using HTTPS for everything). Of course, that's not to say speed is more important than correctness, as obviously fast crypto that isn't actually secure is even more useless, just that both are important.

→ More replies (2)

17

u/happyscrappy Apr 09 '14

Performance is important, because people want to use SSL for everything. https everywhere, remember? So the overhead of SSL really does matter. You may only used it to ssh into your machine, but people out there have systems that want to service hundreds or thousands of SSL connections at once. So performance does matter.

Sure it's secondary to security, but they didn't think they compromised security with this change.

→ More replies (6)

8

u/sirin3 Apr 09 '14

numerical math library

Which will then be used to big ints in crypto software?

→ More replies (7)

13

u/[deleted] Apr 09 '14

Premature optimization is one of the worst practices you can ever do.

Can anyone explain to me why am I being downvoted?

Broad stroke generalized statements that apply one way of thinking to ALL situations is inherently incorrect.

→ More replies (4)
→ More replies (1)
→ More replies (2)