linuxkm/patches/: in regen-patches.sh, structure the pathnames to mollify kernel scripts/checkpatch.pl;

tweak WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v15.patch (mostly whitespace) to mollify scripts/checkpatch.pl.
This commit is contained in:
Daniel Pouzzner
2025-07-11 09:30:23 -05:00
parent 1e3966f06d
commit 0001bf7983
8 changed files with 257 additions and 247 deletions

View File

@@ -1,5 +1,5 @@
--- ./drivers/char/random.c.dist 2020-12-13 16:41:30.000000000 -0600 --- 5.10.17/drivers/char/random.c.dist 2020-12-13 16:41:30.000000000 -0600
+++ ./drivers/char/random.c 2025-07-02 11:59:07.220250957 -0500 +++ 5.10.17/drivers/char/random.c 2025-07-02 11:59:07.220250957 -0500
@@ -344,6 +344,260 @@ @@ -344,6 +344,260 @@
#include <asm/irq_regs.h> #include <asm/irq_regs.h>
#include <asm/io.h> #include <asm/io.h>
@@ -421,8 +421,8 @@
if (flags & GRND_NONBLOCK) if (flags & GRND_NONBLOCK)
return -EAGAIN; return -EAGAIN;
ret = wait_for_random_bytes(); ret = wait_for_random_bytes();
--- ./include/linux/random.h.dist 2020-12-13 16:41:30.000000000 -0600 --- 5.10.17/include/linux/random.h.dist 2020-12-13 16:41:30.000000000 -0600
+++ ./include/linux/random.h 2025-06-30 12:05:59.106440700 -0500 +++ 5.10.17/include/linux/random.h 2025-06-30 12:05:59.106440700 -0500
@@ -158,4 +158,37 @@ static inline bool __init arch_get_rando @@ -158,4 +158,37 @@ static inline bool __init arch_get_rando
} }
#endif #endif

View File

@@ -1,5 +1,5 @@
--- ./drivers/char/random.c.dist 2025-04-29 18:54:03.390121890 -0500 --- 5.10.236/drivers/char/random.c.dist 2025-04-29 18:54:03.390121890 -0500
+++ ./drivers/char/random.c 2025-07-02 11:57:40.176497765 -0500 +++ 5.10.236/drivers/char/random.c 2025-07-02 11:57:40.176497765 -0500
@@ -60,6 +60,260 @@ @@ -60,6 +60,260 @@
#include <asm/irq_regs.h> #include <asm/irq_regs.h>
#include <asm/io.h> #include <asm/io.h>
@@ -420,8 +420,8 @@
if (!crng_ready()) if (!crng_ready())
return -ENODATA; return -ENODATA;
crng_reseed(); crng_reseed();
--- ./include/linux/random.h.dist 2025-04-29 18:54:07.595202807 -0500 --- 5.10.236/include/linux/random.h.dist 2025-04-29 18:54:07.595202807 -0500
+++ ./include/linux/random.h 2025-06-30 12:03:15.263141842 -0500 +++ 5.10.236/include/linux/random.h 2025-06-30 12:03:15.263141842 -0500
@@ -138,4 +138,37 @@ int random_online_cpu(unsigned int cpu); @@ -138,4 +138,37 @@ int random_online_cpu(unsigned int cpu);
extern const struct file_operations random_fops, urandom_fops; extern const struct file_operations random_fops, urandom_fops;
#endif #endif

View File

@@ -1,5 +1,5 @@
--- ./drivers/char/random.c.dist 2021-10-31 15:53:10.000000000 -0500 --- 5.15/drivers/char/random.c.dist 2021-10-31 15:53:10.000000000 -0500
+++ ./drivers/char/random.c 2025-07-02 11:49:13.836320539 -0500 +++ 5.15/drivers/char/random.c 2025-07-02 11:49:13.836320539 -0500
@@ -344,6 +344,260 @@ @@ -344,6 +344,260 @@
#include <asm/irq_regs.h> #include <asm/irq_regs.h>
#include <asm/io.h> #include <asm/io.h>
@@ -411,8 +411,8 @@
if (flags & GRND_NONBLOCK) if (flags & GRND_NONBLOCK)
return -EAGAIN; return -EAGAIN;
ret = wait_for_random_bytes(); ret = wait_for_random_bytes();
--- ./include/linux/random.h.dist 2021-10-31 15:53:10.000000000 -0500 --- 5.15/include/linux/random.h.dist 2021-10-31 15:53:10.000000000 -0500
+++ ./include/linux/random.h 2025-06-28 13:09:13.392547118 -0500 +++ 5.15/include/linux/random.h 2025-06-28 13:09:13.392547118 -0500
@@ -158,4 +158,37 @@ static inline bool __init arch_get_rando @@ -158,4 +158,37 @@ static inline bool __init arch_get_rando
} }
#endif #endif

View File

@@ -1,5 +1,5 @@
--- ./drivers/char/random.c.dist 2022-05-31 08:33:43.006547419 -0500 --- 5.17/drivers/char/random.c.dist 2022-05-31 08:33:43.006547419 -0500
+++ ./drivers/char/random.c 2025-07-02 11:42:10.098166804 -0500 +++ 5.17/drivers/char/random.c 2025-07-02 11:42:10.098166804 -0500
@@ -60,6 +60,260 @@ @@ -60,6 +60,260 @@
#include <asm/irq_regs.h> #include <asm/irq_regs.h>
#include <asm/io.h> #include <asm/io.h>
@@ -420,8 +420,8 @@
if (!crng_ready()) if (!crng_ready())
return -ENODATA; return -ENODATA;
crng_reseed(); crng_reseed();
--- ./include/linux/random.h.dist 2022-05-31 08:33:43.007547457 -0500 --- 5.17/include/linux/random.h.dist 2022-05-31 08:33:43.007547457 -0500
+++ ./include/linux/random.h 2025-06-30 12:06:15.219731761 -0500 +++ 5.17/include/linux/random.h 2025-06-30 12:06:15.219731761 -0500
@@ -138,4 +138,37 @@ int random_online_cpu(unsigned int cpu); @@ -138,4 +138,37 @@ int random_online_cpu(unsigned int cpu);
extern const struct file_operations random_fops, urandom_fops; extern const struct file_operations random_fops, urandom_fops;
#endif #endif

View File

@@ -1,5 +1,5 @@
--- ./drivers/char/random.c.dist 2024-01-19 16:25:03.754138321 -0600 --- 6.1.73/drivers/char/random.c.dist 2024-01-19 16:25:03.754138321 -0600
+++ ./drivers/char/random.c 2025-07-03 15:51:24.282595676 -0500 +++ 6.1.73/drivers/char/random.c 2025-07-03 15:51:24.282595676 -0500
@@ -60,6 +60,260 @@ @@ -60,6 +60,260 @@
#include <asm/irq_regs.h> #include <asm/irq_regs.h>
#include <asm/io.h> #include <asm/io.h>
@@ -433,8 +433,8 @@
if (!crng_ready()) if (!crng_ready())
return -ENODATA; return -ENODATA;
crng_reseed(); crng_reseed();
--- ./include/linux/random.h.dist 2024-01-19 16:25:07.891223702 -0600 --- 6.1.73/include/linux/random.h.dist 2024-01-19 16:25:07.891223702 -0600
+++ ./include/linux/random.h 2025-06-30 12:38:54.353341542 -0500 +++ 6.1.73/include/linux/random.h 2025-06-30 12:38:54.353341542 -0500
@@ -202,4 +202,37 @@ int random_online_cpu(unsigned int cpu); @@ -202,4 +202,37 @@ int random_online_cpu(unsigned int cpu);
extern const struct file_operations random_fops, urandom_fops; extern const struct file_operations random_fops, urandom_fops;
#endif #endif

View File

@@ -1,5 +1,5 @@
--- ./drivers/char/random.c.dist 2025-01-19 19:03:47.877152701 -0600 --- 6.12/drivers/char/random.c.dist 2025-01-19 19:03:47.877152701 -0600
+++ ./drivers/char/random.c 2025-07-02 10:40:21.994303997 -0500 +++ 6.12/drivers/char/random.c 2025-07-02 10:40:21.994303997 -0500
@@ -67,6 +67,260 @@ @@ -67,6 +67,260 @@
#include <asm/irq_regs.h> #include <asm/irq_regs.h>
#include <asm/io.h> #include <asm/io.h>
@@ -442,8 +442,8 @@
if (!crng_ready()) if (!crng_ready())
return -ENODATA; return -ENODATA;
crng_reseed(NULL); crng_reseed(NULL);
--- ./include/linux/random.h.dist 2025-01-19 19:03:57.524328914 -0600 --- 6.12/include/linux/random.h.dist 2025-01-19 19:03:57.524328914 -0600
+++ ./include/linux/random.h 2025-06-30 12:04:32.801676104 -0500 +++ 6.12/include/linux/random.h 2025-06-30 12:04:32.801676104 -0500
@@ -161,4 +161,37 @@ int random_online_cpu(unsigned int cpu); @@ -161,4 +161,37 @@ int random_online_cpu(unsigned int cpu);
extern const struct file_operations random_fops, urandom_fops; extern const struct file_operations random_fops, urandom_fops;
#endif #endif

View File

@@ -1,6 +1,6 @@
--- ./drivers/char/random.c.dist 2025-05-27 15:19:59.167827834 -0500 --- 6.15/drivers/char/random.c.dist 2025-05-27 15:19:59.167827834 -0500
+++ ./drivers/char/random.c 2025-07-02 09:34:56.197972526 -0500 +++ 6.15/drivers/char/random.c 2025-07-11 09:18:33.060365202 -0500
@@ -67,6 +67,260 @@ @@ -67,6 +67,265 @@
#include <asm/irq_regs.h> #include <asm/irq_regs.h>
#include <asm/io.h> #include <asm/io.h>
@@ -12,22 +12,21 @@
+ ATOMIC_INIT((long)NULL); + ATOMIC_INIT((long)NULL);
+static atomic_t random_bytes_cb_refcnt = +static atomic_t random_bytes_cb_refcnt =
+ ATOMIC_INIT(0); /* 0 if unregistered, 1 if no calls in flight. */ + ATOMIC_INIT(0); /* 0 if unregistered, 1 if no calls in flight. */
+static _get_random_bytes_cb_t _get_random_bytes_cb = NULL; +static _get_random_bytes_cb_t _get_random_bytes_cb;
+static get_random_bytes_user_cb_t get_random_bytes_user_cb = NULL; +static get_random_bytes_user_cb_t get_random_bytes_user_cb;
+static crng_ready_cb_t crng_ready_cb = NULL; +static crng_ready_cb_t crng_ready_cb;
+static mix_pool_bytes_cb_t mix_pool_bytes_cb = NULL; +static mix_pool_bytes_cb_t mix_pool_bytes_cb;
+static credit_init_bits_cb_t credit_init_bits_cb = NULL; +static credit_init_bits_cb_t credit_init_bits_cb;
+static crng_reseed_cb_t crng_reseed_cb = NULL; +static crng_reseed_cb_t crng_reseed_cb;
+ +
+int wolfssl_linuxkm_register_random_bytes_handlers( +int wolfssl_linuxkm_register_random_bytes_handlers(
+ struct module *new_random_bytes_cb_owner, + struct module *new_random_bytes_cb_owner,
+ const struct wolfssl_linuxkm_random_bytes_handlers *handlers) + const struct wolfssl_linuxkm_random_bytes_handlers *handlers)
+{ +{
+ if ((! new_random_bytes_cb_owner) || + if ((new_random_bytes_cb_owner == NULL) ||
+ (! handlers) || + (handlers == NULL) ||
+ (! handlers->_get_random_bytes) || + (handlers->_get_random_bytes == NULL) ||
+ (! handlers->get_random_bytes_user)) + (handlers->get_random_bytes_user == NULL)) {
+ {
+ return -EINVAL; + return -EINVAL;
+ } + }
+ +
@@ -38,15 +37,16 @@
+ if (atomic_long_cmpxchg(&random_bytes_cb_owner, + if (atomic_long_cmpxchg(&random_bytes_cb_owner,
+ (long)NULL, + (long)NULL,
+ (long)new_random_bytes_cb_owner) + (long)new_random_bytes_cb_owner)
+ != (long)NULL) + != (long)NULL) {
+ {
+ return -EBUSY; + return -EBUSY;
+ } + }
+ +
+ { + {
+ int current_random_bytes_cb_refcnt = atomic_read(&random_bytes_cb_refcnt); + int current_random_bytes_cb_refcnt = atomic_read(&random_bytes_cb_refcnt);
+
+ if (current_random_bytes_cb_refcnt) { + if (current_random_bytes_cb_refcnt) {
+ pr_err("BUG: random_bytes_cb_refcnt == %d with null random_bytes_cb_owner", current_random_bytes_cb_refcnt); + pr_err("BUG: random_bytes_cb_refcnt == %d with null random_bytes_cb_owner",
+ current_random_bytes_cb_refcnt);
+ atomic_long_set(&random_bytes_cb_owner, (long)NULL); + atomic_long_set(&random_bytes_cb_owner, (long)NULL);
+ return -EFAULT; + return -EFAULT;
+ } + }
@@ -75,7 +75,8 @@
+{ +{
+ int current_random_bytes_cb_refcnt; + int current_random_bytes_cb_refcnt;
+ int n_tries; + int n_tries;
+ if (! atomic_long_read(&random_bytes_cb_owner)) +
+ if (atomic_long_read(&random_bytes_cb_owner) == 0)
+ return -ENODEV; + return -ENODEV;
+ +
+ /* we're racing the kernel at large to try to catch random_bytes_cb_refcnt + /* we're racing the kernel at large to try to catch random_bytes_cb_refcnt
@@ -86,14 +87,16 @@
+ if (current_random_bytes_cb_refcnt == 1) + if (current_random_bytes_cb_refcnt == 1)
+ break; + break;
+ if (current_random_bytes_cb_refcnt < 0) { + if (current_random_bytes_cb_refcnt < 0) {
+ pr_err("BUG: random_bytes_cb_refcnt is %d in wolfssl_linuxkm_unregister_random_bytes_handlers.", current_random_bytes_cb_refcnt); + pr_err("BUG: random_bytes_cb_refcnt is %d in %s.",
+ current_random_bytes_cb_refcnt, __func__);
+ break; + break;
+ } + }
+ if (msleep_interruptible(10) != 0) + if (msleep_interruptible(10) != 0)
+ return -EINTR; + return -EINTR;
+ } + }
+ if (current_random_bytes_cb_refcnt != 1) { + if (current_random_bytes_cb_refcnt != 1) {
+ pr_warn("WARNING: wolfssl_unregister_random_bytes_handlers called with random_bytes_cb_refcnt == %d", current_random_bytes_cb_refcnt); + pr_warn("WARNING: %s called with random_bytes_cb_refcnt == %d", __func__,
+ current_random_bytes_cb_refcnt);
+ return -EBUSY; + return -EBUSY;
+ } + }
+ +
@@ -112,15 +115,17 @@
+} +}
+EXPORT_SYMBOL_GPL(wolfssl_linuxkm_unregister_random_bytes_handlers); +EXPORT_SYMBOL_GPL(wolfssl_linuxkm_unregister_random_bytes_handlers);
+ +
+static __always_inline int reserve_random_bytes_cb(void) { +static __always_inline int reserve_random_bytes_cb(void)
+{
+ int current_random_bytes_cb_refcnt = + int current_random_bytes_cb_refcnt =
+ atomic_read_acquire(&random_bytes_cb_refcnt); + atomic_read_acquire(&random_bytes_cb_refcnt);
+ +
+ if (! current_random_bytes_cb_refcnt) + if (current_random_bytes_cb_refcnt == 0)
+ return -ENODEV; + return -ENODEV;
+ +
+ if (current_random_bytes_cb_refcnt < 0) { + if (current_random_bytes_cb_refcnt < 0) {
+ pr_err("BUG: random_bytes_cb_refcnt is %d in reserve_random_bytes_cb.", current_random_bytes_cb_refcnt); + pr_err("BUG: random_bytes_cb_refcnt is %d in %s.",
+ current_random_bytes_cb_refcnt, __func__);
+ return -EFAULT; + return -EFAULT;
+ } + }
+ +
@@ -132,16 +137,16 @@
+ current_random_bytes_cb_refcnt + 1); + current_random_bytes_cb_refcnt + 1);
+ if (orig_random_bytes_cb_refcnt == current_random_bytes_cb_refcnt) + if (orig_random_bytes_cb_refcnt == current_random_bytes_cb_refcnt)
+ return 0; + return 0;
+ else if (! orig_random_bytes_cb_refcnt) + else if (orig_random_bytes_cb_refcnt == 0)
+ return -ENODEV; + return -ENODEV;
+ else
+ current_random_bytes_cb_refcnt = orig_random_bytes_cb_refcnt; + current_random_bytes_cb_refcnt = orig_random_bytes_cb_refcnt;
+ } + }
+ +
+ __builtin_unreachable(); + __builtin_unreachable();
+} +}
+ +
+static __always_inline void release_random_bytes_cb(void) { +static __always_inline void release_random_bytes_cb(void)
+{
+ atomic_dec(&random_bytes_cb_refcnt); + atomic_dec(&random_bytes_cb_refcnt);
+} +}
+ +
@@ -149,7 +154,7 @@
+{ +{
+ int ret; + int ret;
+ +
+ if (! _get_random_bytes_cb) + if (_get_random_bytes_cb == NULL)
+ return -ENODEV; + return -ENODEV;
+ +
+ ret = reserve_random_bytes_cb(); + ret = reserve_random_bytes_cb();
@@ -167,7 +172,7 @@
+{ +{
+ ssize_t ret; + ssize_t ret;
+ +
+ if (! get_random_bytes_user_cb) + if (get_random_bytes_user_cb == NULL)
+ return -ECANCELED; + return -ECANCELED;
+ +
+ ret = (ssize_t)reserve_random_bytes_cb(); + ret = (ssize_t)reserve_random_bytes_cb();
@@ -189,7 +194,7 @@
+ * called, it will always have or obtain sufficient entropy to fulfill the + * called, it will always have or obtain sufficient entropy to fulfill the
+ * call. + * call.
+ */ + */
+ if (! crng_ready_cb) + if (crng_ready_cb == NULL)
+ return 1; + return 1;
+ +
+ if (reserve_random_bytes_cb() != 0) + if (reserve_random_bytes_cb() != 0)
@@ -206,7 +211,7 @@
+{ +{
+ int ret; + int ret;
+ +
+ if (! mix_pool_bytes_cb) + if (mix_pool_bytes_cb == NULL)
+ return -ENODEV; + return -ENODEV;
+ +
+ ret = reserve_random_bytes_cb(); + ret = reserve_random_bytes_cb();
@@ -224,7 +229,7 @@
+{ +{
+ int ret; + int ret;
+ +
+ if (! credit_init_bits_cb) + if (credit_init_bits_cb == NULL)
+ return -ENODEV; + return -ENODEV;
+ +
+ ret = reserve_random_bytes_cb(); + ret = reserve_random_bytes_cb();
@@ -242,7 +247,7 @@
+{ +{
+ int ret; + int ret;
+ +
+ if (! crng_reseed_cb) + if (crng_reseed_cb == NULL)
+ return -ENODEV; + return -ENODEV;
+ +
+ ret = reserve_random_bytes_cb(); + ret = reserve_random_bytes_cb();
@@ -261,7 +266,7 @@
/********************************************************************* /*********************************************************************
* *
* Initialization and readiness waiting. * Initialization and readiness waiting.
@@ -87,7 +341,15 @@ static enum { @@ -87,7 +346,16 @@ static enum {
CRNG_READY = 2 /* Fully initialized with POOL_READY_BITS collected */ CRNG_READY = 2 /* Fully initialized with POOL_READY_BITS collected */
} crng_init __read_mostly = CRNG_EMPTY; } crng_init __read_mostly = CRNG_EMPTY;
static DEFINE_STATIC_KEY_FALSE(crng_is_ready); static DEFINE_STATIC_KEY_FALSE(crng_is_ready);
@@ -269,7 +274,8 @@
#define crng_ready() (static_branch_likely(&crng_is_ready) || crng_init >= CRNG_READY) #define crng_ready() (static_branch_likely(&crng_is_ready) || crng_init >= CRNG_READY)
+#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS +#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS
+ #define crng_ready_by_cb() (atomic_read(&random_bytes_cb_refcnt) && call_crng_ready_cb()) + #define crng_ready_by_cb() (atomic_read(&random_bytes_cb_refcnt) && call_crng_ready_cb())
+ #define crng_ready_maybe_cb() (atomic_read(&random_bytes_cb_refcnt) ? (call_crng_ready_cb() || crng_ready()) : crng_ready()) + #define crng_ready_maybe_cb() (atomic_read(&random_bytes_cb_refcnt) ? \
+ (call_crng_ready_cb() || crng_ready()) : crng_ready())
+#else +#else
+ #define crng_ready_maybe_cb() crng_ready() + #define crng_ready_maybe_cb() crng_ready()
+#endif +#endif
@@ -277,7 +283,7 @@
/* Various types of waiters for crng_init->CRNG_READY transition. */ /* Various types of waiters for crng_init->CRNG_READY transition. */
static DECLARE_WAIT_QUEUE_HEAD(crng_init_wait); static DECLARE_WAIT_QUEUE_HEAD(crng_init_wait);
static struct fasync_struct *fasync; static struct fasync_struct *fasync;
@@ -112,7 +374,7 @@ MODULE_PARM_DESC(ratelimit_disable, "Dis @@ -112,7 +380,7 @@ MODULE_PARM_DESC(ratelimit_disable, "Dis
*/ */
bool rng_is_initialized(void) bool rng_is_initialized(void)
{ {
@@ -286,7 +292,7 @@
} }
EXPORT_SYMBOL(rng_is_initialized); EXPORT_SYMBOL(rng_is_initialized);
@@ -136,11 +398,11 @@ static void try_to_generate_entropy(void @@ -136,11 +404,11 @@ static void try_to_generate_entropy(void
*/ */
int wait_for_random_bytes(void) int wait_for_random_bytes(void)
{ {
@@ -300,7 +306,7 @@
if (ret) if (ret)
return ret > 0 ? 0 : ret; return ret > 0 ? 0 : ret;
} }
@@ -160,7 +422,7 @@ int __cold execute_with_initialized_rng( @@ -160,7 +428,7 @@ int __cold execute_with_initialized_rng(
int ret = 0; int ret = 0;
spin_lock_irqsave(&random_ready_notifier.lock, flags); spin_lock_irqsave(&random_ready_notifier.lock, flags);
@@ -309,7 +315,7 @@
nb->notifier_call(nb, 0, NULL); nb->notifier_call(nb, 0, NULL);
else else
ret = raw_notifier_chain_register((struct raw_notifier_head *)&random_ready_notifier.head, nb); ret = raw_notifier_chain_register((struct raw_notifier_head *)&random_ready_notifier.head, nb);
@@ -169,7 +431,7 @@ int __cold execute_with_initialized_rng( @@ -169,7 +437,7 @@ int __cold execute_with_initialized_rng(
} }
#define warn_unseeded_randomness() \ #define warn_unseeded_randomness() \
@@ -318,12 +324,12 @@
printk_deferred(KERN_NOTICE "random: %s called from %pS with crng_init=%d\n", \ printk_deferred(KERN_NOTICE "random: %s called from %pS with crng_init=%d\n", \
__func__, (void *)_RET_IP_, crng_init) __func__, (void *)_RET_IP_, crng_init)
@@ -402,6 +664,14 @@ static void _get_random_bytes(void *buf, @@ -402,6 +670,14 @@ static void _get_random_bytes(void *buf,
if (!len) if (!len)
return; return;
+#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS +#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS
+ /* If call__get_random_bytes_cb() doesn't succeed, flow falls through to + /* If call__get_random_bytes_cb() doesn't succeed, flow continues to
+ * the native implementation. _get_random_bytes() must succeed. + * the native implementation. _get_random_bytes() must succeed.
+ */ + */
+ if (call__get_random_bytes_cb(buf, len) == 0) + if (call__get_random_bytes_cb(buf, len) == 0)
@@ -333,7 +339,7 @@
first_block_len = min_t(size_t, 32, len); first_block_len = min_t(size_t, 32, len);
crng_make_state(chacha_state, buf, first_block_len); crng_make_state(chacha_state, buf, first_block_len);
len -= first_block_len; len -= first_block_len;
@@ -448,6 +718,18 @@ static ssize_t get_random_bytes_user(str @@ -448,6 +724,18 @@ static ssize_t get_random_bytes_user(str
if (unlikely(!iov_iter_count(iter))) if (unlikely(!iov_iter_count(iter)))
return 0; return 0;
@@ -341,7 +347,7 @@
+ { + {
+ ssize_t cb_ret = call_get_random_bytes_user_cb(iter); + ssize_t cb_ret = call_get_random_bytes_user_cb(iter);
+ /* If the callback returns -ECANCELED, that signals that iter is + /* If the callback returns -ECANCELED, that signals that iter is
+ * still intact, and flow can safely fall through to the native + * still intact, and flow can safely continue to the native
+ * implementation. + * implementation.
+ */ + */
+ if (cb_ret != -ECANCELED) + if (cb_ret != -ECANCELED)
@@ -352,7 +358,7 @@
/* /*
* Immediately overwrite the ChaCha key at index 4 with random * Immediately overwrite the ChaCha key at index 4 with random
* bytes, in case userspace causes copy_to_iter() below to sleep * bytes, in case userspace causes copy_to_iter() below to sleep
@@ -524,7 +806,7 @@ type get_random_ ##type(void) \ @@ -524,7 +812,7 @@ type get_random_ ##type(void) \
\ \
warn_unseeded_randomness(); \ warn_unseeded_randomness(); \
\ \
@@ -361,31 +367,34 @@
_get_random_bytes(&ret, sizeof(ret)); \ _get_random_bytes(&ret, sizeof(ret)); \
return ret; \ return ret; \
} \ } \
@@ -660,6 +942,11 @@ static void mix_pool_bytes(const void *b @@ -660,6 +948,11 @@ static void mix_pool_bytes(const void *b
{ {
unsigned long flags; unsigned long flags;
+#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS +#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS
+ (void)call_mix_pool_bytes_cb(buf, len); + (void)call_mix_pool_bytes_cb(buf, len);
+ /* fall through to mix into native pool too. */ + /* continue to mix into native pool too. */
+#endif +#endif
+ +
spin_lock_irqsave(&input_pool.lock, flags); spin_lock_irqsave(&input_pool.lock, flags);
_mix_pool_bytes(buf, len); _mix_pool_bytes(buf, len);
spin_unlock_irqrestore(&input_pool.lock, flags); spin_unlock_irqrestore(&input_pool.lock, flags);
@@ -719,7 +1006,11 @@ static void extract_entropy(void *buf, s @@ -719,7 +1012,13 @@ static void extract_entropy(void *buf, s
memzero_explicit(&block, sizeof(block)); memzero_explicit(&block, sizeof(block));
} }
-#define credit_init_bits(bits) if (!crng_ready()) _credit_init_bits(bits)
+#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS +#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS
+#define credit_init_bits(bits) do { (void)call_credit_init_bits_cb(bits); if (!crng_ready()) _credit_init_bits(bits); } while (0) + #define credit_init_bits(bits) do { (void)call_credit_init_bits_cb(bits); \
+ if (!crng_ready()) \
+ _credit_init_bits(bits); } while (0)
+#else +#else
#define credit_init_bits(bits) if (!crng_ready()) _credit_init_bits(bits) + #define credit_init_bits(bits) do { if (!crng_ready()) _credit_init_bits(bits); } while (0)
+#endif +#endif
static void __cold _credit_init_bits(size_t bits) static void __cold _credit_init_bits(size_t bits)
{ {
@@ -1400,7 +1691,7 @@ SYSCALL_DEFINE3(getrandom, char __user * @@ -1400,7 +1699,7 @@ SYSCALL_DEFINE3(getrandom, char __user *
if ((flags & (GRND_INSECURE | GRND_RANDOM)) == (GRND_INSECURE | GRND_RANDOM)) if ((flags & (GRND_INSECURE | GRND_RANDOM)) == (GRND_INSECURE | GRND_RANDOM))
return -EINVAL; return -EINVAL;
@@ -394,7 +403,7 @@
if (flags & GRND_NONBLOCK) if (flags & GRND_NONBLOCK)
return -EAGAIN; return -EAGAIN;
ret = wait_for_random_bytes(); ret = wait_for_random_bytes();
@@ -1416,6 +1707,10 @@ SYSCALL_DEFINE3(getrandom, char __user * @@ -1416,6 +1715,10 @@ SYSCALL_DEFINE3(getrandom, char __user *
static __poll_t random_poll(struct file *file, poll_table *wait) static __poll_t random_poll(struct file *file, poll_table *wait)
{ {
@@ -405,7 +414,7 @@
poll_wait(file, &crng_init_wait, wait); poll_wait(file, &crng_init_wait, wait);
return crng_ready() ? EPOLLIN | EPOLLRDNORM : EPOLLOUT | EPOLLWRNORM; return crng_ready() ? EPOLLIN | EPOLLRDNORM : EPOLLOUT | EPOLLWRNORM;
} }
@@ -1461,10 +1756,10 @@ static ssize_t urandom_read_iter(struct @@ -1461,10 +1764,10 @@ static ssize_t urandom_read_iter(struct
* Opportunistically attempt to initialize the RNG on platforms that * Opportunistically attempt to initialize the RNG on platforms that
* have fast cycle counters, but don't (for now) require it to succeed. * have fast cycle counters, but don't (for now) require it to succeed.
*/ */
@@ -418,7 +427,7 @@
if (!ratelimit_disable && maxwarn <= 0) if (!ratelimit_disable && maxwarn <= 0)
++urandom_warning.missed; ++urandom_warning.missed;
else if (ratelimit_disable || __ratelimit(&urandom_warning)) { else if (ratelimit_disable || __ratelimit(&urandom_warning)) {
@@ -1481,7 +1776,7 @@ static ssize_t random_read_iter(struct k @@ -1481,7 +1784,7 @@ static ssize_t random_read_iter(struct k
{ {
int ret; int ret;
@@ -427,12 +436,12 @@
((kiocb->ki_flags & (IOCB_NOWAIT | IOCB_NOIO)) || ((kiocb->ki_flags & (IOCB_NOWAIT | IOCB_NOIO)) ||
(kiocb->ki_filp->f_flags & O_NONBLOCK))) (kiocb->ki_filp->f_flags & O_NONBLOCK)))
return -EAGAIN; return -EAGAIN;
@@ -1546,6 +1841,14 @@ static long random_ioctl(struct file *f, @@ -1546,6 +1849,14 @@ static long random_ioctl(struct file *f,
case RNDRESEEDCRNG: case RNDRESEEDCRNG:
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
+#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS +#ifdef WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS
+ /* fall through to reseed native crng too. */ + /* continue to reseed native crng too. */
+ if (call_crng_reseed_cb() == 0) { + if (call_crng_reseed_cb() == 0) {
+ if (crng_ready()) + if (crng_ready())
+ crng_reseed(NULL); + crng_reseed(NULL);
@@ -442,8 +451,8 @@
if (!crng_ready()) if (!crng_ready())
return -ENODATA; return -ENODATA;
crng_reseed(NULL); crng_reseed(NULL);
--- ./include/linux/random.h.dist 2025-05-27 15:20:04.394946820 -0500 --- 6.15/include/linux/random.h.dist 2025-05-27 15:20:04.394946820 -0500
+++ ./include/linux/random.h 2025-06-30 12:04:12.032296708 -0500 +++ 6.15/include/linux/random.h 2025-07-11 07:58:55.505031720 -0500
@@ -154,4 +154,37 @@ int random_online_cpu(unsigned int cpu); @@ -154,4 +154,37 @@ int random_online_cpu(unsigned int cpu);
extern const struct file_operations random_fops, urandom_fops; extern const struct file_operations random_fops, urandom_fops;
#endif #endif

View File

@@ -8,6 +8,9 @@ if [[ ! -d 6.15 ]]; then
echo "6.15 not found -- wrong working dir?" >&2 echo "6.15 not found -- wrong working dir?" >&2
exit 1 exit 1
fi fi
cd src || exit $?
for v in *; do for v in *; do
if [[ ! -d "$v" || "$v" == "src" ]]; then if [[ ! -d "$v" || "$v" == "src" ]]; then
continue continue
@@ -16,25 +19,23 @@ for v in *; do
echo "skipping ${v} (malformed version)" echo "skipping ${v} (malformed version)"
continue continue
fi fi
if [[ ! -f "src/${v}/drivers/char/random.c.dist" || if [[ ! -f "${v}/drivers/char/random.c.dist" ||
! -f "src/${v}/drivers/char/random.c" || ! -f "${v}/drivers/char/random.c" ||
! -f "src/${v}/include/linux/random.h.dist" || ! -f "${v}/include/linux/random.h.dist" ||
! -f "src/${v}/include/linux/random.h" ]]; then ! -f "${v}/include/linux/random.h" ]]; then
echo "skipping ${v} (missing src files)" echo "skipping ${v} (missing src files)"
continue continue
fi fi
pushd "src/$v" >/dev/null || break out_f="../${v}/WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-${v//./v}.patch"
out_f="../../${v}/WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-${v//./v}.patch" diff --minimal -up "${v}/drivers/char/"{random.c.dist,random.c} >| "$out_f"
diff --minimal -up ./drivers/char/{random.c.dist,random.c} >| "$out_f"
if [[ $? != "1" ]]; then if [[ $? != "1" ]]; then
echo "diff ${v}/src/drivers/char/{random.c.dist,random.c} exited with unexpected status." >&2 echo "diff ${v}/src/drivers/char/{random.c.dist,random.c} exited with unexpected status." >&2
exit 1 exit 1
fi fi
diff --minimal -up ./include/linux/{random.h.dist,random.h} >> "$out_f" diff --minimal -up "${v}/include/linux/"{random.h.dist,random.h} >> "$out_f"
if [[ $? != "1" ]]; then if [[ $? != "1" ]]; then
echo "diff ${v}/src/include/linux/{random.h.dist,random.h} exited with unexpected status." >&2 echo "diff ${v}/src/include/linux/{random.h.dist,random.h} exited with unexpected status." >&2
exit 1 exit 1
fi fi
popd >/dev/null || exit $?
done done