Add RngRestorePolicy to SandboxConfiguration#1667
Draft
ludfjig wants to merge 1 commit into
Draft
Conversation
ludfjig
marked this pull request as ready for review
July 20, 2026 19:14
ludfjig
requested review from
andreiltd,
danbugs,
dblnz,
devigned,
jprendes,
jsturtevant,
simongdavies,
squillace and
syntactically
as code owners
July 20, 2026 19:14
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new sandbox configuration knob, RngRestorePolicy, to control whether the guest libc PRNG state is preserved from a snapshot or reseeded when restoring/resuming from a snapshot. This fits into the host/guest snapshot/restore flow by using scratch bookkeeping to pass a reseed request from host to guest at restore time.
Changes:
- Add
RngRestorePolicytoSandboxConfigurationand thread it intoMultiUseSandboxso restore/from-snapshot can optionally request a libc PRNG reseed. - Add a scratch bookkeeping field (
SCRATCH_TOP_LIBC_RNG_SEED_OFFSET) plus guest-side logic to consume it and callsrand()before dispatching guest calls. - Add C-guest-based regression tests validating default preservation and optional reseeding behavior across
from_snapshotandrestore.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/tests/c_guests/c_simpleguest/main.c | Adds a NextRandom guest export (wrap + register) for testing libc RNG behavior. |
| src/hyperlight_host/src/sandbox/uninitialized_evolve.rs | Threads RNG restore policy into MultiUseSandbox construction. |
| src/hyperlight_host/src/sandbox/snapshot/file_tests.rs | Adds snapshot/restore tests for libc RNG preservation vs reseeding using the C simple guest. |
| src/hyperlight_host/src/sandbox/mod.rs | Re-exports RngRestorePolicy from the sandbox module. |
| src/hyperlight_host/src/sandbox/initialized_multi_use.rs | Implements host-side reseed requests on from_snapshot and restore, plus stores policy in the sandbox. |
| src/hyperlight_host/src/sandbox/config.rs | Introduces RngRestorePolicy and getters/setters on SandboxConfiguration. |
| src/hyperlight_host/src/mem/mgr.rs | Adds a scratch bookkeeping write helper for the libc RNG seed and clears it during bookkeeping updates. |
| src/hyperlight_guest/src/layout.rs | Exposes the guest virtual address of the libc RNG seed scratch slot. |
| src/hyperlight_guest_bin/src/lib.rs | Adds guest-side reseed logic (refresh_libc_rng) and updates initial srand seeding via a shared fold. |
| src/hyperlight_guest_bin/src/guest_function/call.rs | Calls refresh_libc_rng() on each internal dispatch (libc feature). |
| src/hyperlight_common/src/layout.rs | Defines the new scratch bookkeeping offset constant. |
| CHANGELOG.md | Documents the new configuration option in the unreleased changelog. |
ludfjig
marked this pull request as draft
July 21, 2026 00:52
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.
Adds
RngRestorePolicytoSandboxConfigurationto allow multiple instances of the same snapshot to have differnet rng. This can be useful if somebody expects two sandboxes craeted from the same snapshot to generate different randoms nubmer, for example a key. The default behavior is to maintain the current behavior where rng is never refreshed, and this also allows backwards compatible with old saved snapshots. However if somebody passesRefreshwith an old snapshot it will be silently ignored. We should maybe consider changing this default in future versions.RngRestorePolicy is not saved to disk as part of a snapshot because it's a property of a live sandbox and to allow maximal flexibility.