Use the CPU RNG for entropy (rhbz 1572944)
This commit is contained in:
parent
8465477d10
commit
c96d1d09f0
@ -0,0 +1,78 @@
|
||||
From 39a8883a2b989d1d21bd8dd99f5557f0c5e89694 Mon Sep 17 00:00:00 2001
|
||||
From: Theodore Ts'o <tytso@mit.edu>
|
||||
Date: Tue, 17 Jul 2018 18:24:27 -0400
|
||||
Subject: [PATCH] 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>
|
||||
---
|
||||
drivers/char/Kconfig | 14 ++++++++++++++
|
||||
drivers/char/random.c | 11 ++++++++++-
|
||||
2 files changed, 24 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
|
||||
index 212f447938ae..ce277ee0a28a 100644
|
||||
--- a/drivers/char/Kconfig
|
||||
+++ b/drivers/char/Kconfig
|
||||
@@ -554,3 +554,17 @@ config ADI
|
||||
|
||||
endmenu
|
||||
|
||||
+config RANDOM_TRUST_CPU
|
||||
+ bool "Trust the CPU manufacturer to initialize Linux's CRNG"
|
||||
+ depends on X86 || S390 || PPC
|
||||
+ default n
|
||||
+ help
|
||||
+ Assume that CPU manufacturer (e.g., Intel or AMD for RDSEED or
|
||||
+ RDRAND, IBM for the S390 and Power PC architectures) is trustworthy
|
||||
+ for the purposes of initializing Linux's CRNG. Since this is not
|
||||
+ something that can be independently audited, this amounts to trusting
|
||||
+ that CPU manufacturer (perhaps with the insistence or mandate
|
||||
+ of a Nation State's intelligence or law enforcement agencies)
|
||||
+ has not installed a hidden back door to compromise the CPU's
|
||||
+ random number generation facilities.
|
||||
+
|
||||
diff --git a/drivers/char/random.c b/drivers/char/random.c
|
||||
index 34ddfd57419b..f4013b8a711b 100644
|
||||
--- a/drivers/char/random.c
|
||||
+++ b/drivers/char/random.c
|
||||
@@ -782,6 +782,7 @@ static void invalidate_batched_entropy(void);
|
||||
static void crng_initialize(struct crng_state *crng)
|
||||
{
|
||||
int i;
|
||||
+ int arch_init = 1;
|
||||
unsigned long rv;
|
||||
|
||||
memcpy(&crng->state[0], "expand 32-byte k", 16);
|
||||
@@ -792,10 +793,18 @@ static void crng_initialize(struct crng_state *crng)
|
||||
_get_random_bytes(&crng->state[4], sizeof(__u32) * 12);
|
||||
for (i = 4; i < 16; i++) {
|
||||
if (!arch_get_random_seed_long(&rv) &&
|
||||
- !arch_get_random_long(&rv))
|
||||
+ !arch_get_random_long(&rv)) {
|
||||
rv = random_get_entropy();
|
||||
+ arch_init = 0;
|
||||
+ }
|
||||
crng->state[i] ^= rv;
|
||||
}
|
||||
+#ifdef CONFIG_RANDOM_TRUST_CPU
|
||||
+ if (arch_init) {
|
||||
+ crng_init = 2;
|
||||
+ pr_notice("random: crng done (trusting CPU's manufacturer)\n");
|
||||
+ }
|
||||
+#endif
|
||||
crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
|
||||
}
|
||||
|
||||
--
|
||||
2.17.1
|
||||
|
82
0001-random-make-CPU-trust-a-boot-parameter.patch
Normal file
82
0001-random-make-CPU-trust-a-boot-parameter.patch
Normal file
@ -0,0 +1,82 @@
|
||||
From 9b25436662d5fb4c66eb527ead53cab15f596ee0 Mon Sep 17 00:00:00 2001
|
||||
From: Kees Cook <keescook@chromium.org>
|
||||
Date: Mon, 27 Aug 2018 14:51:54 -0700
|
||||
Subject: [PATCH] random: make CPU trust a boot parameter
|
||||
|
||||
Instead of forcing a distro or other system builder to choose
|
||||
at build time whether the CPU is trusted for CRNG seeding via
|
||||
CONFIG_RANDOM_TRUST_CPU, provide a boot-time parameter for end users to
|
||||
control the choice. The CONFIG will set the default state instead.
|
||||
|
||||
Signed-off-by: Kees Cook <keescook@chromium.org>
|
||||
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
||||
---
|
||||
Documentation/admin-guide/kernel-parameters.txt | 6 ++++++
|
||||
drivers/char/Kconfig | 4 ++--
|
||||
drivers/char/random.c | 11 ++++++++---
|
||||
3 files changed, 16 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
|
||||
index 0c8f7889efa1..227c5c6fa4c1 100644
|
||||
--- a/Documentation/admin-guide/kernel-parameters.txt
|
||||
+++ b/Documentation/admin-guide/kernel-parameters.txt
|
||||
@@ -3390,6 +3390,12 @@
|
||||
ramdisk_size= [RAM] Sizes of RAM disks in kilobytes
|
||||
See Documentation/blockdev/ramdisk.txt.
|
||||
|
||||
+ random.trust_cpu={on,off}
|
||||
+ [KNL] Enable or disable trusting the use of the
|
||||
+ CPU's random number generator (if available) to
|
||||
+ fully seed the kernel's CRNG. Default is controlled
|
||||
+ by CONFIG_RANDOM_TRUST_CPU.
|
||||
+
|
||||
ras=option[,option,...] [KNL] RAS-specific options
|
||||
|
||||
cec_disable [X86]
|
||||
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
|
||||
index ce277ee0a28a..40728491f37b 100644
|
||||
--- a/drivers/char/Kconfig
|
||||
+++ b/drivers/char/Kconfig
|
||||
@@ -566,5 +566,5 @@ config RANDOM_TRUST_CPU
|
||||
that CPU manufacturer (perhaps with the insistence or mandate
|
||||
of a Nation State's intelligence or law enforcement agencies)
|
||||
has not installed a hidden back door to compromise the CPU's
|
||||
- random number generation facilities.
|
||||
-
|
||||
+ random number generation facilities. This can also be configured
|
||||
+ at boot with "random.trust_cpu=on/off".
|
||||
diff --git a/drivers/char/random.c b/drivers/char/random.c
|
||||
index bf5f99fc36f1..c75b6cdf0053 100644
|
||||
--- a/drivers/char/random.c
|
||||
+++ b/drivers/char/random.c
|
||||
@@ -779,6 +779,13 @@ static struct crng_state **crng_node_pool __read_mostly;
|
||||
|
||||
static void invalidate_batched_entropy(void);
|
||||
|
||||
+static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU);
|
||||
+static int __init parse_trust_cpu(char *arg)
|
||||
+{
|
||||
+ return kstrtobool(arg, &trust_cpu);
|
||||
+}
|
||||
+early_param("random.trust_cpu", parse_trust_cpu);
|
||||
+
|
||||
static void crng_initialize(struct crng_state *crng)
|
||||
{
|
||||
int i;
|
||||
@@ -799,12 +806,10 @@ static void crng_initialize(struct crng_state *crng)
|
||||
}
|
||||
crng->state[i] ^= rv;
|
||||
}
|
||||
-#ifdef CONFIG_RANDOM_TRUST_CPU
|
||||
- if (arch_init) {
|
||||
+ if (trust_cpu && arch_init) {
|
||||
crng_init = 2;
|
||||
pr_notice("random: crng done (trusting CPU's manufacturer)\n");
|
||||
}
|
||||
-#endif
|
||||
crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
|
||||
}
|
||||
|
||||
--
|
||||
2.17.1
|
||||
|
1
configs/fedora/generic/CONFIG_RANDOM_TRUST_CPU
Normal file
1
configs/fedora/generic/CONFIG_RANDOM_TRUST_CPU
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
@ -4659,6 +4659,7 @@ CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOMIZE_BASE=y
|
||||
CONFIG_RANDOMIZE_MODULE_REGION_FULL=y
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
CONFIG_RAS_CEC=y
|
||||
CONFIG_RASPBERRYPI_FIRMWARE=y
|
||||
CONFIG_RASPBERRYPI_POWER=y
|
||||
|
@ -4636,6 +4636,7 @@ CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOMIZE_BASE=y
|
||||
CONFIG_RANDOMIZE_MODULE_REGION_FULL=y
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
CONFIG_RAS_CEC=y
|
||||
CONFIG_RASPBERRYPI_FIRMWARE=y
|
||||
CONFIG_RASPBERRYPI_POWER=y
|
||||
|
@ -4939,6 +4939,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
CONFIG_RAS_CEC=y
|
||||
CONFIG_RASPBERRYPI_FIRMWARE=y
|
||||
CONFIG_RASPBERRYPI_POWER=y
|
||||
|
@ -4663,6 +4663,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
CONFIG_RAS_CEC=y
|
||||
CONFIG_RASPBERRYPI_FIRMWARE=y
|
||||
CONFIG_RASPBERRYPI_POWER=y
|
||||
|
@ -4640,6 +4640,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
CONFIG_RAS_CEC=y
|
||||
CONFIG_RASPBERRYPI_FIRMWARE=y
|
||||
CONFIG_RASPBERRYPI_POWER=y
|
||||
|
@ -4916,6 +4916,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
CONFIG_RAS_CEC=y
|
||||
CONFIG_RASPBERRYPI_FIRMWARE=y
|
||||
CONFIG_RASPBERRYPI_POWER=y
|
||||
|
@ -4391,6 +4391,7 @@ CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOMIZE_BASE=y
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -4415,6 +4415,7 @@ CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOMIZE_BASE=y
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -4415,6 +4415,7 @@ CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOMIZE_BASE=y
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -4391,6 +4391,7 @@ CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOMIZE_BASE=y
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -4221,6 +4221,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -4195,6 +4195,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -4159,6 +4159,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -4133,6 +4133,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -4049,6 +4049,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
CONFIG_RAW_DRIVER=y
|
||||
|
@ -4023,6 +4023,7 @@ CONFIG_RADIO_WL1273=m
|
||||
CONFIG_RADIO_ZOLTRIX=m
|
||||
CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
CONFIG_RAW_DRIVER=y
|
||||
|
@ -4459,6 +4459,7 @@ CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOMIZE_BASE=y
|
||||
CONFIG_RANDOMIZE_MEMORY=y
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -4435,6 +4435,7 @@ CONFIG_RAID_ATTRS=m
|
||||
# CONFIG_RANDOM32_SELFTEST is not set
|
||||
CONFIG_RANDOMIZE_BASE=y
|
||||
CONFIG_RANDOMIZE_MEMORY=y
|
||||
CONFIG_RANDOM_TRUST_CPU=y
|
||||
# CONFIG_RAPIDIO is not set
|
||||
CONFIG_RAS_CEC=y
|
||||
# CONFIG_RAVE_SP_CORE is not set
|
||||
|
@ -627,6 +627,10 @@ Patch504: xsa270.patch
|
||||
# rhbz 1627963 1628715
|
||||
Patch505: HID-fixes.patch
|
||||
|
||||
# rhbz 1572944
|
||||
Patch506: 0001-random-add-a-config-option-to-trust-the-CPU-s-hwrng.patch
|
||||
Patch507: 0001-random-make-CPU-trust-a-boot-parameter.patch
|
||||
|
||||
# END OF PATCH DEFINITIONS
|
||||
|
||||
%endif
|
||||
@ -1876,6 +1880,9 @@ fi
|
||||
#
|
||||
#
|
||||
%changelog
|
||||
* Thu Sep 13 2018 Laura Abbott <labbott@redhat.com>
|
||||
- Use the CPU RNG for entropy (rhbz 1572944)
|
||||
|
||||
* Thu Sep 13 2018 Laura Abbott <labbott@redhat.com>
|
||||
- HID fixes (rhbz 1627963 1628715)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user