Skip to content

Commit 39a8883

Browse files
committed
random: add a config option to trust the CPU's hwrng
This gives the user building their own kernel (or a Linux distribution) the option of deciding whether or not to trust the CPU's hardware random number generator (e.g., RDRAND for x86 CPU's) as being correctly implemented and not having a back door introduced (perhaps courtesy of a Nation State's law enforcement or intelligence agencies). This will prevent getrandom(2) from blocking, if there is a willingness to trust the CPU manufacturer. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 3672476 commit 39a8883

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

drivers/char/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,17 @@ config ADI
554554

555555
endmenu
556556

557+
config RANDOM_TRUST_CPU
558+
bool "Trust the CPU manufacturer to initialize Linux's CRNG"
559+
depends on X86 || S390 || PPC
560+
default n
561+
help
562+
Assume that CPU manufacturer (e.g., Intel or AMD for RDSEED or
563+
RDRAND, IBM for the S390 and Power PC architectures) is trustworthy
564+
for the purposes of initializing Linux's CRNG. Since this is not
565+
something that can be independently audited, this amounts to trusting
566+
that CPU manufacturer (perhaps with the insistence or mandate
567+
of a Nation State's intelligence or law enforcement agencies)
568+
has not installed a hidden back door to compromise the CPU's
569+
random number generation facilities.
570+

drivers/char/random.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ static void invalidate_batched_entropy(void);
782782
static void crng_initialize(struct crng_state *crng)
783783
{
784784
int i;
785+
int arch_init = 1;
785786
unsigned long rv;
786787

787788
memcpy(&crng->state[0], "expand 32-byte k", 16);
@@ -792,10 +793,18 @@ static void crng_initialize(struct crng_state *crng)
792793
_get_random_bytes(&crng->state[4], sizeof(__u32) * 12);
793794
for (i = 4; i < 16; i++) {
794795
if (!arch_get_random_seed_long(&rv) &&
795-
!arch_get_random_long(&rv))
796+
!arch_get_random_long(&rv)) {
796797
rv = random_get_entropy();
798+
arch_init = 0;
799+
}
797800
crng->state[i] ^= rv;
798801
}
802+
#ifdef CONFIG_RANDOM_TRUST_CPU
803+
if (arch_init) {
804+
crng_init = 2;
805+
pr_notice("random: crng done (trusting CPU's manufacturer)\n");
806+
}
807+
#endif
799808
crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
800809
}
801810

0 commit comments

Comments
 (0)