Skip to content

Add RngRestorePolicy to SandboxConfiguration#1667

Draft
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:fix_rng
Draft

Add RngRestorePolicy to SandboxConfiguration#1667
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:fix_rng

Conversation

@ludfjig

@ludfjig ludfjig commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Adds RngRestorePolicy to SandboxConfiguration to 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 passes Refresh with 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.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig ludfjig added kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. ready-for-review PR is ready for (re-)review labels Jul 20, 2026
@ludfjig
ludfjig marked this pull request as ready for review July 20, 2026 19:14
Copilot AI review requested due to automatic review settings July 20, 2026 19:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 RngRestorePolicy to SandboxConfiguration and thread it into MultiUseSandbox so 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 call srand() before dispatching guest calls.
  • Add C-guest-based regression tests validating default preservation and optional reseeding behavior across from_snapshot and restore.

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.

Comment thread src/hyperlight_host/src/sandbox/config.rs
@ludfjig
ludfjig marked this pull request as draft July 21, 2026 00:52
@github-actions github-actions Bot removed the ready-for-review PR is ready for (re-)review label Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants