Closed
Bug 1195977
Opened 10 years ago
Closed 10 years ago
Make ThrowRangeError() and ThrowTypeError() type-safe
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla43
Tracking | Status | |
---|---|---|
firefox43 | --- | fixed |
People
(Reporter: mccr8, Assigned: mccr8)
References
Details
(Keywords: sec-audit, sec-want, Whiteboard: [adv-main43-])
Attachments
(8 files, 7 obsolete files)
1.50 KB,
patch
|
peterv
:
review+
|
Details | Diff | Splinter Review |
2.46 KB,
patch
|
peterv
:
review+
|
Details | Diff | Splinter Review |
1.54 KB,
patch
|
peterv
:
review+
|
Details | Diff | Splinter Review |
2.26 KB,
patch
|
peterv
:
review+
|
Details | Diff | Splinter Review |
3.00 KB,
patch
|
peterv
:
review+
|
Details | Diff | Splinter Review |
6.29 KB,
patch
|
peterv
:
review+
|
Details | Diff | Splinter Review |
4.16 KB,
patch
|
peterv
:
review+
|
Details | Diff | Splinter Review |
1.17 KB,
patch
|
peterv
:
review+
|
Details | Diff | Splinter Review |
ErrorResult::ThrowErrorWithMessage (and the methods that call it) use var args, which means they don't do any type checking of their arguments. As seen in bug 1194562, this can result in buffer overflows that are not detected except in ASan builds. It seems like with some template programming we should be able to statically check these arguments.
I can take a look if nobody else is champing at the bit to work on this. I'm filing this as a sec bug because it may turn up more instances of things like bug 1194562.
Assignee | ||
Updated•10 years ago
|
Assignee: nobody → continuation
Depends on: 1197012
Assignee | ||
Comment 1•10 years ago
|
||
This is still in progress, but I figured I might as well upload what I have so far. This depends on the definition of a constant from bug 1196391.
Assignee | ||
Comment 2•10 years ago
|
||
Assignee | ||
Comment 3•10 years ago
|
||
Assignee | ||
Comment 4•10 years ago
|
||
Assignee | ||
Comment 5•10 years ago
|
||
this will enable us to move it to the header in the next part, for templatification
Assignee | ||
Comment 6•10 years ago
|
||
Assignee | ||
Comment 7•10 years ago
|
||
Assignee | ||
Comment 8•10 years ago
|
||
Here's a summary of the changes:
1. Passing an argument of the incorrect type will now cause a compilation error, rather than some kind of weird type confusion problem.
2. Specifying an error message with too many arguments with cause a compilation error (static_assert).
3. Passing too many arguments will cause an assertion in debug builds. In release builds, the additional arguments will be ignored (which is what happens currently).
4. Not passing in enough errors will cause a fatal assertion in both and debug and opt builds. This is to prevent a stack buffer overflow when the JS engine attempts to read arguments that are not there.
5. If we deserialize an ErrorResult, and the message either has too many or too messages, we fail the deserialize (which kills the child process or whatever.). The ErrNum deserialization enforces that the result is a valid enum, and the static_assert enforces that the number of arguments for valid enums is < 10. This is to prevent a hostile child process from causing a stack buffer overflow.
6. Dynamically check that ThrowInvalidThis takes no more than 2 arguments, which is how many we pass in. Again, this prevents a stack buffer overflow if used incorrectly.
Assignee | ||
Comment 9•10 years ago
|
||
I'm narrowing the scope of this a bit and I filed some followup bugs.
Summary: Statically check the arguments to ErrorResult::ThrowErrorWithMessage → Make ThrowRangeError() and ThrowTypeError() type-safe
Updated•10 years ago
|
Group: core-security → dom-core-security
Assignee | ||
Comment 10•10 years ago
|
||
There are a lot of patches here, but they are mostly pretty simple, except part 7.
Attachment #8651295 -
Attachment is obsolete: true
Attachment #8651296 -
Attachment is obsolete: true
Attachment #8651297 -
Attachment is obsolete: true
Attachment #8651298 -
Attachment is obsolete: true
Attachment #8651299 -
Attachment is obsolete: true
Attachment #8651300 -
Attachment is obsolete: true
Attachment #8651301 -
Attachment is obsolete: true
Attachment #8656777 -
Flags: review?(peterv)
Assignee | ||
Comment 11•10 years ago
|
||
This makes it so that we do not need to dynamically enforce this
constraint in ErrorResult::ThrowErrorWithMessage().
This uses a new JS API constant, JS::MaxNumErrorArguments, defined in bug 1196391.
Attachment #8656778 -
Flags: review?(peterv)
Assignee | ||
Comment 12•10 years ago
|
||
This helper is useful later.
Attachment #8656779 -
Flags: review?(peterv)
Assignee | ||
Comment 13•10 years ago
|
||
The new check in ErrorResult::ReportErrorWithMessage() shouldn't be
needed and is just to protect against the possibility of another way
to construct messages being added.
Of particular note, the additional check in ErrorResult::DeserializeMessage() prevents a hostile child process from causing a buffer overflow in our process. We do not need to check against the max number of arguments, because it is statically enforced that all valid enums of this type have less arguments than that, and the IPC deserialize code for enums dynamically enforces that this is a valid enum.
Attachment #8656782 -
Flags: review?(peterv)
Assignee | ||
Comment 14•10 years ago
|
||
This will enable us to move it to the header later, which is needed to
turn it into a template.
Attachment #8656784 -
Flags: review?(peterv)
Assignee | ||
Comment 15•10 years ago
|
||
This is needed to turn these into templates later.
Attachment #8656785 -
Flags: review?(peterv)
Assignee | ||
Comment 16•10 years ago
|
||
This enables type checking of these arguments.
The MOZ_RELEASE_ASSERT in the case with no arguments will become superfluous with bug 1197893 but I left it here for now.
Attachment #8656786 -
Flags: review?(peterv)
Assignee | ||
Comment 17•10 years ago
|
||
We have to permit passing in too many arguments because sometimes the
error is MSG_METHOD_THIS_UNWRAPPING_DENIED which only takes one
argument.
This is another error message function that should be checked.
Attachment #8656787 -
Flags: review?(peterv)
Updated•10 years ago
|
Attachment #8656777 -
Flags: review?(peterv) → review+
Updated•10 years ago
|
Attachment #8656778 -
Flags: review?(peterv) → review+
Updated•10 years ago
|
Attachment #8656779 -
Flags: review?(peterv) → review+
Updated•10 years ago
|
Attachment #8656782 -
Flags: review?(peterv) → review+
Updated•10 years ago
|
Attachment #8656784 -
Flags: review?(peterv) → review+
Updated•10 years ago
|
Attachment #8656785 -
Flags: review?(peterv) → review+
Updated•10 years ago
|
Attachment #8656786 -
Flags: review?(peterv) → review+
Updated•10 years ago
|
Attachment #8656787 -
Flags: review?(peterv) → review+
Comment 18•10 years ago
|
||
Inlining the error throwing code makes me a little sad, but don't see a good way around it :-(.
Assignee | ||
Comment 19•10 years ago
|
||
(In reply to Peter Van der Beken [:peterv] from comment #18)
> Inlining the error throwing code makes me a little sad, but don't see a good
> way around it :-(.
Yeah, it is unfortunate this requires templating.
The blocking bugs have all been fixed, so I think this can be unhidden now.
Group: dom-core-security
Comment 20•10 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/37ceff90f964
https://hg.mozilla.org/integration/mozilla-inbound/rev/505d11fcad96
https://hg.mozilla.org/integration/mozilla-inbound/rev/bd02797d06af
https://hg.mozilla.org/integration/mozilla-inbound/rev/f3075fbc955d
https://hg.mozilla.org/integration/mozilla-inbound/rev/fba22ced664c
https://hg.mozilla.org/integration/mozilla-inbound/rev/8fbf291b2fdc
https://hg.mozilla.org/integration/mozilla-inbound/rev/eae3e7c3dbbd
https://hg.mozilla.org/integration/mozilla-inbound/rev/461b0e3e3071
https://hg.mozilla.org/mozilla-central/rev/37ceff90f964
https://hg.mozilla.org/mozilla-central/rev/505d11fcad96
https://hg.mozilla.org/mozilla-central/rev/bd02797d06af
https://hg.mozilla.org/mozilla-central/rev/f3075fbc955d
https://hg.mozilla.org/mozilla-central/rev/fba22ced664c
https://hg.mozilla.org/mozilla-central/rev/8fbf291b2fdc
https://hg.mozilla.org/mozilla-central/rev/eae3e7c3dbbd
https://hg.mozilla.org/mozilla-central/rev/461b0e3e3071
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla43
Updated•10 years ago
|
Whiteboard: [adv-main43-]
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•