4 ms·
> Part of how they are so easy to overlook is that we are trained to think in terms of abstractions, not the details underneath them. This is a problem in dire
by twic 11y ago
> Part of how they are so easy to overlook is that we are trained to think in terms of abstractions, not the details underneath them.
This is a problem in direct proportion to how leaky the abstractions are. C's abstraction over memory is comically leaky, so indeed, if you're using it, you need to think about the details underneath it.
But the solution isn't for everyone to forget about abstractions, it's to use better-made abstractions.
For memory in particular, it's been understood what it takes to have a safe abstraction for quite a long time now, and numerous widely-available languages provide one. Use one of those instead of C.
- AnimalMuppet 11y agoCould you be more specific on what you have in mind here? As far as I can see, if something like Heartbleed exists, you can't rely on "safe memory abstractions" at a lower level, because Heartbleed let the attacker look at the internal memory of those abstractions. They quit being abstractions; their raw memory is open to the attacker. Or is your claim that safe abstractions would have prevented Heartbleed (and all other possible attacks that let the attacker read memory)?
- voxic11 11y agoPretty sure he is claiming that bad abstractions make it very likely that you will produce code which doesn't do what you think it will do, such as leaking memory contents.
- twic 11y agoFor Heartbleed, you need an abstraction like "container that i can write bytes to and then read the same bytes from" which has the leak "sometimes you can read other bytes too". In C, the memory abstraction the language gives you has that leak, so it's really hard to build a container on top of it that doesn't have that leak. In safer languages, the memory abstraction doesn't have that leak, because bounds are checked, and new byte buffers are initialised to zero. You can still build an abstraction which does have that leak - say, by writing your own reusable byte buffer class which doesn't check bounds or zero on reuse - but at least you have the option of getting it right. In an even safer language, the type system might make it impossible to make that mistake, or the library might supply a safe implementation of that abstraction already. Remember, Heartbleed is not about the attacker doing some kind of Jedi memory trick to read your secrets: they are relying on your own code to read things it shouldn't. If the abstractions your program is built on don't allow that, then there's no way for it to be used to that end.
- cuckcuckspruce 11y ago>In C, the memory abstraction the language gives you has that leak, so it's really hard to build a container on top of it that doesn't have that leak. >In safer languages, the memory abstraction doesn't have that leak, because bounds are checked, and new byte buffers are initialised to zero. Most of the implementations of these safer languages are in C, so clearly there's a way to do this correctly in C.
- mannykannot 11y ago> For memory in particular, it's been understood what it takes to have a safe abstraction for quite a long time now, and numerous widely-available languages provide one. Use one of those instead of C. Is it not the implementation of those abstractions that determines whether they are safe? Offhand, I don't recall seeing guarantees of safety in this regard being offered by any language I am familiar with, though I have to admit that it has not been something I have been looking for.
- twic 11y agoIt is the implementation which matters, or rather, the observable consequences of the implementation, which in effect form part of the interface of the abstraction - they might not be intended, but they're there. Those are what we call leaks. The abstraction i was thinking of was byte arrays, which are provided by the language, rather than anything higher-level. Many languages have byte arrays which guarantee that you can't read past the end, and can't read values that you didn't write. Java would be one example.
- 2trill2spill 11y ago> For memory in particular, it's been understood what it takes to have a safe abstraction for quite a long time now, and numerous widely-available languages provide one. Use one of those instead of C. That advice doesn't really help the OpenSSH team at all. OpenSSH is a C project and it certainly is not going to be rewritten in a safer language. Their are many reasons for that, first reimplementing OpenSSH would take lot's of effort, and the OpenSSH(OpenBSD) people don't have much man power to spare. Secondly OpenBSD is a C shop for better or worse, like most open source operating systems. Thirdly what language can fulfill all the constraints of OpenSSH and be memory safe? Let me try and explain, OpenSSH is included in many operating systems, like OpenBSD, FreeBSD, most of the linux distros, etc. Most of these groups are not going to want to include languages that require big complicated runtimes into their base operating systems. So that get's rid of any JVM based language, erlang, and any other non compiled language. So that leaves languages like Go or rust, which most certainly are safer languages than C, but can they run on all the platforms listed on OpenSSH portable?[1] And just as importantly will Operating systems add another programming language to their base system, which increases the effort required for maintenance just so they can switch the implementation of a working program. I personally don't think most major operating system would make the switch. Finally OpenSSH has a pretty good track record when it comes to security, especially considering how little funding they receive, it would probably require less effort to continue improving OpenSSH then to ditch it and start over and get everyone to use the new version. [1]: http://www.openssh.com/portable.html http://www.openssh.com/portable.html
- twic 11y agoI take your point, but OpenSSH is almost a counterexample. The OpenSSH team's goal is to make the best possible SSH daemon for OpenBSD; it's a nice bonus that they can make a portable version as well. They're doing this as part of the broader OpenBSD effort. OpenBSD is a cohesive, relatively small (for a full-blown operating system!), independent, and tightly focused project; they are in a better position than anyone to introduce a new language. Plus, they already have a track record in throwing away old software and replacing it with something entirely new [1] [2]. You're right that languages with big runtimes would probably not be worth the cost, and new languages like Rust and Go are still too risky. But how about something like Ada or Modula 2? Both are well-established (virtually ancient) languages with mature compilers, small runtimes, and proven use in systems development. [1] http://www.openbsd.org/papers/httpd-asiabsdcon2015.pdf http://www.openbsd.org/papers/httpd-asiabsdcon2015.pdf [2] http://www.openntpd.org/ http://www.openntpd.org/