News for hackers. Stuff that matters.
Re:Select Code_execution from * Using SQLite; (2019) by Quekid5 on Saturday June 13, 2020 @02:18PM (#23511427)
Locks are physical devices and so are susceptible to all manner of wonderful and surprising physical attacks.

Programming languages can artificially limit the attack surface. (Up to hardware exploits which can subvert the processor itself.)

Re:Select Code_execution from * Using SQLite; (2019) by c22 on Saturday June 13, 2020 @02:50PM (#23511690)
I don't understand this reasoning at all. Locks attempt to artificially limit the (physical) attack surface as well. This could, in fact, be a reasonable definition of a lock. So people come up with wonderful and surprising configurations of matter that cause these artificial limitations to fail providing direct access to the lock's root mechanism (via unanticipated route).

This is analogous to virtual attacks on information systems which are hardened against familiar routes of ingress and vulnerable to those which are wonderful and surprising.

Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @03:37PM (#23512063)
You can apply formal methods to code that you cannot in physical reality. If I show you the equation “x == y”, you won’t be able to pick 7 and 8 to make the equation true. If I give you a mechanical device that works with beads to answer the same question, you might make it work.

Of course computers are eventually physical reality, too, and things like rowhammer show that you don’t even need traditional “bugs” to escape your mathematical utopia.

But all the bugs talked about here are entirely the fault of the software.

Re:Select Code_execution from * Using SQLite; (2019) by vntok on Saturday June 13, 2020 @04:21PM (#23512355)
Well one could try to change the meaning of "==" to make the equation true. Think about comparator overloading in supported languages where the x and/or y variables are actually objects, for example.
Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @05:00PM (#23512683)
I was talking about algebra, not about C++.
Re:Select Code_execution from * Using SQLite; (2019) by laumars on Saturday June 13, 2020 @04:39PM (#23512496)
Except you can artificially alter the value of x or y via numerous different methods of attack via frameworks that supersede the code which has been written the formal methods against.
Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @05:00PM (#23512682)
Then you did not do actual formal verification, but something wrong and useless.
Re:Select Code_execution from * Using SQLite; (2019) by laumars on Saturday June 13, 2020 @05:16PM (#23512802)
Fuzz attacks have proven that edge cases are inescapable
Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @05:30PM (#23512915)
Fuzzing is only relevant where formal verification cannot be exhaustively applied (which is reality in turing complete languages), or is too cost-prohibitive. In a formally verified program, fuzzing is redundant and useless.

Are you going to fuzz the program "x = y+1; return x;", or are you convinced already that it will always return either y+1 (with y treated as a natural number, not a finite width integer), or 0 (if y was the maximum value in the unsigned data type of x), and that it will never access memory out of bounds?

Formal verification is exactly that, just usually in less obvious scenarios. Advanced type systems do the same implicitly by making expressions that would violate such properties (or where they cannot be proven) not type check.

Re:Select Code_execution from * Using SQLite; (2019) by laumars on Saturday June 13, 2020 @06:19PM (#23513305)
My point is that only works if you’re writing the entire software stack. The moment you rely on someone else’s library, whether it’s to read from a file descriptor, a libc wrapper around an OS SYSCALL or whatever, you’re opening up your program to unexpected behaviour. And that’s not even taking into account the slew of very real software bugs that can be introduced from unexpected hardware behavior. Using formal method might prove your applications logic but it doesn’t prove a buffer overflow bug in a library you’ve used, or the OS you’re running on, or the compiler you’ve used from introducing a bug, nor even the hardware itself.

Computers these days are sufficiently complex and with enough abstractions that there’s no such thing as a guarantee.

Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @10:10PM (#23514555)
I wrote this:

> Fuzzing is only relevant where formal verification cannot be exhaustively applied (which is reality in turing complete languages), or is too cost-prohibitive.

Re:Select Code_execution from * Using SQLite; (2019) by Sharlin on Saturday June 13, 2020 @07:20PM (#23513696)
> x = y+1; return x;

Funny you should use that specific example, because your analysis fails to account for the case where a) this is C or C++, b) y has a signed integer type, and c) its value is the maximum value of said type. In that case the behavior is, infamously, undefined, and anything can happen including accessing memory out of bounds. This is exactly the sort of corner case that fuzzing is designed to reveal. Formal analysis of the function would, of course, also flag the fact that the set of values of y for which the program is well-defined is not the entire domain of its type.

Re:Select Code_execution from * Using SQLite; (2019) by skissane on Saturday June 13, 2020 @07:47PM (#23513855)
> In that case the behavior is, infamously, undefined, and anything can happen including accessing memory out of bounds

Undefined per the standard, yes. Undefined per a particular implementation? Well, that’s up to each particular implementation. A compiler is free to make stronger guarantees than the standard requires. And, a formal verification is allowed to presume a particular compiler, and rely on whatever stronger guarantees it makes. Which means of course that the verification is only valid as long as that compiler is used, and changing the compiler requires revisiting the verification (even if only just to confirm that the new compiler makes the same guarantees) - but, in many cases, especially the cases in which formal verification is in the most demand (safety critical systems), that’s an acceptable limitation.

Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @09:53PM (#23514483)
I did not fail to take that into account:

> it will always return either y+1 (with y treated as a natural number, not a finite width integer), or 0 (if y was the maximum value in the unsigned data type of x)

And it does not matter, since the point of formal verification is to help taking those issues into account.

Re:Select Code_execution from * Using SQLite; (2019) by Sharlin on Sunday June 14, 2020 @02:28PM (#23519995)
Pardon me if I'm missing something, but I only see the "natural number" case and the "unsigned" case (the latter of which is indeed well-defined to wrap around to zero in C and C++), but I was talking about the case where x and y have, say, type signed int. Then all bets are off if y happens to equal INT_MAX in some execution, because the compiler is allowed to optimize with the assumption that that literally cannot happen. At least as far as the C standard is concerned. So my point was that in the real world, even such a trivial function may not only yield unexpected results but indeed cause the whole program to have arbitrary, undefined behavior.
Re:Select Code_execution from * Using SQLite; (2019) by comex on Saturday June 13, 2020 @04:05PM (#23512258)
I don’t know about the GP’s wording, but there is a difference. It is possible for a piece of software to be perfectly secure against software-based attacks, i.e. there‘s no possible data you can send it that will cause it to misbehave. It is not possible for a lock to be perfectly secure against physical attacks; if nothing else, you can always break it with brute force.

Of course, even perfect software is susceptible to physical attacks on the hardware it’s running on, but that’s different.

Re:Select Code_execution from * Using SQLite; (2019) by tsimionescu on Saturday June 13, 2020 @05:03PM (#23512711)
> It is possible for a piece of software to be perfectly secure against software-based attacks, i.e. there‘s no possible data you can send it that will cause it to misbehave.

I don't think this is obvious, even for theoretical software, much less for practical software. Even formal methods have limitations.

A very public recent example was of the formally proven logic in Intel and other processors around speculative execution (Spectre, Meltdown etc.). That logic was formally proven not to leak information, but the formal model wasn't actually sophisticated enough. Note that these weren't hardware bugs (they weren't bugs in the electrical components of the processor or in the analog logic), they were logic bugs in the processor's code (whether that was microcode or burned into the processor is less relevant).

In general, you can prove that a piece of software adheres to some specification, but you can't prove that the specification itself is complete enough.

Of course, realistic software has many more layers of uncertainty, and realistic formal verification is far to costly to apply to anything but very short programs.

Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @05:14PM (#23512792)
Thanks, this is for once in this thread, a real caveat in the application formal verification (or rigorous type systems). It's hard, it's not unlimited, and one may have fail to state crucial properties that matter in the first place.

Still, there are a lot of properties that are easy to state, and a lot of properties that are feasible to prove, and the intersection of these two can be very valuable in eradicating common issues in critical software, be it out-of-bounds pointers or your garden variety type confusion. (Again, not always possible, thanks to the halting problem, but often.)

The cost may indeed be prohibitive, though.

Re:Select Code_execution from * Using SQLite; (2019) by c22 on Saturday June 13, 2020 @04:45PM (#23512548)
I am not convinced. If your software is secured with any sort of key then you can break this with brute force also. All other attempts to prevent unauthorized access are applications of varying degrees of obfuscation and indirection, the same as in physical lock design.
Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @05:05PM (#23512727)
That is not how privilege boundaries work.
Re:Select Code_execution from * Using SQLite; (2019) by c22 on Saturday June 13, 2020 @06:02PM (#23513170)
Then how do explain privilege escalation attacks other than as a user discovering a path to elevated privileges that was not anticipated by the designers? Can't you "brute force" even the most theoretically rock solid privilege boundary by simply attaching your own computer to the memory in question?
Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @10:20PM (#23514599)
> other than as a user discovering a path to elevated privileges that was not anticipated by the designers

Most of the time, a barrier to elevated privileges that was not correctly implemented, i.e. a bug, not anything the designer did not anticipate.

> Can't you "brute force" even the most theoretically rock solid privilege boundary by simply attaching your own computer to the memory in question?

So? Does that mean it's not worth looking at the paths where the attacker does not have physical access of the machine that sits in some data center's secured basement?

Re:Select Code_execution from * Using SQLite; (2019) by ngneer on Saturday June 13, 2020 @04:35PM (#23512457)
No, there is no difference. Locks and software implement or abide by control laws. In your analogy, if you give perfect software an input and it behaves as expected, then that is the same as walking up to a locked door, trying to open it and failing. Both systems are susceptible to control bypass.
Re:Select Code_execution from * Using SQLite; (2019) by anyfoo on Saturday June 13, 2020 @05:21PM (#23512844)
The point is that for some programs[1], you can prove that all inputs will lead to an output with certain properties. With a physical lock, you cannot.

For physical locks, you cannot even rigorously define the "input".

[1] Not always, unfortunately, if your language is turing complete. You might be able to prove weaker, but still very useful statements, like "no input will cause a point to be dereferenced out of bounds".

Re:Select Code_execution from * Using SQLite; (2019) by ngneer on Sunday June 14, 2020 @02:02PM (#23519770)
Yes, you may prove such a statement about a program. But you will not be able to prove that about the physical system where the program is running (assuming you want to run your program and not just reason about it as a mathematical object). If you need an example, consider Plundervolt.
Re:Select Code_execution from * Using SQLite; (2019) by laumars on Saturday June 13, 2020 @02:51PM (#23511692)
SQLite is a software device and so is susceptible to all manner of wonderful and surprising software attacks
Re:Select Code_execution from * Using SQLite; (2019) by Quekid5 on Saturday June 13, 2020 @04:45PM (#23512543)
SQLite is written in a manner/language which only really affords tests, not proof of correctness. (My point was that it might have been written in a language where many of these exploits would not have been possible without subverting the hardware it's running on, but I see from the other responses that I may have phrased it a bit too obliquely.)
Re:Select Code_execution from * Using SQLite; (2019) by laumars on Sunday June 14, 2020 @07:31PM (#23522378)
Part of the reason SQLite is so prolific is because of the language used, not in spite of it. It’s enabled people to run SQLite on a broad range of hardware, device types and called from any language that supports native C calls (which is a massive array of languages). And let’s not forget the truly amazing performance you get from SQLite too.

Had SQLite been written in a language that would have made it easier to perform a proof of correctness then it wouldn’t be nearly as widely used and because of that language choice and then it likely wouldn’t have had the resources (financial nor community input) to complete a proof anyway. So would it have actually been any less buggy if it weren’t a C project?

Sometimes worse is better and moaning about “what if” is neither constructive nor even warranted when you consider just how well written SQLite already is and how abundant the tests are.

Re:Select Code_execution from * Using SQLite; (2019) by Quekid5 on Thursday June 18, 2020 @03:49PM (#23567107)
Of course it's popularity is due to using C... but that's not what we were talking about, was it?

> Sometimes worse is better and moaning about “what if” is neither constructive[...]

... and yet here we are talking about extremely dangerous and possibly far-reaching vulnerabilities in SQLite.

Re:Select Code_execution from * Using SQLite; (2019) by heavenlyblue on Saturday June 13, 2020 @03:36PM (#23512057)
An electronic lock is a physical device and you won’t be able to pick it as easy as you are saying.