20251210-linuxkm-get_drbg-local_bh_disable #9519
Merged
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.
linuxkm/lkcapi_sha_glue.c:get_drbg(), calllocal_bh_disable()for thecrypto_default_rng, and input_drbg(), calllocal_bh_enable()if needed.migrate_disable()andmigrate_enable()so they're called for any SMP kernel >= 5.7, regardless ofCONFIG_PREEMPT_COUNT.get_drbg_n(), if the caller can't sleep, return immediately if the requested DRBG is busy, to avoid priority inversions and deadlocks.tested with
FORCE_BOOT_LOOP_FOREVER=1 wolfssl-multi-test.sh ... linuxkm-fips-v5-strict-dist-insmod-cust-kernel-2for 101 iterations withdd if=/dev/urandom of=/dev/zero bs=1M count=1200added to the exercise.also tested with
quantum-safe-wolfssl-all-crypto-only-intelasm-fips-dev-linuxkm-next-insmodand'linuxkm-legacy-[56].*-insmod'for portability verification.explanation of the bug fix:
The root cause of the bug was that on non-intelasm modules, the DRBG generator could be interrupted by a softirq that tries to stir entropy into the very same DRBG, resulting in a deadlock as the kthread holding the lock tried to get the lock. With the fixes in this PR, the generator wrapper now always explicitly disables softirqs before locking the DRBG, and the entropy stir-in point of entry fails gracefully if the caller has interrupts disabled and the DRBG can't be locked on the first try.