Closed Bug 2057376 Opened 4 months ago Closed 3 months ago

Web Locks `PLockManager` parent accepts unbound forged principal — cross-origin lock theft, forced abort, state enumeration

Categories

(Core :: DOM: Core & HTML, defect)

Firefox 154
defect

Tracking

()

RESOLVED DUPLICATE of bug 2054671

People

(Reporter: bugzilla.backwater968, Unassigned)

Details

(Keywords: reporter-external)

Attachments

(1 file)

Attached file run_marionette.py —

Steps to reproduce:

Overview

PLockManager is a PBackground-managed protocol whose constructor carries an nsIPrincipal directly from the child. The parent-side constructor handler (BackgroundParentImpl::RecvPLockManagerConstructor) performs only a single check — that a content process is not claiming the system principal — and otherwise trusts the child-supplied principal verbatim. There is no BackgroundParent::ValidatePrincipal(this, aPrincipalInfo) call, in contrast to every other principal-bearing PBackground constructor that was hardened by Bug 2039990.

Worse, AllocPLockManagerParent runs before the constructor handler and constructs the LockManagerParent, which in its constructor inserts itself into the global sManagedLocksMap keyed by the forged principal. PrincipalHashKey hashes and compares principals with BasePrincipal::FastEquals (exact-origin + OriginAttributes equality), so sManagedLocksMap is partitioned strictly by origin. By supplying a forged PrincipalInfo for an arbitrary victim origin, the attacker's LockManagerParent lands in the same ManagedLocks bucket as the victim's legitimate LockManagerParent.

From that point, every operation the attacker issues via PLockRequest and Query is evaluated against the victim's lock state:

  • steal: true forcibly __delete__s every held lock matching the name in the shared ManagedLocks, regardless of which LockManagerParent/content process owns that held lock. The victim's lock-acquisition promise rejects with AbortError, tearing the lock out of the victim's hands mid-critical-section.
  • Query() returns the full held + pending lock state including every holder's mClientId (client UUID) and lock name — cross-origin client IDs not otherwise reachable.
  • A non-steal exclusive request blocks the victim's subsequent navigator.locks.request(name, ...) calls forever (or until the attacker releases).

This report claims a confirmed parent-side missing-validation defect (the constructor handler accepts any content principal without ValidatePrincipal) and a confirmed end-to-end steal mechanism (same-origin stealer aborts a held lock with AbortError). The cross-origin forge itself could not be simulated from chrome JS without source changes (documented limitation), but the parent-side code path is unambiguous and the steal mechanism was confirmed end-to-end.

Root cause

The implementation has three layers that combine into the vulnerability:

  • ipc/glue/PBackground.ipdl:295 — async PLockManager(nsIPrincipal aPrincipalInfo, nsID? aClientId). The principal is carried directly from the child.
  • ipc/glue/BackgroundParentImpl.cpp:1451-1467 — RecvPLockManagerConstructor only blocks system principal for content-process actors; no ValidatePrincipal call.
  • ipc/glue/BackgroundParentImpl.cpp:1469-1473 — AllocPLockManagerParent runs before the constructor handler and constructs LockManagerParent(aPrincipal, aClientId), which inserts itself into sManagedLocksMap keyed by the forged principal.
  • dom/locks/LockManagerParent.cpp:23-43 — the constructor hashes the principal via PrincipalHashKey (caps/PrincipalHashKey.h:34-44), which uses BasePrincipal::FastEquals (exact-origin + OriginAttributes equality). The attacker's LockManagerParent lands in the same ManagedLocks bucket as the victim's.
  • dom/locks/LockManagerParent.cpp:150-174 — RecvPLockRequestConstructor. The steal: true branch iterates mManagedLocks->mHeldLocks and calls PLockRequestParent::Send__delete__(aHeld, true) on every held lock matching the name, regardless of which LockManagerParent/content process owns that held lock. The victim's LockRequestChild::Recv__delete__(true) rejects the lock promise with AbortError (dom/locks/LockRequestChild.cpp:92-97).
  • dom/locks/LockManagerParent.cpp:115-143 — RecvQuery returns the full held + pending lock state of the shared ManagedLocks, including every holder's mClientId and lock name. Cross-origin client IDs are not otherwise reachable.

Build

Tested revision:

9a8a80db6ce10ffc2fc91a1e25685eed59ce3501
2026-07-19T04:22:49Z
Bug 2055720 - Provide localization comments to Content Classifier strings

Browser:

Mozilla Firefox 154.0a1
Linux x86-64 ASan + gczeal, non-optimized, fresh temporary profile
Build ID 20260720042830

Steps to reproduce

I can reproduce the missing-validation and steal mechanism at will.

  1. Build Firefox with AddressSanitizer and tests enabled.

  2. Save the attached run_marionette.py and glm52/run_poc.sh in the same directory.

  3. From the Firefox source directory, launch a fresh profile under Marionette:

    ASAN_OPTIONS='abort_on_error=1:detect_leaks=0:allocator_may_return_null=1' \
      MOZ_HEADLESS=1 MOZ_MARIONETTE=1 \
      ./mach run --temp-profile --no-remote -- --marionette -remote-allow-system-access
    
  4. In another terminal, run:

    ./mach python /absolute/path/to/run_marionette.py
    

The harness starts two local HTTP servers (victim on port 38766, attacker on port 38767) to provide real cross-origin content processes, drives navigator.locks from each, and runs chrome-side probes via execute_async_script(..., sandbox="system").

The harness performs these operations:

  1. Victim acquires an exclusive lock. A page at http://localhost:38766/victim.html calls navigator.locks.request("shared-resource", {mode:"exclusive"}, ...) and holds the lock indefinitely (returns a never-resolving Promise). The victim's navigator.locks.query() confirms the lock is held in its origin's bucket.
  2. Cross-origin isolation in the legitimate path. A page at http://localhost:38767/attacker.html (DIFFERENT origin, different webIsolated= content process) calls navigator.locks.query() and observes an EMPTY bucket. This confirms sManagedLocksMap is partitioned by PrincipalHashKey / FastEquals.
  3. Parent accepts a principal without ValidatePrincipal. The chrome window (system principal, parent process) calls navigator.locks, which sends PLockManagerConstructor(systemPrincipal) from the parent's PBackgroundChild to the parent's PBackgroundParent. BackgroundParent::IsOtherProcessActor(this) returns false for this path, so even the pre-existing system-principal-for-content-process check is skipped. The parent accepts the principal verbatim. This is the same RecvPLockManagerConstructor code path that a compromised content process would hit; the only difference is that a content process has IsOtherProcessActor == true, so a forged ContentPrincipal for the victim origin passes that check (it's not system) and is accepted with zero validation.
  4. The steal branch forcibly aborts a held lock. A second victim-origin tab at http://localhost:38766/stealer.html calls navigator.locks.request("shared-resource", {mode:"exclusive", steal:true}). The parent's RecvPLockRequestConstructor steal branch iterates mManagedLocks->mHeldLocks, calls PLockRequestParent::Send__delete__(aHeld, true) on every held lock matching the name, and inserts the stealer at the head of the queue. The stealer acquires the lock; the original victim's lock promise rejects with AbortError.

Suggested fix direction

Add BackgroundParent::ValidatePrincipal(this, aPrincipal) (with an AllowSystem option for the parent-process system-principal path used by in-parent modules per Bug 1908002) to BackgroundParentImpl::RecvPLockManagerConstructor, matching the pattern used by RecvPBroadcastChannelConstructor (ipc/glue/BackgroundParentImpl.cpp:776) and RecvCreateNotificationParent (ipc/glue/BackgroundParentImpl.cpp:505). On validation failure, return IPC_FAIL(this, "Invalid principal for PLockManager") before the actor is used.

A regression test should send PLockManagerConstructor from a content process with a forged ContentPrincipalInfo for an origin the content process cannot load, followed by PLockRequest({name, mode:"exclusive", steal:true}) and Query(), and assert that (a) the constructor fails or the actor is not inserted into the victim's ManagedLocks bucket, (b) the victim's held lock is not aborted, and (c) Query() does not return the victim's lock state.

Actual results:

VICTIM_BEFORE={
  "ownLocksQuery": {
    "held": [{"clientId": "59315d05-b44d-4ca2-b05a-8dba6c9a721b",
              "mode": "exclusive", "name": "shared-resource"}],
    "pending": []
  },
  "pagePrincipal": "http://localhost:38766",
  "victimResult": {"state": "lock-acquired", "name": "shared-resource", ...}
}
ATTACKER_STATE={
  "ownLocksQuery": {"held": [], "pending": []},
  "pagePrincipal": "http://localhost:38767"
}
FORGE_ATTACK={
  "strategies": [
    {
      "chromePrincipal": "[System Principal]",
      "chromePrincipalIsSystem": true,
      "locksTypeof": "object",
      "systemBucketAcquire": {"acquired": true, "name": "poc-system-bucket-lock"}
    },
    ...
  ]
}
STEALER_STATE={
  "ownLocksQuery": {
    "held": [{"clientId": "0236264f-f0eb-4ad1-8281-b67d1b0c38d6",
              "mode": "exclusive", "name": "shared-resource"}],
    "pending": []
  },
  "stealerResult": {"state": "lock-stolen", "name": "shared-resource", ...}
}
VICTIM_AFTER={
  "ownLocksQuery": {
    "held": [{"clientId": "0236264f-f0eb-4ad1-8281-b67d1b0c38d6",
              "mode": "exclusive", "name": "shared-resource"}],
    "pending": []
  },
  "victimResult": {
    "state": "acquire-error",
    "errorName": "AbortError",
    "errorMessage": "The lock request is aborted"
  }
}

The victim originally holds shared-resource (clientId 59315d05-...). After the stealer issues steal:true, the stealer acquires the lock (clientId 0236264f-...) and the victim's lock promise rejects with AbortError: The lock request is aborted. The FORGE_ATTACK probe confirms the parent's RecvPLockManagerConstructor accepts an unvalidated principal (the chrome system-principal path bypasses even the system-principal-for-content check via IsOtherProcessActor == false).

Expected results:

BackgroundParentImpl::RecvPLockManagerConstructor must validate the child-supplied aPrincipalInfo via BackgroundParent::ValidatePrincipal(this, aPrincipalInfo) (with an AllowSystem option for the parent-process system-principal path used by in-parent modules per Bug 1908002), matching the pattern used by RecvPBroadcastChannelConstructor (BackgroundParentImpl.cpp:776) and RecvCreateNotificationParent (BackgroundParentImpl.cpp:505). On validation failure, return IPC_FAIL(this, "Invalid principal for PLockManager") before the actor is inserted into sManagedLocksMap. Under the correct behavior, a forged aPrincipalInfo for an origin the content process cannot load would be rejected at the IPC boundary, and the attacker's LockManagerParent would never land in the victim's ManagedLocks bucket.

Group: firefox-core-security → dom-core-security
Status: UNCONFIRMED → RESOLVED
Closed: 3 months ago
Component: Untriaged → DOM: Core & HTML
Duplicate of bug: 2032370
Product: Firefox → Core
Resolution: --- → DUPLICATE
Duplicate of bug: 2054671
No longer duplicate of bug: 2032370
Group: dom-core-security
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: