Skip to content

fix: use umask(0177) before bind to prevent S_IXUSR race#12

Open
DonaldoDes wants to merge 1 commit intomobydeck:mainfrom
DonaldoDes:fix/socket-umask
Open

fix: use umask(0177) before bind to prevent S_IXUSR race#12
DonaldoDes wants to merge 1 commit intomobydeck:mainfrom
DonaldoDes:fix/socket-umask

Conversation

@DonaldoDes
Copy link
Contributor

Summary

  • Use umask(0177) before bind() in create_socket() so the socket file is created directly with mode 0600
  • Prevents the TOCTOU window where atch list could read stale S_IXUSR between bind() and chmod()
  • Restore original umask after bind()

Closes #8

Test plan

  • Socket mode is 600 immediately after atch start (no S_IXUSR window)
  • atch list never shows [attached] for freshly started sessions
  • Regression test with stat check on socket permissions

🤖 Generated with Claude Code

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>
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.

New sessions briefly appear as attached due to socket permission race

1 participant