netstat: add cycle detection to Next pointer walk#1997
Open
TristanInSec wants to merge 1 commit into
Open
Conversation
The enumerate_structures_by_port method walks a singly-linked list of TCP_LISTENER/UDP_ENDPOINT objects via the Next field without checking for cycles. A memory dump with a self-referential Next pointer causes an infinite loop. Add a seen_addresses set to detect and break cycles, consistent with cycle detection in LIST_ENTRY.to_list, pidhashtable._walk_upid, and pagecache._walk_dentry.
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
The
enumerate_structures_by_portmethod walks a singly-linked list of network objects via theNextfield without checking for cycles. A memory dump containing a self-referentialNextpointer causes the plugin to loop indefinitely.This adds a
seen_addressesset to detect and break cycles, consistent with existing cycle detection patterns in the codebase:LIST_ENTRY.to_list()uses aseensetpidhashtable._walk_upid()usesseen_upidspagecache._walk_dentry()usesseen_dentriesChange
One file, +9 lines. A
seen_addressesset tracks visited pointer values. If a previously seen address is encountered, the walk logs a warning and stops.