[llvm-bugs] [Bug 31877] New: Program crashes when throwing exception under memory sanitizer.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Feb 6 06:59:36 PST 2017


https://llvm.org/bugs/show_bug.cgi?id=31877

            Bug ID: 31877
           Summary: Program crashes when throwing exception under memory
                    sanitizer.
           Product: libc++abi
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: halyavin at chromium.org
                CC: kcc at google.com, llvm-bugs at lists.llvm.org,
                    mclow.lists at gmail.com
    Classification: Unclassified

The following program crashes with memory sanitizer.

test.cpp:

#include <stdio.h>
#include <exception>

// Poison parameters shadow.
__attribute__ ((noinline)) void func(int, int, int, int, int, int) {
    try {
        throw std::exception();
    } catch (std::exception& e) {
        printf("here\n");
    }
}

int main() {
    int a, b, c, d, e, f;
    func(a, b, c, d, e, f);
}

Compilation:
1. Compile and copy memory-sanitized libc++.so and libc++abi.so to the same
folder as test.cpp.
2. clang++ test.cpp -o test -stdlib=libc++ -L. -Wl,-rpath=. -fsanitize=memory

Output:
./test
==3802==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f51243b3313 in get_thrown_object_ptr
/home/halyavin/other/llvm/projects/libcxxabi/src/cxa_personality.cpp:490:27
    #1 0x7f51243b3313 in __cxxabiv1::scan_eh_tab(__cxxabiv1::(anonymous
namespace)::scan_results&, _Unwind_Action, bool, _Unwind_Exception*,
_Unwind_Context*)
/home/halyavin/other/llvm/projects/libcxxabi/src/cxa_personality.cpp:736
    #2 0x7f51243b14e5 in __gxx_personality_v0
/home/halyavin/other/llvm/projects/libcxxabi/src/cxa_personality.cpp:951:9
    #3 0x7f5124995262  (/lib/x86_64-linux-gnu/libgcc_s.so.1+0x10262)
    #4 0x7f51243aff6d in __cxa_throw
/home/halyavin/other/llvm/projects/libcxxabi/src/cxa_exception.cpp:238:5
    #5 0x489534 in func(int, int, int, int, int, int)
(/home/halyavin/other/msan-exceptions/test+0x489534)
    #6 0x4897f4 in main (/home/halyavin/other/msan-exceptions/test+0x4897f4)
    #7 0x7f51245dc82f  (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #8 0x419c88 in _start (/home/halyavin/other/msan-exceptions/test+0x419c88)

The problem is that libgcc_s.so is not memory sanitized and so it does not
update parameters shadow before calling __gxx_personality_v0 function.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170206/b185af6d/attachment-0001.html>


More information about the llvm-bugs mailing list