r/programming •

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

[deleted] — view deleted post

0 Upvotes

661 comments sorted by

View all comments

1

u/looneysquash Apr 09 '14

I'm not defending OpenSSL in general. I don't know enough about it's internals to comment on it.

But caching memory allocated by malloc() is a pretty common technique. It's not an unreasonable thing to do, and it does not automatically make someone an unreasonable developer.

Doing something like that unconditionally is usually better than doing it conditionally. Maybe some platform has a really fast malloc and it's not necessary, but if you have two code paths, then you have two code paths to debug. (In this case apparently they did support both ways, but the one that wasn't used unsurprisingly didn't work.)

11

u/hegbork Apr 09 '14

But caching memory allocated by malloc() is a pretty common technique. It's not an unreasonable thing to do, and it does not automatically make someone an unreasonable developer.

If someone does this without credentials proving that they've successfully worked in memory management on a real operating system the code gets immediately rejected in review. Clever memory caching is what every malloc does internally, except that the people who wrote malloc hopefully know what they are doing and the average developer doesn't.

There was an excuse to do this on VAX where function call overhead was big, mallocs inefficient, memory small so fragmentation wasn't a problem and heap overflow exploits weren't invented yet.

Malloc is much slower than your freelist? There are options:

  1. You are smarter than whoever wrote it, the glow of your genius outshines the sun, people should bow at your mad skillz.
  2. malloc does those slow things for many reasons that the developers have figured out over decades of debugging and experience. You're disabling important security, debugging, performance and anti-fragmentation features that will bite you when you least expect it leading to undebuggable problems at the worst possible time.
  3. You're in the 0.01% of use cases where a certain use pattern of memory in critically performance sensitive code that just has to use dynamic allocation in the hot path improves things so vastly it is the difference between something working and not working.
  4. You're using an operating system that is shit. Use an external malloc library. You are not the first one to have this problem. One of the dozen popular malloc implementations has surely been ported to your system.
  5. You learned programming in the 80s and are of the opinion that nothing worth knowing has happened since then.

2

u/looneysquash Apr 09 '14

Here's an example: glib Memory Slices.

I've used it before. It sped up my code.

If malloc is slower than my freelist, it's probably because malloc is a very generalized tool and my freelist, or the one I'm using, is much more specialized.

3

u/hegbork Apr 09 '14

The first thing I did when I clicked on that page was Ctrl-f Bonwick and there it is. Therefore I already know that whoever wrote this at least have half a clue of what they are doing. A reference to Bonwick would prevent immediate rejection in code review. It's not a "let's make a singly linked list where we put the last freed chunk in the head" (what OpenSSL did) it's a generalized subsystem with at least some design and research behind it.

Although they are using cache coloring and as far as I know cache coloring has been pretty much abandoned in recent years because it doesn't really map to how modern caches work and can in the worst case increase the cache footprint, so that's a small warning sign. I'm pretty sure the second incarnation of the Bonwick allocator didn't use cache coloring (the first one did because it was still targeting sparcs with their direct mapped caches). I could be wrong, I haven't really followed the trends in the past few years.

btw. If you're even remotely interested in memory management read the Bonwick papers referenced from that documentation. They are quite amazing. Smart as hell and well written.

2

u/RoadieRich Apr 09 '14

It looks like a quick and easy fix - even if it's just a temporary one - is to add a line or two to set the memory contents to zero immediately before it is released back to the cache. You're not disabling the cache just yet, but you're removing (at least, as I understand it) the cause of this exploit. Or am I misunderstanding the vulnerability?

1

u/indeyets Apr 10 '14

set the memory contents to zero

That's expensive, so it is avoided in speed-oriented approaches