Repository navigation
Conversation
- In Device, ensure the size returned by DeviceIoControl does not exceed the buffer length and slice only returned bytes. - Factor out parseDevice and validate that the buffer contains at least sizeof(ioctl.Interface) before reading interface headers. - Track buffer offsets when iterating over peers and allowed IPs, ensuring each struct fits within the remaining buffer before casting or dereferencing. - Add unit tests for truncated buffers and valid configurations. Reported-by: BS.ehlas.cz Signed-off-by: Martin Vlach <mr.huge@seznam.cz>
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
This PR adds bounds checking and truncation validation when parsing responses from the Windows WireGuardNT driver IOCTL:
Device, verify that thesizereturned byDeviceIoControldoes not exceed the slice buffer before slicing.parseDeviceto parse the buffer and validate thatlen(buf) >= unsafe.Sizeof(ioctl.Interface{})before reading interface metadata.interfaze.PeerCountandp.AllowedIPsCount, ensuring each struct fits entirely within the buffer slice before casting or reading fields. If the buffer is truncated or count headers are corrupted,parseDevicereturns a clean error instead of reading past the end of the buffer.client_windows_test.goverifying handling of truncated buffers, corrupted count fields, and valid device configurations.Testing
GOOS=windows go test -c -o /dev/null ./internal/wgwindowscompiles cleanly.go test ./...passes across the repository.