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

941

u/AReallyGoodName Apr 09 '14

Fucking hell. The things that had to come together to make this do what it does and stay hidden for so long blows my mind.

A custom allocator that is written in a way so that it won't crash or show any unusual behavior when allocation bounds are overrun even after many requests.

A custom allocator that favours re-using recently used areas of memory. Which as we've seen, tends to lead it to it expose recently decoded https requests.

Avoidance of third party memory testing measures that test against such flaws under the guise of speed on some platforms.

A Heartbeat feature that actually responds to users that haven't got any sort of authorization.

A Heartbeat feature that has no logging mechanism at all.

A Heartbeat feature that isn't part of the TLS standard and isn't implemented by any other project.

A Heartbeat feature that was submitted in a patch on 2011-12-31 which is before the RFC 6520 it's based on was created. By the same author as the RFC.

Code that is extremely obfuscated without reason.

PHK was right

329

u/pmrr Apr 09 '14

I bet the developer thought he was super-smart at the time.

This is a lesson to all of us: we're not as smart as we think.

514

u/zjm555 Apr 09 '14

Well said. This is why, after years of professional development, I have a healthy fear of anything even remotely complicated.

351

u/none_shall_pass Apr 09 '14

Well said. This is why, after years of professional development, I have a healthy fear of anything even remotely complicated.

After spending the late 90's and early 2000's developing and supporting high profile (read: constantly attacked) websites, I developed my "3am rule".

If I couldn't be woken up out of a sound sleep at 3am by a panicked phone call and know what was wrong and how to fix it, the software was poorly designed or written.

A side-effect of this was that I stopped trying to be "smart" and just wrote solid, plain, easy to read code. It's served me well for a very long time.

This should go triple for crypto code. If anybody feels the need to rewrite a memory allocator, it's time to rethink priorities.

220

u/frymaster Apr 09 '14

A side-effect of this was that I stopped trying to be "smart" and just wrote solid, plain, easy to read code

There's a principle that states that debugging is harder than writing code, so if you write the "smart"est possible code, by definition you aren't smart enough to debug it :)

176

u/dreucifer Apr 09 '14

"Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" -- Brian Kernighan The Elements of Programming Style

→ More replies (1)

36

u/none_shall_pass Apr 09 '14

That works.

I've always thought that complex code was the result of poor understanding of the problem or bad design.

73

u/BigRedRobotNinja Apr 09 '14

Complication is what happens when we "solve" a problem that we don't understand.

0

u/[deleted] Apr 09 '14

[deleted] — view deleted comment

18

u/thermite451 Apr 09 '14

GET OUT OF MY HEAD. I got 2hrs down that road one day before I realized I was being TRULY stupid.

→ More replies (2)
→ More replies (2)
→ More replies (14)
→ More replies (3)

30

u/ericanderton Apr 09 '14

We had this discussion at work. Halfway through, the following phrase lept from my mouth:

Because no good thing ever came from the thought: "Hey, I bet we can write a better memory management scheme than the one we've been using for decades."

38

u/wwqlcw Apr 09 '14

Years ago I was maintaining a system that had its roots in the DOS days. Real-mode, segmented addressing.

My predecessor had some genuine difficulties with real mode, there were structures he wanted to keep in RAM that were too big for the segments. That was a genuine issue for many systems at the time.

The easiest solution would have been to be a little more flexible about his memory structures. Another choice might have been to license a commercial memory extender. He opted to instead roll his own version of malloc.

I would not consider myself to be qualified to undertake such a project, but he was if anything less qualified.

I only discovered all of this at the end of an 11 hour debugging session. The reason my memory was becoming corrupt was because of bugs in the allocator itself. By the time I was working on this project, the compiler had better support for large memory structures, and I was able to fix it by deleting his malloc and twiddling some compiler flags.

Lo and behold, a zillion other bugs went away. And the whole system got faster, too.

The trouble is, if you're not cautious enough to be given pause by the notion of implementing memory management yourself, you're almost certainly the kind of person who needs that pause the most.

→ More replies (3)
→ More replies (3)
→ More replies (9)

163

u/emergent_properties Apr 09 '14

But remember The Linux Backdoor Attempt of 2003

A malicious bug can hide in 1 line of code in plain sight.

Looking complex is not even necessary.

77

u/zjm555 Apr 09 '14

I do indeed remember that :) This is why some teams rigidly enforce, as a coding style rule, that comparisons against literals always have the literal on the left-hand side.

67

u/[deleted] Apr 09 '14

54

u/DarkNeutron Apr 09 '14

Several bugs have I written that this would catch...

42

u/tequila13 Apr 09 '14

As someone who had to maintain Yoda-style code, that's not funny.

43

u/GratefulTony Apr 09 '14

funny: it is not.

→ More replies (10)
→ More replies (1)

45

u/syncsynchalt Apr 09 '14

I prefer to trust the compiler's warnings on this one. I've had to maintain yoda code and it's terrible to read.

→ More replies (14)
→ More replies (14)
→ More replies (25)

26

u/CheezyBob Apr 09 '14

I wish more of my co-workers thought like you. As a programmer, our job should be to manage and reduce complexity whenever possible. Software gets complex plenty fast without adding extra complexity just because it was fun, made you feel smart or was more "optimized".

→ More replies (2)
→ More replies (10)
→ More replies (61)

64

u/dnew Apr 09 '14

submitted in a patch on 2011-12-31 which is before the RFC 6520 it's based on was created. By the same author as the RFC.

To be fair, that's not particularly suspicious. "Hey, I improved the implementation of this protocol I use. We ought to make that a standard so other implementations can add that to the protocol also."

I.e., if RFC-6520 was written by the same author, the patch wasn't based on the RFC. The RFC was based on the patch. Indeed, they're called "requests for comments" for that reason: "Look what I did. What do you think?"

I don't know of any RFC that was written before the first implementation was coded.

→ More replies (16)

94

u/iownacat Apr 09 '14

Code that is extremely obfuscated without reason

The reason is to hide these exploits :)

→ More replies (3)

14

u/xiongchiamiov Apr 09 '14

I generally find that PHK is right about things. He seems to have a really well-tuned engineering spidey-sense.

→ More replies (40)