Repository navigation
Fix reading Unix addresses whose path fills all of sun_path - #1742
Open
EnesKartal wants to merge 1 commit into
Open
EnesKartal wants to merge 1 commit into
EnesKartal wants to merge 1 commit into
Conversation
On Linux, a socket bound to a 108-byte path reports an address length that includes the NUL terminator, which the kernel stores just past sun_path. Converting such an address to SocketAddrUnix, or formatting a SocketAddrAny holding it, indexed sun_path out of bounds and panicked in both backends. Only check for the terminator when it is inside sun_path. Fixes bytecodealliance#1741.
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.
Fixes #1741.
On Linux, when a Unix socket is bound to a path that fills all 108 bytes of
sun_path, the kernel stores the NUL terminator just pastsun_path(inside thesockaddr_storage) and returns an address length of 111.read_sockaddr_unixthen indexedsun_path[108]to check the terminator and panicked, in both backends:src/backend/linux_raw/net/read_sockaddr.rs:124src/backend/libc/net/read_sockaddr.rs:220This happens in
SocketAddrUnix::try_from(SocketAddrAny)and inDebugforSocketAddrAny, for addresses returned bygetsockname,recvfrom,acceptand similar.The fix checks the terminator only when it lies inside
sun_path. A full-length path is passed toSocketAddrUnix::new, which already supports the non-terminated 108-byte form (seetest_long_named_address).Test plan
New test
test_getsockname_long_named_addressintests/net/unix.rsbinds a datagram socket to a 108-byte path in a temp dir, formats thegetsocknameresult withDebug, converts it toSocketAddrUnixand checkspath_bytes().Before the fix:
After the fix (Linux x86_64):
cargo fmtis clean andcargo clippy --testsshows no warnings in the changed files for either backend.