Skip to content

Commit 097cd57

Browse files
committed
linuxkm/module_hooks.c: in wc_linuxkm_GenerateSeed_IntelRD(), log when RDSEED support is missing, and add verbose logging for generation failures.
1 parent 1d64a4e commit 097cd57

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

linuxkm/module_hooks.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,38 @@ int wc_linuxkm_GenerateSeed_IntelRD(struct OS_Seed* os, byte* output, word32 sz)
369369

370370
wc_InitRng_IntelRD();
371371

372-
if (!IS_INTEL_RDSEED(intel_flags))
372+
if (!IS_INTEL_RDSEED(intel_flags)) {
373+
static wolfSSL_Atomic_Int warned_on_missing_RDSEED = WOLFSSL_ATOMIC_INITIALIZER(0);
374+
int expected_warned_on_missing_RDSEED = 0;
375+
if (wolfSSL_Atomic_Int_CompareExchange(
376+
&warned_on_missing_RDSEED, &expected_warned_on_missing_RDSEED, 1))
377+
{
378+
pr_err("ERROR: wc_linuxkm_GenerateSeed_IntelRD() called on CPU without RDSEED support.\n");
379+
}
373380
return -1;
381+
}
374382

375383
for (; (sz / sizeof(word64)) > 0; sz -= sizeof(word64),
376384
output += sizeof(word64)) {
377385
ret = IntelRDseed64_r((word64*)output);
378-
if (ret != 0)
386+
if (ret != 0) {
387+
#ifdef WOLFSSL_LINUXKM_VERBOSE_DEBUG
388+
pr_err("ERROR: IntelRDseed64_r() returned code %d.\n", ret);
389+
#endif
379390
return ret;
391+
}
380392
}
381393
if (sz == 0)
382394
return 0;
383395

384396
/* handle unaligned remainder */
385397
ret = IntelRDseed64_r(&rndTmp);
386-
if (ret != 0)
398+
if (ret != 0) {
399+
#ifdef WOLFSSL_LINUXKM_VERBOSE_DEBUG
400+
pr_err("ERROR: IntelRDseed64_r() returned code %d.\n", ret);
401+
#endif
387402
return ret;
403+
}
388404

389405
XMEMCPY(output, &rndTmp, sz);
390406
wc_ForceZero(&rndTmp, sizeof(rndTmp));

0 commit comments

Comments
 (0)