Skip to content

Comments

Use leak sanitizer instead of internal mdebug to check for memory leaks#9294

Closed
levitte wants to merge 6 commits intoopenssl:masterfrom
levitte:mdebug-sanitizer
Closed

Use leak sanitizer instead of internal mdebug to check for memory leaks#9294
levitte wants to merge 6 commits intoopenssl:masterfrom
levitte:mdebug-sanitizer

Conversation

@levitte
Copy link
Member

@levitte levitte commented Jul 2, 2019

The leak sanitizer gives better reports (complete stack traces) and
works as a wrapper around the application instead of relying on
cooperative enabling and disabling calls (which are too easy to get
unbalanced).

Related to #8322

@levitte levitte added the branch: master Applies to master branch label Jul 2, 2019
@levitte
Copy link
Member Author

levitte commented Jul 2, 2019

This also replaces #8323

@mspncp
Copy link
Contributor

mspncp commented Jul 2, 2019

fly-by-comment: typo in commit message title (and GitHub title): 'sasnitizer'

@richsalz
Copy link
Contributor

richsalz commented Jul 2, 2019

@levitte levitte force-pushed the mdebug-sanitizer branch from 7afb1c6 to 23b6e49 Compare July 2, 2019 17:54
@levitte
Copy link
Member Author

levitte commented Jul 2, 2019

fly-by-comment: typo in commit message title (and GitHub title): 'sasnitizer'

Fixed

I also changed the way it's enabled, as sufficiently old clang doesn't understand -fsanitize=leak, but the address sanitizer has understood to enable the leak sanitizer internally for longer.

@levitte
Copy link
Member Author

levitte commented Jul 2, 2019

Should https://github.com/openssl/tools/blob/master/review-tools/opensslbuild#L36 also be changed?

I think it should. The leak sanitizer gives far better output than our mdebug ever will.

@mattcaswell
Copy link
Member

Travis failure looks relevant:

==34177==AddressSanitizer: detect_leaks is not supported on this platform.

@levitte
Copy link
Member Author

levitte commented Jul 3, 2019

Damn...

@t-j-h
Copy link
Member

t-j-h commented Jul 15, 2019

Drop that platform out for this check.
It is possible to build a mingw cross compiler with asan support - but it isn't necessary to get the testing we need here for most linux-like platforms.

@levitte
Copy link
Member Author

levitte commented Jul 15, 2019

Drop that platform out for this check.

I am worried about corner cases for code paths that only happen on dropped platforms.... on the other hand, since this approach is clang/gcc centric already, maybe I worry too much.

@levitte
Copy link
Member Author

levitte commented Oct 31, 2019

I'll rework this to avoid mingw... that will require some major surgery of the build matrix

@richsalz
Copy link
Contributor

Are you still intending to drop the internal memory-leak tooling? I totally support that in favor of ASAN. ASAN is what everyone is doing. :)

@levitte
Copy link
Member Author

levitte commented Oct 31, 2019

Yup, that's my intention.

(that will be like closing a big circle, considering the mdebug stuff was my first commit as a team member, back almost exactly 20 years ago)

@levitte levitte changed the title Use leak sasnitizer instead of internal mdebug to check for memory leaks WIP: Use leak sasnitizer instead of internal mdebug to check for memory leaks Oct 31, 2019
@levitte
Copy link
Member Author

levitte commented Oct 31, 2019

BTW, I have no idea why mingw was mentioned at all here. The Travis failure happens on MacOS X. So, er, should we simply not do this on MacOS X?

@levitte
Copy link
Member Author

levitte commented Oct 31, 2019

The MacOS problem has been complained about here: google/sanitizers#1026
Apparently, it comes down to clang...

@richsalz
Copy link
Contributor

When you remove the mdebug stuff, please also remove all the fault-insertion stuff in crypto/mem.c (shouldfail(), md_trace_fd, etc)

@mattcaswell
Copy link
Member

I think we should just disable this on MacOS.

@levitte
Copy link
Member Author

levitte commented Nov 22, 2019

I solved the MacOS case by not specifying ASAN_OPTIONS="detect_leaks=1" in .travis.yml. Leak detection is on by default in modern enough ASAN, I hope that makes it all reliable enough.

@mspncp mspncp changed the title WIP: Use leak sasnitizer instead of internal mdebug to check for memory leaks WIP: Use leak sanitizer instead of internal mdebug to check for memory leaks Nov 22, 2019
@mspncp
Copy link
Contributor

mspncp commented Nov 22, 2019

Sorry, I couldn’t resist any longer 😉.

@levitte
Copy link
Member Author

levitte commented Nov 22, 2019

That's all right. Thanks

@levitte levitte marked this pull request as ready for review November 23, 2019 09:40
@levitte levitte changed the title WIP: Use leak sanitizer instead of internal mdebug to check for memory leaks Use leak sanitizer instead of internal mdebug to check for memory leaks Nov 23, 2019
@levitte levitte added the approval: review pending This pull request needs review by a committer label Nov 23, 2019
@levitte
Copy link
Member Author

levitte commented Nov 23, 2019

I'm pondering if I should add a test program that intentionally leaks memory, for demonstration purposes...

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to think yes to the deliberately leaking test program.
We'd quickly find out if leak detection ever stopped working.

Detects if leak sanitizing is on, and directs the exit code accordingly.

Note that this program is designed to fail when leaking, as that's
expected, so to make it easy for wrapper scripts, we also make it look
like it fails when sanitizing isn't on.
@levitte
Copy link
Member Author

levitte commented Dec 3, 2019

CIs are happy. Is @openssl happy?

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this.

@paulidale paulidale added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Dec 4, 2019
@richsalz
Copy link
Contributor

richsalz commented Dec 4, 2019

are you going to remove the current mdebug cruft?

@levitte
Copy link
Member Author

levitte commented Dec 4, 2019

are you going to remove the current mdebug cruft?

That's my intention, yes.

@levitte
Copy link
Member Author

levitte commented Dec 4, 2019

... or... wanna take that on? I wouldn't mind. You do need to retain the public API, though...

@richsalz
Copy link
Contributor

richsalz commented Dec 4, 2019

I will make a PR to remove the existing mem-debug stuff. I had wanted to remove the malloc-fail stuff as well, but it seems there's interest in this now. (I forget which comment in which PR)

@richsalz
Copy link
Contributor

richsalz commented Dec 4, 2019

PR #10572

@levitte levitte added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Dec 10, 2019
openssl-machine pushed a commit that referenced this pull request Dec 10, 2019
The leak sanitizer gives better reports (complete stack traces) and
works as a wrapper around the application instead of relying on
cooperative enabling and disabling calls (which are too easy to get
unbalanced).

Related to #8322

Reviewed-by: Paul Dale <[email protected]>
(Merged from #9294)
openssl-machine pushed a commit that referenced this pull request Dec 10, 2019
Detects if leak sanitizing is on, and directs the exit code accordingly.

Note that this program is designed to fail when leaking, as that's
expected, so to make it easy for wrapper scripts, we also make it look
like it fails when sanitizing isn't on.

Reviewed-by: Paul Dale <[email protected]>
(Merged from #9294)
@levitte
Copy link
Member Author

levitte commented Dec 10, 2019

Merged.

22c2236 Use leak sanitizer instead of internal mdebug to check for memory leaks
ea7a952 test/memleaktest.c: Modify for use with address/leak sanitizer

@levitte levitte closed this Dec 10, 2019
@levitte
Copy link
Member Author

levitte commented Dec 10, 2019

@richsalz, you've got a small update to do with test/memleaktest.c in #10572 😉

@richsalz
Copy link
Contributor

yes, i rebased, took master for the conflicts, squashed, and pushed. i'll note that over there too.

@mattcaswell
Copy link
Member

This doesn't actually seem to work in travis. The memleak test is failing in the extended tests.

@mattcaswell mattcaswell mentioned this pull request Dec 23, 2019
@mattcaswell
Copy link
Member

I'm proposing to temporarily revert this in #10689.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants