Skip to content

grate-rs: return errors instead of panicking in fd translation - #249

Open
Yaxuan-w wants to merge 1 commit into
mainfrom
fix/fd-support-emfile-panic
Open

Yaxuan-w wants to merge 1 commit into
mainfrom
fix/fd-support-emfile-panic

Conversation

@Yaxuan-w

Copy link
Copy Markdown
Member

The default fd handlers in fd_support.rs aborted the whole grate in two cases a cage can cause:

  • pipe/socketpair: get_unused_virtual_fd(...).unwrap() panicked when the cage's fd table in the grate was full. Both fds are now allocated through alloc_vfd_pair, which releases the first virtual fd, closes the two runtime fds and returns EMFILE if the pair does not fit.
  • poll/select/pipe/socketpair: a failed copy to or from cage memory hit panic!, so a bad pointer (for example an invalid sv passed to socketpair) took the grate down. These now return EFAULT. For pipe and socketpair the virtual fds and runtime fds are released first, so the failed call leaves nothing open.

Addresses the remaining panic sites listed in #148. Closed #148

The default fd handlers in fd_support.rs aborted the whole grate in two
cases a cage can cause:

- pipe/socketpair: `get_unused_virtual_fd(...).unwrap()` panicked when
  the cage's fd table in the grate was full. Both fds are now allocated
  through `alloc_vfd_pair`, which releases the first virtual fd, closes
  the two runtime fds and returns EMFILE if the pair does not fit.
- poll/select/pipe/socketpair: a failed copy to or from cage memory hit
  `panic!`, so a bad pointer (for example an invalid `sv` passed to
  socketpair) took the grate down. These now return EFAULT. For pipe and
  socketpair the virtual fds and runtime fds are released first, so the
  failed call leaves nothing open.

Addresses the remaining panic sites listed in #148.
@Yaxuan-w
Yaxuan-w requested a review from F-Wilke November 30, 2026 13:55
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.

fd_support.rs: missing handlers for poll/select/pipe/fchmod/preadv/pwritev; mkdir/mknod/access registered with wrong spec

1 participant