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

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 (4)

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.

→ More replies (21)
→ More replies (1)

32

u/ismtrn Apr 09 '14

Sometimes you have to be quite clever to find the simple solutions though.

→ 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 (5)

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.

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 (13)

27

u/IICVX Apr 09 '14 edited Apr 09 '14

Unfortunately some people try to enforce that sort of thing in languages that aren't C and C++, where you'll actually get type errors because you're trying to put an integer or something where a boolean should go.

Edit: though to be fair, you do see that sort of thing in Java with the whole CONSTANT.equals(variable) thing, but that's just due to Java's handling of the billion dollar mistake.

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

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 (1)

6

u/mycall Apr 09 '14

The best program is one you don't have to write.

10

u/[deleted] Apr 09 '14

Hence the legal disclaimer...

  • THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  • EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  • IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  • PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  • ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  • SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  • NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  • LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  • HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  • STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  • ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  • OF THE POSSIBILITY OF SUCH DAMAGE.
  • ====================================================================
→ More replies (1)

12

u/DoelerichHirnfidler Apr 09 '14

Which makes you a great developer.

→ More replies (5)

58

u/emergent_properties Apr 09 '14

Nothing here implied intent.. but it also didn't discount it either.

Normally, I would say "Do not ascribe to malice to what could be incompetence." HOWEVER considering that this is probably one of THE most relied on packages.. and this is such a FAR REACHING BUG.. the author better have a damn good explanation.

It is speculation, but the converse is also true "Sufficiently advanced malice can be mistaken as incompetence."

What is the audit process? What is the proper discovery and reporting mechanisms of the people who developed OpenSSL?

16

u/amvakar Apr 09 '14

Normally I'd think like you, but OpenSSL is no stranger to no auditing. We had the Debian entropy clusterfuck, where downstream patches were never tested by anybody for years. And then we had the recent failure to implement the Dual EC DRBG algorithm,which was positive in this case for breaking a potential backdoor , but not encouraging considering it means that there are portions of the codebase that nobody has ever used in the history of the project floating around just waiting to break something important. And now this. The incompetence is simply too far reaching to allow a conclusion of malice. I refuse to believe that a good attacker infiltrating the project could not do better.

11

u/jsprogrammer Apr 09 '14

Better than two years of complete, undetectable access?

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

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.

3

u/kolmogorovcomplex Apr 09 '14

Just had a look at the RFC. Why does it list "GWhiz Arts & Sciences" in the authors section? Sounds like a front to me.

Also, 66% of the authors have the first name "Michael". Not sure what to think about that.

→ More replies (12)
→ More replies (1)

94

u/iownacat Apr 09 '14

Code that is extremely obfuscated without reason

The reason is to hide these exploits :)

23

u/myztry Apr 09 '14

Good reasons and bad reasons are both reasons.

→ More replies (2)

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.

10

u/infamous_blah Apr 09 '14

Is there a transcript for that video?

10

u/dezmd Apr 09 '14

In the PHK video, 44:49 cuts out an answer on his advice on how to explain the issue to politicians. Thats pretty fucking surreal.

→ More replies (1)

15

u/input Apr 09 '14

Thanks for the video really entertaining.

2

u/keper Apr 09 '14

Who is that guy? Is what he's talking about sourced somehow?

16

u/Baukelien Apr 09 '14

If it was sourced it would be a hell of a lot bigger news and he wouldn't be doing that talk at a hacker conference he'd be on tv somwhere.

As he said in the beginning of the talk:

It got me thinking, suppose I have a 1 billion dollar budget and I want to capture as much security as aI can what would I do?
[...]
Now I'm an NSA agent giving a briefing and I got lost and ended up here.

It's a thought experiment not him being the next Snowden.

3

u/[deleted] Apr 09 '14

How about the fact that the heartbeat feature was hardly used from what I've read?

3

u/lwdoran Apr 10 '14

I just finished watching that video. That was a very worthwhile 30 minutes. Thanks for link!

3

u/Lord_NShYH Apr 10 '14

PHK was right

"We have all the rooted CAs."

I have been paranoid to suspect this since early on in my career. The CA cartels are so damn powerful.

15

u/gigadude Apr 09 '14

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

First time is happenstance, second time is coincidence, third time is enemy action.

3

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

The NSA budget for putting flaws in commercial software is $250 millions. Snowden says RSA has accepted 10 millions to do that (they deny it) and Linus Torvalds confirmed he was approached to put some vulnerabilities inside the kernel.

Expect these things to have succeeded. We need audits and the sooner the better.

However, TLS has been considered as imperfect security as certificates have been known to be forgeable by authorities since a long time, so I don't think anyone relied on OpenSSL to hide from governments.

41

u/Entropius Apr 09 '14

Linus Torvalds confirmed he was approached to put some vulnerabilities inside the kernel.

No, he was making a joke. A joke you took too seriously.

http://mashable.com/2013/09/19/linus-torvalds-backdoor-linux/

"Oh, Christ. It was obviously a joke, no government agency has ever asked me for a backdoor in Linux," Torvalds told Mashable via email. "Really. Cross my heart and hope to die, really."

→ More replies (1)

12

u/tchebb Apr 09 '14

Linus Torvalds confirmed he was approached to put some vulnerabilities inside the kernel.

Do you have a source for this? I don't doubt the possibility that he's been approached, but all I can find are blogs who are interpreting what could very well have simply been a joke as a cut-and-dried "confirmation."

18

u/Entropius Apr 09 '14

He doesn't know what he's talking about.

http://mashable.com/2013/09/19/linus-torvalds-backdoor-linux/

"Oh, Christ. It was obviously a joke, no government agency has ever asked me for a backdoor in Linux," Torvalds told Mashable via email. "Really. Cross my heart and hope to die, really."

→ More replies (4)

2

u/rabbidpanda Apr 09 '14

I'm suspect about anything that claims to know how much the NSA is spending on anything, even when sourced by leaked documents. Their budget is basically a black box. When you consider how ineffective most government agencies are at keeping a budget even when they're supposed to, it seems pretty incredible to think the NSA takes the idea of a budget even a little seriously.

2

u/[deleted] Apr 10 '14

wow.. PHK was right on the money. Thanks for the video link!

2

u/reaganveg Apr 11 '14

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.

Here is the first published draft of the heartbeat feature:

http://tools.ietf.org/html/draft-ietf-tls-dtls-heartbeat-00

Note the date: June 18, 2010

Of course, that was a draft and not assigned an RFC number. The fact that an implementation was made is probably what got them to assign the RFC number. An implementation is "highly desirable" for RFCs seeking such status. See https://tools.ietf.org/html/rfc2026#section-4.1.2 :

Usually, neither implementation nor operational experience is required for the designation of a specification as a Proposed Standard. However, such experience is highly desirable, and will usually represent a strong argument in favor of a Proposed Standard designation.

2

u/optymizer Apr 09 '14

About the PHK video: HOLY SHIT.

1

u/albertowtf Apr 09 '14

thanks for the video

The insight is strong on that one

1

u/Arsene_Lupin Apr 10 '14

How come heartbeat messages are not logged at all? If they are network traffic then there could or should br some kind of logging. Can someone explain please

1

u/n3hima Apr 10 '14

I was at that talk and when this broke I just imagined what his reaction would be...

1

u/Darksair Apr 10 '14

Code that is extremely obfuscated without reason.

Totally agree.

→ More replies (16)

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.

→ More replies (12)

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

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.

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)

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.

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

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.

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.

1

u/newmewuser Apr 09 '14

Analogy: An ATM trusting in the customer about how much money he can withdraw.

123

u/sigzero Apr 09 '14

"OpenSSL is not developed by a responsible team."

Wow!

111

u/Catsler Apr 09 '14

Some coding style and functions on display.

https://www.peereboom.us/assl/assl/html/openssl.html

35

u/dzamir Apr 09 '14

This was painful to read

31

u/[deleted] Apr 09 '14

When I come to power, indentation practices like that will result in a severe beating. There's no reason for that to have been checked in.

23

u/emergent_properties Apr 09 '14

The idea is that your code is not supposed to look obfuscated BEFORE you put it in an obfuscator!

32

u/[deleted] Apr 09 '14

Beatings will continue until indentation practices improve?

14

u/gthank Apr 09 '14

No. The beatings are punishment for the original sindentation.

→ More replies (1)

5

u/Various_Pickles Apr 09 '14

I enjoy working in Java-land: Eclipse Code Formatter XML file, in version control, at the root directory of the project tree.

Eclipse + IntelliJ use it identically. Developers can write w/e crazy diarrhea-of-consciousness-formatted code they want: one quick action before checkin, and the entire codebase follows the same code style.

→ More replies (1)

38

u/semperverus Apr 09 '14

Why is chrome telling me that sites certificate can't be trusted?

80

u/obfuscation_ Apr 09 '14

Because it's a self-signed certificate

24

u/nosneros Apr 09 '14

Self signed certificate.

21

u/FudgeCakeOmNomNom Apr 09 '14

It is still encrypted, but as others pointed out, your browser doesn't recognize the issuer of their certificate because it was self-signed and not by one of the built-in root certificate authorities.

→ More replies (2)

4

u/Sigals Apr 09 '14

It's a self signed cert.

3

u/kankyo Apr 09 '14

Looks like the code in PuttY. Also POS software, and also the code everyone uses.

→ More replies (14)

18

u/frezik Apr 09 '14

Theo didn't even write the quote in the title. The "responsible team" quote would have been a better choice.

2

u/chengiz Apr 09 '14

Correct and easier to parse! I thought he was praising OpenSSL at first, had to read it again.

2

u/clavicle Apr 10 '14

You're not familiar with Theo, right?

1

u/newmewuser Apr 09 '14

Use the NSA sponsored solution right now!

56

u/jgotts Apr 09 '14

Mr. de Raadt is correct. OpenSSL is a nasty piece of software. Just try doing anything with it using the command-line programs and that fact should become immediately obvious: Poor documentation, too many different intermediate file formats, and non-standard and obsolete command syntaxes.

OpenSSL has always struck me as a package written by mathematicians whose second job is programming. I know there are many mathematicians who are excellent programmers, but when programming is an afterthought to the underlying mathematics chances are you will produce poor-quality software

I hate to be so negative about such a useful piece of software. I think that OpenSSL could be refactored/reorganized to produce a really great piece of software. Mainly, they need to revise the command-line options to be modern (use GNU standards), write proper documenation, and as other people have said, improve the code base.

2

u/darkslide3000 Apr 10 '14

too many different intermediate file formats

You make it sound like this was OpenSSL's fault. Remember, they didn't invent SSL, they just took the crap that was specified by some stillborn monkeys on meth and tried to implement it as best as they could. ASN.1 is a crappy mess and there's just no way to make it look pretty. At least OpenSSL allows you to do all that crazy stuff that you sometimes need to do all from the comfort of their impressively powerful command line... show me another tool that can just encrypt/decrypt/hash random stuff with every single cryptographic algorithm (combination) known to man, create/sign/verify all kinds of certificates, and provide a really useful SSL-telnet for debugging (even with STARTTLS support!).

Also, even if we were to redo the whole SSL/x509/ASN.1 stack from the ground up, I don't think crypto will ever be "easy". It's just complicated stuff and you need to handle things like serialized certificates and arbitrary-length numbers in your code to make it work. This will never look all that pretty in C.

→ More replies (5)

130

u/karlthepagan Apr 09 '14

Voodoo optimization: this is slow in one case 10 years ago. So, we will break the library for many years to come!

→ More replies (8)

154

u/muyuu Apr 09 '14

Yep looking at that part of the code was a bit of a WTF moment. Also, there's a variable called "payload" where the payload length is stored... what kind of monster chose that name, I don't know.

23

u/alektro Apr 09 '14

So if you were to look at the code before this whole thing started you would have recognized the problem? The code is open source after all.

23

u/muyuu Apr 09 '14

Maybe. But this is code that entered OpenSSL 2 years ago.

And in any case one doesn't simply go reading the whole code running in systems. Literally by the time you finish there's a dumpload of new code to check. You'd never finish.

But I'd have expected that important stuff like this was more scrutinized by security people. It was found... 2 years later.

11

u/[deleted] Apr 09 '14

But I'd have expected that important stuff like this was more scrutinized by security people. It was found... 2 years later.

And this right here is critical to understand whenever anyone tries to make the argument that open source is safer just because it's open source. The source has to actually be audited by someone with sufficient qualifications.

→ More replies (4)

8

u/xiongchiamiov Apr 09 '14

Well, that's why pre-merge code review is so important.

8

u/muyuu Apr 09 '14

Apparently they do that, but they are understaffed and they get paid basically zero for that kind of work.

There's a lot to correct in terms of workload and incentives for some crucial OSS projects. Used by many but paid by almost nobody.

→ More replies (4)

72

u/WHY_U_SCURRED Apr 09 '14 edited Apr 09 '14

It raises the questions; who wrote it, who do they work for, and what were their motives?

Edit: English

136

u/dontera Apr 09 '14

This guy http://www.robin-seggelmann.de/ wrote it. His motivations were likely because he wrote his PhD thesis on streaming encryption and he thought he was clever. Also, he wrote the TLS Heartbeat RFC.

Here is the commit that brought us this, https://github.com/openssl/openssl/commit/4817504d069b4c5082161b02a22116ad75f822b1

33

u/Grimoire Apr 09 '14

16

u/thebigslide Apr 09 '14

Haven't we learned a thing or two recently about what can happen if you don't add braces to one line if blocks!? Especially with returns after them... I know it was hurried, but there's really no excuse for that.

→ More replies (2)

4

u/frtox Apr 10 '14

i cant stand gitub code review comments, they take over the screen. oh did you actually want to see what code was changed? no, no. you read comment now.

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

90

u/gvtgscsrclaj Apr 09 '14
  1. Some programmer.
  2. Some corporation.
  3. Laziness and tight deadlines.

I mean, I know the NSA crap that's been floating around makes that a legit possibility, but cases like this really feel like your normal level of sloppiness that's bound to happen in the real world. Nothing and no one is absolutely perfect.

12

u/zjm555 Apr 09 '14

Agreed. This is an Ockham's Razor scenario -- for every NSA backdoor, there are probably thousands of vulnerabilities that simply slip in by pure accident. Probability of such accidents goes up with the complicatedness of the solution, and with the number of lines of code.

41

u/paffle Apr 09 '14 edited Aug 17 '26

Almond cobblestone coherent society encouraging stocking spoon

This post was anonymized with Redact

80

u/cass1o Apr 09 '14

Then again, any respectable deliberate backdoor will have plausible deniability built in - in other words, will be disguised as mere everyday sloppiness.

I mean lack of evidence is just as good as evidence right.

→ More replies (6)
→ More replies (9)

24

u/emergent_properties Apr 09 '14 edited Apr 09 '14

And there is the International Obfuscated C Code Contest The Underhanded C Contest .. of which the goal is to make an app that has a sly code payload hidden in it that can be passed off as a mistake.

Plausible deniability is a thing, ESPECIALLY in this realm.

I am not saying that it was intentional or malicious, but you bet your ass with a security hole this big we shouldn't assume automatically innocence first..

EDIT: Corrected contest URL.

22

u/spook327 Apr 09 '14

I think you've confused two completely different things; the IOCCC is for making unreadable code. The one about programs that have a secret critical vulnerability is The Underhanded C Contest

→ More replies (1)

9

u/gvtgscsrclaj Apr 09 '14

Alternatively, we can change the code review practices to ensure that the potential for both situations are vastly reduced in a practical manner, without needing to distract ourselves with casting blame about in all directions.

→ More replies (15)
→ More replies (1)

6

u/technocratofzigurrat Apr 09 '14

The ASN

7

u/PT2JSQGHVaHWd24aCdCF Apr 09 '14

The ASN.1? I knew they were evil the day I looked at the specs!

→ More replies (3)

5

u/Uber_Nick Apr 09 '14

Which further begs the question, irregardless weather escaped goats could care less.

5

u/WHY_U_SCURRED Apr 09 '14

What? You lost me at "irregardless", and it was all downhill from there.

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

2

u/2Xprogrammer Apr 09 '14 edited Apr 09 '14

I'm pretty sure "payload" is standard networking jargon to refer to the actual data part of a packet (as opposed to the headers etc.), in perfectly legitimate contexts. It's a little odd, in sort of the same way that "hash maps" and "binary search trees" are odd if you think about what those words normally mean, but I don't think that choice of variable name is especially suspicious.

24

u/[deleted] Apr 09 '14

The point was that that variable does not hold the actual data part of a packet. It holds its length.

12

u/muyuu Apr 09 '14 edited Apr 09 '14

This is C code. We have an unsigned int and a pointer, if you don't say it's the length, it can be very easily mistaken for the location/offset of the payload.

In fact the main part of the fix consists of checking that the actual record is sufficiently long. This would be substantially more evident (that this wasn't being checked) if the variable looked like a length.

There are a number of bad practices making this possible, though. The main one being... bypassing the system malloc (!!) just because it may be slow in some systems.

1

u/Grimoire Apr 10 '14

p, s, pl, n2s, s2n, r, bp. All names used in that codebase. It is like the author thinks that using fewer letters in their names results in faster code or something.

→ More replies (2)

84

u/ACTAadACTA Apr 09 '14

There should be an alternative to OpenSSL that is easy to use, formally verified and as small as possible.

I know, I'm a dreamer.

97

u/KitsuneKnight Apr 09 '14

There's several alternatives, including NSS (used by Firefox & Chrome), cryptlib, polarSSL, and even GnuTLS (I wouldn't suggest migrating to that last one :P). Likely none of them are particularly easy to use (which is a major issue that people tend to overlook...), and probably none that are even slightly widely used are formally verified.

Fedora is actually working to migrate things over to using NSS, and has been for a while. At least as things stand right now, NSS seems like a far better option than OpenSSL (plus, there's less issues with the license).

37

u/[deleted] Apr 09 '14

Not like OpenSSL is particularly easy to use.

This has been linked a bunch but it agrees with my experience and random looks at the source have been, if anything, worse than what's in there.

2

u/KitsuneKnight Apr 09 '14

Oh, I didn't mean to imply OpenSSL is easy to use- more so that "easy to use" is not something that's generally used with any of those libraries (OpenSSL seems to take it to a whole different level, though).

31

u/chiniwini Apr 09 '14

I once took a look at the NSS code and after a few hours I wanted to shower myself in napalm. I don't know how bad OpenSSL code is, but I would bet my right hand NSS isn't much better.

5

u/TMaster Apr 09 '14

Chrome is said to be switching to OpenSSL.

I know, I have goosebumps too. The bad kind.

3

u/RealDeuce Apr 09 '14

I actually find cryptlib to be insanely simple to use.

→ More replies (1)

7

u/Hashiota Apr 09 '14

http://en.wikipedia.org/wiki/Comparison_of_TLS_implementations
The implementations targeting embedded systems are usually small and written in readable ANSI C, without many dependencies (some corners of OpenSSL need even Perl to run).

5

u/FUZxxl Apr 09 '14

IMHO it would be a great idea to write a library that puts the encryption keys into a different address space (i.e. a different process) as to make it impossible for any flaw to read it out.

15

u/exscape Apr 09 '14

So this may sound naive, but... If a flaw can't read them from a separate process, how can the program itself? Or can you really write it such that the separate process handles all the encryption/decryption in safe(r) manner?

12

u/FUZxxl Apr 09 '14

The main program cannot read out the key but it can perform cryptographic operations with it, for instance it can tell the key-process to encrypt or decrypt a piece of data for him. Even though an attacker could still do nasty things in such a model, he could not get the key.

5

u/shub Apr 09 '14

Unless the key process is itself vulnerable. But it would still be an improvement.

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

2

u/[deleted] Apr 09 '14

That would have prevented part of this attack, but not all of it. There's plenty of damage done here that doesn't have to do with crypto keys.

→ More replies (4)

3

u/until0 Apr 09 '14

I sit here reading all these articles and all I can think is that I wish I had a better understanding of the inner workings of cryptography so I could make an attempt.

Unfortunately, I don't care much for math. Comp Sci maybe wasn't the smartest idea...

1

u/mgrandi Apr 09 '14

mac os x is transitioning to something other then openssl in the latest version (mavericks)

→ More replies (4)

27

u/zalifer Apr 09 '14

The title is incorrect, so far as it suggests that Theo de Raadt said that.

On Tue, Apr 08, 2014 at 15:09, Mike Small wrote:

nobody <openbsd.as.a.desktop <at> gmail.com> writes:

"read overrun, so ASLR won't save you"

What if malloc's "G" option were turned on? You know, assuming the subset of the worlds' programs you use is good enough to run with that.

No. OpenSSL has exploit mitigation countermeasures to make sure it's exploitable.

As the formatting in reddit shows, Mike Small wrote the sentence quoted in the title.

4

u/amertune Apr 09 '14

To me, it looks like Mike Small wrote

What if malloc's "G" option were turned on? You know, assuming the subset of the worlds' programs you use is good enough to run with that.

12

u/XplodingForce Apr 09 '14 edited Apr 09 '14

No, zalifer is right that the quote is not by Theo de Raadt. The formatting in that usenet log is terrible (somewhat ironically).

Look at it from the top level, the title tells you that the main text was written by Theo de Raadt. He quotes Mike Small, who quotes nobody, who starts his post with a quote of somebody else. The confusing thing is that this last quote does not have any header indicating who it was quoted from.

Luckily, Theo de Raadt seems to ben in agreement with Mike Small Ted Unangst, so the misattribution does not really change much.

Edit: It's even weirder, and even more ironic. Theo de Raadt was quoting Ted Unangst, without having the proper header above the quote. Still, the quote in the title was not from Theo de Raadt.

→ More replies (1)

2

u/[deleted] Apr 09 '14

Actually, it does not show that. The attribution line precedes the quoted lines. Mike Smalls said "What if malloc's "G" option were turned on?".

75

u/[deleted] Apr 09 '14

There are two types of people who write open source code:

Those who have heard the music of the spheres and write in crystalline prose no mortal can ever understand, and those who think a quadruple indented 15 clause if/else tree is a valid way to deal with complexity.

53

u/void_fraction Apr 09 '14

Of course, type B tend to think they're members of type A.

24

u/Neebat Apr 09 '14

Also vice versa. Good programmers tend to distrust themselves.

29

u/shub Apr 09 '14

If mortals can't understand it, it's bad code, although sometimes it's unavoidable. If I've misunderstood and you meant that all open source code is bad then we're in agreement.

31

u/keteb Apr 09 '14

I don't know man... once you reach certain levels of complexity sometimes you need to have absurd amounts of the program & goals in your mind to understand the full scope of what's happening.

I'll have times where I slip back out of the zone, look at my own code, and am like "Damn that works well, but I have zero confidence I could write that again".

20

u/strcrssd Apr 09 '14

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." – Brian W. Kernighan

10

u/0007000 Apr 09 '14

Implying the definition is correct.

2

u/Workaphobia Apr 10 '14

The achievement is not in making something complex. It's in making something complex simple.

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

2

u/myalternatelife Apr 10 '14

Music of the spheres

Hyperion?

1

u/[deleted] Apr 09 '14

For values of two equal to one?

56

u/[deleted] Apr 09 '14

That's insane. If I were writing a SSL library, security takes precedence over performance so long as it's still usable.

35

u/happyscrappy Apr 09 '14

So long as it's still usable depends on the client. If you have a server which handles a hundred requests a second, is openSSL still usable? What if you want to service a thousand?

Problem is it's a library, people use it in different ways.

4

u/[deleted] Apr 09 '14

Those people should fire up more servers to handle the load. Handling a thousand requests per second on all but the most powerful hardware is already ridiculous without the SSL overhead. If you have that much traffic and not enough hardware to handle it, you have bigger problems than poorly performing crypto libraries.

3

u/cparen Apr 11 '14

If that were true, you could run the code under a typesafe language or vm instead. Then you'd prevent the entire class of vulnerabilities instead of just this instance.

→ More replies (8)

2

u/cparen Apr 11 '14

There are other ways to harden a security critical library than to use poor performing allocators. That said, I agree with your greater point -- it would have been wise to test under both the high performance allocator as well as a conservative allocator/analysis - eg valgrind.

14

u/[deleted] Apr 09 '14

The problem is, an SSL library will get called a lot. All your traffic might pass through it. It may in fact not be usable unless it is extremely fast.

8

u/chadmill3r Apr 09 '14

Writing a library? There are hundreds of those already. The market of ideas ignores them because they don't perform as well.

8

u/ithika Apr 09 '14

That it is performing is not under issue. What it is performing is the question we should ask of tools like this.

42

u/_4p3 Apr 09 '14

"Only two remote holes in the default install, in a heck of a long time!"

So, when will they update this?

99

u/[deleted] Apr 09 '14
2002    2007    2014
(x      {x)      x}
 |       |       |
 |       |       |
 '---v---^---v---'
     |       |       
     |       |
   heck     heck
   of a     of a
   long     long
   time     time
→ More replies (1)

20

u/sandsmark Apr 09 '14

AFAIK a default install doesn't listen on anything, and therefore this doesn't impact that.

18

u/protestor Apr 09 '14

That's the default C program:

int main()
{
  return 0;
}

No vulnerabilities yet (as of 2014), if ran on the default operating system.

2

u/6nf Apr 10 '14

The default OS is pencil and paper?

→ More replies (1)

67

u/[deleted] Apr 09 '14

The joke is that they've had quite a lot of more bugs than that, but since most of the features are turned off in default install, they haven't had many bugs in default install

31

u/sigzero Apr 09 '14

Since they're explicit about "default install" I don't think it is a joke.

6

u/[deleted] Apr 09 '14

It's not joke on their part, certainly, but it sure does feel like one sometimen :)

→ More replies (1)

7

u/frezik Apr 09 '14

And it doesn't count if they do a quick switcharoo patch while nobody's looking.

→ More replies (5)

1

u/fragglet Apr 09 '14

So, when will they update this?

Or just remove it. It's a joke.

0

u/[deleted] Apr 09 '14

[deleted] — view deleted comment

5

u/_4p3 Apr 09 '14

OpenBSD default install comes with OpenSSL.

3

u/bordumb Apr 10 '14

Probably built that way so that the NSA could have a nice backdoor to everything :)

2

u/6nf Apr 10 '14

It's funny because it's true

16

u/kevwil Apr 09 '14

Theo de Raadt & Linus Torvalds - opinionated, blunt, maybe even rude, but absofuckinglutely right about almost every thing they've ever said or written. This is what separates them from the rest of us.

6

u/reini_urban Apr 09 '14

Note that Theo de Raadt didn't say that cited headline. He just defends Ted, who said that, and explains why.

3

u/smellyegg Apr 10 '14

'Maybe' even rude? Linus is a total prick.

4

u/niknej Apr 09 '14

I think it is Dijkstra to whom the aphorism "All significant systems still contain bugs" is most commonly attributed, but I'll bet he was not the first to think of it. Nobody can realistically claim that openssl, much less the internet, is trivial.

So let's bite on the bullet. There are (still) security bugs in the net. We should be alert for them, and swat them when they come to light, but there is a limit to how much breast-beating they are worth. This bug is dead (or at least moribund, until people update their openssl). Next week, another bug!

2

u/skillcode Apr 09 '14

This is pretty worrying, especially if we consider the fact that the exploit has been out in the wild for a long, long time. I've patched up all my stuff, and wishing everyone else to do the same quickly.

2

u/stmfreak Apr 10 '14

Smart developers always seem to think they know better than whoever wrote the old code.

2

u/zvrba Apr 10 '14

Hah, I had a good hunch when I wondered how the damn thing didn't crash on so large (64kB, spanning a few pages) buffer overruns.

2

u/i-node Apr 09 '14

He is right. Anyone who has looked at openssl knows he is right. Even their make system doesn't properly track dependencies to build in parallel. (at least it didn't last time I checked) Many of the algorithms they implement are complicated enough most people assume they are correct (it is hard to audit a section of code for correctness when the algorithm is hard to follow) . This feature he shows however only works for the right allocator. Some people would still be affected but it is more likely the openssl team would find this bug had they not worked around the allocator.

2

u/partyboy690 Apr 09 '14

What surprises me by this bug is that a program like OpenSSL isn't that heavily unit tested, I mean the most basic unit test would catch this. It is a programming error and a classic C error too, I don't exactly know how OpenSSL works so forgive me if some of this comes as ignorant but surely this process would be working in its own virtual set of memory, if it did try and access cached memory outside of the virtual set the operating system would complain regardless if it used a bespoke memory allocation routine?

4

u/hastor Apr 10 '14

Exactly, and a unit test would have caught the goto fail from Apple.

The problem with these crypto libraries is that their implementations are made to be untestable. The Chrome guys said that exactly the same code path as the goto fail from Apple was not testable in Chrome either.

We need to "dumb down" our crypto until we can at least write unit tests. Complex algorithms or implementations without tests cannot be used.

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

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?

→ More replies (1)

1

u/hpzr24w Apr 09 '14

It's the sinister option.

1

u/GeorgeForemanGrillz Apr 10 '14

I agree with Theo here. They have the balls to ask for donations too. Fuck them.

1

u/matholio Apr 10 '14

Most of this is whoosh for me, but enjoyed reading the comments of mature coders talking able the perils if feeling smart.

1

u/SlobberGoat Apr 10 '14

a wooden stake being driven through OpenSSL's heart = HeartBleed

1

u/Andrey_Karpov_N Apr 16 '14

Some time ago, a vulnerability was revealed in OpenSSL, and I guess there's no programmer who hasn't been talking about it since then. I knew that PVS-Studio could not catch the bug leading to this particular vulnerability, so I saw no reason for writing about OpenSSL. Besides, quite a lot of articles have been published on the subject recently. However, I received a pile of e-mails, people wanting to know if PVS-Studio could detect that bug. So I had to give in and write this article: http://www.viva64.com/en/b/0250/

1

u/syncsynchalt Apr 09 '14

This email was a lot more confusing until I stopped parsing "openssl" as "openssh" (due to proximity to TdR).

2

u/[deleted] Apr 09 '14

A lot of people do that, it used to be OpenBSD and OpenSSH, so everyone assumed OpenSSL was their work too.

It got even worse with OpenSNMP, OpenNTPD, OpenIKED, OpenBGPD/OpenOSPFD, mandoc, pf, and OpenOffice... Can you name which ones are OpenBSD related?

→ More replies (1)

-2

u/drguildo Apr 09 '14

Remember when that Debian developer "fixed" that OpenSSL Valgrind warning. Yeah. Some people shouldn't be allowed near a C compiler. Actually, can we just stop using C now, please?

10

u/partyboy690 Apr 09 '14

C is an extremely versatile and powerful language, the reason they used it over say Java was for performance reasons, as much as people would like C to go away it is here to stay. Also if you read the content in the link you'll realise that this wasn't caused by a design feature in the C language because if the OpenSSL team hadn't rolled their own custom memory allocation function then the operating system would have taken care of this and the bug would have been found ages ago. The problem is that when the OpenSSL's version of free is called it doesn't zero the memory AND it allows you do to a memcpy over your buffer. The regular C library would mitigate both those issues.

→ More replies (3)

7

u/[deleted] Apr 09 '14

We can stop using C once there's an alternative that fits in all the tight spaces it can.

That single criterion instantly rules out 99% or more of "nice" languages.

6

u/Zarutian Apr 09 '14

FORTH LOVE IF HONK THEN

;-)

→ More replies (1)