5 ms·
> Theoretically, if there were some horrible bugs in the JIT, one could craft malicious input data causing the JIT to insert arbitrary code in the code heap. In
by saagarjha 8y ago
> Theoretically, if there were some horrible bugs in the JIT, one could craft malicious input data causing the JIT to insert arbitrary code in the code heap. In practice, it doesn't seem possible.
This is very possible: just do a search for ${your favorite JIT} arbitrary code execution, and you'll almost certainly see a real-world vulnerability.
> At least HotSpot has been JIT:ing code for decades and no one has been able to find such an exploit.
Yeah, no. See for example https://www.syscan360.org/slides/2013_EN_ExploitYourJavaNativeVulnerabilitiesOnWin7JRE7InOneMinute_YukiChen.pdf https://www.syscan360.org/slides/2013_EN_ExploitYourJavaNati...
- bjourne 8y agoBut the feature the exploit takes advantage of isn't just in time compilation, it is compilation! An ahead of time java compiler would have suffered from the exact same problem. In fact, any language compiling to machine code would be just as vulnerable.
- pitaj 8y agoYes, but when pre-compiling, you implicitly trust the code. JITs like V8 are used to execute arbitrary code on your device, where such an exploit is much more harmful.
- bjourne 8y agoUntrue. Dart code for example is AOT compiled but untrusted. Various Javascript implementations are also AOT but also supposed to be used for untrusted code.
- pitaj 8y agoI have no idea what you're talking about. Under what circumstances is Dart AOT compiled and run untrusted? No browsers support Dart as a first-class citizen. If you're talking about compiling Dart into JS, that's obviously not what anyone is talking about. There are no Ecmascript AOT compilers. By definition, Ecmascript must be run with an interpreter. AFAIK with the dynamic complexity of the language it's impossible to AOT compile even without things like `eval` and `new Function`. A better example would be NaCl which as I understand it runs native machine code in a sandbox.
- bjourne 8y agoWhat I'm talking about? "Yes, but when pre-compiling, you implicitly trust the code." Citation needed. It's not true at all.
- geofft 8y agoCan you give one example of a case where code is compiled AOT and not trusted during compile time? (Your example of Dart was challenged, and I agree that it is not an example, so a more detailed explanation of why it is an example would count.)
- bjourne 8y agoWhy on earth wouldn't Dart count? It is AOT-compiled and meant to be run untrusted inside a Dart VM inside a web browser. That was the intention of the project even if it was cancelled and the VM deprecated. For more examples, see ActionScript on iOS, TFA itself or any of the myriad of projects trying ti AOT-compile JavaScript. For example https://link.springer.com/article/10.1134/S036176881701008X https://link.springer.com/article/10.1134/S036176881701008X
- olliej 8y agoMost of the time they're not bugs in the JIT - they're bugs in other parts of the software, basically your path to exploit is: 1. Find bug that gives you arbitrary read 2. and a bug that lets you write to some arbitrary location 3. Find bug the lets you jump to some location 4. Use [1] to find the location of the RWX region 5. use [2] to copy your exploit code into [4] 6. use [3] to jump to [4] 7. Profit Often times a single use after free gives you 1, 2, and 3. Essentially you use the UaF to get multiple different objects pointing to the same place, but as different types. e.g You get a JS function allocated over the top of a typed array's backing store, then from JS you have an object that the runtime thinks is a typed array, but the pointer to its backing store is actually pointing to part of the RWX heap. Then all you have to do is copy your shell code into the corrupted typed array, and call the function object. (This requires a GC related use after free, and most of the JS runtimes have gotten progressively more aggressive about validating the heap metadata, but fundamentally if there's a GC bug it's mostly likely just a matter of how much work will be needed to exploit it)