Skip to content

fix(sys): handle EACCES from fstat on socketpair fds#30916

Open
springmin wants to merge 1 commit into
oven-sh:mainfrom
springmin:pr/fstat-eacces
Open

fix(sys): handle EACCES from fstat on socketpair fds#30916
springmin wants to merge 1 commit into
oven-sh:mainfrom
springmin:pr/fstat-eacces

Conversation

@springmin
Copy link
Copy Markdown

On some Linux configurations (notably with SELinux), fstat() on socketpair fds returns EACCES. Fall back to a zeroed stat instead of erroring.

Copy link
Copy Markdown
Contributor

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e21d46f3-9d5d-4622-8829-dbd119085c85

📥 Commits

Reviewing files that changed from the base of the PR and between 2ecf453 and 43fcefa.

📒 Files selected for processing (1)
  • src/sys/lib.rs

Walkthrough

On Linux/Android, fstat now treats EACCES from the syscall as a special case: it probes the FD with getsockopt(SO_TYPE) and returns a zero-initialized Stat if the probe succeeds; other errors are returned as before.

Changes

fstat EACCES special-case handling

Layer / File(s) Summary
fstat: EACCES probe and zeroed Stat return
src/sys/lib.rs
fstat now matches on syscall errors: on EACCES it runs getsockopt(SO_TYPE) and returns a zero-initialized Stat if that probe succeeds; other errno values are converted to Error::from_code_int(e, Tag::fstat) as before.
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete; it lacks the required 'How did you verify your code works?' section from the template. Add a 'How did you verify your code works?' section describing testing or verification of the EACCES handling logic.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: handling EACCES errors from fstat on socketpair file descriptors.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/sys/lib.rs`:
- Around line 2098-2103: The current fstat error handling swallows Err(e) if e
== libc::EACCES for any Fd and returns a zeroed stat; restrict that fallback to
socket descriptors only by adding a platform-gated helper (e.g.
is_socket_fd(fd)) that uses getsockopt(SOL_SOCKET, SO_TYPE) on linux/android to
detect sockets, then change the Err(e) branch in the fstat handling so that if e
== libc::EACCES you call is_socket_fd(fd) and only return Ok(zeroed stat) when
true, otherwise propagate Err(Error::from_code_int(e, Tag::fstat)); ensure the
helper is inlined and only compiled on the appropriate targets and reference the
existing Tag::fstat and fstat handling code paths when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7c4ebad3-a34f-463a-b1a3-b579f2200331

📥 Commits

Reviewing files that changed from the base of the PR and between 112f305 and 2ecf453.

📒 Files selected for processing (1)
  • src/sys/lib.rs

Comment thread src/sys/lib.rs
@springmin
Copy link
Copy Markdown
Author

Updated: fstat EACCES fallback is now scoped to socket fds only via getsockopt(SO_TYPE) probe. Non-socket fds will properly propagate the EACCES error.

@springmin springmin reopened this May 17, 2026
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.

1 participant