News for hackers. Stuff that matters.
Re:Shipping Rust code in Firefox by Dylan16807 on Tuesday July 12, 2016 @11:37AM (#12079919)
A JIT doesn't have to be any less safe than compiling Rust code.
Re:Shipping Rust code in Firefox by comex on Tuesday July 12, 2016 @03:02PM (#12081506)
No, but to be safe enough it has to be more safe than the Rust compiler, because the latter doesn't get run on untrusted code (with the result automatically executed)[1]. If bounds checks exist in the compiler IR, they're subject to optimization, which is very helpful for performance but also risky, as incorrect optimizations can easily cause memory unsafety. Optimizer bugs in modern backends are rarely encountered in practice, but from a security perspective, that's like saying your C++ program never crashes in practice: it helps, but it doesn't prove the absence of bugs that can only be triggered by pathological inputs; such bugs in fact tend to be quite common.

I've never tried to find an optimizer bug in LLVM, but I have found more than one in V8, so I have some idea what I'm talking about.

[1] More specifically, this doesn't happen in situations where correctness of the generated code is relied on to provide safety guarantees. There are several websites that will compile and run Rust code for you, but none of them try to ban unsafe code, or filesystem/syscall access for that matter, at the language level; rather, their security model relies entirely on the OS sandbox the process runs in. Google's PNaCl uses (or used to use?) LLVM on untrusted code, but AFAIK the output of LLVM, the machine instructions, are still run through the NaCl validator, so getting LLVM to miscompile something wouldn't accomplish much. (NaCl also runs both LLVM itself and the untrusted code in an OS sandbox.)

Re:Shipping Rust code in Firefox by haberman on Tuesday July 12, 2016 @12:05PM (#12080183)
It seems safe to say that a JIT-trace -> Rust -> machine code compilation pipeline will probably never be fast enough to satisfy the requirements of a high-performance JIT compiler.
Re:Shipping Rust code in Firefox by Dylan16807 on Tuesday July 12, 2016 @12:08PM (#12080213)
Going the long way is just a 'proof of concept' sort of thing. You could design a high-performance JIT around equivalent safety mechanisms, and even prove the tricky parts.
Re:Shipping Rust code in Firefox by pcwalton on Tuesday July 12, 2016 @12:33PM (#12080430)
JavaScript's memory model is incompatible with that of Rust anyhow. You would want something like typed assembly language (Google this--it's a fertile research area). Very researchy though, with uncertain payoff.

But note that a lot of security problems are not in the jitcode but rather in C++ implementations of JS objects and in the compiler itself.

Re:Shipping Rust code in Firefox by nickpsecurity on Tuesday July 12, 2016 @01:08PM (#12080691)
BOOM! Typed, assembly language is exactly what I was going to recommend! TALC assembly, Chlipala's Bedrock, and Microsoft's CoqASM are Google keywords to use for anyone following along.

CakeML or Verisoft's C0 could be useful for assembly generation but not as sure there. Tough constraints in JIT. Edited to add Myreen's JIT that I just remembered.

http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=F58...

Re:Shipping Rust code in Firefox by dman on Tuesday July 12, 2016 @03:39PM (#12081758)
CoqASM looks interesting! Is it publicly available anywhere?
Re:Shipping Rust code in Firefox by nickpsecurity on Tuesday July 12, 2016 @04:07PM (#12081943)
Not that Im aware of. They might privately license it if asked. I mainly bring it up as something worth cloning by FOSS team given there's plenty details in paper. Meanwhile, look up Magnus Myreen's publications and software as they're on a row with verified everything.
Re:Shipping Rust code in Firefox by moosingin3space on Tuesday July 12, 2016 @06:11PM (#12082613)
Typed assembly language would be an excellent addition to the Rust ecosystem -- there are still segments of software which should (or must) be implemented in assembly, so anything that can help make assembly easier to verify would be helpful to the ecosystem.
Re:Shipping Rust code in Firefox by azakai on Tuesday July 12, 2016 @12:27PM (#12080371)
In theory, but there isn't even good research on this, AFAIK. Fast JITs for languages like JavaScript require unsafety in the state of the art today.
Re:Shipping Rust code in Firefox by haberman on Tuesday July 12, 2016 @12:26PM (#12080361)
I'll believe it when I see it. :)