Module Name:    src
Committed By:   riastradh
Date:           Tue Aug 27 00:56:47 UTC 2024

Modified Files:
        src/sys/dev: random.c
        src/sys/dev/acpi: acpi_vmgenid.c
        src/sys/kern: kern_entropy.c
        src/sys/sys: entropy.h

Log Message:
entropy(9): Merge entropy_consolidate, entropy_consolidate_sig.

entropy_consolidate can already be interrupted by a signal -- it just
doesn't tell the caller this happened.  So make it return the error
code, and delete entropy_consolidate_sig.

NOTE: This changes the semantics of an existing symbol, so it can't
be pulled up.  (It might in principle be ABI-compatible because the
old symbol returned void and the new one returns int, so the caller
can just ignore the return value register in most if not all ABIs,
but I organized the relevant changes so we can pull up bug fixes
without thinking about this.)  This is just tidying the kernel API
after all the previous fixes which can be pulled up.

PR kern/58646: /dev/random, kern.entropy.*: signal bugs


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/random.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/acpi_vmgenid.c
cvs rdiff -u -r1.71 -r1.72 src/sys/kern/kern_entropy.c
cvs rdiff -u -r1.6 -r1.7 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/dev/random.c
diff -u src/sys/dev/random.c:1.11 src/sys/dev/random.c:1.12
--- src/sys/dev/random.c:1.11	Mon Aug 26 13:46:51 2024
+++ src/sys/dev/random.c	Tue Aug 27 00:56:47 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: random.c,v 1.11 2024/08/26 13:46:51 riastradh Exp $	*/
+/*	$NetBSD: random.c,v 1.12 2024/08/27 00:56:47 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: random.c,v 1.11 2024/08/26 13:46:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: random.c,v 1.12 2024/08/27 00:56:47 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -299,7 +299,7 @@ random_write(dev_t dev, struct uio *uio,
 
 	/* If we added anything, consolidate entropy now.  */
 	if (any && error == 0)
-		error = entropy_consolidate_sig();
+		error = entropy_consolidate();
 
 	return error;
 }

Index: src/sys/dev/acpi/acpi_vmgenid.c
diff -u src/sys/dev/acpi/acpi_vmgenid.c:1.2 src/sys/dev/acpi/acpi_vmgenid.c:1.3
--- src/sys/dev/acpi/acpi_vmgenid.c:1.2	Mon Aug 26 13:53:22 2024
+++ src/sys/dev/acpi/acpi_vmgenid.c	Tue Aug 27 00:56:46 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_vmgenid.c,v 1.2 2024/08/26 13:53:22 riastradh Exp $	*/
+/*	$NetBSD: acpi_vmgenid.c,v 1.3 2024/08/27 00:56:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_vmgenid.c,v 1.2 2024/08/26 13:53:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_vmgenid.c,v 1.3 2024/08/27 00:56:46 riastradh Exp $");
 
 #include <sys/device.h>
 #include <sys/entropy.h>
@@ -306,9 +306,11 @@ acpivmgenid_reset(void *cookie)
 	 * Grab the current VM generation ID to put it into the entropy
 	 * pool; then force consolidation so it affects all subsequent
 	 * draws from the entropy pool and the entropy epoch advances.
+	 * Again we can't be interrupted by a signal so ignore return
+	 * value.
 	 */
 	acpivmgenid_set(sc, "cloned");
-	entropy_consolidate();
+	(void)entropy_consolidate();
 }
 
 static int

Index: src/sys/kern/kern_entropy.c
diff -u src/sys/kern/kern_entropy.c:1.71 src/sys/kern/kern_entropy.c:1.72
--- src/sys/kern/kern_entropy.c:1.71	Mon Aug 26 15:50:15 2024
+++ src/sys/kern/kern_entropy.c	Tue Aug 27 00:56:47 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_entropy.c,v 1.71 2024/08/26 15:50:15 riastradh Exp $	*/
+/*	$NetBSD: kern_entropy.c,v 1.72 2024/08/27 00:56:47 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.71 2024/08/26 15:50:15 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.72 2024/08/27 00:56:47 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -1355,19 +1355,6 @@ entropy_notify(void)
  * entropy_consolidate()
  *
  *	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
@@ -1377,7 +1364,7 @@ entropy_consolidate(void)
  *	transition to full entropy.
  */
 int
-entropy_consolidate_sig(void)
+entropy_consolidate(void)
 {
 	uint64_t ticket;
 	int error;
@@ -1420,7 +1407,7 @@ sysctl_entropy_consolidate(SYSCTLFN_ARGS
 	if (error || newp == NULL)
 		return error;
 	if (arg)
-		error = entropy_consolidate_sig();
+		error = entropy_consolidate();
 
 	return error;
 }
@@ -2818,7 +2805,7 @@ entropy_ioctl(unsigned long cmd, void *d
 		/* Enter the data and consolidate entropy.  */
 		rnd_add_data(&seed_rndsource, rdata->data, rdata->len,
 		    entropybits);
-		error = entropy_consolidate_sig();
+		error = entropy_consolidate();
 		break;
 	}
 	default:

Index: src/sys/sys/entropy.h
diff -u src/sys/sys/entropy.h:1.6 src/sys/sys/entropy.h:1.7
--- src/sys/sys/entropy.h:1.6	Mon Aug 26 13:52:56 2024
+++ src/sys/sys/entropy.h	Tue Aug 27 00:56:47 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: entropy.h,v 1.6 2024/08/26 13:52:56 riastradh Exp $	*/
+/*	$NetBSD: entropy.h,v 1.7 2024/08/27 00:56:47 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -51,8 +51,7 @@ struct knote;
 void	entropy_bootrequest(void);
 void	entropy_reset(void);
 int	entropy_gather(void);
-void	entropy_consolidate(void);
-int	entropy_consolidate_sig(void);
+int	entropy_consolidate(void);
 unsigned entropy_epoch(void);
 bool	entropy_ready(void);
 int	entropy_extract(void *, size_t, int);

Reply via email to