9 ms·
Here's the counterargument: Regardless of language, all software has bugs; that's such a banal argument it barely even needs to be made. Offensive software sec
by tptacek 7y ago
Here's the counterargument:
Regardless of language, all software has bugs; that's such a banal argument it barely even needs to be made. Offensive software security is the practice of refining and chaining bugs to accomplish attacker goals. You can make it easier or harder to do that, but in the long run, more bugs classes are going to be primitives for attackers than not.
Rust is a fine language to teach people. But what Rust accomplishes for security is table stakes. People building software in Java in 2002 had largely the same promises from their language; Rust just makes those promises viable in a larger class of systems applications. But Java programs are riddled with security vulnerabilities, too! So are Golang programs, and, when Rust gets more mainstream, so too will Rust.
Aside: I'm really frustrated by the advice to validate all input. That's not useful advice and people should stop teaching it. It begs the question: validate for what? If you know every malicious interaction that can occur, you know where all the bugs are. And you don't know where all the bugs are.
- hnick 7y agoI agree with your last point. A lot of programming advice boils down to "do the obvious thing to avoid the obvious issue" and sidesteps the point that it's the "unknown unknowns" that really ruin our day. 'Taint mode' ala Perl[1] turns non-validated input into runtime errors, rather than security bugs. Crashing is nicer than being pwned. "You may not use data derived from outside your program to affect something else outside your program--at least, not by accident." Bugs still exist (as well as bugs in languages themselves), but languages can help mitigate the surface area. [1] - https://perldoc.perl.org/perlsec.html https://perldoc.perl.org/perlsec.html
- blub 7y agoThe validation's still done by the programmer. If they fail to validate correctly or the validation requirements had a bug, taint mode does nothing to help.
- hnick 7y agoTrue, they can do an incorrect validation but at least they can't to forget to validate entirely. That's a positive step.
- pcwalton 7y agoAre you saying that memory safety is valuable or not? If you do think memory safety is valuable, then I don't see how you're disagreeing with the author. Nobody is claiming that memory safety eliminates all bugs.
- tptacek 7y agoMemory safety is valuable! I wouldn't want to implement anything in a memory-unsafe language if I could avoid it, and, thanks to Rust, I can virtually always avoid it now. There's ways to make bugs easier to chain and exploit, and memory unsafety is a big one. But, while I know nothing is a panacea, memory safety is especially not a panacea. We have over a decade worth of experience with software built principally in memory-safe languages; it's hard to find a modern web application --- increasingly, it's even hard to find a modern mobile application --- built in a language as bad as C. And, as you know, all these memory-safe applications are riddled with vulnerabilities. They don't have memory corruption vulnerabilities, but I'm still game-over'ing app pentests, and very unhappy with myself when I can't.
- xwowsersx 7y agoI'm not sure I get what you're saying here. What do you mean you're "game-over'ing app pentests"? You organize penetration tests and are usually able to expose vulnerabilities when you do this?
- tptacek 7y agoYes, I've been doing software security full-time since 2005, and was a vulnerability researcher prior to that. I speak for basically every software security person when I say that memory safe languages are a positive development, but applications remain susceptible to vulnerabilities that result in total compromise.
- xwowsersx 7y agoMakes sense, thanks. I'm not sure how anyone could suggest that vulnerabilities don't exist if you use a memory safe language. That's just demonstrably/factually not true...
- cortesoft 7y agoThat last point is something I feel really needs to be driven home. At my company we often do bug bounty and hacking events where we have people attempt to break into our systems. Some of our engineering team members always make a big deal about making sure only certain things are in scope and that we only allow hackers to break things that won't cause major issues. I always tell them that this is impossible. Sure, we can tell the hackers to only target certain end points, but we have no way of knowing what downstream things will be effected, and if we can't be sure there is no way the hackers could know. If we knew for certain what exactly could be broken by the hackers, we would know exactly where are vulnerabilities were. If we know that, why are we paying hackers in the first place? Sure enough, at one of our events a system waaay out of scope ended up breaking when a hacker triggered a bug on an in scope system. A bunch of our engineers were upset, but the hacker had no way of knowing that his api request would trigger a series of further actions in systems leading eventually to the breakage. Any system connected to an in scope system is automatically going to be in scope.
- lidHanteyk 7y agoIt's all about bug classes. We can use safety guarantees to eliminate certain bug classes at the language level, but some concepts are so high-level that they are independent of language, and their corresponding high-level bug classes are not preventable with a language-based approach to security. For example, plan interference always arises in high-level planning, so no language is going to eliminate that bug class without somehow completely reinventing the philosophy of planning and logistics. We can certainly ask that languages do better around features like FFI, string-building, and error-handling. We keep making the same mistakes. Memory safety is probably the biggest conceptual leap forward in our lifetimes and we are still not yet in agreement as a community that it is clearly good.
- tptacek 7y agoI don't think memory safety is actually a controversy anymore.
- blub 7y ago"Memory safety is probably the biggest conceptual leap forward in our lifetimes and we are still not yet in agreement as a community that it is clearly good." It's not that we're not in agreement. It's just become standard for most developers so they don't care about it. Memory safety is only still relevant in the context where one is using C and C++ and maybe Obj-C. And in that context many do not agree that Rust is the solution for them, even if they appreciate memory safety otherwise.
- EsssM7QVMehFPAs 7y agoA secure language is any strongly typed language that caters well to static analysis. Enterprise (and up to some point open-source) tools exist that are able to capture a vast range of security issues in code with the help of in-depth static analysis. I'd rather consider Java, .NET, C, or to a limited degree C++ as secure because of this. Our compilers should long have included static analysis on par with optimization efforts, because - as you say - people tend to produce errors in code. Strong type systems and memory safety are a very nice first step though. I am certain this will change over the years, but then the trend (that I am also prone to) is to go dynamic for the sake of productivity anyways.
- blub 7y ago"A secure language is any strongly typed language that caters well to static analysis". Where is this definition coming from? Seems arbitrary. Static tools capture the same old range of security issues which is only mostly relevant for C and to some extent to C++ and also Objective-C and unsafe Rust or unsafe Swift.
- carlmr 7y ago>any strongly typed language...I'd rather consider Java, .NET, C, or to a limited degree C++ as secure because of this. Java, C# (not all .NET languages) are both quite strongly typed (it would be nice if there was no implicit toString conversion in C#, I think Java has this, too). F# is a bit better than C# in terms of type system (especially exhaustive pattern matching on discriminated unions leads to a lot more potential type safety). C or C++? They are happy to implicitly convert a lot of things, they're statically typed, but very weakly so. And in terms of memory safety C strings and arrays are the reason why static analysis is absolutely necessary here. >Our compilers should long have included static analysis The Rust compiler is doing a lot of what would be considered static analysis. And if you're dealing with normal strings and arrays you're not prone to C-like buffer overflow behavior. If you run in debug mode then you even get assertions on integer wrapping. This IMHO is also the biggest issue with C/C++. The fact that the compiler still allows so much to go through and only the static analyzer gives you a warning. Big companies rarely have code bases where most of the static analysis warnings are even solved. And it's hard to hire only "disciplined" programmers.
- pera 7y agoYet some languages are extremely helpful in this regard: see for instance F* and the HACL* library.
- throwawayjava 7y agoCounter counter point: SQL injections and buffer overflows now require nearly intentional effort to introduce into a codebase, whereas they used to be the default. The question is: when we find a common class of vulnerability, what's the best way to deal with it?
- tptacek 7y agoWe find SQLI regularly. We don't find buffer overflows very often! That bug class has been mitigated. It's better to eliminate bug classes, and memory safety is a good idea. But it's a good idea we've had in mainstream software engineering for coming up on 2 decades, and your default assumption about any piece of software should still be that it harbors grave vulnerabilities.
- WalterBright 7y agoYes, all software has bugs. But how we make things safe and reliable is not by eliminating the bugs, but by changing the process to make those bugs impossible. We cannot eliminate all bugs, but if for each one we eliminate the flaw in the process that enabled that bug, we get fewer and fewer bugs. This works in the real world. For example, see airliners. A large part of my job as a language designer is to look at the causes of certain kinds of bugs, and find ways to design them out of the language. There's no reason today that array overflows should still be happening.
- tptacek 7y agoI'm confident I didn't word my original comment well, because people are obviously reading it to say "memory safety doesn't matter". It does. It's an absolute requirement for secure software development done at any reasonable scale. But it does not produce "secure software".
- schoen 7y agoIt seems like a counterargument to your counterargument could be to treat memory safety as an example of a thing that languages can help with to eliminate classes of bugs. There are other such things too. We could regard memory safety as a great success in this area that programmers can easily appreciate. Then a follow-up question would be what indications we have that other classes of bugs can or can't also be eliminated with help from languages. (Of course there's also potentially a lot of space between "it's inherently impossible to write programs that are incorrect or unsafe in a specific way", which is something that things like memory safety and static typing can help with, and "it's possible for a programmer to do extra work to prove that a specific program is correct or safe in a specific way", which has been a common workflow in formal methods.) I would be interested in your view of this; after memory safety and perhaps type safety, what kinds of bugs do you think could be eliminated by future language improvements, and what kinds of bugs do you think can't be eliminated that way?
- nullc 7y ago> We could regard memory safety as a great success in this area that programmers can easily appreciate. No one wants the overhead on current hardware but C can be made memory safe with bounds checked pointers (although not particularly type safe without introducing a lot of code incompatibilities). It's important to distinguish actual language advantages from indulging the common fetish of wouldn't-it-all-be-better-if-we-rewrote-it. There has been fairly little rigorous study of programming factors leading to more reliable software (esp in the kinds of environment most software we use is created and used in, as opposed to say aerospace). Wouldn't it be sad if enormous amounts of effort were spent rewriting everything in a new language only to later discover that other properties of that language, such as higher levels of abstraction or 'package ecosystems' that cause importing impossible to audit millions of lines of code to get trivial features, lead to lower reliability than something silly like using C on hardware with fast bounds/type checked pointers?
- baroffoos 7y agoThe counter counter argument is that while you can write bugs in any language, there are a huge number of bugs that simply wouldn't have existed in a safer language. I write ruby code at work and every time I find a bug I think "Would this bug have been possible in rust" And most of the time the answer is no because the bug is because of a typo or a nil value where it shouldn't be or should have been handled.
- blub 7y agoYour typos and nil values are only relevant if they somehow lead to security issues. Not impossible... but not the biggest concern either.
- jdnenej 7y agoThere was a bug in a php app where someone had typed `flase` which evaluated to `"flase"` which is truthy so the authentication check passed.
- mrkeen 7y ago> It begs the question: validate for what? Functions must only accept input which they can properly act on. A function serving web pages needs a different notion of String than a database function. There are Strings which are safe for a SQL use but unsafe to serve on a web page, and vice-versa. Validation is restricting your input to only those things your function can act on.
- squiggleblaz 7y agoBut it's the typechecker's job to make sure you don't give an SqlCodeString to a function which takes a HtmlCodeString. Surely then a person writing such software isn't validating anything. So what should be validated?
- mrkeen 7y agoThe transition from String to SqlCodeString is the validation.
- tptacek 7y agoI'm not saying SQLString is a bad idea. It's a good idea. I'm saying that the strategic advice to "validate input" didn't help you here, because to get to SQLString, you had to know specifically that there was a string-based SQL attack to mitigate. "Validate input" is like saying "know all possible bugs". Obviously, you should mitigate the bugs you know about! You just shouldn't pretend that telling someone to "validate input" is going to accomplish that. It's like telling people "don't have bugs".
- carty76ers 7y agoWhat’s your alternative high-level advice then?
- tptacek 7y agoFor generalist developers who have to get things done: learn at least a little about the major classes of security vulnerabilities that impact your development environment, and select libraries designed to mitigate them. For students: learn a lot about the most important classes of security vulnerabilities, of which memory corruption is one important example but just one, and then take the time to learn how to exploit at least simple variants of all of them in a realistic setting, to cultivate the mindset needed to think critically about software security. Don't write anything in C. Sure. But really almost nobody does that anymore anyways.
- loup-vaillant 7y ago> Aside: I'm really frustrated by the advice to validate all input. That's not useful advice and people should stop teaching it. Do you realise this reads as "don't bother validating your inputs"? Surely that's not what you meant? > It begs the question: validate for what? All inputs necessarily follow some protocol. Command line options and configuration files have syntax. Network packets have sizes & fields. Binary files have some format. So you just make sure your input correctly follows the protocol, and reject anything that doesn't. Now the protocol itself should also be designed such that implementations are easily correct and secure. In practice, this generally means your protocol must be as simple as possible. And it's probably a good idea to make sure your parser is cleanly separated from the rest of your program, either by the OS (qmail splits itself in several processes), or by the programming language itself (with type/memory safety).
- draw_down 7y ago> Do you realise this reads as "don't bother validating your inputs"? Surely that's not what you meant? I agree, surely that’s not what GP meant. So it would seem to be in bad faith to portray it that way. Come on.
- deleted 7y ago[deleted]
- tptacek 7y agoThat's a silly way to read what I said.
- loup-vaillant 7y agoOf course it is. But no matter how I read that sentence, I cannot parse something someone of your calibre could possibly have meant. Unless I missed something, you couldn't have meant that input validation is useless. You most probably didn't mean that input validation is superseded by some other technique, and therefore best ignored. You couldn't possibly think that everyone already does input validation, and therefore don't need the advice. But then I wonder. Why saying "validate all your inputs" is not useful? What would you say instead?
- _wldu 7y ago> Aside: I'm really frustrated by the advice to validate all input... It begs the question: validate for what? If your software asks users to input their age, to validate that, you would discard any input not in the set 0123456789, and any valid input (a number) that is less than 1 or greater than 130. It's not so much about input validation as it is about sanity checking the input. Is it sane? If so, then you should accept it. It may still be incorrect (user input error.. entered 24 rather than 25) but it should be safe to treat this input as an unsigned 8 bit number and manipulate it as such. The difficulty is that some inputs have a large, varied set, but even those can be bounded (and are) in the real-world. So if someone enters a first name that is 500 characters long, that should fail sanity checks. The problem with CS people is that they obsess over edge cases (100% correct and verifiable solutions) sometimes when they should not. I don't blame them for this, as that's a large part of what they were taught to focus on in school. User input is not an algorithms problem that needs a 100% correct and verifiable solution, it's real-world, can be reasonably bounded and good enough solutions are sufficient. Edge cases can be handled manually and added to the existing solution, too, if they are more common than what they initially seemed.
- naasking 7y ago> Aside: I'm really frustrated by the advice to validate all input. That's not useful advice and people should stop teaching it. This suggests teaching what validation means, not abandoning the idea of validating. In other words, be especially aware that you're crossing a trust boundary when accepting input, and use proper validation algorithms, like proper parsing instead of ad-hoc pseudo-parsing using regexes.
- jpgoldberg 7y agoI'm hoping that parser generators get more usable. I completely concur that using parser-generators to create safe parsers that will accept all and only valid input is a way to eliminate a large class of bugs. But getting developers to use parser generators has been a struggle because I'm finding it hard to give dev team tools they can use and integrate into their build systems. It also doesn't help that most developers have forgotten anything they learned about formal language theory, so it's hard to communicate the value of using parser generators. But we are getting there. Slowly, but there is progress.
- ken 7y agoThe banality of saying "all software has bugs" to begin an argument can only serve to distract. It's software whataboutism.
- mbrodersen 7y ago> all software has bugs Nope. See (for example) CompCert, SeL4, ...