Closed
Bug 1199740
Opened 11 years ago
Closed 8 years ago
Nascent memory-safety bug in XPCWrappedNativeScope (via nsTArray)
Categories
(Core :: XPConnect, defect)
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: q1, Assigned: froydnj)
Details
(Keywords: reporter-external, sec-audit, sec-want)
Attachments
(12 files, 1 obsolete file)
|
6.51 KB,
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
|
15.48 KB,
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
|
9.71 KB,
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
|
3.96 KB,
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
|
3.77 KB,
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
|
2.66 KB,
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
|
1.09 KB,
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
|
4.05 KB,
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
|
6.54 KB,
patch
|
khuey
:
review+
|
Details | Diff | Splinter Review |
|
10.43 KB,
patch
|
Details | Diff | Splinter Review | |
|
7.10 KB,
patch
|
erahm
:
feedback+
|
Details | Diff | Splinter Review |
|
6.30 KB,
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
XPCWrappedNativeScope indirectly puts JS::Heap objects into an nsTArray. This is unsafe because nsTArray relocates objects with memcpy when it expands its embedded array, but the JS garbage collector maintains its own pointers to JS::Heap objects, which nsTArray does not (by default) update. This can cause the JS garbage collector to peruse and destroy "objects" in memory that it doesn't own.
The bug is nascent because the code in question is behind the preference dom.compartment_per_addon, which is currently false in production Firefox (but true in nightly builds). The compartment-per-addon capability appears to be slated for future release: https://bugzilla.mozilla.org/show_bug.cgi?id=1030420 .
Details:
--------
XPCWrappedNativeScope contains
1248: // Lazily created sandboxes for addon code.
1249: nsTArray<JS::ObjectPtr> mAddonScopes;
but JS::ObjectPtr contains:
1163: class JS_PUBLIC_API(ObjectPtr)
1164: {
1165: Heap<JSObject*> value;
While nsTArray has the specialization:
663: //
664: // Some classes require constructors/destructors to be called, so they are
665: // specialized here.
666: //
667: template<class E>
668: struct nsTArray_CopyChooser<JS::Heap<E>>
669: {
670: typedef nsTArray_CopyWithConstructors<JS::Heap<E>> Type;
671: };
Updated•11 years ago
|
Component: JavaScript: GC → XPConnect
| Assignee | ||
Comment 1•11 years ago
|
||
Maybe it's time to suck it up and just use mozilla::Vector for everything. Or make things opt-in for memory copying (performance) instead of opt-in for correctness.
Updated•11 years ago
|
Flags: sec-bounty?
In practice I don't think this is a problem. According to Terrence, we don't add things to the store buffer if they're not in the nursery. Nothing in mAddonScopes is going to be in the nursery, so none of these will get added to the store buffer.
We should make this better though. ObjectPtr is of questionable relevance, and it would be nice to make this particular pointer a TenuredHeap.
Comment 3•11 years ago
|
||
At the very least we should be asserting that the thing is tenured.
It doesn't seem like any of us are at all certain why the pre-barrier is needed, however, so I'd be much more comfortable if we just made the container C++ safe. If that's a large regression, then we'll need to do something more sophisticated, but I'd like to at least try the obviously correct approach first.
This array is typically very short so there's no reason to do anything for performance here.
(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #1)
> Maybe it's time to suck it up and just use mozilla::Vector for everything.
> Or make things opt-in for memory copying (performance) instead of opt-in for
> correctness.
I'd lean toward opt-in: why risk subtle memory-corruptor bugs? It'd be interesting to see what happens to performance if nsTArray were changed to copy with constructors. It seems that the impact should be small except for arrays that are frequently reallocated, and I'd guess that those already have an initial size set to minimize reallocations.
Updated•11 years ago
|
Updated•11 years ago
|
Group: core-security → dom-core-security
Comment 6•11 years ago
|
||
If an audit of the code turns up any further bugs, please nominate those for bounty.
Flags: sec-bounty? → sec-bounty-
| Assignee | ||
Comment 7•10 years ago
|
||
They are unused, except for tests.
I apologize in advance for attaching so many patches to a security bug. I
considered doing some of the work in separate bugs, but then we have to
coordinate uplifts from several bugs if we decide to do that, patches later in
the series may become more difficult to review, etc. Some of the patches in
the middle of the series could probably be squashed together prior to commit if
people wanted to do that.
Attachment #8763963 -
Flags: review?(erahm)
| Assignee | ||
Comment 8•10 years ago
|
||
This change enables some of the methods in nsTArray to be lazily
instantiated, particularly the ones that care about whether the element
type is copyable. Since we have a number of places where nsTArray is
used with move-only types, we need to ensure that unless methods
requiring copyability are actually called, those methods are not
instantiated.
Attachment #8763964 -
Flags: review?(erahm)
| Assignee | ||
Comment 9•10 years ago
|
||
The names {Copy,Move}Elements are based on the use of mem{cpy,move},
respectively. However, I submit that we really want the names to
reflect the C++ operations being done, rather than the underlying
implementation details. So let's rename these to reflect that we are
always copying the elements, and discriminate between the two cases
based on whether the regions being copied overlap or not.
Bring CopyHeaderAndElements along for the ride, as well.
Attachment #8763965 -
Flags: review?(erahm)
| Assignee | ||
Comment 10•10 years ago
|
||
We'll need these for future patches as we transition nsTArray to use
moves for most of its operations rather than copies. The implementation
of these functions are essentially cut-and-paste versions of the Copy*
functions, but using moves.
Attachment #8763966 -
Flags: review?(erahm)
| Assignee | ||
Comment 11•10 years ago
|
||
Whenever we're copying the header, we can be guaranteed that we're never
going to use the elements from the old array afterward, so can move (in
the C++ sense) the elements rather than copying them.
Attachment #8763967 -
Flags: review?(erahm)
| Assignee | ||
Comment 12•10 years ago
|
||
In all of the calls to CopyNonOverlappingRegion from within nsTArray, we
don't care about the contents of the source afterwards. So we can use
moves instead of copies to potentially make things more efficient.
Attachment #8763968 -
Flags: review?(erahm)
| Assignee | ||
Comment 13•10 years ago
|
||
This change eliminates the last use of the Copy* family of functions.
Attachment #8763969 -
Flags: review?(erahm)
| Assignee | ||
Comment 14•10 years ago
|
||
After all the previous patches, we never call these functions. Any
copying required by nsTArray is taken care of by other means.
Attachment #8763970 -
Flags: review?(erahm)
| Assignee | ||
Updated•10 years ago
|
Assignee: nobody → nfroyd
| Assignee | ||
Comment 15•10 years ago
|
||
This is a rollup patch of several modifications that don't need to go
together, but are too tedious to do as separate patches. The basic idea
is that some objects in Gecko were written assuming that nsTArray uses
raw memory operations. Now that we want to change that, we need to
change those classes to cope. We can either add move constructors to
classes or we can specialize nsTArray for those classes to use memcpy.
A summary of what was chosen and why follows:
* StructuredCloneHolder/StructuredCloneData: It seemed simplest to
maintain the status quo for these classes.
* StructuredCloneReadInfo: This class already has a move assignment
operator, so it's a bit unusual for it not to have a move constructor.
* nsMathMLChar: All of the member types of this class are movable, so we
might as well permit it to be moved as well.
* nsRevocableEventPtr: This class just wraps RefPtr, so making the class
movable is reasonable.
* nsAutoRef: Even though we want to specialize nsTArray<nsAutoRef<T>> to
use memcpy, making this class movable means that classes that have
nsAutoRef members can become movable themselves. Otherwise, classes
that have nsAutoRef members and are stored in arrays need to add a
bunch of extra code, either by hand-rolling move construction for
nsAutoRef so the enclosing class can have a move constructor, or
providing appropriate specializations.
Attachment #8763973 -
Flags: review?(khuey)
| Assignee | ||
Comment 16•10 years ago
|
||
Bindings codegen creates a number of classes that aren't copyable, but
are stored in nsTArray--sometimes via Sequence<T>, sometimes by virtue
of being included in classes that themselves get stored in nsTArray.
This patch adds nsTArray specializations for such classes in codegen.
Attachment #8763974 -
Flags: review?(peterv)
| Assignee | ||
Comment 17•10 years ago
|
||
Attachment #8763975 -
Flags: review?(erahm)
Attachment #8763973 -
Flags: review?(khuey) → review+
Updated•10 years ago
|
Attachment #8763963 -
Flags: review?(erahm) → review+
| Reporter | ||
Comment 18•10 years ago
|
||
I'm glad you've changed nsTArray to copy with contructors by default. BTW, I'm back from a very long personal task, and will be working on bugs again soon.
Updated•10 years ago
|
Attachment #8763964 -
Flags: review?(erahm) → review+
Updated•10 years ago
|
Attachment #8763965 -
Flags: review?(erahm) → review+
Comment 19•10 years ago
|
||
Nathan, why wouldn't we just use the existing semantics for all unions and dictionaries, as opposed to just non-copy-constructible ones? Seems like we're at risk of introducing a bunch of string copies, refcounting, array copies, etc, when none of that is necessary.
Comment 20•10 years ago
|
||
Also, we should probably add memcpy specializations for RuleValue over in nsCSSRuleProcessor.cpp. That stuff is fairly performance-sensitive.
Comment 21•10 years ago
|
||
And also also, what behavior does nsTArray<nsString> end up with after these patches? What about nsTArray<Foo*>? Is is_arithmetic true in the latter case?
Flags: needinfo?(nfroyd)
| Assignee | ||
Comment 22•10 years ago
|
||
(In reply to Boris Zbarsky [:bz] (Out June 25-July 6) from comment #19)
> Nathan, why wouldn't we just use the existing semantics for all unions and
> dictionaries, as opposed to just non-copy-constructible ones? Seems like
> we're at risk of introducing a bunch of string copies, refcounting, array
> copies, etc, when none of that is necessary.
Ah, I didn't think about that. That seems reasonable.
(In reply to Boris Zbarsky [:bz] (Out June 25-July 6) from comment #21)
> And also also, what behavior does nsTArray<nsString> end up with after these
> patches? What about nsTArray<Foo*>? Is is_arithmetic true in the latter
> case?
Those would both be subject to copy constructors. We should fix that.
(I wanted to use std::is_pod instead of std::is_arithmetic, as that would catch a lot more stuff, but std::is_pod requires that the type you provide be a complete type, which is...untenable.)
Flags: needinfo?(nfroyd)
Comment 23•10 years ago
|
||
Comment on attachment 8763966 [details] [diff] [review]
part 3 - add Move{Non,}OverlappingRegion
Review of attachment 8763966 [details] [diff] [review]:
-----------------------------------------------------------------
This at least needs some clarification, if I'm interpreting correctly the implementation of Overlapping looks incorrect. If the fixup differs drastically you might want to update this part of the commit comment: "The implementation of these functions are essentially cut-and-paste versions..."
::: xpcom/glue/nsTArray.h
@@ +675,5 @@
> + ElemType* destElemEnd = destElem + aCount;
> + ElemType* srcElemEnd = srcElem + aCount;
> + if (destElem == srcElem) {
> + return; // In practice, we don't do this.
> + } else if (srcElemEnd > destElem && srcElemEnd < destElemEnd) {
I don't think this check for overlapping is right. Imagine:
> ARRAY [12345]
> SRC [2345]
> DST [1234]
(So shifting the last 4 elements left 1 position)
In this case |srcElemEnd > destElem| == TRUE, |srcElemEnd < destElemEnd| == FALSE, so we'd end up dropping to the else and memcpy'ing an overlapping region rather than memmove'ing
In general I don't get why were special casing the right shift case. Can you add some comments?
@@ +680,5 @@
> + while (destElemEnd != destElem) {
> + --destElemEnd;
> + --srcElemEnd;
> + traits::Construct(destElemEnd, mozilla::Move(*srcElemEnd));
> + traits::Destruct(srcElem);
Should this be |srcElemEnd|?
@@ +683,5 @@
> + traits::Construct(destElemEnd, mozilla::Move(*srcElemEnd));
> + traits::Destruct(srcElem);
> + }
> + } else {
> + MoveNonOverlappingRegion(aDest, aSrc, aCount, aElemSize);
Maybe this was supposed to be |MoveOverlappingRegion|?
Attachment #8763966 -
Flags: review?(erahm) → review-
Comment 24•10 years ago
|
||
(In reply to Eric Rahm [:erahm] from comment #23)
> Comment on attachment 8763966 [details] [diff] [review]
> part 3 - add Move{Non,}OverlappingRegion
>
> Review of attachment 8763966 [details] [diff] [review]:
> -----------------------------------------------------------------
>
> This at least needs some clarification, if I'm interpreting correctly the
> implementation of Overlapping looks incorrect. If the fixup differs
> drastically you might want to update this part of the commit comment: "The
> implementation of these functions are essentially cut-and-paste versions..."
>
Also can you please add tests if we don't have any yet?
Updated•10 years ago
|
Attachment #8763967 -
Flags: review?(erahm) → review+
Updated•10 years ago
|
Attachment #8763968 -
Flags: review?(erahm) → review+
Updated•10 years ago
|
Attachment #8763969 -
Flags: review?(erahm) → review+
Updated•10 years ago
|
Attachment #8763970 -
Flags: review?(erahm) → review+
| Assignee | ||
Comment 25•10 years ago
|
||
(In reply to Eric Rahm [:erahm] from comment #23)
> ::: xpcom/glue/nsTArray.h
> @@ +675,5 @@
> > + ElemType* destElemEnd = destElem + aCount;
> > + ElemType* srcElemEnd = srcElem + aCount;
> > + if (destElem == srcElem) {
> > + return; // In practice, we don't do this.
> > + } else if (srcElemEnd > destElem && srcElemEnd < destElemEnd) {
>
> I don't think this check for overlapping is right. Imagine:
>
> > ARRAY [12345]
> > SRC [2345]
> > DST [1234]
>
> (So shifting the last 4 elements left 1 position)
>
> In this case |srcElemEnd > destElem| == TRUE, |srcElemEnd < destElemEnd| ==
> FALSE, so we'd end up dropping to the else and memcpy'ing an overlapping
> region rather than memmove'ing
>
> In general I don't get why were special casing the right shift case. Can you
> add some comments?
Ah, so this is not at all obvious. What this check is trying to do is figuring out which direction we need to copy (resp. move) elements in. If we are copying such that:
SRC: ..XXXXX...
DST: XXXXX.....
then we can copy starting at the front of each, to the back. If instead, we are copying such that:
SRC: XXXXX....
DST: ..XXXXX..
(i.e. the above check is true) then we need to copy back-to-front; if we were to copy front-to-back, then the third element to be copied would be the first element that we had copied into its new position. MoveNonOverlappingRegion always copies front-to-back; MoveOverlappingRegion needs to check whether it can call MoveNonOverlappingRegion (i.e. copy front-to-back) or needs to do back-to-front copying.
The STL has |copy| and |copy_backward| to address this situation. I agree that it's not at all obvious that calling MoveNonOverlappingRegion here the right thing to do, but I don't know that renaming these to MoveForward and MoveBackward would clarify the situation. (I think MoveNonOverlappingRegion reads better in the code that calls it directly, but I am open to hearing other opinions about that.) Some comments would definitely resolve the "huh?" that this code inspires; I will add those.
> @@ +680,5 @@
> > + while (destElemEnd != destElem) {
> > + --destElemEnd;
> > + --srcElemEnd;
> > + traits::Construct(destElemEnd, mozilla::Move(*srcElemEnd));
> > + traits::Destruct(srcElem);
>
> Should this be |srcElemEnd|?
Uh. Hm. Yeah, that seems like a bug, in this patch and pre-existing code! I wonder if we have any code that performs weirdly because of this...
> @@ +683,5 @@
> > + traits::Construct(destElemEnd, mozilla::Move(*srcElemEnd));
> > + traits::Destruct(srcElem);
> > + }
> > + } else {
> > + MoveNonOverlappingRegion(aDest, aSrc, aCount, aElemSize);
>
> Maybe this was supposed to be |MoveOverlappingRegion|?
We don't want this to be MoveOverlappingRegion, because then we are calling ourself, with no change in the arguments, which cannot be a good thing.
Comment 26•10 years ago
|
||
Comment on attachment 8763975 [details] [diff] [review]
part 10 - copy objects by default in nsTArray
Review of attachment 8763975 [details] [diff] [review]:
-----------------------------------------------------------------
::: xpcom/glue/nsTArray.h
@@ +708,1 @@
> };
Where did these specializations come from? Just stuff you knew about? The follow-up being: are there others?
@@ +721,5 @@
> +
> +template<class E>
> +struct nsTArray_CopyChooser
> +{
> + typedef typename ::detail::CopyChooser<E, std::is_arithmetic<E>::value>::Type Type;
I'm a little confused by the use of |is_arithmetic| here. Is this supposed to deal with POD too (a comment would be useful if so)? Or is that handled elsewhere that's not obvious in this diff?
Attachment #8763975 -
Flags: review?(erahm) → feedback+
Comment 27•10 years ago
|
||
FWIW I think we're going to need some talos runs here. Maybe a rollup w/o a bug number would be okay, there's nothing obviously sec sensitive in the patches themselves.
Comment 28•10 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #25)
> (In reply to Eric Rahm [:erahm] from comment #23)
> > ::: xpcom/glue/nsTArray.h
> > @@ +675,5 @@
> > > + ElemType* destElemEnd = destElem + aCount;
> > > + ElemType* srcElemEnd = srcElem + aCount;
> > > + if (destElem == srcElem) {
> > > + return; // In practice, we don't do this.
> > > + } else if (srcElemEnd > destElem && srcElemEnd < destElemEnd) {
> >
> > I don't think this check for overlapping is right. Imagine:
> >
> > > ARRAY [12345]
> > > SRC [2345]
> > > DST [1234]
> >
> > (So shifting the last 4 elements left 1 position)
> >
> > In this case |srcElemEnd > destElem| == TRUE, |srcElemEnd < destElemEnd| ==
> > FALSE, so we'd end up dropping to the else and memcpy'ing an overlapping
> > region rather than memmove'ing
> >
> > In general I don't get why were special casing the right shift case. Can you
> > add some comments?
>
> Ah, so this is not at all obvious. What this check is trying to do is
> figuring out which direction we need to copy (resp. move) elements in. If
> we are copying such that:
>
> SRC: ..XXXXX...
> DST: XXXXX.....
>
> then we can copy starting at the front of each, to the back. If instead, we
> are copying such that:
>
> SRC: XXXXX....
> DST: ..XXXXX..
>
> (i.e. the above check is true) then we need to copy back-to-front; if we
> were to copy front-to-back, then the third element to be copied would be the
> first element that we had copied into its new position.
> MoveNonOverlappingRegion always copies front-to-back; MoveOverlappingRegion
> needs to check whether it can call MoveNonOverlappingRegion (i.e. copy
> front-to-back) or needs to do back-to-front copying.
>
> The STL has |copy| and |copy_backward| to address this situation. I agree
> that it's not at all obvious that calling MoveNonOverlappingRegion here the
> right thing to do, but I don't know that renaming these to MoveForward and
> MoveBackward would clarify the situation. (I think MoveNonOverlappingRegion
> reads better in the code that calls it directly, but I am open to hearing
> other opinions about that.) Some comments would definitely resolve the
> "huh?" that this code inspires; I will add those.
Considering this is all internal I'm fine with just adding comments about the directionality (and why calling NonOverlapped is a-okay here).
> > @@ +683,5 @@
> > > + traits::Construct(destElemEnd, mozilla::Move(*srcElemEnd));
> > > + traits::Destruct(srcElem);
> > > + }
> > > + } else {
> > > + MoveNonOverlappingRegion(aDest, aSrc, aCount, aElemSize);
> >
> > Maybe this was supposed to be |MoveOverlappingRegion|?
>
> We don't want this to be MoveOverlappingRegion, because then we are calling
> ourself, with no change in the arguments, which cannot be a good thing.
Ah right I was looking at the implementation above in the patch (the memmove version) rather than below.
| Assignee | ||
Comment 29•10 years ago
|
||
OK, testing shows that while these patches definitely compile, there's a ton of classes where the automatically generated move constructor is completely bogus. So a bit more thought will be required here...I really don't want to go around defining specializations for every. single. class.
| Reporter | ||
Comment 30•10 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #29)
> OK, testing shows that while these patches definitely compile, there's a ton
> of classes where the automatically generated move constructor is completely
> bogus.
Doesn't that mean that the existing code, which memcpys objects of those types, also causes problems?
| Assignee | ||
Comment 31•10 years ago
|
||
(In reply to q1 from comment #30)
> (In reply to Nathan Froyd [:froydnj] from comment #29)
> > OK, testing shows that while these patches definitely compile, there's a ton
> > of classes where the automatically generated move constructor is completely
> > bogus.
>
> Doesn't that mean that the existing code, which memcpys objects of those
> types, also causes problems?
No. Well, at least not necessarily. Consider nsHtml5TreeOperation, where this problem initially manifests (or at least where running the browser first crashes):
http://dxr.mozilla.org/mozilla-central/source/parser/html/nsHtml5TreeOperation.h#89
We have a union of various flavors of pointers and an enum to discriminate between them. When arrays of this object are memcpy'd, pointers get copied around, but object destructors are not called; the memory containing the objects is simply free'd. So using memcpy for this structure (and a number of other structures, I'd imagine) works just fine.
However, if you're going to use actual constructors, the compiler silently generates a move constructor for the object which does essentially the same thing. (The silent generation doesn't always happen; it's subject to a number of constraints, but it does happen in this case.) But with actual constructors, we *also* call destructors for objects which we just moved around, which frees whatever those pointers might have been pointing at. And that is a recipe for problems.
We have roughly 700 different classes which would need move constructors defined for them or template specializations to use memcpy added.
Comment 32•10 years ago
|
||
So would it make sense to add a specialization for JS::ObjectPtr and move on with life?
| Assignee | ||
Comment 33•10 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #31)
> However, if you're going to use actual constructors, the compiler silently
> generates a move constructor for the object which does essentially the same
> thing.
I misspoke here (credit to Eric for pointing this out): the compiler silently generates a *copy* constructor for this class, which it then proceeds to misuse in the same fashion.
Cleaning up implicitly-declared copy constructors would be nice, but that'd be a project for a separate bug.
Comment 34•10 years ago
|
||
(In reply to Eric Rahm [:erahm] from comment #32)
> So would it make sense to add a specialization for JS::ObjectPtr and move on
> with life?
Sorry if I wasn't clear, I think these changes are valuable (up to patch 9), but we should move them to a follow-up in a public bug and just add the template specialization here as a much simpler fix for the sec issue.
| Reporter | ||
Comment 35•10 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #33)
> (In reply to Nathan Froyd [:froydnj] from comment #31)
> > However, if you're going to use actual constructors, the compiler silently
> > generates a move constructor for the object which does essentially the same
> > thing.
>
> I misspoke here (credit to Eric for pointing this out): the compiler
> silently generates a *copy* constructor for this class, which it then
> proceeds to misuse in the same fashion.
Ah, yes, that can happen, per C++11 s.12.8(8), though that section says "Such an implicit declaration is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor". Really the compiler should throw an error in that case, since objects of classes with user-defined copy-assignment operators or user-defined destructors are very likely unsafe if copied in member-by-member fashion.
| Assignee | ||
Comment 36•10 years ago
|
||
The backwards copying case in MoveOverlappingRegion had a bug: rather
than destroying each element from the source range as we moved it, we
would always destroy the element at the beginning of the source range.
Fortunately, none of the existing types that were copied via
constructors seem to trigger the problematic code.
Attachment #8764660 -
Flags: review?(erahm)
| Assignee | ||
Comment 37•10 years ago
|
||
So, parts 0-7a are all independent of the issue here, and I was considering committing them separately as bug 1271751. What's not clear to me is whether moving patches out of a security bug to commit someplace else is OK.
I do not believe that parts 0-7 have any security implications; they are straightforward refactorings of what we already do. Part 7a *might* have some security implications, but I went over all the places I could see where we used nsTArray with types that use constructors, and none of them would trigger the problematic code.
What's the path forward here? Should I commit them as a part of this bug or split them out into a separate bug?
Flags: needinfo?(abillings)
| Assignee | ||
Comment 38•10 years ago
|
||
Comment on attachment 8763966 [details] [diff] [review]
part 3 - add Move{Non,}OverlappingRegion
Review of attachment 8763966 [details] [diff] [review]:
-----------------------------------------------------------------
Re-asking for review here, since I think the just-posted part 7a patch covers Eric's concerns here.
Attachment #8763966 -
Flags: review- → review?(erahm)
Comment 39•10 years ago
|
||
Comment on attachment 8764660 [details] [diff] [review]
part 7a - fix bug in nsTArray_CopyWithConstructors
Review of attachment 8764660 [details] [diff] [review]:
-----------------------------------------------------------------
This looks good, I'd just like to see the test expanded a bit.
::: xpcom/glue/nsTArray.h
@@ +634,5 @@
> + // front-to-back. MoveNonOverlappingRegion assumes that moving
> + // front-to-back is always valid. So they're really more like
> + // std::move{_backward,} in that respect. We keep these names because
> + // we think they read slightly better, and MoveNonOverlappingRegion is
> + // only ever called on overlapping regions from MoveOverlappingRegion.
Thank you for the thorough comment.
::: xpcom/tests/gtest/TestTArray.cpp
@@ +125,5 @@
> + // ..XXXXX..
> + //
> + // such that it overlaps the destination region:
> + //
> + // ....XXXXX
While we're in here can you add a test for left shifting? So a |RemoveElementAt(0)| or something like that.
@@ +142,5 @@
> + array.InsertElementsAt(0, rangeLength);
> +
> + // We expect *2* destructions: one for the resize (and copying the old
> + // objects into newly-allocated memory) required by InsertElementsAt,
> + // the other for shifting the data around.
1) Lets do this without a resize. Can you just reserve enough space at the beginning? Hopefully at some point we'll improve on that behavior.
2) We inserted 16 elements but are only checking 8 of them. Lets check them all.
3) I'd like to make sure other elements don't get destructed. So maybe insert at 1, make sure idx 0 has 0 destructions.
Attachment #8764660 -
Flags: review?(erahm) → feedback+
Comment 40•10 years ago
|
||
Comment on attachment 8763966 [details] [diff] [review]
part 3 - add Move{Non,}OverlappingRegion
Review of attachment 8763966 [details] [diff] [review]:
-----------------------------------------------------------------
Yes, 7a is sufficient. Thanks!
Attachment #8763966 -
Flags: review?(erahm) → review+
| Assignee | ||
Comment 41•10 years ago
|
||
I think this is sort of the test you're asking for. Doing the test for forward
copying with Copyable is a bit boring, as every element ends up destructed, so
I changed things up a bit.
I didn't see a good way to assert that the inserted elements weren't destroyed
that that wasn't trivially true. I guess you could insert them one at a time?
That would cause havoc with the other numbers, though...
Attachment #8764727 -
Flags: review?(erahm)
| Assignee | ||
Updated•10 years ago
|
Attachment #8764660 -
Attachment is obsolete: true
Comment 42•10 years ago
|
||
Comment on attachment 8764727 [details] [diff] [review]
part 7a - fix bug in nsTArray_CopyWithConstructors
Review of attachment 8764727 [details] [diff] [review]:
-----------------------------------------------------------------
Thanks for expanding the tests.
Attachment #8764727 -
Flags: review?(erahm) → review+
Updated•10 years ago
|
Flags: needinfo?(abillings) → needinfo?(dveditz)
| Assignee | ||
Comment 43•10 years ago
|
||
Comment on attachment 8763974 [details] [diff] [review]
part 9 - specialize nsTArray for bindings unions and dictionaries
Removing review, since we're not looking to commit this part currently, and we might as well enable memory operations for *all* binding unions and dictionaries while we're at it.
Attachment #8763974 -
Flags: review?(peterv)
Comment 44•10 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #43)
> Removing review, since we're not looking to commit this part currently, and
> we might as well enable memory operations for *all* binding unions and
> dictionaries while we're at it.
Hmm, ok. I had just one comment, which was to store directly into the nsTArrayCopiers in the loop over dependencySortObjects(...), instead of using the temporary cgdictionaries/unions lists.
Comment 45•10 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #37)
> So, parts 0-7a are all independent of the issue here, and I was considering
> committing them separately as bug 1271751. [...]
>
> What's the path forward here? Should I commit them as a part of this bug or
> split them out into a separate bug?
Can you bundle up those parts, stick them in bug 1271751 and carry over erahm's r+? It's fine to add a comment over there referencing this bug (e.g. "carrying over erahm's r+ from bug 1199740"). As long as you've got that other bug that'd be a clearer way forward -- especially since tagging them with this bug will somewhat confuse what those patches are doing since you say they're independent to the security issue.
Flags: needinfo?(dveditz)
Comment 46•9 years ago
|
||
What's going on with this bug, Nathan? Did all of it get landed in bug 1271751, so we can close the bug?
Flags: needinfo?(nfroyd)
| Assignee | ||
Comment 47•9 years ago
|
||
(In reply to Andrew McCreight [:mccr8] from comment #46)
> What's going on with this bug, Nathan? Did all of it get landed in bug
> 1271751, so we can close the bug?
All of it didn't get landed, parts 8 and onward are still reasonable things to try and fix.
However, they also require a bunch of work to actually make the browser runnable. But without all of that work, we haven't really closed the original hole. So...leave the bug open, I guess?
Flags: needinfo?(nfroyd)
Comment 48•8 years ago
|
||
It seems like dom.compartment_per_addon has gone away, and I can't find any references to things like mAddonScopes. Is all this gone, and we can close this?
Flags: needinfo?(nfroyd)
| Assignee | ||
Comment 49•8 years ago
|
||
We could close this, as the immediate problem has gone away. Or we could repurpose it to making nsTArray work more like std::vector, since that was really the underlying bug.
My vote is clone this bug to a new security bug for the nsTArray issue, and close this one. WDYT?
Flags: needinfo?(nfroyd)
Updated•8 years ago
|
Flags: needinfo?(nfroyd)
| Reporter | ||
Comment 50•8 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #49)
> We could close this, as the immediate problem has gone away. Or we could
> repurpose it to making nsTArray work more like std::vector, since that was
> really the underlying bug.
>
> My vote is clone this bug to a new security bug for the nsTArray issue, and
> close this one. WDYT?
Please CC me on the new bug. Thanks!
| Assignee | ||
Comment 51•8 years ago
|
||
Created bug 1447047 as a clone of this bug for tracking nsTArray issues.
Status: NEW → RESOLVED
Closed: 8 years ago
Flags: needinfo?(nfroyd)
Resolution: --- → WORKSFORME
Updated•6 years ago
|
Group: dom-core-security
Updated•2 years ago
|
Keywords: reporter-external
You need to log in
before you can comment on or make changes to this bug.
Description
•