Repository navigation
mux: Fix OOM crash on UDP keep frames - #5902
Closed
herenickname wants to merge 1 commit into
Closed
herenickname wants to merge 1 commit into
herenickname wants to merge 1 commit into
Conversation
FrameMetadata.WriteTo dereferences b.UDP.Address (a non-atomic two-word
interface) on the UDP keep-frame path while the upstream UDP reader is
free to mutate the same *net.Destination for its next packet. The
resulting torn read produces a DomainAddress whose backing string header
has a garbage (ptr, len) pair.
isDomainTooLong used a signed `len(domain) > 256` comparison, so a
negative torn length slipped through and reached
runtime.stringtoslicebyte with a uint length of ~9 EB, aborting the
process with "fatal error: out of memory".
The error from WriteAddressPort on this branch was also discarded, so
even the existing guard would have produced a malformed frame instead
of a clean failure.
Fix both:
* common/protocol/headers.go: switch to `uint(len(domain)) > 255` so
any negative or absurd length is rejected, and tighten the bound to
the actual one-byte wire-format limit.
* common/mux/frame.go: snapshot *b.UDP into a local before writing
the address bytes (closes the window between the network-type byte
and the address bytes), and actually return WriteAddressPort's
error instead of dropping it.
Refs #5901
Member
|
除了你手动使用unsafe构造的非法数据并触发panic 我没在核心发现任何有尝试在赋值后修改UDP携带数据的位置 b.UDP 应该是一个不变量 如果你发现有对其的覆盖操作应该修复这点 至少我翻了一下核心没有发现 如果你发现可以指出 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5901.
FrameMetadata.WriteToon the UDP keep-frame path dereferencesb.UDP.Address(a non-atomic two-word interface) while the upstream UDP reader is free to mutate the same*net.Destinationfor its next packet. The resulting torn read can produce aDomainAddresswhose backing string header has a garbage(ptr, len)pair.isDomainTooLongthen fails to catch it because it uses a signedlen(domain) > 256comparison: a negative torn length is< 256, slips through, and reachesruntime.stringtoslicebytewith auintlength of ~9 EB, aborting the process withfatal error: out of memory.The error from
WriteAddressPorton this branch was also discarded, so even the existing guard would have produced a malformed frame instead of a clean failure.This PR fixes both halves:
common/protocol/headers.go— switch touint(len(domain)) > 255so any negative or absurd length is rejected, and tighten the bound to the actual one-byte wire-format limit.common/mux/frame.go— snapshot*b.UDPinto a local before writing the address bytes (closes the window between the network-type byte and the address bytes), and actually returnWriteAddressPort's error instead of dropping it.Full root-cause writeup, production stack trace, and a deterministic standalone reproducer are in #5901. With this PR applied the reproducer cleanly returns
Super long domain is not supported: ...instead of crashing.Note on the underlying race
This patch stops the crash and stops the malformed frame, but it does not fix the root of the data race — a producer that keeps mutating a
*net.Destinationafter handing the pointer to a buffer is fundamentally unsafe, and the proper long-term fix is to make UDP producers either allocate a freshDestinationper packet or store it by value onbuf.Buffer. I haven't tracked down the specific producer that triggers it; happy to follow up in a separate PR if you'd like.