udp: release the cloned PacketBuffer in Forwarder.HandlePacket#13242
Open
ibondarenko1 wants to merge 1 commit into
Open
udp: release the cloned PacketBuffer in Forwarder.HandlePacket#13242ibondarenko1 wants to merge 1 commit into
ibondarenko1 wants to merge 1 commit into
Conversation
Forwarder.HandlePacket clones the incoming PacketBuffer into a ForwarderRequest but never releases the clone. Neither the unhandled path nor CreateEndpoint takes ownership of it, so every packet entering the UDP forwarder leaks one PacketBuffer. The TCP forwarder holds its segment with an explicit IncRef and releases it in ForwarderRequest.Complete(), which a client must call because the TCP handshake is asynchronous. The UDP forwarder handler is synchronous (it returns whether the request was handled), so the request never outlives the handler call. Release the clone in HandlePacket once the handler returns.
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.
Problem
udp.Forwarder.HandlePacketclones the incomingPacketBufferinto aForwarderRequest:pkt.Clone()returns a new refcountedPacketBuffer. Nothing releases it:ForwarderRequestis discarded with no release.CreateEndpoint, that passesr.pkttoendpoint.HandlePacket, which reads it and copies the payload into audpPacketwithout taking ownership;CreateEndpointthen returns without releasingr.pkt.So every packet entering the UDP forwarder leaks one
PacketBufferand its buffer chunks.ForwarderRequestexposes no release method.TCP precedent
The TCP forwarder holds its
segmentwith an explicitIncRefand releases it inForwarderRequest.Complete()(pkg/tcpip/transport/tcp/forwarder.go):TCP needs a client-called
Complete()because the TCP handshake is asynchronous. The UDP forwarder handler is synchronous:ForwarderHandlerreturnshandled boolinline, so the request never outlives the handler call. UDP therefore needs noComplete();HandlePacketcan release the clone itself once the handler returns.Change
Hold the
ForwarderRequestin a local anddefer r.pkt.DecRef()before invoking the handler, so the clonedPacketBufferis released on every return path.NewForwarderRequestcallers, which supply their ownpkt, are unaffected.Notes
Same "the handler consumes the request" contract cleanup as #13189 for ICMP echo handlers. Honest scope: this is a netstack
PacketBufferresource leak; the practical effect depends on a deployment that wires a UDP forwarder. A refs-leak-checker build flags the leak on any UDP forwarder test.