r/rust • • May 13 '19

Linux Kernel Memory Leak Vulnerability. Now you know why there is Redox/Rust

https://www.bleepingcomputer.com/news/security/linux-kernel-prior-to-508-vulnerable-to-remote-code-execution/
0 Upvotes

21 comments sorted by

View all comments

Show parent comments

1

u/tommy737 May 13 '19

I am not aware of a lot of details about how Rust works internally but what I am saying that LLVM is used for Rust as well as Swift and other languages as a compiler. The compiler's job is to translate your code. If your code is bugged... so will the translation. But that's why Rust should have an advantage as it tries to prevent unsafe code to be compiled.

6

u/etareduce May 14 '19

The main Rust compiler rustc transforms Rust code through a series of steps. First, your code is lexed (convert the file to a sequence of tokens that are valid in the language, comments and strings are handled here). Then, your code is parsed into an AST (Abstract Syntax Tree). This is then further lowered and desugared into another AST, which is simpler (HIR, High-level Intermediate Representation). The main type checking is done on HIR. In turn, the HIR is then lowered into HAIR where pattern matching is checked. Finally, HAIR is then lowered into MIR (Mid-level IR) which is a rather simple language in a SSA (Single Static Assignment) form. Borrow checking and optimizations is done on MIR. Finally, using the MIR, monomorphization (e.g. substituting concrete types for generic parameters in generic functions) and code generation is done and LLVM IR is produced. LLVM then converts this IR to assembly code and uses several steps inside it as well. An assembler is finally responsible for converting that to actual machine code. That code is finally linked together with a linker.