NetBSD Problem Report #59709

From www@netbsd.org  Sat Oct 18 17:59:39 2025
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 8749E1A923C
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 18 Oct 2025 17:59:39 +0000 (UTC)
Message-Id: <20251018175938.314431A923E@mollari.NetBSD.org>
Date: Sat, 18 Oct 2025 17:59:38 +0000 (UTC)
From: sr@genyosha.net
Reply-To: sr@genyosha.net
To: gnats-bugs@NetBSD.org
Subject: inconsistent entropy $random_file locations settings
X-Send-Pr-Version: www-1.0

>Number:         59709
>Category:       security
>Synopsis:       inconsistent entropy $random_file locations settings
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    security-officer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 18 18:00:00 +0000 2025
>Last-Modified:  Thu Nov 13 16:53:10 +0000 2025
>Originator:     Steve Rikli
>Release:        10.1 11.0_BETA
>Organization:
>Environment:
NetBSD vm01.home.genyosha.net 11.0_BETA NetBSD 11.0_BETA (GENERIC) #0: Thu Oct  9 09:29:07 UTC 2025  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
There are several separate methods and config files to set the system entropy
$random_file location, and they are independent/disconnected. This can lead to
unexpected entropy selection.

A recent email thread about this:
  https://mail-index.netbsd.org/netbsd-users/2025/10/12/msg033274.html

The /etc/rc.d/random_seed script sets:
  random_file="${random_file:-/var/db/entropy-file}"

this setting is in /etc/defaults/security.conf :
  random_file=/var/db/entropy-file

there is no setting or mention of random_file in /etc/defaults/rc.conf .

However, setting random_file in /etc/security.conf doesn't result in system
entropy using that file; instead the random_file location must be set in
/etc/rc.conf for the system to use it.

Note: sysinst properly adds a random_file setting to /etc/rc.conf during
initial install if needed, e.g. if / and /var/ are separate filesystems.

Documentation (man pages and /etc/defaults/* data) for the methods could be
better. The possible config files for setting entropy file location are:

1. /etc/rc.conf; random_file is mentioned but not described in rc.conf(5)
2. /etc/security.conf; security.conf(5) describes random_file pretty well
3. /boot.cfg; rndseed keyword is described in boot.cfg(5)

>How-To-Repeat:
1. set random_file location in /etc/security.conf, e.g. /etc/entropy-file
2. no random_file setting in /etc/rc.conf
3. during reboot, random_file location from /etc/security.conf is unused
4. /var/db/entropy-file will be created by /etc/rc.d/random_seed
 NOTE: this may be an undesired result, e.g. if / and /var/ are separate
  filesystems

The reverse case:

1. set random_file location in /etc/rc.conf, e.g. /etc/entropy-file
2. no random_file setting in /etc/security.conf
3. during reboot, random_file setting from rc.conf is used for system entropy

It's also possible to set different random_file values in rc.conf and
security.conf, but only rc.conf setting will be used for system entropy.
The 2nd file set by /etc/security.conf is mostly harmless, but pointless.

>Fix:
Summary from the mailing list thread: location of the entropy random_file should
be defined in one place, and rc.conf is the right place.

1. add to /etc/defaults/rc.conf

   random_file=/var/db/entropy-file

2. add text entry for random_file from security.conf(5) to rc.conf(5)

   random_file    Name of the entropy seed file used at boot.  Default is
                  /var/db/entropy-file as used by /etc/rc.d/random_seed.
                  Set random_file to empty to disable saving a seed every
                  time /etc/security runs.

3. Greg Troxel also suggests /etc/security should call /etc/rc.d/random_seed
   for entropy instead of separate code for random_file

Depending on step 3, these additional steps should be considered:

4. remove the random_file line from /etc/defaults/security.conf
5. remove the random_file text from security.conf(5)

>Release-Note:

>Audit-Trail:
From: Steve Rikli <sr@genyosha.net>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: misc/59709: inconsistent entropy $random_file locations settings
Date: Tue, 21 Oct 2025 14:35:00 -0700

 I did go ahead with Greg Troxel's suggestion to use etc/rc.d/random_seed
 in etc/security for saving entropy. It was a few lines of shell and
 config files, plus man page updates.

 My build.sh release is running now, I'll test the new sets afterwards,
 and see if I can figure out how to add the cvs diffs here.

From: Steve Rikli <sr@genyosha.net>
To: gnats-bugs@netbsd.org
Cc: misc-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: misc/59709: inconsistent entropy $random_file locations settings
Date: Fri, 24 Oct 2025 08:57:28 -0700

 PR misc/59709:
   location of the entropy random_file should be defined in one place, rc.conf

 changes:
 1. add missing random_file variable to /etc/defaults/rc.conf; sysinst already
    creates this setting in /etc/rc.conf but it is not documented

 2. add 'checkpoint' verb to /etc/rc.d/random_seed to distinguish from stop_cmd

 3. modify /etc/security to call /etc/rc.d/random_seed directly instead of
    running duplicate 'rndctl' code

 4. add new random_seed boolean to /etc/defaults/security.conf, remove
    now-unused random_file variable

 5. add random_file description to rc.conf(5)

 6. add random_seed description to security.conf(5), remove description for
    now-unused random_file

 Note that status quo behavior is unchanged:  /etc/security still saves
 system entropy periodically by default when run by daily cron. This fix
 unifies the command and file location for those system entropy updates.

 ----
 Index: etc/security
 ===================================================================
 RCS file: /cvsroot/src/etc/security,v
 retrieving revision 1.132
 diff -u -r1.132 security
 --- etc/security	21 Jul 2024 14:56:16 -0000	1.132
 +++ etc/security	24 Oct 2025 15:42:39 -0000
 @@ -1062,11 +1062,10 @@
  	CHANGELIST="$CHANGEFILES $CHANGELIST"
  fi

 -# Save entropy to ${random_file} if defined, like
 -# /etc/rc.d/random_seed.
 +# Save entropy if enabled, using /etc/rc.d/random_seed.
  #
 -if [ -n "${random_file:-}" ]; then
 -	rndctl -S "$random_file"
 +if checkyesno random_seed; then
 +	/etc/rc.d/random_seed checkpoint
  fi

  # Special case backups, including the master password file and
 Index: etc/defaults/rc.conf
 ===================================================================
 RCS file: /cvsroot/src/etc/defaults/rc.conf,v
 retrieving revision 1.167
 diff -u -r1.167 rc.conf
 --- etc/defaults/rc.conf	5 Oct 2023 08:19:27 -0000	1.167
 +++ etc/defaults/rc.conf	24 Oct 2025 15:42:39 -0000
 @@ -387,6 +387,7 @@
  # Entropy load/save to/from /dev/random at startup/shutdown
  #
  random_seed=YES
 +random_file=/var/db/entropy-file

  # Set to `check' to abort multi-user boot if not enough entropy, or
  # `wait' to wait until enough entropy, or `' (empty) to boot without
 Index: etc/defaults/security.conf
 ===================================================================
 RCS file: /cvsroot/src/etc/defaults/security.conf,v
 retrieving revision 1.28
 diff -u -r1.28 security.conf
 --- etc/defaults/security.conf	10 Jan 2021 23:24:25 -0000	1.28
 +++ etc/defaults/security.conf	24 Oct 2025 15:42:39 -0000
 @@ -48,4 +48,4 @@
  max_loginlen=16
  max_grouplen=16

 -random_file=/var/db/entropy-file
 +random_seed=YES
 Index: etc/rc.d/random_seed
 ===================================================================
 RCS file: /cvsroot/src/etc/rc.d/random_seed,v
 retrieving revision 1.15
 diff -u -r1.15 random_seed
 --- etc/rc.d/random_seed	8 Sep 2020 12:52:18 -0000	1.15
 +++ etc/rc.d/random_seed	24 Oct 2025 15:42:39 -0000
 @@ -21,6 +21,8 @@
  rcvar=$name
  start_cmd="random_load"
  stop_cmd="random_save"
 +checkpoint_cmd="random_save"
 +extra_commands="checkpoint"

  random_file="${random_file:-/var/db/entropy-file}"

 Index: share/man/man5/rc.conf.5
 ===================================================================
 RCS file: /cvsroot/src/share/man/man5/rc.conf.5,v
 retrieving revision 1.194
 diff -u -r1.194 rc.conf.5
 --- share/man/man5/rc.conf.5	2 Oct 2024 15:56:37 -0000	1.194
 +++ share/man/man5/rc.conf.5	24 Oct 2025 15:42:51 -0000
 @@ -547,6 +547,12 @@
  .Xr quotacheck 8
  and
  .Xr quotaon 8 .
 +.It Sy random_file
 +Name of the entropy seed file used at boot.
 +Default is
 +.Pa /var/db/entropy-file
 +as used by
 +.Pa /etc/rc.d/random_seed .
  .It Sy random_seed
  Boolean value.
  During boot-up, runs the
 Index: share/man/man5/security.conf.5
 ===================================================================
 RCS file: /cvsroot/src/share/man/man5/security.conf.5,v
 retrieving revision 1.44
 diff -u -r1.44 security.conf.5
 --- share/man/man5/security.conf.5	14 Nov 2024 19:57:41 -0000	1.44
 +++ share/man/man5/security.conf.5	24 Oct 2025 15:42:51 -0000
 @@ -165,6 +165,11 @@
  .It Sy check_pkg_signatures
  Checks the digital signature of all files installed by packages against
  the expected values stored in the packages database.
 +.It Sy random_seed
 +Save
 +.Xr entropy 7
 +seed file used at boot, by running 
 +.Pa /etc/rc.d/random_seed.
  .El
  .Pp
  The variables described below can be set to modify the tests:
 @@ -285,17 +290,6 @@
  and
  .Sy check_changelist
  instead of just keeping a current copy and a backup copy.
 -.It Sy random_file
 -Name of the entropy seed file used at boot.
 -Default is
 -.Pa /var/db/entropy-file
 -as used by
 -.Pa /etc/rc.d/random_seed .
 -Set
 -.Sy random_file
 -to empty to disable saving a seed every time
 -.Pa /etc/security
 -runs.
  .El
  .Sh FILES
  .Bl -tag -width /etc/defaults/security.conf -compact

From: Steve Rikli <sr@genyosha.net>
To: gnats-bugs@netbsd.org
Cc: misc-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: misc/59709: inconsistent entropy $random_file locations settings
Date: Wed, 12 Nov 2025 20:06:22 -0800

 Should this PR have been filed under Category: security rather than misc?

Responsible-Changed-From-To: misc-bug-people->security-officer
Responsible-Changed-By: gutteridge@NetBSD.org
Responsible-Changed-When: Thu, 13 Nov 2025 16:53:10 +0000
Responsible-Changed-Why:
Move to security, per submitter's suggestion.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.