Skip to content

Reseed the provider DRBGs when the VMClock generation changes - #33286

Open
KurathSec wants to merge 12 commits into
openssl:masterfrom
KurathSec:stutter-vmclock-reseed
Open

KurathSec wants to merge 12 commits into
openssl:masterfrom
KurathSec:stutter-vmclock-reseed

Conversation

@KurathSec

@KurathSec KurathSec commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

A new feature, offered for a future release as discussed with the OpenSSL team by mail: the
provider DRBGs reseed when the VMClock generation counter changes, which is the signal Linux
gives a process that its virtual machine has been restored from a snapshot.

Since Linux 7.0 the VMClock device (drivers/ptp/ptp_vmclock.c, include/uapi/linux/vmclock-abi.h)
shares one read-only page with the guest; it carries a vm_generation_counter that the
hypervisor bumps on every load from saved state, flagged by VMCLOCK_FLAG_VM_GEN_COUNTER_PRESENT,
beside a disruption_marker that also moves on migration. Firecracker attaches the device to
every guest; QEMU exposes it with -device vmclock (as of 10.2.2 without the counter, with the
marker). The DRBGs today reseed on a change of pid, on the request count and on the time
interval, and none of these changes across a restore, so every copy restored from one image
continues from the same state (RAND(7) documentation of that behaviour is in a separate pull
request).

The change: providers/implementations/rands/vmclock.c, built into the default and FIPS
providers, maps the page of /dev/vmclock0 once per library context and reads, under the page's
sequence count, the generation counter (when the flags say it is present) and the disruption
marker, folded to one value. Each provider DRBG keeps the value it last saw in PROV_DRBG, and
ossl_prov_drbg_generate treats a change like a change of pid, so the public and private DRBGs
reseed from the primary and the primary from its seed source; after generating it reads the value
again and, if it moved, reseeds and generates the output once more. That reseed draws on the
kernel's generator, which the guest's kernel may not have reseeded yet, so a DRBG reseeds again
on its first call at least 1 s, and at least 64 s, after it. A page that stays in mid-update for
a whole read counts as a change once, and once more when it can be read again. Where the device
does not exist the cost is one null compare per generate call; where it does, a few loads under a
sequence count before and after. vmclock_test builds its own copy of the reader with a file
standing in for the page, moves the counter and checks the reseeds of the default provider's DRBGs.
Nothing else in the DRBGs changes: not the algorithms, the entropy sources or the fork handling.

Measured with the harness that found the gap (the same cells before and after): under
Firecracker with VMGenID and VMClock attached the restore cell goes from 32 of 32 identical
blocks to 0 of 32, under QEMU with the VMClock device from 32 of 32 to 0 of 32 (through the
marker), under QEMU without the device it stays 32 of 32 and under CRIU 14 of 14, and the fork
cells are unchanged. Per-call timing of RAND_bytes on 32-byte requests is within the spread
between benchmark batches of the unpatched build, with and without the page.

Checklist
  • documentation is added or updated
  • tests are added or updated
  • CHANGES.md updated

Copilot AI balanced review requested due to automatic review settings October 20, 2026 15:29
@openssl-ci-bot openssl-ci-bot Bot added the approval: review pending This pull request needs review by a committer label Oct 20, 2026
@openssl-cla-check openssl-cla-check Bot added the hold: cla required The contributor needs to submit a license agreement. label Oct 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@KurathSec
KurathSec force-pushed the stutter-vmclock-reseed branch from 6af10ee to de49bb5 Compare October 20, 2026 15:53
uint8_t rest[72];
uint64_t vm_generation_counter;
};
# define OSSL_VMCLOCK_MAGIC 0x4b4c4356u

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this code need to take into account platforms using Big Endian?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. Every field of the page is little-endian (__le32 and __le64 in
include/uapi/linux/vmclock-abi.h), and the kernel reads them with le32_to_cpu() and
le64_to_cpu(). Today the driver only builds where that is the native order (depends on X86_TSC || ARM_ARCH_TIMER and ARCH_SUPPORTS_INT128, and big-endian arm64 depends on BROKEN
in 7.2), but the ABI says little-endian, so the new revision converts every field it reads, the
magic and version included, using DECLARE_IS_ENDIAN. On little-endian targets the conversion
compiles away. The test now writes the fake page in little-endian byte order, so on a big-endian
host it exercises the conversion.

if (!RUN_ONCE(&vmclock_once, do_vmclock_init) || vmclock_page == NULL)
return 0;
do {
while (((seq = vmclock_page->seq_count) & 1) != 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this busy loop a potential issue? (Does it need to timeout ?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it should be bounded. The kernel's own readers of the page give up after 100 ms
(VMCLOCK_MAX_WAIT in drivers/ptp/ptp_vmclock.c) and return -ETIMEDOUT. Here the read now
looks at the sequence count at most 1000 times, and a read that gives up counts as a change, so
the DRBG reseeds. A bound that turns out too short then costs an extra reseed, and a page that
stays odd can no longer keep a DRBG lock held. A new test leaves the page odd and checks that
RAND_bytes() returns and reseeds, and that the reseeding stops once the page is consistent
again.

@slontis

slontis commented Oct 21, 2026

Copy link
Copy Markdown
Member

I asked gpt about threading in this PR

1. Busy-waiting can block other threads indirectly

The reader spins until it sees a stable sequence counter:

while (((seq = vmclock_page->seq_count) & 1) != 0)
    ;

It also retries indefinitely if the counter changes during the read.

Although this happens before ossl_prov_drbg_generate() acquires its own lock, a caller can already hold locks. During child reseeding, get_entropy() holds the child’s lock, acquires its parent’s lock, and calls the parent to generate seed material. That parent then reads VMClock.

A stuck reader can therefore hold both locks indefinitely, blocking other threads needing the shared primary DRBG. This is a liveness problem rather than a demonstrated lock-order deadlock. Parent locking

2. Reading the epoch before locking permits observations to arrive out of order

The code does this:

vmclock_epoch = ossl_prov_vmclock_epoch();
/* ... */
CRYPTO_THREAD_write_lock(drbg->lock);
/* ... */
drbg->vmclock_epoch = vmclock_epoch;

For a shared DRBG, this sequence is possible:

Step | Thread A | Thread B -- | -- | -- 1 | Reads epoch 1, then pauses |   2 |   | VMClock changes to epoch 2 3 |   | Reads 2, locks DRBG, reseeds, records 2 4 | Resumes, locks DRBG, sees remembered 2 versus local 1 |   5 | Reseeds again and records the stale value 1 |   6 | Next caller observes 2 and reseeds again |  

The write itself is protected by the lock, so this is a stale-observation race, not an unsynchronized memory write. It causes unnecessary reseeds and lets the remembered epoch move backwards.

This matters particularly for the shared primary DRBG; normal public and private DRBGs are associated with individual threads. Reading the epoch after acquiring the DRBG lock would prevent this ordering problem. Read and lock placement

3. A restore can occur after the check

If a snapshot captures a thread after it reads the old epoch, that thread can resume after restoration using its saved local value. If the remembered epoch matches, it can generate output without detecting the restore on that call.

Moving the read inside the lock narrows this window but cannot eliminate snapshots occurring after the check. This is a limitation of the detection design, beyond ordinary thread synchronization.

The initialization looks sound: RUN_ONCE() synchronizes initialization and publication of the mapping. Updates to the DRBG’s remembered epoch occur under its existing lock when locking is enabled.

I would prioritize bounded reader retries with explicit failure handling, moving the epoch read under the DRBG lock, and adding concurrency tests. The new test changes the fake page between calls, so it exercises neither concurrent page updates nor competing callers.

1. Busy-waiting can block other threads indirectly The reader spins until it sees a stable sequence counter: while (((seq = vmclock_page->seq_count) & 1) != 0) ; It also retries indefinitely if the counter changes during the read. Although this happens before ossl_prov_drbg_generate() acquires its own lock, a caller can already hold locks. During child reseeding, get_entropy() holds the child’s lock, acquires its parent’s lock, and calls the parent to generate seed material. That parent then reads VMClock. A stuck reader can therefore hold both locks indefinitely, blocking other threads needing the shared primary DRBG. This is a liveness problem rather than a demonstrated lock-order deadlock. [Parent locking](https://github.com/openssl/openssl/blob/de49bb5101421a13f02d18e61e9b841cafc98305/providers/implementations/rands/drbg.c#L219-L244) 2. Reading the epoch before locking permits observations to arrive out of order The code does this: vmclock_epoch = ossl_prov_vmclock_epoch(); /* ... */ CRYPTO_THREAD_write_lock(drbg->lock); /* ... */ drbg->vmclock_epoch = vmclock_epoch; For a shared DRBG, this sequence is possible: Step Thread A Thread B 1 Reads epoch 1, then pauses 2 VMClock changes to epoch 2 3 Reads 2, locks DRBG, reseeds, records 2 4 Resumes, locks DRBG, sees remembered 2 versus local 1 5 Reseeds again and records the stale value 1 6 Next caller observes 2 and reseeds again

The write itself is protected by the lock, so this is a stale-observation race, not an unsynchronized memory write. It causes unnecessary reseeds and lets the remembered epoch move backwards.
This matters particularly for the shared primary DRBG; normal public and private DRBGs are associated with individual threads. Reading the epoch after acquiring the DRBG lock would prevent this ordering problem. Read and lock placement
3. A restore can occur after the check
If a snapshot captures a thread after it reads the old epoch, that thread can resume after restoration using its saved local value. If the remembered epoch matches, it can generate output without detecting the restore on that call.
Moving the read inside the lock narrows this window but cannot eliminate snapshots occurring after the check. This is a limitation of the detection design, beyond ordinary thread synchronization.
The initialization looks sound: RUN_ONCE() synchronizes initialization and publication of the mapping. Updates to the DRBG’s remembered epoch occur under its existing lock when locking is enabled.
I would prioritize bounded reader retries with explicit failure handling, moving the epoch read under the DRBG lock, and adding concurrency tests. The new test changes the fake page between calls, so it exercises neither concurrent page updates nor competing callers.

@slontis

slontis commented Oct 21, 2026

Copy link
Copy Markdown
Member

@aisle-research

@aisle-research-bot

aisle-research-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

✅ No new security issues found in this run.

Aisle supplements but does not replace security review.

Last updated on: 2026-10-21T03:24:51Z

@openssl-cla-check openssl-cla-check Bot removed the hold: cla required The contributor needs to submit a license agreement. label Oct 21, 2026
@KurathSec

Copy link
Copy Markdown
Contributor Author

Thank you for the careful review. All three points hold, and the new commit addresses each.

1. Spinning with a lock held. The read is bounded, as in the inline reply. In master ossl_drbg_lock() is a hint that does nothing, so a parent's lock is taken inside the
parent's own ossl_prov_drbg_generate(); with the read under the lock (point 2), a stuck read
would hold both the child's and the parent's, which is one more reason for the bound.

2. Reading before the lock. The epoch is now read, compared and stored under drbg->lock in
one call, ossl_prov_vmclock_changed(&drbg->vmclock_epoch), so the remembered value can no longer
move backwards. A stale store could only cause extra reseeds, since a missed reseed needs the remembered value to
equal the current one and a stale store makes them differ, but the new order is simpler to reason
about.

3. A snapshot after the check. Agreed: a check before generating cannot see a snapshot taken
between the check and the output. The new commit does what the vDSO getrandom() does
(lib/vdso/getrandom.c, which reads the generation again after generating and retries once):
after generating, still under the lock, it reads the epoch again, and if it moved it reseeds and
generates the output once more. That second reseed keeps the caller's request: prediction
resistance if it was asked for, and the caller's additional input. If the reseed or the generate
fails, the output is cleared before the error is returned.

We measured this window on a reference consumer of the same shape under Firecracker, snapshotting
a process that draws without pause, with a delay forced between check and output. Without the
second read, restores of 41 of 295 snapshots (0.5 ms delay) and 113 of 296 (1.5 ms) returned
output from the shared state. With it, 0 of 98 and 0 of 99, although 13 and 26 of those snapshots
fell between check and output.

What the second read cannot see is a snapshot taken after RAND_bytes() has returned, when the
bytes are already with the caller. A second snapshot during the regeneration is also not read
again; the vDSO falls back to the system call at that point, and a loop here would cover it if you
prefer.

Two limits of the design.

  • The reseed is as fresh as the kernel. The page changes before the guest's vCPUs resume, while
    the kernel learns of the restore only through the VMGenID notification, which it handles in a
    work item after they resume (drivers/virt/vmgenid.c); the VMClock driver does not reseed it. A DRBG that
    reseeds from getrandom() in between gets the duplicated kernel output, records the new epoch,
    and stays duplicated until its next scheduled reseed. Without the vmgenid driver in the guest this
    is every restore: under Firecracker with a guest kernel built without it, the patched library was
    identical in 33 of 33 blocks, beside the kernel's own first block identical in 1 of 33. With the
    driver it is a race: under host load the first getrandom() after a QEMU restore returned the old
    state in 6 of 200 restores in our runs, and in none of 200 on an idle host. Two ways to close it
    in the library, if you want either: mix the CPU's random instruction into a reseed that the page
    triggered (AWS-LC mixes RDRAND into its
    reseeds, and its patched build was distinct, 0 of 33, in that configuration), or reseed once
    more a little later. Both are policy choices, so I have left them to you; the CHANGES entry states the dependency.
  • CRIU. The mapping of /dev/vmclock0 lives as long as the process, and CRIU 4.2.1 refuses to
    checkpoint a process that maps a character device other than /dev/zero ("Can't handle
    non-regular mapping", criu/proc_parse.c). So a process inside a VMClock guest that can open the
    device, which by default means root, could no longer be checkpointed with CRIU. Nothing would be
    gained there anyway, since a CRIU restore inside the same VM does not move the counter. Would you
    want a way to switch the check off, for example a configuration option, or should this wait for
    CRIU to handle the mapping?

The CHANGES entry names the default provider's DRBGs (the FIPS provider does not read the page) and
says that a process that cannot open the device is unaffected.

Setup. OPENSSL_VMCLOCK can point at anything, so the setup opens with O_NONBLOCK
(a FIFO cannot block it), maps only a character device or a regular file that holds the whole
structure (a shorter file would fault), and checks the version as well as the magic, as the kernel
does before it creates the device. If you would rather not have an environment variable in
libcrypto for a test, I can replace it with an internal hook.

Tests. Four VMClock tests:

  • the existing one (a bump reseeds the public DRBG, the primary and the private DRBG once each);
  • a DRBG chained to a small test seed source that bumps the counter while the DRBG reseeds, which
    only the read after generating can see: the DRBG must reseed a second time, with the prediction
    resistance the caller asked for;
  • the page left odd;
  • four threads drawing from their public and private DRBGs, and so from the shared primary, while
    the counter is bumped 2000 times under them, every hundredth bump holding the page odd for
    200 µs. Afterwards one more bump must reseed the primary exactly once and each thread's public
    DRBG on its next call, and a further call must not reseed. This checks that concurrent callers
    succeed and end settled; it cannot force the interleaving of point 2, which the new order removes
    by construction.

Removing the second read fails the second and third tests; dropping prediction resistance from the
second reseed fails the second; the old unbounded loop hangs the third. drbgtest passed 20 runs out
of 20 here, test_rand, test_rand_config and test_threads pass, and the temporary file is
removed at the end. If the stand-in file cannot be created, the VMClock tests are skipped.

Cost. Where the device exists, the second read adds one more read of the page per generate
call; where it does not, one more check that no page is mapped.

@t8m t8m added branch: master Applies to master branch triaged: feature The issue/pr requests/adds a feature tests: exempted The PR is exempt from requirements for testing tests: present The PR has suitable tests present and removed tests: exempted The PR is exempt from requirements for testing labels Oct 21, 2026
@github-actions github-actions Bot added the severity: fips change The pull request changes FIPS provider sources label Oct 21, 2026
Comment thread doc/man7/openssl-env.pod Resolved
Comment thread providers/implementations/rands/drbg.c Resolved
@KurathSec
KurathSec force-pushed the stutter-vmclock-reseed branch from de57eee to 840d826 Compare November 2, 2026 00:31
paulidale
paulidale previously approved these changes Nov 3, 2026

@paulidale paulidale 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.

LGTM

@openssl-cla-check openssl-cla-check Bot added the hold: cla required The contributor needs to submit a license agreement. label Nov 3, 2026
@KurathSec
KurathSec force-pushed the stutter-vmclock-reseed branch from 6462211 to bf536a9 Compare November 3, 2026 11:19
@openssl-cla-check openssl-cla-check Bot removed the hold: cla required The contributor needs to submit a license agreement. label Nov 3, 2026
@KurathSec
KurathSec force-pushed the stutter-vmclock-reseed branch from 33f20bd to 600a474 Compare November 8, 2026 13:00
@KurathSec

Copy link
Copy Markdown
Contributor Author

Rebased onto master, which picks up the pkcs11-provider update (c4b5515) for the failing external test. @paulidale, your approval was dismissed by the push that addressed @esyr's comment on ossl_safe_getenv(); could you both take another look when you have time?

paulidale
paulidale previously approved these changes Nov 8, 2026

@bukka bukka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks reasonable, just few things

*/
static const char *vmclock_path(void)
{
const char *path = ossl_safe_getenv("OPENSSL_VMCLOCK");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't this be used on on debug build or under some macro like in other similar envs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, it is a test hook. It is now read only where NDEBUG is not defined, and a release build also accepts nothing but the device for the page, no regular file. drbgtest registers the VMClock tests in the same builds, so they run in the --debug jobs. If you would rather have a Configure option than NDEBUG for this, I will change it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't really like that NDEBUG as it kind of doesn't fit. The env is really just for test and I actually wonder if it's needed at all. What I was thinking is to separate the test to its own file (it's kind of separate from drbgtest.c anyway). This new test could then link it statically (using ../libcrypto.a) and could just pre-define OSSL_VMCLOCK_DEVICE. The source would just do ifndef precheck so it can be overwritten just with macro. That could be a bit more flexible and should still work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is changed now. The reader takes the device path from OSSL_VMCLOCK_DEVICE, defined under #ifndef, and no longer reads an environment variable. The VMClock tests moved to test/vmclock_test.c, which defines OSSL_VMCLOCK_DEVICE as a file in its working directory, compiles its own copy of vmclock.c with it and links ../libcrypto.a, so the default provider's DRBGs use that copy; only such a copy accepts a regular file. The tests now run in release builds too. They do not cover the FIPS provider, whose copy of the reader a test cannot replace.

Comment thread providers/implementations/rands/drbg.c Resolved
@KurathSec

KurathSec commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@bukka thank you for the review. Four commits, one per comment, with replies inline:

  • 51afc23 the byte swaps use the built-ins
  • 2c4e079 OPENSSL_VMCLOCK is read only in a debug build
  • dc2d58e a page stuck in mid-update causes one reseed, and one more when it settles
  • a8bacfb a DRBG reseeds again 1 s and 64 s after a change, once the kernel has had time to reseed

CHANGES.md and openssl-env(7) are updated to match.

The commit messages now carry Assisted-by trailers, which changed the hashes above; the tree is the same as at 4becb19.

@KurathSec
KurathSec requested a review from bukka November 10, 2026 15:46
@KurathSec
KurathSec force-pushed the stutter-vmclock-reseed branch from 4becb19 to a8bacfb Compare November 10, 2026 16:24
@KurathSec

Copy link
Copy Markdown
Contributor Author

@bukka, when you have time to take another look, the commits are already in.

@bukka

bukka commented Nov 22, 2026

Copy link
Copy Markdown
Member

@KurathSec It looks good. Just added comment to that env as I'm not sure it's needed. Otherwise I think it's good.

A guest restored from a snapshot continues with the memory it had when the
snapshot was taken, the DRBG states included, and its clocks resume from the
snapshot too, so neither the pid check nor the time-based reseed sees the
restore, and two guests loaded from one snapshot continue the same DRBG state
until the next scheduled reseed. Linux exposes the hypervisor's VMClock page
as /dev/vmclock0; its vm_generation_counter (Linux 7.0) changes every time
the guest is loaded from saved state and its disruption_marker on a restore
or a live migration. Firecracker attaches the device to every guest, QEMU
with -device vmclock.

Map the page once and read the two fields under its sequence lock on every
generate call, and treat a change like a change of pid. Hosts without the
device are unaffected. OPENSSL_VMCLOCK names another file for tests; the new
drbgtest case bumps the counter on such a file and checks that the public
DRBG and the primary reseed once.

Assisted-by: Claude Code:claude-fable-5-1
Every field of the VMClock page is little-endian; convert the fields
read, and check the version as well as the magic. Open the page with
O_NONBLOCK and map only a character device or a regular file that holds
the whole structure. Bound the wait on the page's sequence count and
treat a read that gives up as a change, so that a page left in
mid-update costs a reseed and cannot keep a DRBG lock held. Read,
compare and store the epoch under the DRBG's lock, so that the
remembered value cannot move backwards. After generating, read the
epoch again, as the vDSO getrandom() does, and if it moved, reseed with
the caller's prediction resistance and additional input and generate
the output once more; clear the output if that fails. Use the page only
where the compiler provides the fences.

drbgtest gains a test with a seed source that moves the counter while a
DRBG reseeds from it, one that leaves the page in mid-update, and one
with four threads drawing while the counter moves; the stand-in file is
removed at the end, and the VMClock tests are skipped if it cannot be
created. CHANGES now names the default provider and states that the
reseed is only as fresh as the guest kernel's generator.

Assisted-by: Claude Code:claude-opus-5-5
The fake VMClock page is shared by every library context. Each VMClock
test now runs in its own context and puts the generation counter back
before it returns, so the default DRBGs' reseed counts, which
test_rand_fork_safety and test_rand_reseed compare, do not depend on
the test order (OPENSSL_TEST_RAND_ORDER).

Use snprintf rather than BIO_snprintf, deprecated in 4.0, and
OSSL_sleep rather than usleep, which a strict C99 build does not
declare. Document OPENSSL_VMCLOCK in openssl-env(7).

Assisted-by: Claude Code:claude-opus-5-5
Move the VMClock reader from providers/implementations/rands/seeding/,
which holds the entropy sources, to providers/implementations/rands/
beside drbg.c, and build it into the FIPS provider as well as the
default one. The DRBGs of both providers reseed when the generation
changes.

The mapping belongs to the library context, in the OSSL_LIB_CTX slot 7
that was unused: the first DRBG created in a context maps the page, and
freeing the context unmaps it, so the FIPS provider keeps no global
data outside a library context. The FIPS provider has no
ossl_safe_getenv(), so it reads OPENSSL_VMCLOCK after making the check
of OPENSSL_issetugid() itself.

drbgtest takes an optional configuration file; given one, it runs only
the VMClock tests, in library contexts that load it. test_rand runs it
with fips-and-base.cnf when the FIPS provider is built; FIPS providers
older than 4.2 are skipped.

Drop the security-sensitive note on OPENSSL_VMCLOCK in openssl-env(7).

Assisted-by: Claude Code:claude-opus-5-5
Move getenv.c and uid.c from libcrypto's own sources to UTIL_COMMON, so
that the FIPS provider has ossl_safe_getenv() and OPENSSL_issetugid()
too, and read OPENSSL_VMCLOCK through ossl_safe_getenv() in both
providers.

Assisted-by: Claude Code:claude-opus-5-5
Give ossl_prov_vmclock_ctx_new(), ossl_prov_vmclock_ctx_free(),
ossl_prov_vmclock_page() and ossl_prov_vmclock_changed() the doxygen
blocks that DOCUMENTATION.md asks of internal functions.

Assisted-by: Claude Code:claude-opus-5-5
The page's little-endian fields are converted in code that is compiled
only for Linux with GCC or a compatible compiler, so the three helpers
can use __builtin_bswap16(), __builtin_bswap32() and __builtin_bswap64()
in place of shifts.

Assisted-by: Claude Code:claude-fable-5-2
OPENSSL_VMCLOCK lets a test name a file in place of /dev/vmclock0. It is
now read only where NDEBUG is not defined, as is the acceptance of a
regular file for the page; a release build opens the device and nothing
else. drbgtest registers the VMClock tests in the same builds.

Assisted-by: Claude Code:claude-fable-5-2
A read gives up when the page's sequence count stays odd for all of its
looks. The first read that gives up counts as a change and the DRBG
reseeds; it is then left alone until the page can be read again, which
counts as a change once more, whatever the counter holds by then. While
the page is unreadable a call looks at it once, so a page that does not
settle costs a generate call two loads and no reseed, and is treated,
after the one reseed, like a missing device.

What a DRBG remembers between looks moves into PROV_VMCLOCK_STATE, which
keeps the unreadable state apart from the generation value.

Assisted-by: Claude Code:claude-fable-5-2
The reseed that a change causes draws on the kernel's generator, and the
page can change before the guest's kernel has reseeded its own: the
kernel does that on the VMGenID notification, shortly after the guest
resumes, or else on its periodic reseed, at most 60 seconds apart. A DRBG
called sooner takes seed that every copy of the snapshot may hold.

After a change a DRBG therefore reseeds again on its first call at least
one second, and at least 64 seconds, after the reseed that the change
caused. The waits count from the completion of that reseed, which for a
DRBG with a parent comes after the parent's, so a DRBG whose wait is over
takes seed from a parent that has reseeded after the wait as well. They
are counted on the monotonic clock.

This bounds how long a DRBG keeps such seed. Output drawn before the
kernel has reseeded can still repeat across the copies.

Assisted-by: Claude Code:claude-fable-5-2
OSSL_VMCLOCK_DEVICE names the device, and a test may define it to name a
regular file instead; only such a copy of the reader accepts a regular
file. The reader no longer looks at an environment variable, so debug
and release builds read the page the same way.

The VMClock tests move from drbgtest to vmclock_test, which builds its
own copy of the reader with a file in its working directory in place of
the device and links libcrypto statically, so that the default
provider's DRBGs use that copy. They run in every build on Linux.

Assisted-by: Claude Code:claude-opus-5-5
The FIPS provider took getenv.c and uid.c from UTIL_COMMON for the
VMClock reader's environment variable, which the reader no longer
reads. Nothing in the provider calls ossl_safe_getenv() or
OPENSSL_issetugid() now, so they go back to libcrypto's own sources.

Assisted-by: Claude Code:claude-opus-5-5
@KurathSec
KurathSec force-pushed the stutter-vmclock-reseed branch from 43f5250 to 89a189b Compare November 23, 2026 12:33
@KurathSec

Copy link
Copy Markdown
Contributor Author

Rebased onto master for the conflict in CHANGES.md with the new ML-DSA entry; nothing else changed. 7aac64e and 43f5250 are now 83fd1be and 89a189b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: review pending This pull request needs review by a committer branch: master Applies to master branch severity: fips change The pull request changes FIPS provider sources tests: present The PR has suitable tests present triaged: feature The issue/pr requests/adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants