Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LeakSanitizer fails based on stack layout #42932

Open
llvmbot opened this issue Oct 7, 2019 · 4 comments
Open

LeakSanitizer fails based on stack layout #42932

llvmbot opened this issue Oct 7, 2019 · 4 comments
Labels
bugzilla Issues migrated from bugzilla compiler-rt:asan Address sanitizer

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 7, 2019

Bugzilla Link 43587
Version 9.0
OS Linux
Attachments demonstration and further details
Reporter LLVM Bugzilla Contributor
CC @vit9696,@vitalybuka

Extended Description

LeakSanitizer may fail to catch leaked memory based on stack layout.

While I did not perform any extensive research, I did verify that stack layout is the only changing factor in my compiled binaries by disassembly comparison. I did not verify whether the underlying issue can cause other problems than the one described by this report.

Please find attached a C program with comments about the verified environments and different ways to reproduce.

@vitalybuka
Copy link
Collaborator

I afraid it's work as intended.

LeakSanitizer scans stack for pointers. It's possible that old frame with dead pointers (main here) overlapped by new frame which does not use bytes with pointers. For leak sanitizer this looks like alive pointers in useful flame, so no leak.

To fix this we can clean stack on return, but it's going to hit performance.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Oct 7, 2019

Thank you very much for your explaination.

I won't pretend to know how LeakSan works, and especially not how it should work, but if I understood it correctly, it does solely by stack analysis. Is it too expensive to keep track of all mallocs? While that obviously does not allow tracing, it at least would give an indicator at termination that there is a leak at all.

@vitalybuka
Copy link
Collaborator

LSAN tracks all mallocs.
But it must not report stuff which is not leak. E.g. pointer in global variable is not considered a leak even on termination.

Maybe ignoring some pointers from main thread doing final leak-checking will work.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Oct 10, 2019

While programs keeping allocations alive past the termination of the entry point is a valid concept, I think the majority expects to be purged entirely, especially when not release software itself is sanitized but specific function calls from unit test applications. Can the data segment be scanned in the way the stack is?

I'd imagine there could be 1) a compilation switch to toggle whitelisting all global pointers and/or 2) a way to explicitly flag whitelisted pointers (i.e. alarm on all dangling allocations not referenced by a whitelisted pointer when main terminates). I do not know about implementation difficulties, so please excuse me if this is not feasible.

For instance, in a project I am contributing to, we have small unit test applications that call library functions from the main project and are both fuzzed and sanitized simultaneously and are not supposed to leave anything alive after termination. It would be invaluable to us to be notified about all leaked memory.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
vitalybuka pushed a commit that referenced this issue Oct 12, 2022
…ves.

As shown in #42932 dead
pointers might be overlapped by a new stack frame inside CheckForLeaks,
which does not use bytes with pointers. This leads to false negatives.

It's not a full solution for the problem as it does not solve
"overlapping" new/old frames for frames below the CheckForLeaks and in
other threads. It should improve leaks found in direct callers of
__lsan_do_leak_check.

Differential Revision: https://reviews.llvm.org/D130237
veselypeta pushed a commit to veselypeta/cherillvm that referenced this issue May 28, 2024
…ves.

As shown in llvm/llvm-project#42932 dead
pointers might be overlapped by a new stack frame inside CheckForLeaks,
which does not use bytes with pointers. This leads to false negatives.

It's not a full solution for the problem as it does not solve
"overlapping" new/old frames for frames below the CheckForLeaks and in
other threads. It should improve leaks found in direct callers of
__lsan_do_leak_check.

Differential Revision: https://reviews.llvm.org/D130237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla compiler-rt:asan Address sanitizer
Projects
None yet
Development

No branches or pull requests

2 participants