Closed Bug 2028416 Opened 7 months ago Closed 7 months ago

Key color not corectly updated when marking WeakMap symbol keys

Categories

(Core :: JavaScript: GC, defect, P1)

defect

Tracking

()

RESOLVED FIXED
151 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- unaffected
firefox149 --- wontfix
firefox150 --- fixed
firefox151 --- fixed

People

(Reporter: jonco, Assigned: jonco)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: regression, sec-high, Whiteboard: [adv-main150+r])

Attachments

(3 external files)

Claude pointed out that we don't update |keyColor| in WeakMap::markEntry after making a symbol key that is referenced by an uncollected zone. This means that we may not mark the value of a weakmap entry when we should. It doesn't think this is a big deal because it thinks that this will be marked by iterative weak map marking.

However we don't usually do that any more since we use incremental weak map marking, so I think this could be a problem. Having said that, we've had a bunch of bugs in this area and we do have tests that exercise this and those tests pass. So I'm not sure whether this is a real problem or not, but out of caution I'll make this security sensitive. I'll mark it sec-other to start with.

Full Claude output:

  Finding 6: markEntry stale keyColor after symbol key marking                                                           
                                                                                                                           
  File: WeakMap-inl.h:217-230 and 249
                                                                                                                           
  CellColor keyColor = gc::detail::GetEffectiveColor(marker, key.get());  // line 217                                    
  ...                                                                                                                      
  if (keyIsSymbol && keyColor < markColor) {                                                                               
      ...                                                                                                                  
      TraceEdge(trc, &key, "WeakMap symbol key");  // May mark key! (line 228)                                             
      // keyColor is NOT updated here                                                                                      
  }                                                                                                                        
  ...                                                                                                                      
  if (IsMarked(keyColor)) {  // line 249: uses stale keyColor                                                              
                                                                                                                           
  After tracing a symbol key at line 228, the key's color increases, but keyColor is not updated. This means the           
  value-marking check at line 249 uses a stale keyColor. If the key was just marked from White, IsMarked(keyColor) is      
  false, and the value is NOT marked in this iteration.                                                                    
                                                                                                                         
  The comment at line 223 says "There's no need to set |marked| as this would have been marked later anyway" -- the symbol 
  was going to be marked anyway (referenced by an uncollected zone). The value will be marked on a subsequent markEntries
  iteration when the key's new color is observed. So correctness is maintained through the iterative marking loop.         
                                                                                                                         
  Severity: None for correctness; the iterative algorithm handles it. Noting it because the stale variable is subtle and a 
  future refactor could break the invariant.
Attached file (secure) —

This updates the local |keyColor| when marking the symbol key. We check this
below when working out whether to trace the value.

Blocks: sm-security
Severity: -- → S3
Priority: -- → P1
Group: javascript-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
Target Milestone: --- → 151 Branch

Upgrading this to sec-high now Claude found a way to trigger this in bug 2029788. I'll dupe that to this one.

Keywords: sec-other → sec-high
Duplicate of this bug: 2029788
Keywords: regression
Regressed by: 1994871

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: Potential crash or security vulnerability.
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: yes
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: This is a simple fix and has been verified by tests. It's been on central without issues for 4 days.
  • String changes made/needed?: None
  • Is Android affected?: yes
Attachment #9566867 - Flags: approval-mozilla-beta?
Attached file (secure) —

This updates the local |keyColor| when marking the symbol key. We check this
below when working out whether to trace the value.

Original Revision: https://phabricator.services.mozilla.com/D291527

A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)

does this need a delayed sec-approval to uplift now that it is sec-high?

Flags: needinfo?(tom)
Flags: needinfo?(tom)
Attachment #9566867 - Flags: sec-approval+
Attachment #9566867 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
QA Whiteboard: [sec] [uplift] [qa-triage-done-c151/b150]
Whiteboard: [adv-main150+r]
Group: core-security-release
Attachment #9566864 - Attachment description: (secure) → Bug 2028416 - Add testcase r?sfink
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: