3 ms·
Let’s be generous and assume that 5% of the overall code remains unsafe. That’s 95% of the code that doesn’t need to be checked extra. Additionally, that 5% is
by vlovich123 5y ago
Let’s be generous and assume that 5% of the overall code remains unsafe. That’s 95% of the code that doesn’t need to be checked extra. Additionally, that 5% is likely to remain static. With C any “securing” effort is a snapshot effort that bitrots quickly as more code is added.
- tptacek 5y agosqlite is renowned as a project that tests meticulously; they claim 100% branch test coverage, to the point where a reason they reject current Rust is that they can't achieve similar coverage against the branches the compiler itself inserts as safety checks (that is: they can't use Rust because they can't test safety checks that don't even exist in the language they use today). And the track record of that approach is, well, right there for you to see. The idea that what's needed for sqlite's C to be safe is more of the approach sqlite already uses seems pre-falsified, doesn't it?
- infogulch 5y agoI think 100% machine code branch test coverage is legally required in some of the environments that SQLite targets. That is, there must be a test that exercises both sides of every machine code branch instruction emitted in the final binary. Basically, every branch must have a justification for why it exists. I feel like that's not such a bad target for rust to aim for.
- vlovich123 5y ago> sqlite is renowned as a project that tests meticulously; they claim 100% branch test coverage You realize that there are lots of test coverage metrics and none of them tell you anything about the correctness or safety of the code or about how thoroughly the edge cases have been tested, right? 100% branch coverage is neat and may indicate that the testing is thorough, or it might just indicate the project is chasing it as a metric. I’ll bet on compile time lifetime and ownership analysis guaranteed by the language every time over metrics of how good the test suite is (a test suite is important but classes of bugs are just impossible in Rust and don’t need testing/coverage in the first place). > that is: they can't use Rust because they can't test safety checks that don't even exist in the language they use today Can you back up this claim? This feels like a very FUD statement as any high level language (including C) has a risk that the compiler inserts branches that aren’t present in the code. Regardless, AFAIK, coverage instrumentation happens at a level below where the distinction between C and Rust matters, so any coverage should be the same. I buy the argument that replicating the test suite may be time consuming bit, but the claim that there’s something inherent about Rust preventing branch coverage feels extraordinary to me. Also, I’m not even sure where the extra branches are being inserted. Are you referring to drop statements the compiler injects for lifetimes? > And the track record of that approach is, well, right there for you to see. Constant CVEs and a fundamental inability to handle maliciously crafted files? I’m not shitting on the SQLite team. The project is amazing and a marvel. I’m just saying that its C heritage has some inescapable realities. Also remember that studies tend to show that the bug rate is pretty constant across languages in terms of LOC. This you want the language and stdlib doing as much as possible for you if you’re prioritizing correctness and security.
- tptacek 5y agoI'm simply citing the article we're commenting on.
- ansible 5y ago> sqlite is renowned as a project that tests meticulously... Any language that can produce a C library interface identical to the existing one for sqlite3 would be a good candidate for a reimplementation. If you show me a Rust library that passes all the sqlite3 tests flawlessly on my platform (typically x86-64) then I'd include that in my project, and sleep soundly at night afterwards. There might be problems, but the chances are very low. Most other libraries don't nave nearly as good coverage, and it is much riskier to switch over an implementation.
- eloff 5y agoIt is better, definitely safer. But it's not perfect. I write rust on a daily basis. I've written a lot of C++ in the past. It's safer, but I have memory safety issues in both. It's more a matter of degree. For a large existing code base that are well written I think it's easier to improve the safety of the existing code than rewrite it completely in a safer language.
- tptacek 5y agoPeople talk about having memory safety issues in Rust and Go, and my general reaction is that these claims tend to be pretty artificial (for instance: they've managed to introduce concurrency bugs that abort their program). If you've got a war story about a security-relevant memory corruption vulnerability you managed to introduce into a Rust codebase (that wasn't in straight-up `unsafe` code), I'd be interested in hearing more about it. My position right now, before hearing that war story, is that Rust vs. C is more than a difference of degree. It's a difference of degree in security writ large, to be sure. But for memory corruption? I'd say the distinction is close to categorical.
- pjmlp 5y agoIt was already like that in the Pascal/Modula/Ada vs C days. Just because it isn't 100% bullet prof, just 95% better, the C team always advocates it isn't worth the effort.
- eloff 5y ago> If you've got a war story about a security-relevant memory corruption vulnerability you managed to introduce into a Rust codebase (that wasn't in straight-up `unsafe` code), I'd be interested in hearing more about it. No, they're in unsafe code. Except Go where you don't get memory safety with some kinds of race conditions. I'm debugging a segfault in Rust today as it turns out. I guarantee it's in unsafe code. But I have some unsafe code. A database would also definitely have quite a bit of unsafe code. It's a lot better than the situation in C. But rewrites always introduce bugs. And sqlite is so well written and tested, it's not a low quality code base. I don't think a rewrite makes sense here, it'd be better to improve the existing code to make it safer. That's my opinion anyway.