Module Name: src
Committed By: riastradh
Date: Mon Aug 26 13:46:03 UTC 2024
Modified Files:
src/sys/kern: kern_entropy.c
src/sys/sys: entropy.h
Log Message:
entropy(9): New function entropy_consolidate_sig.
This is the same as entropy_consolidate, but it returns EINTR if
interrupted by a signal and 0 otherwise. (entropy_consolidate can
already be interrupted by a signal -- it just doesn't tell you if it
was.)
Eventually these will be merged into a single entropy_consolidate
that returns the error code, but adding a new symbol first makes it
safe for pullup-10.
PR kern/58646: /dev/random, kern.entropy.*: signal bugs
To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/kern/kern_entropy.c
cvs rdiff -u -r1.4 -r1.5 src/sys/sys/entropy.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/kern_entropy.c
diff -u src/sys/kern/kern_entropy.c:1.66 src/sys/kern/kern_entropy.c:1.67
--- src/sys/kern/kern_entropy.c:1.66 Wed Oct 4 20:28:06 2023
+++ src/sys/kern/kern_entropy.c Mon Aug 26 13:46:03 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_entropy.c,v 1.66 2023/10/04 20:28:06 ad Exp $ */
+/* $NetBSD: kern_entropy.c,v 1.67 2024/08/26 13:46:03 riastradh Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.66 2023/10/04 20:28:06 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.67 2024/08/26 13:46:03 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -1354,7 +1354,21 @@ entropy_notify(void)
/*
* entropy_consolidate()
*
- * Trigger entropy consolidation and wait for it to complete.
+ * Trigger entropy consolidation and wait for it to complete, or
+ * return early if interrupted by a signal.
+ */
+void
+entropy_consolidate(void)
+{
+
+ (void)entropy_consolidate_sig();
+}
+
+/*
+ * entropy_consolidate_sig()
+ *
+ * Trigger entropy consolidation and wait for it to complete, or
+ * return EINTR if interrupted by a signal.
*
* This should be used sparingly, not periodically -- requiring
* conscious intervention by the operator or a clear policy
@@ -1362,8 +1376,8 @@ entropy_notify(void)
* when enough entropy has been gathered into per-CPU pools to
* transition to full entropy.
*/
-void
-entropy_consolidate(void)
+int
+entropy_consolidate_sig(void)
{
uint64_t ticket;
int error;
@@ -1381,6 +1395,8 @@ entropy_consolidate(void)
break;
}
mutex_exit(&E->lock);
+
+ return error;
}
/*
Index: src/sys/sys/entropy.h
diff -u src/sys/sys/entropy.h:1.4 src/sys/sys/entropy.h:1.5
--- src/sys/sys/entropy.h:1.4 Fri Aug 14 00:53:16 2020
+++ src/sys/sys/entropy.h Mon Aug 26 13:46:03 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: entropy.h,v 1.4 2020/08/14 00:53:16 riastradh Exp $ */
+/* $NetBSD: entropy.h,v 1.5 2024/08/26 13:46:03 riastradh Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -50,6 +50,7 @@ struct knote;
void entropy_bootrequest(void);
void entropy_consolidate(void);
+int entropy_consolidate_sig(void);
unsigned entropy_epoch(void);
bool entropy_ready(void);
int entropy_extract(void *, size_t, int);