<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Apr 30, 2020, at 02:16, JF Bastien via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class="" style="caret-color: rgb(0, 0, 0);">I’ve consulted with folks in security, compilers, and developers of security-sensitive codebases. A few points:</div><div class="" style="caret-color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0);"><ul class="MailOutline"><li class="">They like that automatic variable initialization provides a security mitigation for a significant percentage of observed zero-day exploits, at extremely low cost, with little chance of regression.</li><li class="">They like that pattern initialization is a “smoking gun” when seen in a crash log. The size+performance costs have decreased in the last year, but they’d like to see it improve further.</li><li class="">They like the lower size+performance cost of zero initialization as well as the safety it offers for e.g. size variables (because a size of 0xAA…AA is “infinite” which is bad for bounds checking, whereas zero isn’t). They don’t like that zero is often a valid pointer sentinel value (i.e. initializing pointers to zero can be used in unexpected data flow). They don’t like the silly long compiler flag.</li><li class="">We’ve deployed automatic variable initialization in a significant amount of code. The vast majority of our deployment uses pattern initialization. A small number uses zero, of which you’ll note <a href="https://opensource.apple.com/source/xnu/xnu-6153.11.26/makedefs/MakeInc.def.auto.html" class="">XNU</a>. We’ve only chosen zero in cases where size or performance were measured issues.</li><li class="">Automatic variable initialization which might sometimes trap (as Richard suggests) is a proposal we’d like to see implemented, but we’d like to see it under its own separate flag, something like UBSan does with developers choosing trapping or logging modes. The main reason is that pure trapping with zero-init will make deployment significantly harder (it’s no longer a low-risk mitigation), and it’ll make updating our compiler significantly harder (because it might change where it generates traps over time). We also think that trapping behavior would need good tooling, for example through opt remarks, to help find and fix parts of the code where the compiler added traps. A logging mode would ease some of this burden. As well, we’re not convinced on the size+performance cost of either tapping nor logging, complicating the adoption of the mitigation.</li><li class="">We don’t think the design space has been explored enough. We might want to differentiate initialization more than just “floating point is 0xFF…FF, everything else is 0xAA…AA”. For example:</li><ul class=""><li class="">We could pattern-init pointers (maybe with compile-time random different patterns), and zero-init scalars. This has a good mix of performance and security upsides.</li><li class="">We could key off heuristics to choose how to initialize, such as variable names, function names, or some machine learning model (and for those who know me: I’m not joking).</li><li class="">We could use a variety of runtime pseudo-random sources to initialize values.</li><li class="">We could add a new IR “undef” type, or different late-stage treatment of “undef”, to apply initialization after optimizations have found interesting facts about the program.</li></ul></ul></div><div class="" style="caret-color: rgb(0, 0, 0);"><br class=""></div><div class="" style="caret-color: rgb(0, 0, 0);">We’d like to see work continue on improving this mitigation, optimizations around it, and other similar mitigations.</div></div></div></div></blockquote><br class=""></div><div><br class=""></div><div>On the optimization side, work on cross-basicblock DSE using MemorySSA is currently underway. The goal is to remove a major limitation of the current DSE implementation. A few initial patches landed already, but there’s still plenty of work to do. I’ve created <a href="https://bugs.llvm.org/show_bug.cgi?id=45792" class="">https://bugs.llvm.org/show_bug.cgi?id=45792</a> to collect information, in case anyone is interested in working on this.</div><div><br class=""></div><div>Cheers,</div><div>Florian</div></body></html>