Bug 140194 - Make bmalloc work with ASan
Summary: Make bmalloc work with ASan
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Geoffrey Garen
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-01-07 12:41 PST by Geoffrey Garen
Modified: 2015-01-09 16:30 PST (History)
6 users (show)

See Also:


Attachments
Patch (4.32 KB, patch)
2015-01-07 12:57 PST, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch (4.31 KB, patch)
2015-01-07 13:00 PST, Geoffrey Garen
mark.lam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey Garen 2015-01-07 12:41:16 PST
Make bmalloc work with ASan
Comment 1 Geoffrey Garen 2015-01-07 12:57:51 PST
Created attachment 244180 [details]
Patch
Comment 2 Geoffrey Garen 2015-01-07 12:58:42 PST
<rdar://problem/19401435>
Comment 3 Geoffrey Garen 2015-01-07 13:00:27 PST
Created attachment 244181 [details]
Patch
Comment 4 WebKit Commit Bot 2015-01-07 13:03:31 PST
Attachment 244181 [details] did not pass style-queue:


ERROR: Source/bmalloc/bmalloc/Environment.cpp:26:  Found other header before WebCore config.h. Should be: config.h, primary header, blank line, and then alphabetically sorted.  [build/include_order] [4]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Mark Rowe (bdash) 2015-01-07 13:14:31 PST
Is there some advantage to doing the check in this manner rather than using a compile-time check as mentioned at <http://clang.llvm.org/docs/AddressSanitizer.html#has-feature-address-sanitizer>?
Comment 6 Mark Lam 2015-01-07 13:41:41 PST
Comment on attachment 244181 [details]
Patch

r=me
Comment 7 Mark Lam 2015-01-07 13:57:08 PST
(In reply to comment #6)
> r=me

I missed Mark Rowe's comment.  Based on that, I think that it is better for isASanEnabled() to rely on the __has_feature(address_sanitizer) test instead of the _dyld_get_image_name checks.
Comment 8 Alexey Proskuryakov 2015-01-07 14:11:09 PST
This patch is right if bmalloc causes problems when used in a client app that is built with ASan. I.e.,
1. WebKit is built without ASan (e.g. just using the shipping one in /System/Library).
2. Client app is built with ASan.

There are at least two kinds of possible problems:
1. bmalloc would cause false positives.
2. bmalloc would hinder ASan's ability to find bugs in client apps.

I do not know if either problem exists in practice.
Comment 9 Geoffrey Garen 2015-01-07 14:57:05 PST
(In reply to comment #8)
> This patch is right if bmalloc causes problems when used in a client app
> that is built with ASan. I.e.,
> 1. WebKit is built without ASan (e.g. just using the shipping one in
> /System/Library).
> 2. Client app is built with ASan.
> 
> There are at least two kinds of possible problems:
> 1. bmalloc would cause false positives.
> 2. bmalloc would hinder ASan's ability to find bugs in client apps.
> 
> I do not know if either problem exists in practice.

Right -- I originally wrote a compile-time check, but then I realized that a compile-time check is not friendly to a client library or app that wants to build with ASan and then link against WebKit/JavaScriptCore that was built without it.

I also plan to make bmalloc independently linkable, for clients that just want a fast malloc, and a compile-time check will be unfriendly to those clients.

I don't know of any such clients that have problems right now, but I'd like to make bmalloc friendly to such clients in the future. 

Does that sound reasonable?
Comment 10 Mark Lam 2015-01-07 15:00:16 PST
(In reply to comment #9)
> (In reply to comment #8)
> > This patch is right if bmalloc causes problems when used in a client app
> > that is built with ASan. I.e.,
> > 1. WebKit is built without ASan (e.g. just using the shipping one in
> > /System/Library).
> > 2. Client app is built with ASan.
> > 
> > There are at least two kinds of possible problems:
> > 1. bmalloc would cause false positives.
> > 2. bmalloc would hinder ASan's ability to find bugs in client apps.
> > 
> > I do not know if either problem exists in practice.
> 
> Right -- I originally wrote a compile-time check, but then I realized that a
> compile-time check is not friendly to a client library or app that wants to
> build with ASan and then link against WebKit/JavaScriptCore that was built
> without it.
> 
> I also plan to make bmalloc independently linkable, for clients that just
> want a fast malloc, and a compile-time check will be unfriendly to those
> clients.
> 
> I don't know of any such clients that have problems right now, but I'd like
> to make bmalloc friendly to such clients in the future. 
> 
> Does that sound reasonable?
Comment 11 Mark Lam 2015-01-07 15:00:55 PST
(In reply to comment #9)
> Does that sound reasonable?

Oops ... accidentally committed last comment.  Meant to say ...

Sounds good to me.
Comment 12 Alexey Proskuryakov 2015-01-07 15:24:51 PST
I don't know if the theoretical problems are real, so I can't agree that the substantially more complicated runtime solution is warranted. Are there at least speculative reasons to believe that the problems are real?
Comment 13 Geoffrey Garen 2015-01-07 15:53:15 PST
> Are there at least speculative reasons to believe that the problems are real?

Yes:

(1) I make bmalloc a stand-alone .dylib.
(2) Client [redacted] adopts bmalloc.
(3) Client [redacted] adopts ASan.
--> ASan doesn't work because none of [redacted]'s allocations register with ASan's runtime system.
--> Client [redacted] sends me a mean email and unadopts bmalloc.
Comment 14 Alexey Proskuryakov 2015-01-07 16:40:52 PST
Yes, a bmalloc dylib case seems convincing. We just need to double-check that the dynamic check actually works in this case (unsure what guarantees that ASan dylib will be in dyld image list early enough).
Comment 15 David Kilzer (:ddkilzer) 2015-01-07 20:02:01 PST
Another option is to teach ASan about bmalloc so everything just works, although that would also rely on bmalloc exposing a stable API.
Comment 16 Geoffrey Garen 2015-01-08 16:38:49 PST
(In reply to comment #14)
> Yes, a bmalloc dylib case seems convincing. We just need to double-check
> that the dynamic check actually works in this case (unsure what guarantees
> that ASan dylib will be in dyld image list early enough).

I verified with a test program that the full list of linked libraries is available to _dyld_get_image_name() at static initialization time.
Comment 17 Geoffrey Garen 2015-01-08 16:41:55 PST
Committed r178144: <http://trac.webkit.org/changeset/178144>
Comment 18 Geoffrey Garen 2015-01-09 16:30:54 PST
Committed r178221: <http://trac.webkit.org/changeset/178221>