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

150

u/tenpn Apr 09 '14

Can someone explain that in english?

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)
→ More replies (1)

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 (7)
→ More replies (10)
→ More replies (29)

170

u/turol Apr 09 '14

OpenBSD has protections in place to mitigate this kind of bug. Instead of leaking info it should crash the program. The side effect is slightly slower malloc/free.

OpenSSL developers decided that on some platforms malloc/free is too slow and implemented their own allocators on top of it. This neatly sidesteps the exploit mitigation features.

0

u/[deleted] Apr 09 '14

[deleted] — view deleted comment

26

u/tdammers Apr 09 '14

They are independent, but OpenSSL throws away one while solving the other, that is, it uses a custom memory allocator to "fix" the slow performance of the platform-provided malloc, and in doing that, also bypasses the security checks of the default allocator.

8

u/shub Apr 09 '14

Tests don't pass if you turn off the allocator cache.

30

u/hegbork Apr 09 '14

And since they appear to be equivalent to malloc and free the question is which other bugs in OpenSSL those allocator wrappers hide.

8

u/ajanata Apr 09 '14

So fix the code that fails when you turn off the allocator cache. If you simply "must" use it, then it shouldn't even be an option to compile without it.

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

21

u/emergent_properties Apr 09 '14

Choices to override default security behavior should be a BIG red flag.

We didn't notice because either no auditing was done, shitty auditing was done, or the auditing didn't matter.

Because bounds checks are one of the oldest exploitation techniques..

31

u/WhoTookPlasticJesus Apr 09 '14

To be fair, there's no indication that they rolled their own mem management explicitly to avoid security protection nor that the OpenSSL team was even aware of the security benefits of built-in malloc and free. If you've ever spent any time in the OpenSSL codebase I think you'll instead come to the same conclusion as I: it was a hazardous combination of incompetence and hubris.

→ More replies (3)

69

u/willvarfar Apr 09 '14
  • OpenSSL has been run on a very wide range of platforms and architectures.
  • It's performance is critical.
  • At one time, they found that some platforms had very very slow malloc()
  • So they wrote their own.

Its enabled by default, and they've long stopped testing it disabled.

54

u/criolla Apr 09 '14 edited Apr 09 '14

At one time, they found that some platforms had very very slow malloc()

Are the specifics of this documented somewhere? In a commit message?

What platforms? How slow? That little comment is very sloppy and written with a "this is the way it is, for all time" arrogance.

edit: here's the full comment and the relevant commit. Any further details are not documented there as far as I can see.

20

u/xiongchiamiov Apr 09 '14

Memory saving patch.

I mean, what more could you want from a commit message? /s

→ More replies (1)

7

u/ciny Apr 09 '14

so he basically changed the way memory is allocated because 1 in a million users could experience slow performance.

→ More replies (1)

7

u/[deleted] Apr 09 '14

its performance is critical

I can definitely see that for Yahoo!, Google et al. But I wonder how critical the performance would be for the bottom 95% of sites? The bottom 50%?

Where is the threshold where security trumps performance? Certainly I would rather my bank run a more expensive/powerful server than be vulnerable to Heartbeat for two years.

Surely there'd be a market for an extra-fortified, not-as-fast version of SSL?

5

u/RICHUNCLEPENNYBAGS Apr 10 '14

I think the performance argument is also belied by technologies people choose to actually host their Web sites. PHP, C#, Java, RoR... I don't see the people using C and C++ to write Web apps.

→ More replies (3)