-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ThreadSanitizer crashes on indirect use of stack-referenced SystemRandomNumberGenerator #66099
Comments
Apple folk, this is tracked as rdar://109594242 and seems to reproduce on Apple Silicon only on both macOS & Linux. Thanks very much for to Vapor's websocket-kit and @gwynne for reporting and reducing this bug so much, even contributing a new SwiftNIO patch which runs into this. Fab work! |
This is still happening in the latest 5.9.1 (most recently encountered via https://github.com/apple/swift-nio/blob/main/Sources/NIOWebSocket/NIOWebSocketClientUpgrader.swift#L157-L160) |
I tinkered with NIOWebSocketClientUpgrader. randomRequestKey() a little, and found out that:
|
Additional information: The crash no longer seems to occur on macOS. Environment is macOS 14.1.1 (23B81), Xcode 15.0.1 (15A507), Swift The crash also no longer appears on Linux under standard
Notably, the error on the Intel image (with Rosetta emulation enabled) is different; rather than crashing with a segfault mid-test, ThreadSanitizer immediately fails with the message Edit: Perhaps unsurprisingly, the address range in question appears to be allocated to Docker's revised Rosetta support; this entry appears in the
Environment: Docker Desktop for Mac, version 4.25.1 (128006), Linux kernel |
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):
git clone https://github.com/apple/swift-nio.git && cd swift-nio
swift test --sanitize=thread --filter=testRandomMaskingKeyIsNotAlwaysZeroWithDefaultGenerator
Expected behavior
The tests pass.
Environment
Failure observed against:
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 versionswift-5.8-RELEASE
swiftlang/swift:nightly-5.9-jammy
Docker image, Swift versionswift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-22-a
swiftlang/swift:nightly-main-jammy
Docker image, Swift versionswift-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
The text was updated successfully, but these errors were encountered: