4 ms·
Transitioning an existing C codebase to checked C has to be easier than transitioning to Rust.
by naasking 5y ago
Transitioning an existing C codebase to checked C has to be easier than transitioning to Rust.
- Diggsey 5y agoMaybe / maybe not. It's relatively easy to translate C to unsafe Rust, which is a mostly automatic process. The hard part is taking that unsafe C/Rust and turning it into checked/safe code. For this part, Rust has many benefits over C: - As a language it is easier to refactor. This is due to a more hygenic macro system, a lack of header files, etc. - The safe subset of Rust is much larger and more expressive than the subset of checked C. This provides more options for the unsafe -> safe translation effort. - The safe subset of Rust is more powerful than the subset of checked C. This means that it's more likely that a piece of code can be translated 1:1 into safe Rust, compared to a more complex transformation. For example, code which returns a pointer into one of its arguments is not uncommon in C, and this can be directly translated into Rust lifetime annotations.
- miffy900 5y ago> Maybe / maybe not. It's relatively easy to translate C to unsafe Rust, which is a mostly automatic process. This makes no sense; extending C code with Checked-C would still be easier as with Checked-C you wouldn't do any translation at all; it's a superset of C, in the same way that TypeScript is to JavaScript.
- Diggsey 5y agoFirst, we're talking about "Transitioning an existing C codebase to checked C". If you're just adding new checked C code, then you're not doing that. Second, you can't just add checked C to a codebase, because you have to actually interop with the unchecked C code, which uses different pointer types. My argument is that it may be easier to do an automatic migration to unsafe Rust, and then incrementally convert to safe Rust, than it would be to leave the codebase as C and try to incrementally convert it to checked C, because the "incremental conversion to checked C" is extremely difficult.
- naasking 5y agoIf you read the abstract of the linked paper, you'd see they assert that the annotated pointers can be safely erased, thus making them ordinary pointers again.
- opnitro 5y agoMuch easier. It doesn't change the runtime representation of types at all. It also supports a gradual typing-esque system for adding more precise types onto existing languages without changing the source code.
- ck45 5y agoYes, it reminds me of this project, using Checked C for the FreeBSD kernel: http://secdev.ieee.org/wp-content/uploads/2020/11/s1-02-Duan.pdf http://secdev.ieee.org/wp-content/uploads/2020/11/s1-02-Duan...
- roca 5y agoYes, but without temporal safety, it's not that valuable.
- naasking 5y agoSpatial errors still account for almost 30% of yearly security vulnerabilities via buffer overflows alone, which is only one subclass. I think solving those makes it plenty useful. Then add the fact that exist transformations that turn temporal errors into spatial errors, and you'll see it's not necessarily much of a limitation even then: https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2105 https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2105
- roca 5y agoWow, that paper is extremely wrong. > Memory deallocation can be modeled as an assignment. For example, the statement free(p) can be represented by the statement p=invalid, where invalid is a special untyped pointer to a temporally ‘invalid’ range of memory. Absolutely not. That works for memory accesses through 'p'. It doesn't help you at all for memory accesses through other pointer aliases to the same memory block. I mean, it's trivial to replace "free(p)" with a macro that also nulls out 'p', but no-one claims that that solves UAF bugs.
- naasking 5y agoYou can't quote a paragraph out of context and simply claim it's wrong. Whether their claim is wrong depends entirely on the global invariants their analysis ensures.
- roca 5y agoI skimmed the entire paper before making that comment. I'm pretty sure I understand it. BTW I have a PhD in static program analysis. If you think the paper is right, just explain how it detects use-after-free in the following code fragment: int* p = (int*)malloc(sizeof(int)); int* q = p; free(p); *q = 1;