<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><blockquote type="cite" class=""><div class="">On Sep 7, 2017, at 1:20 AM, Kostya Serebryany <<a href="mailto:kcc@google.com" class="">kcc@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Sep 6, 2017 at 2:42 PM, Jonas Devlieghere <span dir="ltr" class=""><<a href="mailto:jdevlieghere@apple.com" target="_blank" class="">jdevlieghere@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><span class="gmail-"><blockquote type="cite" class=""><div class="">On Sep 6, 2017, at 9:14 PM, Kostya Serebryany <<a href="mailto:kcc@google.com" target="_blank" class="">kcc@google.com</a>> wrote:</div><br class="gmail-m_-1091325060882693480Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Sep 6, 2017 at 8:43 AM, Jonas Devlieghere via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br class="">
<br class="">
Is it possible to change the value of ASan's allocator_may_return_null at runtime or somehow disable this check temporarily? If I install an LLVM bad_alloc_error_handler, ASan's allocator wrapper detects this first and terminates the process instead of returning 0, preventing the custom handler from being called.<br class=""></blockquote><div class=""><br class=""></div>Is this question related to "r312582 - Revert "[Decompression] Fail gracefully when out of memory”"? </div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">It is! Though even if we don't need it, I’d still be interested to know whether this is possible. </div></div></div></blockquote><div class=""><br class=""></div><div class="">I'm not sure what you are asking for, exactly. </div><div class="">Here is how it works: </div><div class=""><br class=""></div><div class="">% clang++ -fsanitize=address  ~/llvm/projects/compiler-rt/test/asan/TestCases/<a href="http://allocator_returns_null.cc" class="">allocator_returns_null.cc</a><br class=""></div><div class=""><br class=""></div><div class="">% ./a.out malloc<br class=""></div><div class=""><div class="">==2503==WARNING: AddressSanitizer failed to allocate 0x10000000001 bytes</div></div><div class=""><div class="">==2503==AddressSanitizer's allocator is terminating the process instead of returning 0</div><div class="">==2503==If you don't like this behavior set allocator_may_return_null=1</div></div><div class=""><br class=""></div><div class="">% ASAN_OPTIONS=allocator_may_return_null=1 ./a.out malloc<br class=""></div><div class=""><div class="">==2513==WARNING: AddressSanitizer failed to allocate 0x10000000001 bytes</div><div class="">errno: 12</div><div class="">x: 0</div></div><div class=""><br class=""></div><div class="">So you can change the value of allocator_may_return_null at startup. </div></div></div></div></div></blockquote><div><br class=""></div><div>I considered doing that for my test case, but fuzzing (with ASan) would still trigger a crash. </div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">There is no way to change this while the process is running.</div></div></div></div></div></blockquote><div><br class=""></div>That answers my question, thanks! <br class=""><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">You can set allocator_may_return_null per binary using __asan_default_options</div><div class="">(see llvm/projects/compiler-rt/include/sanitizer/asan_interface.h)</div><div class="">but unless absolutely necessary I'd try to avoid this. Lots of things may go wrong. </div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class="">If the answer is no, I wonder how useful error handler is (which isn't currently used, at least not upstream). </div></div></div></blockquote><div class=""><br class=""></div><div class="">Imho, an error handler that tries to recover from OOM is a very dangerous thing and should be avoided. </div><div class="">This essentially introduces a very fragile code to the least tests path. </div></div></div></div></div></blockquote><div><br class=""></div><div>I totally agree, and in that respect it’s probably a good thing that it can’t be disabled at run time. </div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">--kcc </div><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><span class="gmail-"><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br class="">
Thanks,<br class="">
Jonas<br class="">
______________________________<wbr class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><br class="">
</blockquote></div><br class=""></div></div>
</div></blockquote></span></div><br class=""></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>