core: restore port-remap transparency and tighten bind path#48
Merged
Conversation
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
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
handle_getsocknamenow performs getsockname on-behalf and rewrites real ports back to the virtual port the child requested, andconnect_on_behalfuses the cached real port for loopback dials. Previously the supervisor read child memory before the kernel filled the buffer, so the rewrite was a no-op and the remap was silently broken in the conflict path.dup_fd; onEADDRINUSEretry with port 0 so the kernel atomically picks a free real port.record_bindruns only after the bind succeeds, so a failed bind leaves no stale mapping. Stale cached real ports (reclaimed by another host process while the sandbox's prior socket was closed) also fall through to the bind 0 retry.dup_fd_from_pidat six callsites instead of always returningENOSYS.ENOSYSremains accurate for kernel-too-old failures;EBADF/ESRCH/EPERMnow surface honestly for runtime failures (child exited, child closed the fd, permission).getsocknamereturns the virtual port under host conflict (test_port_remap_conflicttightened fromstarts_with("BOUND:")to exact match) and that a loopback bind/listen/connect round-trip works end-to-end under forced remap (test_port_remap_loopback_under_conflict).Test plan
cargo test -p sandlock-corepasses (490 tests: 275 unit + 213 integration + 2 sandbox_validate)pytest python/testspasses (247 tests)