nstun: fail closed on invalid policy rule fields#289
Open
carrerasdarren-cell wants to merge 1 commit into
Open
nstun: fail closed on invalid policy rule fields#289carrerasdarren-cell wants to merge 1 commit into
carrerasdarren-cell wants to merge 1 commit into
Conversation
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
uint16_tSecurity rationale
nstun_init_parent()previously logged malformed policy fields but continued with a zero-initialized rule. ForHOST_TO_GUESTredirects, an invalidsrc_iptherefore becameINADDR_ANYwhen the host listener was bound. For guest-to-host policy, an invalid selector on anALLOWrule became a wildcard match, potentially bypassing a later deny rule.Port fields are
uint32in the protobuf butuint16_tinternally. Values such as65536silently became zero, which is the internal wildcard sentinel, while other values could select a different host port. Prefix lengths were not range-checked, and the IPv4 mask expression could shift by an invalid count.Local proof
With stock master and a local
HOST_TO_GUESTrule containingsrc_ip: "127.0.0.999"anddport: 18080:/proc/net/tcpshowed00000000:46A0, a listener on0.0.0.0:18080With this patch, the same config aborts before command execution and leaves no listener. The proof used only disposable local containers and no external network service.
Validation
-Werrorflagsmake nstun_policy_teston both architecturesclang-format --dry-run --Werrorgit diff --check