7 ms·
It's time to start converting the low-level Linux/UNIX utilities to a language with subscript checking. Go, or Rust (if and when it's finished), or D, or somet
by Animats 12y ago
It's time to start converting the low-level Linux/UNIX utilities to a language with subscript checking. Go, or Rust (if and when it's finished), or D, or something. We have some good options now.
- blinkingled 12y agoIt's not the utilities themselves that are the bigger problem - rather a library the utility uses. libbfd in this case. Problem with writing libraries in anything other than C of course is that they are not very usable by a large variety of software.
- gizmo686 12y agoMost languages have some type of "extern C" as part of their FFI. It should be possible to use C as a langua franca between two non C languages.
- blinkingled 12y ago> It should be possible to use C Ugh, wouldn't that fall in "just because you can do something doesn't mean you actually should" category? :) Suppose I wrote the library in Go and exported some type of C wrapper and then I loaded that in Rust using Rust->C mechanism - that will load the Golang runtime in Rust! And you still got non-trivial C code to deal with anyways!
- gizmo686 12y agoIf you want to interface two languages, then I do not see a way arround involving the runtime of both languages (in the same way that linking to C code still uses the C runtime). However, using my method does not actually involve any C code. "extern C" makes the compiler produce object code that can be called as if it was produced by C code; it does not produce any C code that would compile to the given object code. Of course, it will also produce C headers to give the type information of the exported symbols, but I wouldn't call that code.
- steveklabnik 12y agoIt's pretty easy to call into a Rust library from C. The lack of a garbage collector makes embedding Rust quite nice. Lately I've even been playing with a Ruby gem that's a C extension that calls into a Rust .a that exposes itself via extern C.
- blinkingled 12y agoThings get uglier when I want to then call the whole shebang from - let's say - Go! Go -> C -> Rust. Now I am paying the penalty for 2 runtimes!
- SwellJoe 12y agoHow high is that penalty, relative to, say, loading a variety of C shared libraries? At some point safety and security trumps saving a few kilobytes of memory...in a server environment, that point probably has already been passed a decade ago. Of course, if the penalty is hundreds of megabytes, then the equation might add up differently. But, we already have a huge number of system tools and utilities running in a huge number of languages. Python has become the lingua franca of Linux management tools; Perl was in that role in the past, and still exists in a lot of places; bash and shell are integral. All have separate runtimes, and sometimes interact with system-level C libraries, either directly or through command line interfaces. Is it really that big of a deal to have a Rust or Go shared library in a system that already has a half dozen different languages and a variety of shared and unshared libraries existing at once? I suspect it would be unnoticeable on a modern system. I'd choose safety over shaving a few kilobytes of memory used. There would be a cost in having that interface friction for developers...and we'd be paying that cost for years. But, it seems like both Rust and Go have planned for the languages to be integrated with C libraries from the beginning, so it seems less of a problem. If I were going to attempt such a thing, I'd probably start with the front end utilities that use the libraries and then work my way down to converting the libraries (even though the libraries, in this case, are where the problems lie). But, maybe it's possible to make Go or Rust code that provide the same C interface as the existing libraries...I don't know enough to even guess.
- steveklabnik 12y ago
- thecatsass 12y agoOr, the authors of Linux/UNIX utilities should have implemented and should be implementing bound checking. It seems excessive to switch languages rather than encourage stronger programming habits.
- _delirium 12y agoAre there any examples of that being successfully done? Even djb's software, intentionally written to be minimalist and as secure as possible, has had exploitable overflows (both qmail and djbdns have suffered from this). Every Linux and BSD distribution (even OpenBSD) has suffered buffer overflows so severe that arbitrary internet users could get remote root access. Etc.
- vezzy-fnord 12y agoThe Cyclone dialect of the C language comes to mind: https://en.wikipedia.org/wiki/Cyclone_%28programming_language%29 https://en.wikipedia.org/wiki/Cyclone_%28programming_languag... Unfortunately, it's a dead project, and as far as I recall, never compiled on 64-bit architectures.
- _delirium 12y agoThat's one approach, yeah. I used to think it was a likely one, but I now think three others are more likely: 1. A language that is low-level and safe but also gives you enough interesting & new to build some buzz/interest, rather than "just" safety. Rust is a candidate here, perhaps. 2. Static analyzers in C advance to the point where a subset of C large enough to be useful can be routinely checked for common types of errors. And it then becomes socially expected that at least core OS stuff will be written in that "checkable" subset of C, treating "unable to prove safety" warnings as errors, or at the very least as suspicious. 3. Mitigate it at the OS level with finer-grained access controls. Utilities like strings(1) or objdump(1) are the easy case here: they do not need to actually have permissions other than "read a file" and "print to output". Even in the worst case, arbitrary code execution in objdump(1) should not be able to delete your home directory, join a botnet, or email your ssh key somewhere, because objdump(1) does not need those permissions. FreeBSD's libcapsicum looks promising, in the sense that it is actually being implemented in the base system, rather than just being yet another ACL proposal going nowhere (Solaris/Illumos also has an actually-shipped privileges system, but I don't know how extensively the base install itself uses it).
- wyager 12y ago>to a language with subscript checking Or, more generally, memory safety. Of the three you described, Rust makes the strongest memory safety guarantees. Neither D nor Rust require a complicated runtime. I'd say this isn't really Go's intended area of usage. Also, Go is missing things like ASLR and DEP (last time I checked), which means that if you link to any vulnerable non-Go code using cgo (which is almost inevitable when writing core utils), or if you find a good bug in the Go runtime, it's trivial to get code execution.
- Animats 12y agoAddress space randomization is security theater. It slows down attackers, but doesn't stop them. See "stack spraying". What it does prevent is replication of security bugs, which allows vendors to ignore them.
- wyager 12y agoCounter-ASLR measures are not always viable. Regardless, Go also lacks DEP, which is the more important of the two.
- vezzy-fnord 12y agoIf it slows them down and makes their lives harder, then it is a worthy mitigation. That's what a mitigation is, after all: it reduces severity and effectiveness. It's not a full stopgap. Even still, ASLR implementation quality has left much to be desired throughout the years.
- imanaccount247 12y agoNo it isn't. If trying to exploit some daemon requires thousands of tries instead of one try, I am thousands of times more secure. Because they will almost certainly fail the first time, causing the daemon to crash, and then have no more tries. It is only security theater if you live in the land of "lets use broken software that crashes all the time and then run a monitoring tool to automatically restart it". That is the problem.
- f- 12y agoThe Linux kernel and the core utilities needed for an user-friendly OS add up to a mind-boggling amount of code, written by thousands of hobbyists over the course of decades. That code base has the benefit of actually existing, being familiar to a lot of people, and (mostly) behaving in predictable ways that are consistent from one un*x-like system to another. So in that sense, it's somewhat counterproductive to just say "somebody oughta rewrite this stuff", unless (like RMS) you're willing to dedicate a good chunk of your life to that mission - or think that your post will inspire somebody else to do the same.
- WalterBright 12y agoAs I wrote some time ago, http://www.drdobbs.com/architecture-and-design/cs-biggest-mistake/228701625 http://www.drdobbs.com/architecture-and-design/cs-biggest-mi... it is easy to add bounds checking arrays to the C language. The trouble is, nobody is interested in doing it. It'd be a heckuva lot easier than changing languages.
- CamperBob2 12y agoHow would that fix the problem at hand? The code in question isn't using array notation. At the end of the day, it's not a case of using C when another language would be better, it's a case of crappy coding.
- WalterBright 12y agoIt helps because instead of rewriting the whole app, just the function parameter types are redone where pointers to data are changed to bounds checked arrays, on a case by case basis. It isn't a magic bullet, but as buffer overflows are (I presume) the most common cause of C security exploits, this would help a lot.
- CamperBob2 12y agoMaybe, but my fear would be that the act of rewriting it to use array notation will introduce yet more bugs. Some of the comments point out that the problem exists because nobody cared enough to fix it for several years. Having seen that nobody cared enough to fix it, it's not clear that anyone will care enough to fix it properly.
- Animats 12y ago(Bright, of course, is the creator of D.) I agree completely about C. I've been saying this for years. There are three big problems that cause crashes in C programs: "How big is it?", "Who owns it?", and "Who locks it?". The result is over three decades of segfaults and buffer overflows. There have been three or four variants on C which address some of those issues. I've proposed one myself. None got any traction. The only thing that might work is if someone developed a safe variant of C which could be machine-generated from existing C code, and didn't add significant overhead. GCC already has a fat-pointer subscript checking option, but nobody uses it. That approach is usually slow, with a subscript check on every reference. If you do it right, most subscript checks get hoisted out of loops. Go does that for many FOR statements. Rust is one of the very few languages which addresses all three of those issues without resorting to garbage collection. I really hope the Rust crowd doesn't screw it up.
- stevekemp 12y agoThere was a project to rewrite common binaries in Perl a few years back, the "perl power tools project". https://metacpan.org/pod/PerlPowerTools https://metacpan.org/pod/PerlPowerTools I'd rather see that than a language such as Rust, D, or Go.