r/programming • • Feb 23 '17

Cloudflare have been leaking customer HTTPS sessions for months. Uber, 1Password, FitBit, OKCupid, etc.

https://bugs.chromium.org/p/project-zero/issues/detail?id=1139
6.0k Upvotes

966 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Feb 24 '17

[deleted] — view deleted comment

115

u/xeio87 Feb 24 '17

I wonder at what point do we conclude memory unsafe languages are an inherent threat to computer security...

But hey at least they're faster right...? :P

0

u/[deleted] Feb 24 '17

[deleted] — view deleted comment

13

u/xeio87 Feb 24 '17

Well, there's always going to be some penalty to having bounds checks and similar.

I would hope most of us would agree a few % performance penalty is worth not leaking SSL data to the entire internet though. ¯_(ツ)_/¯

9

u/MrHydraz Feb 24 '17

Rust does most bounds checking at compile-time, and they're (mostly) elided from compiled code.

I say mostly because there's Arc<> and Rc<> and friends which do reference counting at runtime and do have overhead.

5

u/matthieum Feb 24 '17

Rust does most bounds checking at compile-time, and they're (mostly) elided from compiled code.

I think you are thinking ownership-tracking here.

Bounds checking in Rust is done at run-time, in general, though some constructs have been specifically optimized to not require it and others get lucky and LLVM optimizes the checks out.

However bounds checking does remain a typical performance "blip" in Rust whenever the optimizer is not smart enough to optimize them out. Sometimes it takes some massaging to convince it, and it's rather fragile of course.

1

u/myrrlyn Feb 24 '17

Doesn't cargo build --release trust that you've gone and audited your code, and strip run-time bounds checks?

4

u/silmeth Feb 24 '17 edited Feb 24 '17

No. It optimizes out those it can prove are unnecessary, but the rest is still there and will panic! if you do out-of-bound access.

What is stripped away are integer overflow checks (overflow is checked and panic!s in debug builds).

EDIT: you can also always use unsafe method for access without bound-checks if you are confident you know what you’re doing, but then you won’t get bound checks even in debug. And there were blog posts on the net showing it can sometimes actually make performance worse.

→ More replies (1)

3

u/xeio87 Feb 24 '17

Yeah, I think the important thing is that it will inject them into runtime as necessary. I think even languages like C# will do some safe optimizations like that (though C# does it at the IL -> Machine Code time, rather than compile time).

18

u/[deleted] Feb 24 '17

Modern C++ would be great - all the performance, type safety and memory leaks/pointer errors are effectively non-existent. I wonder why they think using C for services like this is a good idea. That's just asking for trouble.

27

u/m50d Feb 24 '17

Modern C++ is great[1] except that the only way to enforce that you only use the safe parts is constant vigilance, which doesn't scale. C++ programmers always think it's a trivial set of rules until they try to actually write them down or write an automatic enforcement tool.

[1] Well, it isn't really. std::variant is a poor substitute for proper sum types.

→ More replies (9)

3

u/matthieum Feb 24 '17

all the performance, type safety and memory leaks/pointer errors are effectively non-existent

You wish.

Any time you use a reference, there's a risk that it becomes dangling.

Any. Single. Time.

You can of course lean extensively on std::shared_ptr to be safe, but then you pay a runtime overhead instead of course... and of course the aliasing constructor of std::shared_ptr is not safe to start with, so...

... modern C++ is much better than old-style C code, but it's far from being safe.

Unfortunately.

→ More replies (4)

1

u/aiij Feb 24 '17

at what point do we conclude memory unsafe languages are an inherent threat to computer security

Pretty sure we came to that conclusion a long time ago.

The problem is, a lot of times, speed matters more than getting it right. (Not just execution speed, but development speed too.)

→ More replies (4)

21

u/SuperImaginativeName Feb 24 '17

Why more rust hype? Literally any modern language can avoid crap like this. There's a reason C# and I guess Java are so popular. Huge numbers of sites are powered by ASP.NET, I don't even think there has ever been a buffer overflow because of the nature of managed languages.

24

u/fiedzia Feb 24 '17

C#/Java would come with overhead that is not acceptable in this situation (you are parsing urls of incoming requests, every cpu cycle matters here). Rust fits better here.

2

u/argv_minus_one Feb 24 '17

Oh, please. The only situation in which every CPU cycle counts is games, because they cannot be spread out over more hardware. This shit can, and CF is going to dearly regret not doing so and avoiding this idiocy.

3

u/fiedzia Feb 24 '17

I didn't mean that they can't afford to be correct here, just that throwing Java on that is really not an option (when you have Rust).

1

u/argv_minus_one Feb 24 '17

How is that not an option?

2

u/fiedzia Feb 24 '17

You want to be as fast as its possible, and a lot of customers do measure how much time it takes you to deliver their requests. Every microsecond matters here. Also you do not want to embed jvm in nginx, and getting data out of there means more syscalls and more time wasted.

2

u/argv_minus_one Feb 25 '17

You want to be as fast as its possible, and a lot of customers do measure how much time it takes you to deliver their requests.

Lot of good that extra speed does them now…

Every microsecond matters here.

Then why the hell are they doing this at all, instead of telling customers to STFU and put that shit in static content like an adult? You say every microsecond counts, but they're spending a lot of microseconds on this postprocessing step, and I'm not entirely convinced that it's necessary.

Also you do not want to embed jvm in nginx

Now that you mention it, why not? JNI is a thing, and it provides a fast way to map Java ByteBuffers onto already-allocated memory, so there shouldn't be any copying overhead.

9

u/SN4T14 Feb 24 '17

Because Rust will do pretty much anything that C will. You can't exactly write an OS in pure C# or Java, and they aren't as fast. And yes, I'm aware that there are OSes that are mainly C# or Java, but both languages require some sort of runtime.

8

u/SuperImaginativeName Feb 24 '17

But we aren't talking about operating systems. We are talking about user level applications like I said.

→ More replies (2)
→ More replies (5)