Repository navigation
leakpocalypse in internal resource table API - #2076
Open
syntactically wants to merge 1 commit into
Open
syntactically wants to merge 1 commit into
syntactically wants to merge 1 commit into
Conversation
syntactically
requested review from
andreiltd,
danbugs,
dblnz,
devigned,
jprendes,
jsturtevant,
ludfjig,
simongdavies and
squillace
as code owners
November 19, 2026 01:09
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The resource safety documentation contains an unresolvable Lend intra-doc link and a borrowg typo that need correction.
2 open issues
What changed in this PR
This PR makes the resource-lending safety requirement explicit in Hyperlight’s shared resource API and component bindings.
Changes:
- Marks
ResourceEntry::lendas unsafe and requires callers to run the guard’s destructor before the borrowed lifetime expires. - Wraps the generated call in an unsafe block with a cleanup justification.
| File | Description |
|---|---|
src/hyperlight_component_util/src/hl.rs |
Handles the unsafe lending call in generated bindings. |
src/hyperlight_common/src/resource.rs |
Defines the unsafe lending contract and updates its safety documentation. |
Review effort: Balanced
| /// (a) there are no outstanding [`BorrowedResourceGuard`]s alive | ||
| /// (since they would be holding the read side of the [`RwLock`] if | ||
| /// they were), and that (b) the shared flag has been set to false, so | ||
| /// [`ResourceEntry::borrow`] will never create another borrowg |
Using the reference produced by `ResourceEntry::borrow` soundly requires the guarantee that destructors of `LentResourceGuard`s are properly run, which is famously not provided in Rust. The relevant APIs are only used internally by the component bindgen macros, and are always used in the correct fashion, but the functions are `pub` in `hyperlight_common` to allow them to be used from generated code. This commit just makes the minimal change of marking `ResourceEntry::lend()` as unsafe and making it the caller's responsibility to ensure that `drop` is called properly. A more satisfying solution would be to switch the `lend` API to only lend the resource entry within the scope of a passed-in closure. Unfortunately, (a) this would require restructuring the component bindgen code significantly and (b) it is not entirely clear that it would be expressive enough to support upcoming async guest calls. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
syntactically
force-pushed
the
lm/lent-guard
branch
from
November 19, 2026 01:15
ac13d9a to
5ec974b
Compare
Benchmark ResultsMeasured commit: kvm / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
kvm / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / amd (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / intel (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
Reported by |
This branch has not been deployed
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.

Using the reference produced by
ResourceEntry::borrowsoundly requires the guarantee that destructors ofLentResourceGuards are properly run, which is famously not provided in Rust. The relevant APIs are only used internally by the component bindgen macros, and are always used in the correct fashion, but the functions arepubinhyperlight_commonto allow them to be used from generated code.This commit just makes the minimal change of marking
ResourceEntry::lend()as unsafe and making it the caller's responsibility to ensure thatdropis called properly.A more satisfying solution would be to switch the
lendAPI to only lend the resource entry within the scope of a passed-in closure. Unfortunately, (a) this would require restructuring the component bindgen code significantly and (b) it is not entirely clear that it would be expressive enough to support upcoming async guest calls.