Skip to content

GC related safety and soundness issues #569

Open
@gmorenz

Description

@gmorenz

While working on #520 other soundness and safety issues came up, this is something of an omnibus issue regarding them.

By "handle like types" I mean RootedGuard, RootedVec, MutableHandle, and JS::MutableHandle, as well as potentially RootedTraceableBox, and CustomAutoRooter.

Soundness - correct use of the public API results in undefined behavior

  • Traceable modifies values behind a &T reference (Traceable is unsound #560).
  • RootedGuard stores a &mut reference to data the GC looks at and modifies over GC pauses (RootedGuard<T> construction related unsoundness #564).
  • MutableHandle is constructed via a &mut reference, which will be invalidated by GC (Remove DerefMut impl for RootedGuard #572).
  • Handle stores an & reference to data (not wrapped in a Cell type) that the GC modifies over GC pauses.
  • The Deref implementations for handle like types allow for safe code to hold an & reference to data (not wrapped in a Cell type) that the GC will modify at over GC pauses. (Arguably a safety issue not a soundness issue, but I think we'll end up allowing borrowing over GC pauses).
    • Some of this data is modified via Traceable.
    • Some of this data is modified directly in Rooted via RootKind.
  • (TODO: Verify) ForOfIteratorGuard::new is suspicious, it likely has issues similar to those described in RootedGuard<T> construction related unsoundness #564.

Safety - it's possible to use this improperly in safe code

Assumptions in comments on public APIs

  • The comment added in Remove DerefMut impl for RootedGuard #572 on the as_ptr method assumes that the GC will only read - i.e. writes will occur through interior mutability. If that ends up not being the case, the comment should be updated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions