Skip to content

internal/wgwindows: add bounds checking to Device IOCTL parser - #163

Open
Huge wants to merge 1 commit into
WireGuard:masterfrom
Huge:fix/windows-ioctl-bounds-check
Open

Huge wants to merge 1 commit into
WireGuard:masterfrom
Huge:fix/windows-ioctl-bounds-check

Conversation

@Huge

@Huge Huge commented Oct 6, 2026

Copy link
Copy Markdown

Summary

This PR adds bounds checking and truncation validation when parsing responses from the Windows WireGuardNT driver IOCTL:

  1. In Device, verify that the size returned by DeviceIoControl does not exceed the slice buffer before slicing.
  2. Factored out parseDevice to parse the buffer and validate that len(buf) >= unsafe.Sizeof(ioctl.Interface{}) before reading interface metadata.
  3. Track buffer offset bounds when iterating through interfaze.PeerCount and p.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, parseDevice returns a clean error instead of reading past the end of the buffer.
  4. Added unit tests in client_windows_test.go verifying handling of truncated buffers, corrupted count fields, and valid device configurations.

Testing

  • Verified GOOS=windows go test -c -o /dev/null ./internal/wgwindows compiles cleanly.
  • go test ./... passes across the repository.

- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant