Skip to content

Commit

Permalink
v23.05.5 test release
Browse files Browse the repository at this point in the history
waiting for v24.10.0-rc1
follow upstream changes

Signed-off-by: Nicholas Sun <nicholas-sun@outlook.com>
  • Loading branch information
nicholas-opensource committed Oct 4, 2024
1 parent 6dbc5ba commit 0b06200
Show file tree
Hide file tree
Showing 36 changed files with 139 additions and 93 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 7d6d5d1f77e12aac55d6866680953834b6f9d02f Mon Sep 17 00:00:00 2001
From 97702627d98871f458fbbbcb8a3e9f0c94eab32e Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Tue, 25 Apr 2023 22:22:44 +0200
Subject: [PATCH v54 01/25] LRNG: Entropy Source and DRNG Manager
Subject: [PATCH v56 01/25] LRNG: Entropy Source and DRNG Manager

The kernel crypto API contains deterministic random number generators
(DRNG) which a caller must seed and reseed. The task of seeding a DRNG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From d16bd27b6b5a601b1f7a32a3aaa5902789a96e04 Mon Sep 17 00:00:00 2001
From 1709738191e259781661475ec28ec4131646ec74 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Sun, 15 May 2022 15:40:46 +0200
Subject: [PATCH v54 02/25] LRNG - allocate one DRNG instance per NUMA node
Subject: [PATCH v56 02/25] LRNG - allocate one DRNG instance per NUMA node

In order to improve NUMA-locality when serving getrandom(2) requests,
allocate one DRNG instance per node.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From a84797fca4d52f9d04efc3324a11b6563e3055ad Mon Sep 17 00:00:00 2001
From e120986802c8263caa77a27d1d26a22aa7140dc6 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Sun, 18 Dec 2022 21:12:42 +0100
Subject: [PATCH v54 03/25] LRNG - /proc interface
Subject: [PATCH v56 03/25] LRNG - /proc interface

The patch adds the file lrng_type which provides details about
the LRNG:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 65ec0bf459062920eda9b5760c3490328a58b3fe Mon Sep 17 00:00:00 2001
From ecf010dc84f1eb933a6c54d022e108b7227a6845 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Mon, 20 Feb 2023 22:02:06 +0100
Subject: [PATCH v54 04/25] LRNG - add switchable DRNG support
Subject: [PATCH v56 04/25] LRNG - add switchable DRNG support

The DRNG switch support allows replacing the DRNG mechanism of the
LRNG. The switching support rests on the interface definition of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 6134a95c87d8e9137458631319c6d7cd0f485361 Mon Sep 17 00:00:00 2001
From 70b1edffaa3ea044545962666548124e1872115a Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Sun, 15 May 2022 16:01:44 +0200
Subject: [PATCH v54 05/25] LRNG - add common generic hash support
Subject: [PATCH v56 05/25] LRNG - add common generic hash support

The LRNG switchable DRNG support also allows the replacement of the hash
implementation used as conditioning component. The common generic hash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From de74ad0f7fd8308c6a85e01a02ef25db800bf72c Mon Sep 17 00:00:00 2001
From 367e6de94ae073eaacdd5618fa5d3c662417abca Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Thu, 21 Mar 2024 14:17:33 +0100
Subject: [PATCH v54 06/25] crypto: DRBG - externalize DRBG functions for LRNG
Subject: [PATCH v56 06/25] crypto: DRBG - externalize DRBG functions for LRNG

This patch allows several DRBG functions to be called by the LRNG kernel
code paths outside the drbg.c file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From cfe74800406f877aae5dbd5a4fa3662100c51686 Mon Sep 17 00:00:00 2001
From f2adaf830c3738be1aa466cbd9607ed323a3e814 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Mon, 20 Feb 2023 22:22:25 +0100
Subject: [PATCH v54 07/25] LRNG - add SP800-90A DRBG extension
Date: Sun, 28 Jul 2024 21:39:01 +0200
Subject: [PATCH v56 07/25] LRNG - add SP800-90A DRBG extension

Using the LRNG switchable DRNG support, the SP800-90A DRBG extension is
implemented.
Expand All @@ -22,10 +22,10 @@ provide random data produced by an SP800-90A DRBG.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
---
drivers/char/lrng/Kconfig | 78 ++++++-------
drivers/char/lrng/Kconfig | 78 +++++------
drivers/char/lrng/Makefile | 1 +
drivers/char/lrng/lrng_drng_drbg.c | 179 +++++++++++++++++++++++++++++
3 files changed, 219 insertions(+), 39 deletions(-)
drivers/char/lrng/lrng_drng_drbg.c | 215 +++++++++++++++++++++++++++++
3 files changed, 255 insertions(+), 39 deletions(-)
create mode 100644 drivers/char/lrng/lrng_drng_drbg.c

--- a/drivers/char/lrng/Kconfig
Expand Down Expand Up @@ -145,7 +145,7 @@ Signed-off-by: Stephan Mueller <smueller@chronox.de>
+obj-$(CONFIG_LRNG_DRBG) += lrng_drng_drbg.o
--- /dev/null
+++ b/drivers/char/lrng/lrng_drng_drbg.c
@@ -0,0 +1,179 @@
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/*
+ * Backend for the LRNG providing the cryptographic primitives using the
Expand All @@ -157,8 +157,8 @@ Signed-off-by: Stephan Mueller <smueller@chronox.de>
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <crypto/drbg.h>
+#include <linux/lrng.h>
+#include <linux/init.h>
+#include <linux/lrng.h>
+#include <linux/module.h>
+
+#include "lrng_drng_drbg.h"
Expand Down Expand Up @@ -193,23 +193,26 @@ Signed-off-by: Stephan Mueller <smueller@chronox.de>
+MODULE_PARM_DESC(lrng_drbg_type, "DRBG type used for LRNG (0->CTR_DRBG, 1->HMAC_DRBG, 2->Hash_DRBG)");
+
+struct lrng_drbg {
+ const char *hash_name;
+ const char *drbg_core;
+ const char* hash_name;
+ const char* drbg_core;
+};
+
+static const struct lrng_drbg lrng_drbg_types[] = {
+ { /* CTR_DRBG with AES-256 using derivation function */
+ {
+ /* CTR_DRBG with AES-256 using derivation function */
+ .drbg_core = "drbg_nopr_ctr_aes256",
+ }, { /* HMAC_DRBG with SHA-512 */
+ }, {
+ /* HMAC_DRBG with SHA-512 */
+ .drbg_core = "drbg_nopr_hmac_sha512",
+ }, { /* Hash_DRBG with SHA-512 using derivation function */
+ }, {
+ /* Hash_DRBG with SHA-512 using derivation function */
+ .drbg_core = "drbg_nopr_sha512"
+ }
+};
+
+static int lrng_drbg_drng_seed_helper(void *drng, const u8 *inbuf, u32 inbuflen)
+static int lrng_drbg_drng_seed_helper(void* drng, const u8* inbuf, u32 inbuflen)
+{
+ struct drbg_state *drbg = (struct drbg_state *)drng;
+ struct drbg_state* drbg = (struct drbg_state*)drng;
+ LIST_HEAD(seedlist);
+ struct drbg_string data;
+ int ret;
Expand All @@ -224,16 +227,16 @@ Signed-off-by: Stephan Mueller <smueller@chronox.de>
+ return ret;
+}
+
+static int lrng_drbg_drng_generate_helper(void *drng, u8 *outbuf, u32 outbuflen)
+static int lrng_drbg_drng_generate_helper(void* drng, u8* outbuf, u32 outbuflen)
+{
+ struct drbg_state *drbg = (struct drbg_state *)drng;
+ struct drbg_state* drbg = (struct drbg_state*)drng;
+
+ return drbg->d_ops->generate(drbg, outbuf, outbuflen, NULL);
+}
+
+static void *lrng_drbg_drng_alloc(u32 sec_strength)
+static void* lrng_drbg_drng_alloc(u32 sec_strength)
+{
+ struct drbg_state *drbg;
+ struct drbg_state* drbg;
+ int coreref = -1;
+ bool pr = false;
+ int ret;
Expand All @@ -255,8 +258,8 @@ Signed-off-by: Stephan Mueller <smueller@chronox.de>
+
+ if (sec_strength > drbg_sec_strength(drbg->core->flags)) {
+ pr_err("Security strength of DRBG (%u bits) lower than requested by LRNG (%u bits)\n",
+ drbg_sec_strength(drbg->core->flags) * 8,
+ sec_strength * 8);
+ drbg_sec_strength(drbg->core->flags) * 8,
+ sec_strength * 8);
+ goto dealloc;
+ }
+
Expand All @@ -269,18 +272,18 @@ Signed-off-by: Stephan Mueller <smueller@chronox.de>
+
+ return drbg;
+
+dealloc:
+ dealloc:
+ if (drbg->d_ops)
+ drbg->d_ops->crypto_fini(drbg);
+ drbg_dealloc_state(drbg);
+err:
+ err:
+ kfree(drbg);
+ return ERR_PTR(-EINVAL);
+}
+
+static void lrng_drbg_drng_dealloc(void *drng)
+static void lrng_drbg_drng_dealloc(void* drng)
+{
+ struct drbg_state *drbg = (struct drbg_state *)drng;
+ struct drbg_state* drbg = (struct drbg_state*)drng;
+
+ if (drbg && drbg->d_ops)
+ drbg->d_ops->crypto_fini(drbg);
Expand All @@ -289,26 +292,48 @@ Signed-off-by: Stephan Mueller <smueller@chronox.de>
+ pr_info("DRBG deallocated\n");
+}
+
+static const char *lrng_drbg_name(void)
+static const char* lrng_drbg_name(void)
+{
+ return lrng_drbg_types[lrng_drbg_type].drbg_core;
+}
+
+const struct lrng_drng_cb lrng_drbg_cb = {
+ .drng_name = lrng_drbg_name,
+ .drng_alloc = lrng_drbg_drng_alloc,
+ .drng_dealloc = lrng_drbg_drng_dealloc,
+ .drng_seed = lrng_drbg_drng_seed_helper,
+ .drng_generate = lrng_drbg_drng_generate_helper,
+ .drng_name = lrng_drbg_name,
+ .drng_alloc = lrng_drbg_drng_alloc,
+ .drng_dealloc = lrng_drbg_drng_dealloc,
+ .drng_seed = lrng_drbg_drng_seed_helper,
+ .drng_generate = lrng_drbg_drng_generate_helper,
+};
+
+static int __init lrng_drbg_selftest(void)
+{
+ struct crypto_rng *drbg;
+
+ /* Allocate the DRBG once to trigger the kernel crypto API self test */
+ drbg = crypto_alloc_rng(lrng_drbg_types[lrng_drbg_type].drbg_core, 0,
+ 0);
+ if (IS_ERR(drbg)) {
+ pr_err("could not allocate DRBG and trigger self-test: %ld\n",
+ PTR_ERR(drbg));
+ return PTR_ERR(drbg);
+ }
+ crypto_free_rng(drbg);
+
+ return 0;
+}
+
+#ifndef CONFIG_LRNG_DFLT_DRNG_DRBG
+static int __init lrng_drbg_init(void)
+{
+ int ret = lrng_drbg_selftest();
+
+ if (ret)
+ return ret;
+
+ if (lrng_drbg_type >= ARRAY_SIZE(lrng_drbg_types)) {
+ pr_err("lrng_drbg_type parameter too large (given %u - max: %lu)",
+ lrng_drbg_type,
+ (unsigned long)ARRAY_SIZE(lrng_drbg_types) - 1);
+ (unsigned long)ARRAY_SIZE(lrng_drbg_types) - 1);
+ return -EAGAIN;
+ }
+ return lrng_set_drng_cb(&lrng_drbg_cb);
Expand All @@ -324,4 +349,15 @@ Signed-off-by: Stephan Mueller <smueller@chronox.de>
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_AUTHOR("Stephan Mueller <smueller@chronox.de>");
+MODULE_DESCRIPTION("Entropy Source and DRNG Manager - SP800-90A DRBG backend");
+#else
+
+/*
+ * Note, this call may result in the use of the DRBG before the self-test is
+ * run. However, that usage is not relevant to any FIPS-140 consideration as
+ * the data is used for non-cryptographic purposes. The call below guarantees
+ * that the self-tests are run before user space is started and thus callers
+ * with needs to comply with FIPS-140 appear.
+ */
+late_initcall(lrng_drbg_selftest);
+
+#endif /* CONFIG_LRNG_DFLT_DRNG_DRBG */
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From c1901cc389ae7d28927121008830098ea28d6090 Mon Sep 17 00:00:00 2001
From 2f28e58ceafa631451faf9d3b5082277fed8553a Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Mon, 20 Feb 2023 22:23:59 +0100
Subject: [PATCH v54 08/25] LRNG - add kernel crypto API PRNG extension
Subject: [PATCH v56 08/25] LRNG - add kernel crypto API PRNG extension

Add runtime-pluggable support for all PRNGs that are accessible via
the kernel crypto API, including hardware PRNGs. The PRNG is selected
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 5490dc9b65c3c038947cc54ff6e1d25ca8bfbf42 Mon Sep 17 00:00:00 2001
From e2c4873e2635a36355f1625b1b45836b43a432ca Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Mon, 20 Feb 2023 22:05:24 +0100
Subject: [PATCH v54 09/25] LRNG - add atomic DRNG implementation
Subject: [PATCH v56 09/25] LRNG - add atomic DRNG implementation

The atomic DRNG implementation supports the in-kernel use cases which
request random numbers in atomic contexts. It uses the ChaCha20 DRNG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 380258b6701df7d1b6d3f24fcb2a4ee048638a88 Mon Sep 17 00:00:00 2001
From d3a8d413a8af062d076a1ebfef58e7c75247782c Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Sun, 15 May 2022 16:21:44 +0200
Subject: [PATCH v54 10/25] LRNG - add common timer-based entropy source code
Subject: [PATCH v56 10/25] LRNG - add common timer-based entropy source code

The code shared for timer-based entropy sources offers the following
support:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From dbe4eac3e7ff8c7b90e89574fb43bbad475396d1 Mon Sep 17 00:00:00 2001
From 859300f8e2c5788b55612ead32a9acc23d020309 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Tue, 25 Apr 2023 23:03:39 +0200
Subject: [PATCH v54 11/25] LRNG - add interrupt entropy source
Subject: [PATCH v56 11/25] LRNG - add interrupt entropy source

The interrupt entropy source (ES) consumes the events triggered by the
kernel invoked with the add_interrupt_randomness. Its main goal is:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 20088d8f89721d054d971eeb9f51ce89176a352a Mon Sep 17 00:00:00 2001
From 3227bfd639f805edcfeaf9a155ea6cd63c0aaa3f Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Sun, 15 May 2022 16:39:02 +0200
Subject: [PATCH v54 12/25] scheduler - add entropy sampling hook
Subject: [PATCH v56 12/25] scheduler - add entropy sampling hook

The scheduler can be used as a source of entropy. This requires the
presence of a hook that invokes the entropy source implementation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From f2358fa2e3a57f6a21dab3f86da31f84ad853a32 Mon Sep 17 00:00:00 2001
From 7ee7dd37ebc292e423d4430982f83434a8385150 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Wed, 22 Feb 2023 07:05:59 +0100
Subject: [PATCH v54 13/25] LRNG - add scheduler-based entropy source
Subject: [PATCH v56 13/25] LRNG - add scheduler-based entropy source

The scheduler-based entropy source (ES) consumes the events triggered by
the kernel invoked with the add_sched_randomness. Its main goal is:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 03b71ae17aa42b2d7c86fdd641846a7588772365 Mon Sep 17 00:00:00 2001
From 625c81ceab737e3377d9f7887b1e18c299d27ab4 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Tue, 25 Apr 2023 23:13:30 +0200
Subject: [PATCH v54 14/25] LRNG - add SP800-90B compliant health tests
Subject: [PATCH v56 14/25] LRNG - add SP800-90B compliant health tests
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 19aadf94056c4facfb8cd1cb8188111a6c7bc15c Mon Sep 17 00:00:00 2001
From e4b954e07e769b86c49da5f40ba7d66506abc6b7 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Mon, 20 Feb 2023 22:07:27 +0100
Subject: [PATCH v54 15/25] LRNG - add random.c entropy source support
Subject: [PATCH v56 15/25] LRNG - add random.c entropy source support

The random.c implementation can be used as an entropy source by the
LRNG. This support can be enabled at compile time.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From f4b2a37dacad06aec332fcf1b265b95cc637b3c2 Mon Sep 17 00:00:00 2001
From e21f9a4d1b391678f27eca3a1b792c63dac8b534 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Mon, 20 Feb 2023 22:08:23 +0100
Subject: [PATCH v54 16/25] LRNG - CPU entropy source
Subject: [PATCH v56 16/25] LRNG - CPU entropy source

Certain CPUs provide instructions giving access to an entropy source
(e.g. RDSEED on Intel/AMD, DARN on POWER, etc.). The LRNG can utilize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 2c9dbafb0fbcd8b7ab9ed64b4d5cd041fc97e851 Mon Sep 17 00:00:00 2001
From 775a02c9afb75f600cd1a0468dcabb54c6d4d565 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Sun, 27 Aug 2023 17:11:37 +0200
Subject: [PATCH v54 17/25] LRNG - add Jitter RNG fast noise source
Subject: [PATCH v56 17/25] LRNG - add Jitter RNG fast noise source

The Jitter RNG fast noise source implemented as part of the kernel
crypto API is queried for 256 bits of entropy at the time the seed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 3bc8c2b99e00b8902c2641b5b24d3a47e56ffbf7 Mon Sep 17 00:00:00 2001
From d7a03ab120326629d2c9d490c964b5a78cb6ee13 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Sun, 15 May 2022 17:56:56 +0200
Subject: [PATCH v54 18/25] LRNG - add option to enable runtime entropy rate
Subject: [PATCH v56 18/25] LRNG - add option to enable runtime entropy rate
configuration

The entropy rate for the different entropy sources is configured at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From d1b4b3dfabe5f5cae94c8b096cf607df96f46996 Mon Sep 17 00:00:00 2001
From 32a0a2000d27dc1021f3b5a3181139f54bf4cc1f Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Sun, 18 Dec 2022 21:22:36 +0100
Subject: [PATCH v54 19/25] LRNG - add interface for gathering of raw entropy
Subject: [PATCH v56 19/25] LRNG - add interface for gathering of raw entropy

The test interface allows a privileged process to capture the raw
unconditioned noise that is collected by the LRNG for statistical
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From ec3c3f2642600277e2e688ac5020b2613c477a90 Mon Sep 17 00:00:00 2001
From 7053e9b48bb4cff6d225e2738028038b4e02229b Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Sun, 15 May 2022 18:13:56 +0200
Subject: [PATCH v54 20/25] LRNG - add power-on and runtime self-tests
Subject: [PATCH v56 20/25] LRNG - add power-on and runtime self-tests

Parts of the LRNG are already covered by self-tests, including:

Expand Down
Loading

0 comments on commit 0b06200

Please sign in to comment.