<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 30, 2015 at 9:11 AM, Brian Cain via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=llvm-dev@lists.llvm.org&cc=&bcc=&su=&body=','_blank');return false;">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Sun, Aug 30, 2015 at 9:30 AM, Greg Stark via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=llvm-dev@lists.llvm.org&cc=&bcc=&su=&body=','_blank');return false;">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I have a project I want to do based on Libfuzzer. Is there a separate<br>
list for it or should I bring up any ideas for it here?<br>
<br></blockquote></span></div></div></div></blockquote><div>No separate list so far, this one should be good. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
What I have in mind is to fuzz Postgres. Trying to fuzz the SQL<br>
interpreter in general<br>
is not very productive because traditional fuzzers try to execute the<br>
entire program repeatedly and it has a fairly high startup and<br>
shutdown cost. Also the instrumentation-guided approach has<br></blockquote><div><br></div></span><div>One challenge in leaving the daemon up while testing is knowing how well isolated the test cases are from one another.  It may be the case that the test cases somehow accumulate some global state (test case N triggers heap corruption, N + 23 crashes as a result of that earlier corruption).  At least that specific failure mode can probably be mitigated by using one or more of the sanitizers though.</div><span class=""><div> </div></span></div></div></div></blockquote><div><br></div><div>This is true, however accumulating global state increases the chances to find complex bugs (at the cost of increased cost of analyzing bugs). </div><div>We have seen a few such cases, e.g. <a href="https://sourceware.org/bugzilla/show_bug.cgi?id=18043#c11">https://sourceware.org/bugzilla/show_bug.cgi?id=18043#c11</a></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">limitations due to the way lexing and parsing works as well as the<br>
large amount of<br>
internal state causing non-deterministic internal behaviour (garbage<br>
collecting persistent data structures, etc).<br>
<br>
However there are a number of internal functions that would be very<br>
feasible to fuzz. Things like the datatype input/output functions (I'm<br>
particularly thinking of the datetime parser), regular expression<br>
library, etc.<br></blockquote></span></div></div></div></blockquote><div><br></div><div>In my (biased) opinion libFuzzer is particularly well suited for this task</div><div>(fuzzing individual libraries, as opposed to fuzzing the whole postgress).</div><div>I've played with a dozen of regular expression libs and found bugs in all of them</div><div>(e.g. search for "Fuzzer" in <a href="http://vcs.pcre.org/pcre2/code/trunk/ChangeLog?view=markup&pathrev=360">http://vcs.pcre.org/pcre2/code/trunk/ChangeLog?view=markup&pathrev=360</a>)</div><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
To do this effectively I think it would be best to invoke the fuzzer<br>
from inside Postgres. </blockquote></span></div></div></div></blockquote><div><br></div><div>Never tied this. </div><div>Can't you just link libFuzzer with a part of the code you want to test? </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Essentially provide bindings for Libfuzzer so<br>
you can I can have Libfuzzer provide all the test cases to repeatedly<br>
call the internal functions on.<br>
<br>
Is there any example of doing something like this already? Am I taking<br>
a crazy approach?<br>
<br></blockquote><div><br></div></span><div>I don't have enough experience to say if it's crazy or not.  But if your LLVMFuzzerTestOneInput() queues some work for the server and pends on a response -- that seems like a sane approach.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
There are other approaches possible. It would be nice if I could run<br>
afl or libfuzzer on a client program and have the client program tell<br>
afl or libfuzzer the pid of the server to watch and then request test<br>
cases to feed to the server. That seems like it would be a more<br>
flexible approach for a lot of use cases where the server requires<br>
setting up a complex environment.<br><br></blockquote><div><br></div></span><div>Great idea, but it seems tricky to get the execution coverage feedback in this case.</div></div></div></div></blockquote><div><br></div><div>Not very tricky, but less efficient. </div><div>The major benefit of libfuzzer is that it get the coverage feedback from inside the process </div><div>avoiding any kind of inter-process communication (no syscalls even). </div><div>So for things like simple parsers you can get 50K executions per second (unless the fuzzer finds  exponential algorithms in the parser).</div><div>  </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div><br></div><div>Let me know if you're interested in collaborating, it sounds interesting.  Though at first glance, I'd prefer the "not very productive" brute force option and just toss more resources at it.</div><span class=""><font color="#888888"><div> </div>-- <br><div>-Brian</div>
</font></span></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=llvm-dev@lists.llvm.org&cc=&bcc=&su=&body=','_blank');return false;">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>