Skip to content

internal/poll: move rsan to heap on windows#159

Merged
nickkhyl merged 1 commit intotailscale.go1.26from
nickkhyl/fix-wsa-stack-corruption
Mar 9, 2026
Merged

internal/poll: move rsan to heap on windows#159
nickkhyl merged 1 commit intotailscale.go1.26from
nickkhyl/fix-wsa-stack-corruption

Conversation

@nickkhyl
Copy link
Member

@nickkhyl nickkhyl commented Mar 9, 2026

According to https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsarecvfrom, the memory pointed to by lpFromlen must remain available during the overlapped I/O, and therefore cannot be allocated on the stack.

CL 685417 moved the rsan field out of the operation struct and placed it on stack, which violates the above requirement and causes stack corruption.

Unfortunately, it is no longer possible to cleanly revert CL 685417. Instead of attempting to revert it, this CL bundles rsan together with rsa in the same sync.Pool. The new wsaRsa struct is still in the same size class, so no additional overhead is introduced by this change.

Updates golang#77975
Updates tailscale/tailscale#18884
Updates #158

Cherry-picked from https://go-review.googlesource.com/c/go/+/753040 v4

Reviewed-on: https://go-review.googlesource.com/c/go/+/753040
Reviewed-by: Quim Muntal quimmuntal@gmail.com
Reviewed-by: Damien Neil dneil@google.com

Change-Id: I5ffbccb332515116ddc03fb7c40ffc9293cad2ab

@nickkhyl nickkhyl requested a review from bradfitz March 9, 2026 17:42
According to https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsarecvfrom,
the memory pointed to by lpFromlen must remain available during the
overlapped I/O, and therefore cannot be allocated on the stack.

CL 685417 moved the rsan field out of the operation struct and placed
it on stack, which violates the above requirement and causes stack
corruption.

Unfortunately, it is no longer possible to cleanly revert CL 685417.
Instead of attempting to revert it, this CL bundles rsan together
with rsa in the same sync.Pool. The new wsaRsa struct is still in the
same size class, so no additional overhead is introduced by this
change.

Updates golang#77975
Updates tailscale/tailscale#18884
Updates #158

Cherry-picked from https://go-review.googlesource.com/c/go/+/753040 v4

Reviewed-on: https://go-review.googlesource.com/c/go/+/753040
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>

Change-Id: I5ffbccb332515116ddc03fb7c40ffc9293cad2ab
@nickkhyl nickkhyl force-pushed the nickkhyl/fix-wsa-stack-corruption branch from deda68a to 5cce30e Compare March 9, 2026 17:44
@nickkhyl nickkhyl merged commit 5cce30e into tailscale.go1.26 Mar 9, 2026
4 checks passed
@nickkhyl nickkhyl deleted the nickkhyl/fix-wsa-stack-corruption branch March 9, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants