<div dir="ltr">Hi everbody, <div><br>I had some difficulties with taint2, which I was unable to debug with my current qemu and llvm knowledge, so I decided to make a quick attempt to port the tcg-based taint instrumentation from Qtrace (<a href="https://github.com/rpaleari/qtrace" target="_blank">https://github.com/<wbr>rpaleari/qtrace</a>), a different qemu port by @rpaleari. I&#39;ve suprisingly managed to get something working well enough for my purposes (or so appears from a few tests), and I thougth I&#39;d share it with you. Most of the credit goes to Roberto Paleari for publishing the original Qtrace code.</div><div><br></div><div>The plugin is not a full replacement for taint2, as it&#39;s not as general or powerful, but it seems lighter on resources. It only supports the i386 target, doesn&#39;t instrument helpers, and it is composed of two parts: the instrumentation (additional helper calls generated inside of tcg&#39;s frontend), and the &quot;tcgtaint&quot; plugin, managing the data structures, and exposing an interface similar to the one of taint2.</div><div><br></div><div>The approach is probably not the cleanest, as it requires some insertions to qemu&#39;s tcg code, and is maybe not general enough to be included in panda.</div><div>If by the way Panda developers are interesting in including it (in the main or in a separate branch), I&#39;d be happy to do some cleanup and prepare a PR.</div><div><br></div><div>All the relevant code is in ifdefs (you can grep for &quot;CONFIG_QTRACE_TAINT&quot;), and is only built when the &quot;--enable-tcgtaint&quot; switch is present. The instrumentation helper calls are only generated when requested via the plugin api, and shouldn&#39;t affect the performances when disabled.</div><div><br>Differences with respect to taint2:<br></div><div>- comparatively very light on memory (unless you actually taint a lot)<br>- a little faster<br>- can be enabled and disabled via the plugin api, can also be told to only instrument user-level code<br>- doesn&#39;t instrument helpers (the main use case is being able to tell the provenance of some piece of data, so the focus was on getting movs, memcpys and similar working correctly)<br>- the instrumentation is added before stores, so you safely can taint on a &quot;virt_mem_after_write&quot; callback<br>- doesn&#39;t support tainting through pointer dereference</div><div>- doesn&#39;t suppot tainted branches<br>- only partial support to xmm registers (movs only) <br><br>Differences with respect to the original instrumentation in qtrace:<br>- it uses panda&#39;s memory functions and callbacks instead of qtrace&#39;s<br>- I moved load instrumentation deeper down in tcg&#39;s frontend, so to support `rep mov` and similar<br>- added partial support to xmm registers, in order to support `movqda`<br>- some bug fixes</div><div><br>The code still lacks some comments, copyright notices, and documentation, but it should work. Any comment or feedback is welcome! </div><div><br></div><div>You can find the code at the tcgtaint branch in my repo <a href="https://github.com/vigliag/panda/tree/tcgtaint" target="_blank">https://github.com/vigliag/<wbr>panda/tree/tcgtaint</a></div><div><br></div><div>changes wrt panda&#39;s master are here: <a href="https://github.com/panda-re/panda/compare/master...vigliag:tcgtaint" target="_blank">https://github.com/panda-re/<wbr>panda/compare/master...<wbr>vigliag:tcgtaint</a><br><br>Best regards,<br>Gabriele<br></div></div>