Skip to content

Add DescriptorHandle and return Result from descriptor table methods #2691

Merged
stevenengler merged 2 commits intoshadow:mainfrom
stevenengler:descriptor-result
Jan 25, 2023
Merged

Add DescriptorHandle and return Result from descriptor table methods #2691
stevenengler merged 2 commits intoshadow:mainfrom
stevenengler:descriptor-result

Conversation

@stevenengler
Copy link
Copy Markdown
Contributor

@stevenengler stevenengler commented Jan 24, 2023

The descriptor table shouldn't ever allow descriptors to be registered with a handle larger than libc::c_int::MAX. The old code also had a loop that could wrap around unexpectedly in release builds.

While the libc API uses int values for file handles, the Linux syscall API uses unsigned int for file handles. This means that when you pass a file handle of -1 to a close() call for example, Linux will see this as 4,294,967,295. If we read file handles in Shadow's syscall handlers as libc::c_uint values, we run into problems in these edge cases (for example with dup2(fd, -1)). We can continue reading them as signed integers and casting them to unsigned for now, but I think it's nicer to force us to handle these edge cases.

The public API to DescriptorTable now uses DescriptorHandle objects. The register_descriptor and register_descriptor_with_min_fd methods also now return results if the descriptor could not be added.

@stevenengler stevenengler self-assigned this Jan 24, 2023
@github-actions github-actions bot added the Component: Main Composing the core Shadow executable label Jan 24, 2023
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 24, 2023

Codecov Report

Base: 68.18% // Head: 67.50% // Decreases project coverage by -0.69% ⚠️

Coverage data is based on head (0604cb8) compared to base (1fc493a).
Patch coverage: 59.13% of modified lines in pull request are covered.

❗ Current head 0604cb8 differs from pull request most recent head e4e847f. Consider uploading reports for the commit e4e847f to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2691      +/-   ##
==========================================
- Coverage   68.18%   67.50%   -0.69%     
==========================================
  Files         202      202              
  Lines       30326    30378      +52     
  Branches     5916     5935      +19     
==========================================
- Hits        20678    20506     -172     
- Misses       4969     5214     +245     
+ Partials     4679     4658      -21     
Flag Coverage Δ
tests 67.50% <59.13%> (-0.69%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/main/host/syscall/handler/eventfd.rs 0.00% <0.00%> (-72.23%) ⬇️
src/main/host/syscall/handler/fcntl.rs 47.29% <0.00%> (-18.42%) ⬇️
src/main/host/syscall/handler/mod.rs 76.06% <0.00%> (-4.28%) ⬇️
src/main/host/syscall/handler/unistd.rs 57.25% <44.44%> (-15.48%) ⬇️
src/main/host/descriptor/descriptor_table.rs 67.61% <65.30%> (-12.10%) ⬇️
src/main/host/process.rs 78.09% <76.92%> (-0.08%) ⬇️
src/main/host/syscall/handler/socket.rs 67.72% <100.00%> (-0.72%) ⬇️
src/main/host/descriptor/eventfd.rs 0.00% <0.00%> (-65.66%) ⬇️
src/main/host/syscall/handler/ioctl.rs 40.00% <0.00%> (-17.15%) ⬇️
... and 25 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@stevenengler stevenengler removed the request for review from sporksmith January 24, 2023 03:57
@stevenengler stevenengler force-pushed the descriptor-result branch 3 times, most recently from 9857571 to 08545ed Compare January 24, 2023 21:59
@stevenengler stevenengler changed the title Return results from descriptor table methods Add DescriptorHandle and return results from descriptor table methods Jan 24, 2023
@stevenengler stevenengler changed the title Add DescriptorHandle and return results from descriptor table methods Add DescriptorHandle and return Result from descriptor table methods Jan 24, 2023
There is a duplicate `DescriptorTable::register_descriptor_with_fd`, so use
that instead.
The descriptor table shouldn't ever allow descriptors to be registered with a
handle larger than `libc::c_int::MAX`. The old code also had a loop that could
wrap around unexpectedly in release builds.

The public API to `DescriptorTable` now uses `DescriptorHandle` objects. The
`register_descriptor` and `register_descriptor_with_min_fd` methods also now
return results if the descriptor could not be added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Main Composing the core Shadow executable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants