Re:Orange_slice: Research Kernel and Hypervisor in Rust
by oconnor663 on Friday April 12, 2019 @10:31AM
(#19645106)
> if your Rust code has memory errors, there's a bug in an "unsafe" block
Minor clarification around this part. It's possible for a bug in safe code to break an invariant that some correct unsafe code is relying on, if that safe code has private access to something that the rest of the world doesn't. For example, by changing only safe code inside of Vec, you could introduce a bug that set the wrong capacity. Since all the unsafe code in Vec assumes the capacity is correct, that would break everything and cause tons of UB. Vec is sound, though, because the capacity is a private field, and safe code in the caller can't change it. But it does mean that when we're auditing unsafe blocks, we might also need to audit the safe code in the same module, depending on what invariants the unsafe blocks are assuming.
Re:Orange_slice: Research Kernel and Hypervisor in Rust
by glennpratt on Friday April 12, 2019 @10:50AM
(#19645242)
I guess that's debatable, your point is that code that should be unsafe might not be, but then that did mean the unsafe code is wrong in a sense. It assumes an invariant that isn't enforced.
Re:Orange_slice: Research Kernel and Hypervisor in Rust
by oconnor663 on Friday April 12, 2019 @10:59AM
(#19645331)
Some people describe it as unsafe code "infecting" its containing module. This section of the nomicon goes into more detail: https://doc.rust-lang.org/nomicon/working-with-unsafe.html
I believe so, yes.
https://www.zdnet.com/article/microsoft-70-percent-of-all-se...
> IIUC, Rust can prevent these kinds of memory vulnerabilities.
Yes: if your Rust code has memory errors, there's a bug in an "unsafe" block (~1% of the code in a project of mine, which I think is typical) or in the compiler.
> But it cant really present the million of other types of vulnerabilities, such as mis-configuration, wrong logic in the code, races, etc
It can prevent data races. It can't prevent all possible race conditions.
https://doc.rust-lang.org/nomicon/races.html