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

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

58

u/[deleted] Apr 09 '14

[removed] — view removed comment

4

u/droogans Apr 10 '14

Simplicity is hard.

5

u/bobes_momo Apr 10 '14

Controlling complexity is the essence of organization

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

2

u/[deleted] Apr 10 '14

Yea, once I spent an hour writing a shell script to do exactly what mkdir -p already does, well.

→ More replies (1)

14

u/[deleted] Apr 09 '14

I think that's true in the majority of cases, but it's important to remember a complex problem does not always have a non-complex solution.

8

u/newmewuser Apr 09 '14

And that is why you don't add extra complexity.

→ More replies (11)
→ More replies (1)

6

u/ltlgrmln Apr 09 '14

That's an interesting point on learning how to code too. When I was learning python I would get ahead of myself by not fully understanding the code I was using. When it broke, I would basically have to abandon the project.

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.

11

u/Choralone Apr 10 '14

While I don't disagree with any of that... I do recall that back when we were dealing with segmented real-mode stuff on x86, and not dealing with paging and cache issues as we are today, the concept of mucking about with memory allocation wasn't seen as the same enormous task it is today. Today I wouldn't even think of touching it - but back then? If I'd had to, I would have considered it seriously. What I'm saying is it wasn't that far-fetched, even if it was a less than perfect decision.

2

u/wwqlcw Apr 10 '14

I would have considered it seriously.

Oh, if you'd done it seriously I'm sure you would have been more successful than my predecessor - who had no design, no spec, no tests and no reviews - was.

2

u/Choralone Apr 10 '14

Fair point. I'm just saying that, for the right programmer, it wasn't nearly as much of a horrendously bad idea as it would be today.

8

u/cparen Apr 10 '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."

Sigh. I wrote a custom allocator for a fairly trivial event query system once.

I built the smallest thing I could that solved the problem. I tried to keep it simple. We cache the most recent N allocations for a number of size buckets. It's a bucket lookaside list, that's it. The idea was clever enough; the implementation didn't need to be, and it was about 20% comments.

This ultimately let to a 2x speedup in end-to-end query execution. Not 10%. Not 50%. 100% more queries per second, sustained. This took us from being allocation bound to not.

This gave me a lot of respect for the "terrible" code I sometimes see in terrible systems. I know that at least one or two "terrible" programs were just good programmers trying to do the best they could with what they had at hand, when doing nothing just wasn't cutting it. Could be all of them, for all I know.

tl;dr? I dunno. Maybe "don't hate the player, hate the game".

7

u/Crazy__Eddie Apr 09 '14

Ugh. This one hits me right where I live. There's a certain implementation of the standard C++ library that has a "smart" allocator which is constantly causing me torture. I have a flat spot on my head where I'm constantly pounding it on this brick wall.

Why won't we stop using it? Because, reasons.

→ More replies (1)

1

u/rekk_ Apr 09 '14

Well said, I'm going to adopt this rule.

1

u/[deleted] Apr 10 '14

I've only started four years ago in the automotive industry, but after my first project, now this is my mantra.

I'm never going to write clever code again. It only has downsides in the long, inevitable run.

→ More replies (7)