7 ms·
Formal methods are a powerful security tool because they produce useful code so slowly that they necessarily minimize attack surface.
by tptacek 7y ago
Formal methods are a powerful security tool because they produce useful code so slowly that they necessarily minimize attack surface.
- exdsq 7y agoIt doesn’t have to be that slow! The tooling has advanced quite significantly over the last few years.
- MaxBarraclough 7y agoIt's still fair to say that formal methods produces software far, far more slowly than ordinary methods. Look at how little functionality seL4 provides, compared to hobbyist operating systems.
- lmm 7y agoFor equal time and effort, I'm not at all convinced that it's slower. It's easy to underestimate how much time gets spent on debugging, you just don't see it in the up-front cost.
- thanksforfish 7y agoIf you don't use formal methods, how do you know when your work is done?
- im3w1l 7y agoWhen the checks clear.
- ternaryoperator 7y agoOne of the finest puns I've seen on HN ever!
- bluGill 7y agoWhen the rate of bugs coming in from test goes below some threshold that your boss is comfortable with. Note that formal methods don't get around this as they do nothing for the class of bugs where it works as specified but now that we see it in operation we know the specification was wrong. (once the spec is right though it is faster)
- deleted 7y ago[deleted]
- oldgradstudent 7y agoIf you do use formal methods, how do you know you completed the proof?
- MaxBarraclough 7y agoI don't follow. The proof is complete when all proof obligations have been discharged.
- oldgradstudent 7y agoBut how do you know you have the right proof obligations? It's very easy to discharge a massive number of proof obligations while proving nothing of interest. Formal methods don't just make bugs and debugging disappear, they just move it to a different domain - the development of the proofs.
- MaxBarraclough 7y agoI can't make sense of what you're saying. You've completed the proofs when you've discharged all proof obligations. The proof obligations will depend on the formal modelling system you use (Event-B, say), and of course on your formal model. You aren't left in a state of uncertainty as to whether you've finished discharging the proof obligations. Are you referring to the possibility of errors in your model? That's not the same thing.
- oldgradstudent 7y ago> Are you referring to the possibility of errors in your model? That's not the same thing. It is very easy to complete a proof on the wrong model, and there are always errors in the model, at least initially. There's always an iterative process of refining the model until you are confident in its being good enough. When are you confident it is good enough? That's quite similar to asking "If you don't use formal methods, how do you know when your work is done?"
- 7y ago
- ashafer 7y agoAs one of my coworkers put it: "A talented programmer can write and verify 4 lines of code a day" seL4 has some cool ideas, but I can't stress enough how miserable it is to develop for.
- CalChris 7y agoDo you mean it's miserable to develop the seL4 microkernel or do you mean it's miserable to develop applications on top of seL4? If the latter, is it any different from any other microkernel?
- exdsq 7y agoYou don't have to jump in 100%, you can just add formal methods to the things that require it. Cryptographic algorithms, network protocols, distributed protocols, etc, could all be completed in Isabelle or Coq and then generate Haskell from the formal spec. For less-critical parts of the system you could use property based testing and various other "semi-formal" techniques which take less time but still add to the overall quality. I actually work in an agile environment that uses formal methods and it is possible!
- CalChris 7y agoSEL4 found the opposite. They could formally verify away run time checks. Algorithmic invariants: Many optimizations rely on certain properties being always true, so specific checks can be left out or can be replaced by other, more efficient checks. A simple example is that the distinguished idle thread is always in thread state idle and therefore can never be blocked or otherwise waiting for I/O. This can be used to remove checks in the code paths that deal with the idle thread. https://cacm.acm.org/magazines/2010/6/92498-sel4-formal-verification-of-an-operating-system-kernel/fulltext https://cacm.acm.org/magazines/2010/6/92498-sel4-formal-veri...
- tptacek 7y agoDifferent meanings of "slow". I like L4 a lot though. But, I mean, you're generally attacking the things running on top of it.
- CalChris 7y agoI see your point.
- CalChris 7y agoI still see your point but quoting the How Amazon Web Services Uses Formal Methods paper: In each, TLA+ has added significant value, either finding subtle bugs we are sure we would not have found by other means, or giving us enough understanding and confidence to make aggressive performance optimizations without sacrificing correctness. Type checking, borrow checking and unit testing are similar albeit weaker tools that allow rapid development by providing a safety net.
- tptacek 7y agoI'm on the "yes type checking" side of the perennial "which is more efficient" programming language debate, but when we talk about "formal methods" in the context of eradicating security vulnerabilities, the subtext is "formally proving correctness", not simply any tool that increases rigor. I agree, boringly, that there are PL tools that apply rigor to increase development speed.
- f00_ 7y agoThe most interesting thing I've seen as far as this is concerned is Taint Analysis. You can label functions as returning user input, some functions take user input and turn it into sanitized input, and there are functions that should never take non-sanitized input. It's all statically-checked and you can incorporate it into your CI/CD: https://pyre-check.org/docs/pysa-basics.html https://pyre-check.org/docs/pysa-basics.html See also: Property-based testing, and TLA+
- sk5t 7y agoFWIW the first practical application of input tainting that comes to mind is Perl's circa 2001, although I wouldn't be surprised to hear Smalltalk went there before.
- bawolff 7y agoI'm not familar with pyre, but i have experimented with some security static analysis tools. The one's i have experimented with take some normal program and try to analyse it. The analysis is usually far from complete, and as a result has so many false positives that its difficult to adopt. Anyways, i would say those are rather different from systems where you give an actual proof of correctness.
- sterlind 7y agoI hear this claim a lot but I question it's truth. I'm faster with formal tools than without. For instance, this week I needed to build a distributed locking mechanism so a collection of asynchronous actors could only access resources in one region at a time. I described my two requirements in TLA+: only one zone at a time, and everyone who wants a zone eventually gets it (with the assumption nobody goes down forever - weak fairness.) I had several bugs which it caught, until I finally arrived at a protocol that was proven correct (at least for a handful of workers on a handful of zones.) It took around a day from start to finish, and now I know my design is literally flawless. Sure, I didn't prove it in the general case, nor did I prove that my code implements the spec, but this was still extremely useful! Having the machine check your designs frees you from worrying if you've caught all the races and corner cases.
- tptacek 7y agoYou can easily convince me that formal methods are more efficient for complex distributed systems problems, or for cryptographic protocols, or things like that. But even in systems whose whole premise is algorithmic, the hairy stuff provers are designed against are a small part of the overall coding task. And for the kind of security this article is talking about, it's not enough to have a proven core algorithm or protocol; your dumb input parsers and output renderers and all that other boring integration code also needs to be bug-free, because those kinds of joinery are where we tend to find vulnerabilities.
- danmaz74 7y agoIndeed. What is unbearably slow is creating the whole software with formal verification, not just the core algorithm.
- drdrey 7y agoTLA+ doesn't prove anything to be "correct" or "flawless", I find it extremely worrisome that you claim as much. It failed to exhibit traces that violated your invariants, which says something completely different.
- ethanwillis 7y agoAnd agile methods are so powerful because they.. move fast and make broken things?
- rustybolt 7y agoThere's some truth in that. They force you to scrutinize every line of code. This creates a focus on minimizing attack surface but also produces code with significantly less bugs.
- marceloabsousa 7y agoI think your statement is very misleading: - There's no clear definition for formal methods. One of the fundamental problems with 'formal methods' is that it's a very fragmented community of researchers and practitioners (many who never built a real-world software systems). Formal methods depends very much of who you talk with: static analysis, dynamic analysis, type systems, writing specs in Z notation, writing code in a subset of C without malloc, etc. - Formal methods doesn't produce code: humans produce code. A side note: people forget one of the major successes of 'formal methods' is actually hardware synthesis and verification. - Security is about risk management. Attack surfaces is a classification of some types of risk but not all. Anyway, formal methods can only help you to protect against attacks that you are already aware. None of this has anything to do with the speed which with code is being produced.
- SkyMarshal 7y ago> Anyway, formal methods can only help you to protect against attacks that you are already aware. Not sure exactly what you mean here but on its face it isn’t true. Formal Methods are arguably the single best way of protecting you against attacks that you are not already aware of, by eliminating entire classes of bugs, errors or attack vectors, without regard to what type of attacks may be used against them.
- hwayne 7y agoIt depends on what you mean by "formal methods". Fully verifying code is fully correct is extremely expensive. Partially verifying code is somewhat correct is a lot less expensive. Verifying the _design_ you intend to code is less expensive than that, and is actually pretty economical. I wrote about this in-depth here: https://www.hillelwayne.com/post/why-dont-people-use-formal-methods/ https://www.hillelwayne.com/post/why-dont-people-use-formal-...