Bug 107699 - Add SECURITY_ASSERT
Summary: Add SECURITY_ASSERT
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 109449 107748 108150 108153 108307 108503 108522 108699 108702 108828 108829 108833 108838 108839 109293 109448 109450 110058
  Show dependency treegraph
 
Reported: 2013-01-23 08:58 PST by Abhishek Arya
Modified: 2013-02-17 11:44 PST (History)
12 users (show)

See Also:


Attachments
Patch (3.26 KB, patch)
2013-01-23 09:19 PST, Abhishek Arya
no flags Details | Formatted Diff | Diff
Patch (3.93 KB, patch)
2013-01-23 09:34 PST, Abhishek Arya
no flags Details | Formatted Diff | Diff
Patch (4.44 KB, patch)
2013-01-23 14:28 PST, Abhishek Arya
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Abhishek Arya 2013-01-23 08:58:17 PST
SECURITY_ASSERT will replace some asserts that are known to cause security vulnerabilities and will be enabled in our fuzzing builds (e.g. http://trac.webkit.org/changeset/97009).
Comment 1 Abhishek Arya 2013-01-23 09:06:57 PST
Some candidates are all the bad cast catchers [long-list, will be another bug]

e.g.
 inline RenderSVGShape* toRenderSVGShape(RenderObject* object)
 {
-    ASSERT(!object || object->isSVGShape());
+    SECURITY_ASSERT(!object || object->isSVGShape());
     return static_cast<RenderSVGShape*>(object);
 }

and some of Sergey's recent dom tree corruption bug due to document confusion

void ContainerNode::parserAppendChild(PassRefPtr<Node> newChild)
{
.......
    ASSERT(document() == newChild->document());
Comment 2 Abhishek Arya 2013-01-23 09:19:03 PST
Created attachment 184251 [details]
Patch
Comment 3 Abhishek Arya 2013-01-23 09:34:42 PST
Created attachment 184252 [details]
Patch
Comment 4 WebKit Review Bot 2013-01-23 09:47:55 PST
Attachment 184252 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WTF/ChangeLog', u'Source/WTF/wtf/Assertions.h', u'Source/WTF/wtf/Vector.h', u'Source/WebCore/ChangeLog', u'Source/WebCore/dom/ContainerNode.cpp']" exit_code: 1
Source/WTF/wtf/Assertions.h:276:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
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 Abhishek Arya 2013-01-23 09:48:55 PST
(In reply to comment #4)
> Attachment 184252 [details] did not pass style-queue:
> 
> Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WTF/ChangeLog', u'Source/WTF/wtf/Assertions.h', u'Source/WTF/wtf/Vector.h', u'Source/WebCore/ChangeLog', u'Source/WebCore/dom/ContainerNode.cpp']" exit_code: 1
> Source/WTF/wtf/Assertions.h:276:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
> Total errors found: 1 in 5 files
> 
> 
> If any of these errors are false positives, please file a bug against check-webkit-style.

false positive indeed, see the code in ASSERT().
Comment 6 Eric Seidel (no email) 2013-01-23 10:55:23 PST
Crazy.  Seems reasonable that you might want some, but not all ASSERTS on for specific builds.
Comment 7 Eric Seidel (no email) 2013-01-23 10:55:58 PST
At some level though, aren't all ASSERTS security asserts? :)  I guess it's too slow to turn them all on?
Comment 8 Abhishek Arya 2013-01-23 10:57:19 PST
(In reply to comment #7)
> At some level though, aren't all ASSERTS security asserts? :)  I guess it's too slow to turn them all on?

I think only 5-10% asserts cause security bugs. We can't turn them all on. For a fuzzed testcase, some of the ones will always hit like unsupported css property value, etc.
Comment 9 Abhishek Arya 2013-01-23 10:58:33 PST
(In reply to comment #8)
> (In reply to comment #7)
> > At some level though, aren't all ASSERTS security asserts? :)  I guess it's too slow to turn them all on?
> 
> I think only 5-10% asserts cause security bugs. We can't turn them all on. For a fuzzed testcase, some of the ones will always hit like unsupported css property value, etc.

And yes, it makes build slow to turn everything on. And we are making security_asserts for only those asserts that we know 100% sure to cause security vulns, like all the bad cast ones.
Comment 10 Benjamin Poulain 2013-01-23 13:38:20 PST
I like the idea but:
-I would add a descriptive comment in Assertions.h explaining its purpose. Contrary to regular assertions, this concept is not common and would benefit from an explanation.

-I think the name is not great. SECURITY_ASSERT could be the name of an Assertion that would always cause a crash because hitting it means a security issue. We have various ASSERT_FOOBAR already. What about ASSERT_WITH_SECURITY_RISK || ASSERT_WITH_SECURITY_IMPLICATION || ASSERT_WITH_SECURITY_HINT or something like that?

-In addition to Vector.h, HashTable has many very good assertion that have helped catching use after free in the past.
Comment 11 Abhishek Arya 2013-01-23 14:16:44 PST
(In reply to comment #10)
> I like the idea but:
> -I would add a descriptive comment in Assertions.h explaining its purpose. Contrary to regular assertions, this concept is not common and would benefit from an explanation.
> 

Fixed.

> -I think the name is not great. SECURITY_ASSERT could be the name of an Assertion that would always cause a crash because hitting it means a security issue. We have various ASSERT_FOOBAR already. What about ASSERT_WITH_SECURITY_RISK || ASSERT_WITH_SECURITY_IMPLICATION || ASSERT_WITH_SECURITY_HINT or something like that?

Fixed.

> 
> -In addition to Vector.h, HashTable has many very good assertion that have helped catching use after free in the past.

This is just the beginning, we need to change many of these asserts from now on. As i was looking at HashTable, it has far too many interesting ones (also hidden behind CHECK_HASHTABLE_ITERATORS), i will add it in follow up patches, just like the numerous others I have in plans already. ASSERT(!object || object->isSVGShape());. Phase 1 for this will be only changing those we are sure for 100% security vulnerability indicator.
Comment 12 Abhishek Arya 2013-01-23 14:28:28 PST
Created attachment 184315 [details]
Patch
Comment 13 Eric Seidel (no email) 2013-01-23 14:31:04 PST
Comment on attachment 184315 [details]
Patch

Seems reasonable.  I'm concerned that this list will grow out of control, and I'm not sure who's going to audit it. :)
Comment 14 WebKit Review Bot 2013-01-23 14:31:36 PST
Attachment 184315 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WTF/ChangeLog', u'Source/WTF/wtf/Assertions.h', u'Source/WTF/wtf/Vector.h', u'Source/WebCore/ChangeLog', u'Source/WebCore/dom/ContainerNode.cpp']" exit_code: 1
Source/WTF/wtf/Assertions.h:282:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 15 Benjamin Poulain 2013-01-23 14:32:28 PST
Comment on attachment 184315 [details]
Patch

I like this a lot. I don't cq+ to give a chance for other to raise concerns. Give it a little time before landing.

Good luck finding new security issues.
Comment 16 Benjamin Poulain 2013-01-23 14:32:30 PST
Comment on attachment 184315 [details]
Patch

I like this a lot. I don't cq+ to give a chance for other to raise concerns. Give it a little time before landing.

Good luck finding new security issues.
Comment 17 Abhishek Arya 2013-01-23 14:34:38 PST
(In reply to comment #16)
> (From update of attachment 184315 [details])
> I like this a lot. I don't cq+ to give a chance for other to raise concerns. Give it a little time before landing.
> 

Sure. Sounds good.

> Good luck finding new security issues.

I gave it a shot with very few asserts locally, and already found some bad casts. The key was to filter these interesting asserts out and i am thankful to you and Eric for the support of this idea.
Comment 18 Abhishek Arya 2013-01-23 18:57:09 PST
Comment on attachment 184315 [details]
Patch

Clearing flags on attachment: 184315

Committed r140633: <http://trac.webkit.org/changeset/140633>
Comment 19 Abhishek Arya 2013-01-23 18:57:12 PST
All reviewed patches have been landed.  Closing bug.
Comment 20 Abhishek Arya 2013-01-23 23:14:10 PST
On Wed, Jan 23, 2013 at 10:59 PM, Simon Fraser <simon.fraser@apple.com> wrote:
It seems weird to add this new kind of assertion under the cover of a security bug, for two reasons. First, how are WebKit developers supposed to know when to use it? Second, it's just adding  release-build assertion that (I'm guessing) you enable for fuzzing. That doesn't seem to be exposing new vulnerabilities.

My mistake for filing it as a security bug, i just made it public. However, I did leave out a comment in the code explaining the purpose of this ASSERT. We cannot enable all asserts on our fuzzing cluster since only few asserts are known to cause security vulnerabilities. These asserts added in the two patches are known to cause bad casts [static_cast problems], out of bounds reads[vector.h ones], containernode document confusion[use after frees]. The places we are adding them are sure-shot security bugs, like bad cast due to wrong static_cast usage, out of bounds access in vector and list will grow with time. In normal builds, it will work as regular asserts. This assert will also help a dev hitting it to know that they should file a security bug when they encounter such issues (also in the comment) [seeing the assert name and read the description in assertions.h]. Regarding how webkit developers should add it is still hard and not encouraged in the first phase. We want security group members who know about these security problems should add it for now.
Comment 21 Abhishek Arya 2013-01-23 23:16:48 PST
To give you examples of bugs we found using this in a trial run.

https://bugs.webkit.org/show_bug.cgi?id=107748
https://bugs.webkit.org/show_bug.cgi?id=107237