News for hackers. Stuff that matters.
Re:Formal Verification Creates Hacker-Proof Code (2016) by tptacek on Saturday April 25, 2020 @07:59PM (#22982792)
Formal methods are a powerful security tool because they produce useful code so slowly that they necessarily minimize attack surface.
Re:Formal Verification Creates Hacker-Proof Code (2016) by sterlind on Saturday April 25, 2020 @10:08PM (#22983673)
I 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.

Re:Formal Verification Creates Hacker-Proof Code (2016) by tptacek on Saturday April 25, 2020 @11:12PM (#22984038)
You 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.

Re:Formal Verification Creates Hacker-Proof Code (2016) by danmaz74 on Sunday April 26, 2020 @02:03AM (#22984919)
Indeed. What is unbearably slow is creating the whole software with formal verification, not just the core algorithm.
Re:Formal Verification Creates Hacker-Proof Code (2016) by drdrey on Sunday April 26, 2020 @01:25AM (#22984739)
TLA+ 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.
Re:Formal Verification Creates Hacker-Proof Code (2016) by pron on Friday May 01, 2020 @07:28PM (#23047564)
1. TLA+ doesn't "find" or not find anything. It is a mathematical language for describing systems and assertions about them. There is a proof assistant for TLA+ that checks your formal proofs of theorems that say that your assertions follow from the description, and model checkers that verify your theorems automatically.

2. If you use the model checker, it's not about it "failing to find" a counter example. A model checker result is a proof that no such example exists. True, it is usually a proof about some finite instance of your system description.

3. There is just no such thing as proving a system flawless. Software systems are physical systems exhibiting probabilistic behaviors. At best you can prove things about a mathematical description of a system, which mean that as long as the physical system behaves according to the description, the result follows. Of course, the first part at best holds with some probability.

Re:Formal Verification Creates Hacker-Proof Code (2016) by p0llard on Sunday April 26, 2020 @09:17AM (#22986915)
I've never actually used TLA+, but my understanding is that it does exhaustive model checking (presumably using some suitable simulation relation), so in this case failure to find a violating trace indicates that no such trace exists, and the invariants always hold.

Correctness might well be defined solely by a set of invariants, so I don't quite understand your point here?

Re:Formal Verification Creates Hacker-Proof Code (2016) by drdrey on Sunday April 26, 2020 @05:35PM (#22990462)
Imagine the following scenario, you have encountered an actual bug in concurrent code, and you think it would be great to work on a model and invariants that lets TLA+ find the bug (as an exercise).

So you start writing a model, and a set of invariants, you run the tool and... it finds nothing. Does that mean you just proved the bug does not exist? No, you _know_ the bug exists, what it means is that you didn't write a correct model on your first try. So you iterate on it, add a few things you missed, put some extra labels, read the docs a bit more, maybe refine your invariants, make them stronger, work through a couple traces that don't actually make sense in practice (e.g. actors just never taking any action whatsoever). During all this time, you either found nothing or things that were not interesting. At no time have you ever proved anything correct, you just iterated on your model until you managed to capture a real life scenario.

It takes some convincing to make the jump from "this model does not violate my invariants" to "I think this model and the invariants are close enough to what I care about that I think it's good enough"... I don't know how to go from there to things like "proven correct" and "flawless".

Re:Formal Verification Creates Hacker-Proof Code (2016) by sterlind on Monday April 27, 2020 @12:53PM (#22997563)
I mean, specific to my scenario, my invariant was "only one zone at a time" and the liveness property was "everyone who wants a zone eventually gets one", so respectively:

1. \A z \in Zones: Active(z) => ~\E o \in Zones: z # o /\ Active(o) 2. \A w \in Workers: \A z \in Zones: WorkerWantsZone(w, z) ~> WorkerHasZone(w, z)

Unlike your scenario, I am checking the spec here. I know that code that properly implements the spec satisfies these two properties, therefore I've proven the spec correct. You can disagree on the importance of those two properties but I've mechanically checked that those properties are always preserved in my finite models, so I know the spec is correct, at least for the model size.

You know, it's really not too hard to get started with this stuff. You can always nit-pick but why not try it out and see if it's useful for you?

Re:Formal Verification Creates Hacker-Proof Code (2016) by drdrey on Friday May 01, 2020 @08:45PM (#23048042)
I am using it, I just don't use it to make claims of correctness.
Re:Formal Verification Creates Hacker-Proof Code (2016) by p0llard on Sunday April 26, 2020 @06:09PM (#22990708)
Ah sure. I interpreted "proven correct" to mean "proven correct wrt a set of invariants" in this context.
Re:Formal Verification Creates Hacker-Proof Code (2016) by hwayne on Sunday April 26, 2020 @11:55AM (#22988006)
This is correct: the TLA+ model checker (TLC) will check all possible behaviors for the finite model. As the GP said, they were only working with a finite number of workers, but within those constraints it guarantees the spec always satisfies the invariants.

(This is of course assuming that TLC doesn't have any bugs that would cause it to misreport. By contrast something like randomized testing doesn't guarantee the spec satisfies the invariants even if the tester is bug-free.)

Re:Formal Verification Creates Hacker-Proof Code (2016) by sterlind on Sunday April 26, 2020 @05:23PM (#22990380)
exactly. I've proven that in a scenario with a certain number of zones and workers, the invariants and temporal properties cannot be violated.

With more work, I could prove the invariants for any number of workers and zones using TLAPS rather than TLC, though I couldn't prove the temporal properties in this way (since TLAPS doesn't support temporal logic, it can only prove invariants.)

Re:Formal Verification Creates Hacker-Proof Code (2016) by CalChris on Saturday April 25, 2020 @08:21PM (#22982958)
SEL4 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-veri...

Re:Formal Verification Creates Hacker-Proof Code (2016) by tptacek on Saturday April 25, 2020 @08:24PM (#22982977)
Different meanings of "slow". I like L4 a lot though. But, I mean, you're generally attacking the things running on top of it.
Re:Formal Verification Creates Hacker-Proof Code (2016) by CalChris on Sunday April 26, 2020 @11:54AM (#22988004)
I 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.
Re:Formal Verification Creates Hacker-Proof Code (2016) by tptacek on Sunday April 26, 2020 @03:23PM (#22989454)
I'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.
Re:Formal Verification Creates Hacker-Proof Code (2016) by pron on Friday May 01, 2020 @07:34PM (#23047602)
The belief that software could be affordably proven correct was pervasive in the 70s, it led to a research winter, and now formal methods is very much about adding rigor and catching more bugs (some of the most promising directions in contemporary formal methods research revolve around reducing soundness to help find more bugs more quickly).

There is a small subdiscipline of formal methods that comes from programming language theory (judging by conferences, it makes up no more than 10-20%) that does still have this 1970s "subtext", but actual researchers or practitioners are usually careful with what they actually say, and you'll most often find such claims explicitly made only by fans.

Re:Formal Verification Creates Hacker-Proof Code (2016) by CalChris on Saturday April 25, 2020 @08:26PM (#22982995)
I see your point.
Re:Formal Verification Creates Hacker-Proof Code (2016) by f00_ on Saturday April 25, 2020 @09:00PM (#22983230)
The 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

See also: Property-based testing, and TLA+

Re:Formal Verification Creates Hacker-Proof Code (2016) by sk5t on Saturday April 25, 2020 @09:46PM (#22983521)
FWIW 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.
Re:Formal Verification Creates Hacker-Proof Code (2016) by eesmith on Sunday April 26, 2020 @06:10AM (#22986014)
Re:Formal Verification Creates Hacker-Proof Code (2016) by rurban on Monday April 27, 2020 @02:58AM (#22993550)
Yeah, but with holes. Eg affecting Bugzilla. Only closed 2018 in cperl (hash keys). perl5 never cared to close its taint holes.
Re:Formal Verification Creates Hacker-Proof Code (2016) by bawolff on Sunday April 26, 2020 @12:06AM (#22984319)
I'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.

Re:Formal Verification Creates Hacker-Proof Code (2016) by hwayne on Sunday April 26, 2020 @12:00PM (#22988045)
It 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-...
Re:Formal Verification Creates Hacker-Proof Code (2016) by marceloabsousa on Sunday April 26, 2020 @09:48AM (#22987106)
I 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.

Re:Formal Verification Creates Hacker-Proof Code (2016) by SkyMarshal on Sunday April 26, 2020 @12:42PM (#22988317)
> 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.

Re:Formal Verification Creates Hacker-Proof Code (2016) by exdsq on Saturday April 25, 2020 @08:02PM (#22982821)
It doesn’t have to be that slow! The tooling has advanced quite significantly over the last few years.
Re:Formal Verification Creates Hacker-Proof Code (2016) by MaxBarraclough on Saturday April 25, 2020 @08:06PM (#22982847)
It'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.

Re:Formal Verification Creates Hacker-Proof Code (2016) by lmm on Saturday April 25, 2020 @08:35PM (#22983044)
For 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.
Re:Formal Verification Creates Hacker-Proof Code (2016) by ashafer on Saturday April 25, 2020 @09:53PM (#22983566)
As 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.

Re:Formal Verification Creates Hacker-Proof Code (2016) by CalChris on Sunday April 26, 2020 @09:04AM (#22986845)
Do 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?
Re:Formal Verification Creates Hacker-Proof Code (2016) by thanksforfish on Saturday April 25, 2020 @08:47PM (#22983140)
If you don't use formal methods, how do you know when your work is done?
Re:Formal Verification Creates Hacker-Proof Code (2016) by bluGill on Saturday April 25, 2020 @09:42PM (#22983494)
When 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)

Re:Formal Verification Creates Hacker-Proof Code (2016) by im3w1l on Saturday April 25, 2020 @09:19PM (#22983366)
When the checks clear.
Re:Formal Verification Creates Hacker-Proof Code (2016) by ternaryoperator on Saturday April 25, 2020 @09:39PM (#22983478)
One of the finest puns I've seen on HN ever!
Re:Formal Verification Creates Hacker-Proof Code (2016) by oldgradstudent on Sunday April 26, 2020 @05:14AM (#22985752)
If you do use formal methods, how do you know you completed the proof?
Re:Formal Verification Creates Hacker-Proof Code (2016) by lmm on Sunday April 26, 2020 @08:57AM (#22986819)
You have an automatic tool that tells you. Your program won't "compile" unless the proof is correct.

Whether you've proven the right thing still requires judgement - what you end up with is a provably correct implementation of what you thought you wanted. But that's a much smaller problem, and at a minimum you're guaranteed to have an unambiguous definition of what it is you actually built.

Re:Formal Verification Creates Hacker-Proof Code (2016) by oldgradstudent on Sunday April 26, 2020 @10:25AM (#22987367)
> Whether you've proven the right thing still requires judgement

That's my point.

Formal methods don't make bugs or debugging disappear. They move it to different domain - the development of the proof.

> what you end up with is a provably correct implementation of what you thought you wanted.

You end up with a provably correct implementation of what you thought you stated on what you thought you wanted.

Serious proofs are highly non-trivial. I've seen experts debate the exact semantics of the most simple properties.

Re:Formal Verification Creates Hacker-Proof Code (2016) by lmm on Sunday April 26, 2020 @11:02AM (#22987625)
> Formal methods don't make bugs or debugging disappear. They move it to different domain - the development of the proof.

They make the thing we usually call bugs and usually experience as debugging disappear. The thing that remains is a very different activity with very different properties.

Re:Formal Verification Creates Hacker-Proof Code (2016) by oldgradstudent on Sunday April 26, 2020 @11:13AM (#22987698)
> The thing that remains is a very different activity with very different properties.

Do you write a correct formal spec the first time round? I don't. Proofs sometimes pass or fail when they shouldn't.

When these problem occur I call them bugs, and I call process of finding and fixing them debugging.

Re:Formal Verification Creates Hacker-Proof Code (2016) by lmm on Sunday April 26, 2020 @11:59AM (#22988041)
> When these problem occur I call them bugs, and I call process of finding and fixing them debugging.

What do you find it has in common with the activities that we normally call debugging? For me debugging is characteristically about understanding how a system is behaving, essentially by bisecting: it's all about figuring out what should be the case at each point and identifying the point at which things start to go wrong. Whereas correcting a proof is very different: you immediately know where the problem is, and it's more about coming up with a new lemma or strategy - it's the same kind of activity as writing a new proof/program, whereas (traditional) debugging is very much a separate skill, IME.

Re:Formal Verification Creates Hacker-Proof Code (2016) by oldgradstudent on Monday April 27, 2020 @04:02PM (#22999397)
I view these as very similar.

A proof can fail for many reasons, and even in the simplest possible case, where the tool provides you with a counter example it could either be a real bug in the design/program/protocol, but there could also be something wrong with the specification you were given, or in your implementation of the specification, or in some assumptions you've made to simplify the proof, or there's ambiguity in the natural language description, or even some typo somewhere.

You now need to understand the domain and the system well enough to come up with an explanation of the phenomena. This is debugging.

Re:Formal Verification Creates Hacker-Proof Code (2016) by lmm on Monday April 27, 2020 @09:08PM (#23002205)
But you have access to everything at every stage. There's no need to figure out what the data is or how it got that way - the hard part of debugging - because there is no data, no state, no user input. It's more like fixing a compilation error than debugging.
Re:Formal Verification Creates Hacker-Proof Code (2016) by MaxBarraclough on Sunday April 26, 2020 @06:07AM (#22986002)
I don't follow. The proof is complete when all proof obligations have been discharged.
Re:Formal Verification Creates Hacker-Proof Code (2016) by oldgradstudent on Sunday April 26, 2020 @09:37AM (#22987041)
But 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.

Re:Formal Verification Creates Hacker-Proof Code (2016) by MaxBarraclough on Sunday April 26, 2020 @04:45PM (#22990098)
I 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.

Re:Formal Verification Creates Hacker-Proof Code (2016) by oldgradstudent on Monday April 27, 2020 @04:07PM (#22999457)
> 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?"

Re:Formal Verification Creates Hacker-Proof Code (2016) by MaxBarraclough on Tuesday April 28, 2020 @06:43AM (#23005640)
> It is very easy to complete a proof on the wrong model

That doesn't sound right. Automatic proof assistants/verifiers won't approve your proof unless it really is a proof for the model, right?

> there are always errors in the model, at least initially

Agreed.

> 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?

It's true that bugs in the model are a possibility.

More broadly, it's possible for defects to get through a formal software-development methodology. There was an interesting case study done on this. [0] Vastly fewer than if formal methods are not used, but you're still right that ultimately it's not a completely rock-solid guarantee. (And that's not counting things like bugs in the proof-assistant, or bugs in the non-verified compiler you end up using.)

[0] https://www.adacore.com/tokeneer ('Analysis' section is on page 59 of PDF)

See also https://blog.adacore.com/tokeneer-fully-verified-with-spark-... , https://github.com/AdaCore/spark2014/tree/master/testsuite/g...

Re:Formal Verification Creates Hacker-Proof Code (2016) by exdsq on Sunday April 26, 2020 @04:31AM (#22985560)
You 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!

Re:Formal Verification Creates Hacker-Proof Code (2016) by ethanwillis on Sunday April 26, 2020 @02:38AM (#22985064)
And agile methods are so powerful because they.. move fast and make broken things?
Re:Formal Verification Creates Hacker-Proof Code (2016) by rustybolt on Sunday April 26, 2020 @05:21AM (#22985784)
There'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.