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

Show parent comment

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)

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.

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

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.

→ More replies (2)

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".

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

29

u/zjm555 Apr 09 '14 edited Apr 09 '14

I agree that it's worse to read. A good style checker that will cause an automated test to fail is my preference. My style rule is simply "no assignment inside an if statement".

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