Commit Graph

4 Commits

Author SHA1 Message Date
b5844c443f bcrypt_rng: BCryptCloseAlgorithmProvider waits for a BCryptGenRandom in flight
gen_random() looked the handle up under g_lock (shared), released the
lock, and then called the host BCryptGenRandom with the host handle. A
concurrent close_algorithm_provider() could unlink the wrapper, close the
host handle and free the wrapper while the host call was still using it
(kevincommits' finding in #1608, item 3).

gen_random() now keeps g_lock shared across the lookup and the host call,
and close_algorithm_provider() closes the host handle under the exclusive
lock, so a close waits for calls in flight on any handle and no later
call can find the closed one. Calls still run side by side. The
system-preferred path takes no handle and no lock, and the seeded path
fills after the shared hold ends, since fill_seeded() takes the lock
exclusive.

A test hook, swap_host_functions_for_test(), lets bcrypt_rng_test install
fake host functions: the fake generate call blocks until released, and
the fake close records whether a call was still running. The new case
fails twice with main's bcrypt_rng.cpp (hook only) and passes with the
fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 18:42:21 -06:00
76a03f293f test(bcrypt_rng): exercise fail-closed STATUS_UNSUCCESSFUL path when host CSPRNG unavailable 2026-11-24 05:30:36 +07:00
5d801afc11 bcrypt_rng: fail closed on missing host CSPRNG and log seeded mode once 2026-11-24 04:44:30 +07:00
f967225be8 runtime/shims: shim bcrypt.dll provider lifecycle and RNG with deterministic seed support
Refs: https://github.com/ItsNotRexed/Leonida/issues/9065#issuecomment-7114352737
2026-11-24 04:23:26 +07:00