Fix: SMB pivot session memory leak causing server OOM kill#340
Open
Cherno-x wants to merge 1 commit into
Open
Conversation
When SMB pivot sessions are active, the server's memory grows unboundedly until the OS kills the process. Root cause is a data starvation-accumulation cycle in extractPivotTasks. - extractPivotTasks: ensure minimum 64KB allocation per pivot child so tasks can be extracted instead of accumulating - Queue: cap capacity at 65536 items, drop oldest/newest when full instead of unbounded resize - TsAgentProcessData: update LastTick for non-async (SMB/TCP) agents so the server can track their liveness - SMB/TCP InternalHandler: add bounds check before slicing decrypted agent info Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
extractPivotTasks: ensure a minimum 64KB allocation per pivot child so SMB agent tasks can be extracted instead of accumulating indefinitelyresize(), preventing memory from growing without limitTsAgentProcessDataso the server can track their liveness and detect stale sessionsInternalHandlerbefore slicing decrypted agent info dataRoot Cause
When a parent HTTP agent checks in,
extractPivotTaskspasseslostSize = availableSize - usedSizeto each SMB child. After packing the parent's own tasks,lostSizeis often too small or near-zero, causingTsAgentGetHostedAllfor the child to return empty. Meanwhile,TsAgentProcessData(triggered byCOMMAND_PIVOT_EXEC) keeps generating new response tasks that get queued into the child'sHostedTasks. These tasks are never extracted and accumulate indefinitely, causing the Queue to grow without bound until the server is OOM-killed.Additionally, non-async agents (SMB/TCP) never get their
LastTickupdated, preventing the server from detecting and cleaning up dead sessions.Testing
Files Changed
core/server/ts_tasks.gocore/utils/safe/queue.gocore/server/ts_agent.goextenders/beacon_listener_smb/pl_main.goextenders/beacon_listener_tcp/pl_main.go🤖 Generated with Claude Code