Skip to content

ThreadSanitizer crashes on indirect use of stack-referenced SystemRandomNumberGenerator #66099

Open
@gwynne

Description

@gwynne

Description

When Thread Sanitizer is enabled, an apparent miscompile takes place in NIOWebSocket.WebSocketMaskingKey.random(), causing a write to an invalid address on the second invocation of the method on macOS and on the first invocation thereof on Linux, in all current and development Swift versions (see below for specifics). The issue does not appear when no sanitizer is enabled, nor with --sanitize=address.

Steps to reproduce

This is the most minimal reproducer I could find (simplified post-merge of apple/swift-nio#2433):

  1. git clone https://github.com/apple/swift-nio.git && cd swift-nio
  2. swift test --sanitize=thread --filter=testRandomMaskingKeyIsNotAlwaysZeroWithDefaultGenerator

Expected behavior
The tests pass.

Environment
Failure observed against:

  • macOS 13.4 (22F66), Xcode 14.3 (Build version 14E222b), Swift version swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)\nTarget: arm64-apple-macosx13.0
  • swift:5.8-jammy Docker image, Swift version swift-5.8-RELEASE
  • swiftlang/swift:nightly-5.9-jammy Docker image, Swift version swift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-22-a
  • swiftlang/swift:nightly-main-jammy Docker image, Swift version swift-DEVELOPMENT-SNAPSHOT-2023-05-20-a

Additional Context
Output from the crash in each test environment is attached (note: these were made before the new test was added to NIO and thus refer to the tweaked versions of the existing tests - the logs are otherwise identical using the new tests):
tsan-crash-macos.txt
tsan-crash-swift-5.8-jammy.txt
tsan-crash-swift-nightly-5.9-jammy.txt
tsan-crash-swift-nightly-main-jammy.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSanFor issues in the Thread Sanitizer itselfarm64Architecture: arm64 (aarch64) — any 64-bit ARMbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions