fix: use umask(0177) before bind to prevent S_IXUSR race#12
Open
DonaldoDes wants to merge 1 commit intomobydeck:mainfrom
Open
fix: use umask(0177) before bind to prevent S_IXUSR race#12DonaldoDes wants to merge 1 commit intomobydeck:mainfrom
DonaldoDes wants to merge 1 commit intomobydeck:mainfrom
Conversation
create_socket restored the original umask before calling bind(2).
With a typical shell umask of 022, bind created the socket file with
mode 0755 (S_IXUSR set). chmod(0600) was called right after, but the
tiny window between bind and chmod was enough for a concurrent
`atch list` to see the stale execute bit and report a freshly started
session as [attached] — even though no client had ever connected.
The fix switches to umask(0177) before bind so the kernel creates the
socket file directly at mode 0600 (0777 & ~0177). S_IXUSR is never
present on the socket path during creation, closing the TOCTOU window
entirely. The subsequent chmod(0600) is kept for explicitness and to
guard against any platform-specific deviations.
Adds regression test 24 (start-inside-session) that:
- starts an outer session and attaches a python client to it
- starts an inner session with ATCH_SESSION set (simulating being
inside the outer session)
- asserts the inner session socket has no execute bit immediately
after creation
- asserts `atch list` does not show the inner session as [attached]
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
umask(0177)beforebind()increate_socket()so the socket file is created directly with mode0600atch listcould read staleS_IXUSRbetweenbind()andchmod()bind()Closes #8
Test plan
atch start(no S_IXUSR window)atch listnever shows[attached]for freshly started sessions🤖 Generated with Claude Code