<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 7, 2017 at 4:08 AM, Michal Privoznik <span dir="ltr"><<a href="mailto:mprivozn@redhat.com" target="_blank">mprivozn@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 03/07/2017 06:27 AM, D L wrote:<br>
> On Sun, Mar 5, 2017 at 2:47 AM, Michal Privoznik <<a href="mailto:mprivozn@redhat.com">mprivozn@redhat.com</a>><br>
> wrote:<br>
><br>
>> On 04.03.2017 07:23, Da L wrote:<br>
>>> Dear all,<br>
>>><br>
>><br>
>> Hey,<br>
>><br>
>>> This is my first post in the list.<br>
>><br>
>> Very well. Welcome. It is always nice to see people interested in libvirt.<br>
>><br>
>> Hi Michal,<br>
><br>
> Thank you very much for the explanation and encouragement.<br>
> I am so glad to join the community.<br>
><br>
><br>
>>><br>
>>> I am currently a graduate student studying computer science, particularly<br>
>>> interested in visualization technologies and I have been using QEMU for a<br>
>>> variety of projects for a while. Two of the courses that I am taking this<br>
>>> semester really attracted me to the libvirt community  are Advanced<br>
>>> Operating Systems and Secure Software Development. I have been learning<br>
>>> kernel fuzzing as well as other general fuzzing tools.<br>
>>><br>
>>> Then I found the topic of "QEMU command line generator XML fuzzing" is<br>
>>> pretty interesting and totally in line with my interest and background.<br>
>>> Though I have read through the documentations on the website, just to<br>
>> make<br>
>>> sure I am doing it correctly, could anyone confirm this project is still<br>
>>> available? And what I need to do next in order to participate the project<br>
>>> this summer? Do I need to find a mentor by myself? Potentially, I could<br>
>>> find my OS or Security professor as my mentor, but I am not sure yet<br>
>> which<br>
>>> would be the best way.<br>
>><br>
>> Yes, the project is still on. It does not have a mentor assigned yet,<br>
>> but don't worry about that now - there is a lot of mentors around. For<br>
>> now, I can be your point of contact.<br>
>><br>
>> So, just to explain you some details of the project: libvirt's format<br>
>> for storing domain configuration is XML. However, none of the<br>
>> hypervisors out there uses XML to describe domain configuration. For<br>
>> instance, in qemu it's all about the command line. You want this disk<br>
>> for you domain? You have to put it onto the command line. And so on.<br>
>> Therefore, in a very simplistic way, for qemu libvirt translates the XML<br>
>> into qemu command line language. Now, this process is very complex and<br>
>> sort of tricky. That's why we would like to generate "all" possible<br>
>> combinations of XML, let the command line generator crunch them and<br>
>> produce qemu command line. Well, that's not entirely true, because<br>
>> command line generator works over some internal representation of domain<br>
>> (not XML) that is produced by our XML parser:<br>
>><br>
> Please correct me if I am wrong about  my following understanding:<br>
> 1. Regarding XML config file, one typical usage with libvirt could be:<br>
</div></div>>     $ virsh define <domain_config_file.xml <<a href="http://your_xml_config_file.ml" rel="noreferrer" target="_blank">http://your_xml_config_file.<wbr>ml</a>>><br>
<br>
The file has to be stored locally. Libvirt doesn't have an<br>
'url-grabber'. In fact, our APIs expect XML document passed as string<br>
(not a filename where it is stored). It's just virsh that allows users<br>
to point it to a file which is read and passed to the define API.<br>
<span class=""><br>
> 2. I noticed in the source code of libvirt, there exist several files in<br>
> close relation<br>
> to xml, including src/util/virxml.{c,h}, which might be the target of this<br>
> project?<br>
<br>
</span>Sort of. virxml.c file contains XML parsing helpers (mostly higher-level<br>
APIs over libxml2). The XML parsing is done in src/conf/domain_conf.c<br>
(or network_conf.c for libvirt networks, etc.). The entry point for<br>
exploring domain XML parsing can be virDomainDefParseString() function.<br>
BTW: while exploring libvirt sources I strongly advice to use so called<br>
tagged sources ("make tags" or "ctags -R ." or some equivalent), because<br>
libvirt sources consists of lots of short functions calling other<br>
functions. Tagged sources then allow developers to jump onto symbol<br>
under cursor (in vim it is "CTRL + ]" or "g + ]" if the symbol is<br>
defined at multiple locations).<br>
<br></blockquote><div>Hi Michal,</div><div><br></div><div>Thank you so much for the detailed description. I will get back to you for </div><div>each point in detail next week.  </div><div><br>By the way, so nice to see the power of vi in a real project.</div><div><br></div><div>Best,</div><div><br></div><div>Dan</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Now that we have parsed the domain XML into internal representation<br>
(virDomainDef), we can look into qemu command line generation. I think<br>
the whole process is best visible in qemuDomainCreateXML() (e.g. "vim -t<br>
qemuDomainCreateXML" ;-)). This is qemu driver implementation of public<br>
API virDomainCreateXML(). It allows users to create so called transient<br>
domains. Long story short: "here, I have domain XML, start it up for me,<br>
will you?". Therefore at the beginning the domain XML is parsed (using<br>
the function described above), several not-important-right-now functions<br>
are called and then qemuProcessStart() is called which calls<br>
qemuProcessLaunch() which calls qemuBuildCommandLine(). Finally, this is<br>
the function that takes the virDomainDef (among other arguments) and<br>
produces yet another internal representation of qemu command line<br>
(virCommandPtr). This command line is then executed later in the process.<br>
<span class=""><br>
> 3. And libvirt also is compiled with libxml2.<br>
<br>
</span>Yes. This has strong historical background (hint: look who started<br>
libvirt and who wrote libxml2 ;-)). Frankly, I don't think we've ever<br>
considered a different xml parsing library.<br>
<span class=""><br>
> 4. Then in virt-xml-validate, which is a bash script,<br>
>   (in build/bin directory after make install) calling xmllint.<br>
<br>
</span>Yeah. Writing our XMLs by hand can be overwhelming. Moreover, libvirt<br>
has this philosophy of ignoring unknown elements/attributes. So it might<br>
happen that for instance you have a typo in an element name and you're<br>
still wondering why libvirt ignores that particular setting (e.g. path<br>
to disk of domain). Therefore we have grammar rules (RNG) that could<br>
help you here - virt-xml-validate would error out in this example. Well,<br>
even virsh errors our now because it instructs libvirt to do the XML<br>
validation before parsing. But that hasn't been always the case.<br>
<span class=""><br>
><br>
> I have not been able to get round to figure out the relations of the above<br>
> pieces yet.<br>
> I spent some time to try to instrument and compile the executables with<br>
> AFL, but so<br>
>  far with no luck. (The idea is as simple as changing gcc in<br>
> Makefile/configure to afl-gcc).<br>
> The attached figure is just a demo showing using AFL to fuzz virt-admin,<br>
> which is<br>
> not instrumented, (so kinda of boring and not quite useful). But I think<br>
> AFL could be<br>
>  one of the candidate as a fuzzer for this project due its prevalence and<br>
> proved effectiveness.<br>
<br>
</span>We don't have to limit ourselves just for domain XML -> qemu cmd line<br>
fuzzing. We can look into other areas too (there's a lot of inputs for<br>
libvirt), e.g. RPC protocol (we have our own protocol for communication<br>
with distant server/client over network), fuzz XML parsers themselves<br>
(domain is not the only object that libvirt manages, we have networks,<br>
interfaces, storage pools/volumes, etc.). It's just that qemu cmd line<br>
fuzzing seemed complicated enough so that the chances of running a<br>
fuzzer successfully are high.<br>
<span class=""><br>
><br>
> Regarding fuzzing, I think we can try several fuzzing tools to run in<br>
> parallel, as different<br>
>  fuzzers tend to find different kinds of bugs.<br>
<br>
</span>True. I had this on my mind as well.<br>
<span class=""><br>
> Thus, AFL (American Fuzz<br>
> Lop) [1],<br>
> which is a coverage-guided mutation-based fuzzer with genetic algorithm,<br>
> can<br>
> take hand-crafted xml seed to fuzz our libvert target. Alternatively, we<br>
> could<br>
> develop generation-based grammar module in AFL (which is definitely<br>
> non-trivial);<br>
<br>
</span>Yeah, I thought about this when watching a talk on AFL. We might explore<br>
other possibilities - they already might have something we want.<br>
<span class=""><br>
> so far I have not seen active development in AFL community on xml format<br>
> grammar generation. Another option could be clang-libfuzzer [2].<br>
><br>
> Several related articles show examples of fuzzing are using AFL to generate<br>
> SQL [3], llvm-afl [4], and hexml fuzzing with AFL [5]. In combination with<br>
> lcov, we<br>
>  could compare different fuzzers and guide our fuzzing tuning.<br>
<br>
</span>Yes, good idea.<br>
<span class=""><br>
><br>
> NOTE  the [5] example is quite interesting; it is fuzzing a haskell-written<br>
> xml paser.<br>
<br>
</span>Indeed.<br>
<span class=""><br>
><br>
> I will probably not update more until next week; I am having three<br>
> mid-terms this week.<br>
<br>
</span>Good luck.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> [1] <a href="http://lcamtuf.coredump.cx/afl/" rel="noreferrer" target="_blank">http://lcamtuf.coredump.cx/<wbr>afl/</a><br>
> [2] <a href="http://llvm.org/docs/LibFuzzer.html" rel="noreferrer" target="_blank">http://llvm.org/docs/<wbr>LibFuzzer.html</a><br>
> [3]<br>
> <a href="https://lcamtuf.blogspot.com/2015/01/afl-fuzz-making-up-grammar-with.html" rel="noreferrer" target="_blank">https://lcamtuf.blogspot.com/<wbr>2015/01/afl-fuzz-making-up-<wbr>grammar-with.html</a><br>
> [4] <a href="http://lists.llvm.org/pipermail/llvm-dev/2014-December/079390.html" rel="noreferrer" target="_blank">http://lists.llvm.org/<wbr>pipermail/llvm-dev/2014-<wbr>December/079390.html</a><br>
> [5] <a href="https://github.com/ndmitchell/hexml/issues/6" rel="noreferrer" target="_blank">https://github.com/ndmitchell/<wbr>hexml/issues/6</a><br>
><br>
> Again, thanks a lot. Any guidance, comments, or suggestions would be more<br>
> than<br>
> welcome and highly appreciated.<br>
><br>
> Best,<br>
><br>
><br>
> Dan<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">Michal<br>
</font></span></blockquote></div><br></div></div>