Skip to content

Commit dd6da70

Browse files
Merge pull request #10732 from douzzer/20260618-FORCE_FAILURE_RDSEED-fixes
20260618-FORCE_FAILURE_RDSEED-fixes
2 parents d379e83 + 296bfc8 commit dd6da70

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

linuxkm/linuxkm_wc_port.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
#endif
218218
#endif
219219

220-
#if defined(HAVE_FIPS) && FIPS_VERSION3_LT(5, 2, 4)
220+
#if defined(HAVE_FIPS) && FIPS_VERSION3_LT(7, 0, 0)
221221
#if defined(HAVE_HASHDRBG) && \
222222
defined(HAVE_ENTROPY_MEMUSE) && \
223223
!defined(WC_LINUXKM_WOLFENTROPY_IN_GLUE_LAYER)
@@ -227,6 +227,11 @@
227227
!defined(HAVE_ENTROPY_MEMUSE) && \
228228
!defined(WC_LINUXKM_RDSEED_IN_GLUE_LAYER)
229229
#define WC_LINUXKM_RDSEED_IN_GLUE_LAYER
230+
/* Work around -Wmaybe-uninitialized in old FIPS random.c.
231+
* Glue-layer wc_linuxkm_GenerateSeed_IntelRD() always forces
232+
* failure if RDSEED is missing or fails.
233+
*/
234+
#undef FORCE_FAILURE_RDSEED
230235
#endif
231236
#endif
232237
#if defined(WC_LINUXKM_WOLFENTROPY_IN_GLUE_LAYER)

wolfcrypt/src/random.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,7 +3934,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
39343934
}
39353935
#endif
39363936

3937-
#ifdef HAVE_INTEL_RDSEED
3937+
#if defined(HAVE_INTEL_RDSEED) || defined(HAVE_AMD_RDSEED)
39383938
if (IS_INTEL_RDSEED(intel_flags)) {
39393939
if (!wc_GenerateSeed_IntelRD(NULL, output, sz)) {
39403940
/* success, we're done */
@@ -3945,7 +3945,13 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
39453945
return READ_RAN_E;
39463946
#endif
39473947
}
3948-
#endif /* HAVE_INTEL_RDSEED */
3948+
#ifdef FORCE_FAILURE_RDSEED
3949+
else {
3950+
/* Don't fall back to system randomness */
3951+
return MISSING_RNG_E;
3952+
}
3953+
#endif
3954+
#endif /* HAVE_INTEL_RDSEED || HAVE_AMD_RDSEED */
39493955

39503956
#ifdef WIN_REUSE_CRYPT_HANDLE
39513957
/* Check that handle was initialized.
@@ -4914,7 +4920,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
49144920
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
49154921
{
49164922
(void)os;
4917-
int ret;
4923+
int ret = WC_NO_ERR_TRACE(RNG_FAILURE_E);
49184924

49194925
#ifdef HAVE_ENTROPY_MEMUSE
49204926
ret = wc_Entropy_Get(MAX_ENTROPY_BITS, output, sz);
@@ -4934,6 +4940,12 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
49344940
return ret;
49354941
#endif
49364942
}
4943+
#ifdef FORCE_FAILURE_RDSEED
4944+
else {
4945+
/* Don't fall back to get_random_bytes() */
4946+
return MISSING_RNG_E;
4947+
}
4948+
#endif
49374949
#endif /* HAVE_INTEL_RDSEED || HAVE_AMD_RDSEED */
49384950

49394951
#ifdef LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT
@@ -4957,7 +4969,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
49574969
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
49584970
{
49594971
(void)os;
4960-
int ret;
4972+
int ret = WC_NO_ERR_TRACE(RNG_FAILURE_E);
49614973

49624974
#ifdef HAVE_ENTROPY_MEMUSE
49634975
ret = wc_Entropy_Get(MAX_ENTROPY_BITS, output, sz);
@@ -4980,6 +4992,12 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
49804992
return ret;
49814993
}
49824994
}
4995+
#ifdef FORCE_FAILURE_RDSEED
4996+
else {
4997+
/* Don't fall back to arc4random_buf() */
4998+
return MISSING_RNG_E;
4999+
}
5000+
#endif
49835001
#endif /* HAVE_INTEL_RDSEED || HAVE_AMD_RDSEED */
49845002

49855003
(void)ret;

0 commit comments

Comments
 (0)