Bound SACL/DACL Unmarshal by AclSize to prevent over-reading adjacent components (#78)#86
Merged
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.
Linked Issue
Closes #78Motivation
AccessControlList.Unmarshalis handed the entire remaining buffer of a security descriptor — in a real descriptor the ACL is followed by the Owner and Group SIDs. The ACE loop was bounded only byHeader.AceCount, and eachAccessControlEntry.Unmarshalonly checked its size against that whole tail. A corrupt or oversizedAceCounttherefore walked past the ACL and mis-parsed the following SID bytes as ACEs. Parsing must be confined to the region the header declares viaAclSize.What Changed
DiscretionaryAccessControlList.UnmarshalandSystemAccessControlList.Unmarshalnow compute the ACE region asAclSize - headerSizeand slice the working buffer to exactly that region (aceData) before the loop.AclSizesmaller than the header size, andAclSizeclaiming more bytes than are available, each return a descriptive error.aceData; ifAceCountcannot be satisfied withinAclSize, the per-ACEUnmarshalnow fails and the error is wrapped with the ACE index.Design Notes
For well-formed input
AclSize == headerSize + sum(ACE sizes), so the accumulatedRawBytesSize(and the returned consumed count) is unchanged — the real-dataset involution test confirms byte-for-byte round-trips still hold. The bound only changes behavior for malformed input, turning a silent over-read into an error.Acceptance Criteria Check
TestDACL_Unmarshal_AceCountExceedsAclSize.TestDACL_Unmarshal_TrailingBytesNotConsumed.DEADBEEFnot consumed).go test ./...green, includingTestNtSecurityDescriptor_Involutionover the real Windows/AD datasets.How Verified
acl/DiscretionaryAccessControlList_aclsize_test.go—TestDACL_Unmarshal_TrailingBytesNotConsumed,TestDACL_Unmarshal_AceCountExceedsAclSize.go build ./...andgo test ./...pass.Test Coverage
Scope of Change
acl/DiscretionaryAccessControlList.go,acl/SystemAccessControlList.go,acl/DiscretionaryAccessControlList_aclsize_test.goUnmarshalmay now return an error on malformed input it previously mis-parsed)Risk and Rollout
Low. Well-formed descriptors are unaffected (verified against the dataset involution test); only malformed/oversized ACLs now error instead of silently over-reading. Safe to merge.