Closed Bug 1243463 Opened 8 years ago Closed 2 years ago

Make nsTArrayHeader::sEmptyHdr const

Categories

(Core :: XPCOM, defect)

42 Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
82 Branch
Tracking Status
firefox-esr68 --- wontfix
firefox-esr78 --- wontfix
firefox80 --- wontfix
firefox81 --- wontfix
firefox82 --- fixed

People

(Reporter: q1, Assigned: froydnj)

References

Details

(Keywords: sec-want, Whiteboard: [post-critsmash-triage][adv-main82-])

Attachments

(3 files)

If a bug lets an attacker cause FF to write beyond the end of an empty nsTArray, she can overwrite static variables inside xul.dll. This is very dangerous, because the exact identity and order of those variables is fixed by the build, and is thus known to the attacker.

Putting nsTArrayHeader::sEmptyHdr into readonly memory would much reduce the risk posed by this kind of bug.

I raised this issue in https://bugzilla.mozilla.org/show_bug.cgi?id=1232069#c2 (a bug that allows exactly this kind of write-beyond-end), but think that it deserves its own bug.  Andrew McCreight also raised a related issue in https://bugzilla.mozilla.org/show_bug.cgi?id=1240838 .

I marked this bug as closed because it might suggest targets to attackers.
Some amount of memory (perhaps a few pages?) following &nsTArrayHeader::sEmptyHdr should also be readonly, because an empty nsTArray indexes the byte just following nsTArrayHeader::sEmptyHdr.
Keywords: sec-want
Group: core-security → dom-core-security
Do we need this now that we bounds-check array accesses?
(In reply to Nathan Froyd [:froydnj] from comment #2)
> Do we need this now that we bounds-check array accesses?

That doesn't help if a caller uses nsTArray::Elements() to get a pointer to the first element, then overruns the array.
(In reply to Nathan Froyd [:froydnj] from comment #2)
> Do we need this now that we bounds-check array accesses?

Ack! What I mean is that the bounds-check doesn't help if a caller uses nsTArray::Elements() to get a pointer to the first element, then overruns the array.

We fixed what I think is the lone instance of writing into the (empty)
header in SetLength because it was causing TSan violations, so we should
be clear to make this const. This change is not terribly effective on its
own (cf. the const_cast required to make this work at all), but in the
next patch, we can rig up sEmptyTArrayHeader to be surrounded with "guard
pages" and make rogue accesses off the array header a little more protected.

Assignee: nobody → nfroyd
Status: NEW → ASSIGNED

Bug 1240838 is related.

See Also: → 1240838
Group: dom-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 82 Branch
Flags: qe-verify-
Whiteboard: [post-critsmash-triage]
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Flags: needinfo?(tom)
Flags: needinfo?(tom)
Whiteboard: [post-critsmash-triage] → [post-critsmash-triage][adv-main82-]
Flags: needinfo?(tom)
Flags: needinfo?(tom)

The bug assignee didn't login in Bugzilla in the last 7 months.
:nika, could you have a look please?
For more information, please visit auto_nag documentation.

Assignee: froydnj+bz → nobody
Flags: needinfo?(nika)

Tom, why did you reopen this issue? If there's some remaining hardening that could be done here, perhaps you could file a new bug for it? Thanks.

Status: REOPENED → RESOLVED
Closed: 4 years ago2 years ago
Flags: needinfo?(nika) → needinfo?(tom)
Resolution: --- → FIXED
Assignee: nobody → froydnj+bz

We did not resolve this issue fully - we made the object const, but not read-only. I will open a new bug for that task.

Flags: needinfo?(tom)
Summary: Make nsTArrayHeader::sEmptyHdr readonly → Make nsTArrayHeader::sEmptyHdr const
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: