4 ms·
There’s of course a couple of notes on combating this attack: most compilers of today don’t actually produce exactly the same code if you run them twice. In bro
by saagarjha 3y ago
There’s of course a couple of notes on combating this attack: most compilers of today don’t actually produce exactly the same code if you run them twice. In broad strokes they do but often they’ll have randomness creep in, such as different build hashes or iteration order of associative containers. To truly get a bit-for-bit identical output you may need to do some extra work, or perhaps run yet another step in a controlled environment to protect against this.
Second, and more importantly, many people carry a copy of a trusted compiler around, though it’s rarely mention in attacks like these: their head. In a pinch people can do spot checks to verify codegen to see whether it looks correct, unless the backdoor is incredibly subtle. But experience shows us that the more complex and hidden a backdoor is the more likely it is to break when subjected to unfamiliar examination.
- wyldfire 3y agoclang+llvm releases do a three stage build and compare the output of the third stage with the second. This is fairly effective at rooting out many sources of indeterminate behavior. > In broad strokes they do but often they’ll have randomness creep in, such as different build hashes or iteration order of associative containers. In order to find defects related to codegen being altered by incidental ordering of objects in containers, a build option called LLVM_ENABLE_REVERSE_ITERATION was created. Builders periodically run with this mode to verify that the regression test suite still passes when containers iterate in reverse. That said, it's true that there are probably remaining sources of variation among builds. There is a significant effort [1] to find these and avoid them. [1] https://reproducible-builds.org/ https://reproducible-builds.org/
- vlovich123 3y agoNot all containers right? Just unordered containers. It’s a bit weird of a strategy though - most other applications use a random seed for unordered hash tables.
- wyldfire 3y agoRather than change the implementation of the DenseMap/DenseSet/StringMap/StringSet containers to mask such codegen defects, the community opted to create a test strategy to find the defects instead. I would guess that this may also end up favoring the execution performance of the compiler over other design choices, but I could be wrong about that one.
- JonChesterfield 3y agoA random seed for unordered hash tables would make a mess of reproducibility. Bad thing in this context.
- vlovich123 3y agoThe iteration order is undefined for these containers. The whole point of the reverse iteration is to find when reproducibility is dependent on undefined iteration order. If the reverse iteration accomplishes this, so would a random seed.
- userbinator 3y agomost compilers of today don’t actually produce exactly the same code if you run them twice. Timestamps are one of the biggest offenders, but this is also why reproducible builds are important. Nondeterministic codegen is just scary. Second, and more importantly, many people carry a copy of a trusted compiler around, though it’s rarely mention in attacks like these: their head. This is also why I'm against inefficient bloated software in general: the bigger a binary is, the easier it is to hide something in it. Along the same lines, a third idea I have for defending against such attacks is better decompilers --- ideally, repeatedly decompiling and recompiling should converge to a fixed point, whereas a backdoor in a compiler should cause it to decompile into source that's noticeably divergent.
- charcircuit 3y ago>Timestamps are one of the biggest offenders >Nondeterministic codegen is just scary. Why not focus on deterministic codegen only? Caring about some metadata changing does not seem to be as useful from a security perspective.
- Quekid5 3y ago> Caring about some metadata changing does not seem to be as useful from a security perspective. If the metadata were neatly separated from the executable portions of an artifact then it indeed wouldn't be too much of an issue[1], but it often isn't. It sometimes gets embedded into strings and other places in the executable itself where it theoretically could have an impact on the runtime (and of course makes executable signatures unreliable, etc.). Without that separation comparing two potentially-the-same executables becomes equivalent to the Halting Problem. [1] You could sign only portions of the executable, for example... but such signature schemes are brittle and error-prone in practice, so best avoided. So you'd ideally want any and all metadata totally separate from the executable.
- charcircuit 3y ago>where it theoretically could have an impact on the runtime If there is a backdoor in the code there is a backdoor regardless of if there is an extra timestamp that exists.
- yjftsjthsd-h 3y ago> most compilers of today don’t actually produce exactly the same code if you run them twice. By default, but https://reproducible-builds.org/ https://reproducible-builds.org/ has made excellent headway on allowing that to be fixed if you care.