Repository navigation
Conversation
- In parseEndpoint, check that the input slice is large enough to contain unix.RawSockaddr, unix.RawSockaddrInet4, and unix.RawSockaddrInet6 before reading fields, avoiding out-of-bounds reads and panics on empty slices. - In parsePeer, check public-key and preshared-key slice lengths before converting to wgtypes.Key. - In parseAllowedIP, safely check type assertions to avoid runtime panics on unexpected nvlist data. - In nv.Unmarshal, return an error if input buffer is empty, verify that nvlist_unpack succeeded, and destroy the allocated nvlist on return. - In nv.marshal, check for integer overflow in allocation size, check for C.malloc failure, and free allocated nvlist items on sub-marshal errors. Signed-off-by: Martin Vlach <mr.huge@seznam.cz>
Huge
force-pushed
the
fix/freebsd-bounds-and-overflow
branch
from
October 5, 2026 12:54
7a5cc22 to
bcdefac
Compare
Author
|
Gentle ping on this one and #163. About the red |
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 hardens the FreeBSD kernel backend and its internal
nvpackage with defensive boundary checks, type assertion safeguards, and memory leak cleanups:parseEndpoint: Validate that the input sliceepcontains at leastsizeof(unix.RawSockaddr)(andRawSockaddrInet4orRawSockaddrInet6respectively) before accessing fields, preventing out-of-bounds reads and panics on empty or short slices.parsePeer: Validate thatpublic-keyandpreshared-keyslices are exactly 32 bytes before casting towgtypes.Key, preventing runtime conversion panics.parseAllowedIP: Safe comma-ok type assertions oncidr,ipv4, andipv6nvlist values to prevent unexpected panics on malformed kernel responses.nv.Unmarshal: Return an error on empty input buffers (preventing&d[0]panic), verify thatnvlist_unpacksucceeded, and ensureC.nvlist_destroyis called to prevent heap memory leaks.nv.marshal: Guard against integer overflow inC.sizeof_nvlist_ptr * szduring[]Listallocation, verify thatC.mallocsucceeded, and clean up previously allocated sub-nvlists and buffers on error.Testing
go test ./...andgo vet ./...cleanly across the repository.Disclaimer: Found the issue by test-driving an LM-powered vulnerability scanner I work on heavily.