mirror of
https://github.com/opnsense/src.git
synced 2026-02-15 16:48:36 -05:00
Refactor of /dev/random device. Main points include: * Userland seeding is no longer used. This auto-seeds at boot time on PC/Desktop setups; this may need some tweeking and intelligence from those folks setting up embedded boxes, but the work is believed to be minimal. * An entropy cache is written to /entropy (even during installation) and the kernel uses this at next boot. * An entropy file written to /boot/entropy can be loaded by loader(8) * Hardware sources such as rdrand are fed into Yarrow, and are no longer available raw. ------------------------------------------------------------------------ r256240 | des | 2013-10-09 21:14:16 +0100 (Wed, 09 Oct 2013) | 4 lines Add a RANDOM_RWFILE option and hide the entropy cache code behind it. Rename YARROW_RNG and FORTUNA_RNG to RANDOM_YARROW and RANDOM_FORTUNA. Add the RANDOM_* options to LINT. ------------------------------------------------------------------------ r256239 | des | 2013-10-09 21:12:59 +0100 (Wed, 09 Oct 2013) | 2 lines Define RANDOM_PURE_RNDTEST for rndtest(4). ------------------------------------------------------------------------ r256204 | des | 2013-10-09 18:51:38 +0100 (Wed, 09 Oct 2013) | 2 lines staticize struct random_hardware_source ------------------------------------------------------------------------ r256203 | markm | 2013-10-09 18:50:36 +0100 (Wed, 09 Oct 2013) | 2 lines Wrap some policy-rich code in 'if NOTYET' until we can thresh out what it really needs to do. ------------------------------------------------------------------------ r256184 | des | 2013-10-09 10:13:12 +0100 (Wed, 09 Oct 2013) | 2 lines Re-add /dev/urandom for compatibility purposes. ------------------------------------------------------------------------ r256182 | des | 2013-10-09 10:11:14 +0100 (Wed, 09 Oct 2013) | 3 lines Add missing include guards and move the existing ones out of the implementation namespace. ------------------------------------------------------------------------ r256168 | markm | 2013-10-08 23:14:07 +0100 (Tue, 08 Oct 2013) | 10 lines Fix some just-noticed problems: o Allow this to work with "nodevice random" by fixing where the MALLOC pool is defined. o Fix the explicit reseed code. This was correct as submitted, but in the project branch doesn't need to set the "seeded" bit as this is done correctly in the "unblock" function. o Remove some debug ifdeffing. o Adjust comments. ------------------------------------------------------------------------ r256159 | markm | 2013-10-08 19:48:11 +0100 (Tue, 08 Oct 2013) | 6 lines Time to eat crow for me. I replaced the sx_* locks that Arthur used with regular mutexes; this turned out the be the wrong thing to do as the locks need to be sleepable. Revert this folly. # Submitted by: Arthur Mesh <arthurmesh@gmail.com> (In original diff) ------------------------------------------------------------------------ r256138 | des | 2013-10-08 12:05:26 +0100 (Tue, 08 Oct 2013) | 10 lines Add YARROW_RNG and FORTUNA_RNG to sys/conf/options. Add a SYSINIT that forces a reseed during proc0 setup, which happens fairly late in the boot process. Add a RANDOM_DEBUG option which enables some debugging printf()s. Add a new RANDOM_ATTACH entropy source which harvests entropy from the get_cyclecount() delta across each call to a device attach method. ------------------------------------------------------------------------ r256135 | markm | 2013-10-08 07:54:52 +0100 (Tue, 08 Oct 2013) | 8 lines Debugging. My attempt at EVENTHANDLER(multiuser) was a failure; use EVENTHANDLER(mountroot) instead. This means we can't count on /var being present, so something will need to be done about harvesting /var/db/entropy/... . Some policy now needs to be sorted out, and a pre-sync cache needs to be written, but apart from that we are now ready to go. Over to review. ------------------------------------------------------------------------ r256094 | markm | 2013-10-06 23:45:02 +0100 (Sun, 06 Oct 2013) | 8 lines Snapshot. Looking pretty good; this mostly works now. New code includes: * Read cached entropy at startup, both from files and from loader(8) preloaded entropy. Failures are soft, but announced. Untested. * Use EVENTHANDLER to do above just before we go multiuser. Untested. ------------------------------------------------------------------------ r256088 | markm | 2013-10-06 14:01:42 +0100 (Sun, 06 Oct 2013) | 2 lines Fix up the man page for random(4). This mainly removes no-longer-relevant details about HW RNGs, reseeding explicitly and user-supplied entropy. ------------------------------------------------------------------------ r256087 | markm | 2013-10-06 13:43:42 +0100 (Sun, 06 Oct 2013) | 6 lines As userland writing to /dev/random is no more, remove the "better than nothing" bootstrap mode. Add SWI harvesting to the mix. My box seeds Yarrow by itself in a few seconds! YMMV; more to follow. ------------------------------------------------------------------------ r256086 | markm | 2013-10-06 13:40:32 +0100 (Sun, 06 Oct 2013) | 11 lines Debug run. This now works, except that the "live" sources haven't been tested. With all sources turned on, this unlocks itself in a couple of seconds! That is no my box, and there is no guarantee that this will be the case everywhere. * Cut debug prints. * Use the same locks/mutexes all the way through. * Be a tad more conservative about entropy estimates. ------------------------------------------------------------------------ r256084 | markm | 2013-10-06 13:35:29 +0100 (Sun, 06 Oct 2013) | 5 lines Don't use the "real" assembler mnemonics; older compilers may not understand them (like when building CURRENT on 9.x). # Submitted by: Konstantin Belousov <kostikbel@gmail.com> ------------------------------------------------------------------------ r256081 | markm | 2013-10-06 10:55:28 +0100 (Sun, 06 Oct 2013) | 12 lines SNAPSHOT. Simplify the malloc pools; We only need one for this device. Simplify the harvest queue. Marginally improve the entropy pool hashing, making it a bit faster in the process. Connect up the hardware "live" source harvesting. This is simplistic for now, and will need to be made rate-adaptive. All of the above passes a compile test but needs to be debugged. ------------------------------------------------------------------------ r256042 | markm | 2013-10-04 07:55:06 +0100 (Fri, 04 Oct 2013) | 25 lines Snapshot. This passes the build test, but has not yet been finished or debugged. Contains: * Refactor the hardware RNG CPU instruction sources to feed into the software mixer. This is unfinished. The actual harvesting needs to be sorted out. Modified by me (see below). * Remove 'frac' parameter from random_harvest(). This was never used and adds extra code for no good reason. * Remove device write entropy harvesting. This provided a weak attack vector, was not very good at bootstrapping the device. To follow will be a replacement explicit reseed knob. * Separate out all the RANDOM_PURE sources into separate harvest entities. This adds some secuity in the case where more than one is present. * Review all the code and fix anything obviously messy or inconsistent. Address som review concerns while I'm here, like rename the pseudo-rng to 'dummy'. # Submitted by: Arthur Mesh <arthurmesh@gmail.com> (the first item) ------------------------------------------------------------------------ r255319 | markm | 2013-09-06 18:51:52 +0100 (Fri, 06 Sep 2013) | 4 lines Yarrow wants entropy estimations to be conservative; the usual idea is that if you are certain you have N bits of entropy, you declare N/2. ------------------------------------------------------------------------ r255075 | markm | 2013-08-30 18:47:53 +0100 (Fri, 30 Aug 2013) | 4 lines Remove short-lived idea; thread to harvest (eg) RDRAND enropy into the usual harvest queues. It was a nifty idea, but too heavyweight. # Submitted by: Arthur Mesh <arthurmesh@gmail.com> ------------------------------------------------------------------------ r255071 | markm | 2013-08-30 12:42:57 +0100 (Fri, 30 Aug 2013) | 4 lines Separate out the Software RNG entropy harvesting queue and thread into its own files. # Submitted by: Arthur Mesh <arthurmesh@gmail.com> ------------------------------------------------------------------------ r254934 | markm | 2013-08-26 20:07:03 +0100 (Mon, 26 Aug 2013) | 2 lines Remove the short-lived namei experiment. ------------------------------------------------------------------------ r254928 | markm | 2013-08-26 19:35:21 +0100 (Mon, 26 Aug 2013) | 2 lines Snapshot; Do some running repairs on entropy harvesting. More needs to follow. ------------------------------------------------------------------------ r254927 | markm | 2013-08-26 19:29:51 +0100 (Mon, 26 Aug 2013) | 15 lines Snapshot of current work; 1) Clean up namespace; only use "Yarrow" where it is Yarrow-specific or close enough to the Yarrow algorithm. For the rest use a neutral name. 2) Tidy up headers; put private stuff in private places. More could be done here. 3) Streamline the hashing/encryption; no need for a 256-bit counter; 128 bits will last for long enough. There are bits of debug code lying around; these will be removed at a later stage. ------------------------------------------------------------------------ r254784 | markm | 2013-08-24 14:54:56 +0100 (Sat, 24 Aug 2013) | 39 lines 1) example (partially humorous random_adaptor, that I call "EXAMPLE") * It's not meant to be used in a real system, it's there to show how the basics of how to create interfaces for random_adaptors. Perhaps it should belong in a manual page 2) Move probe.c's functionality in to random_adaptors.c * rename random_ident_hardware() to random_adaptor_choose() 3) Introduce a new way to choose (or select) random_adaptors via tunable "rngs_want" It's a list of comma separated names of adaptors, ordered by preferences. I.e.: rngs_want="yarrow,rdrand" Such setting would cause yarrow to be preferred to rdrand. If neither of them are available (or registered), then system will default to something reasonable (currently yarrow). If yarrow is not present, then we fall back to the adaptor that's first on the list of registered adaptors. 4) Introduce a way where RNGs can play a role of entropy source. This is mostly useful for HW rngs. The way I envision this is that every HW RNG will use this functionality by default. Functionality to disable this is also present. I have an example of how to use this in random_adaptor_example.c (see modload event, and init function) 5) fix kern.random.adaptors from kern.random.adaptors: yarrowpanicblock to kern.random.adaptors: yarrow,panic,block 6) add kern.random.active_adaptor to indicate currently selected adaptor: root@freebsd04:~ # sysctl kern.random.active_adaptor kern.random.active_adaptor: yarrow # Submitted by: Arthur Mesh <arthurmesh@gmail.com> Submitted by: Dag-Erling Smørgrav <des@FreeBSD.org>, Arthur Mesh <arthurmesh@gmail.com> Reviewed by: des@FreeBSD.org Approved by: re (delphij) Approved by: secteam (des,delphij) |
||
|---|---|---|
| .. | ||
| arm | ||
| common | ||
| efi | ||
| fdt | ||
| ficl | ||
| ficl64 | ||
| forth | ||
| i386 | ||
| ia64 | ||
| ofw | ||
| pc98 | ||
| powerpc | ||
| sparc64 | ||
| uboot | ||
| usb | ||
| userboot | ||
| zfs | ||
| Makefile | ||
| Makefile.amd64 | ||
| Makefile.arm | ||
| Makefile.i386 | ||
| Makefile.ia64 | ||
| Makefile.inc | ||
| Makefile.pc98 | ||
| Makefile.powerpc | ||
| Makefile.sparc64 | ||
| README | ||
$FreeBSD$
README file, for the boot config file setup. This is meant
to explain how to manage the loader configuration process.
The boot and loading process is either defined, or being
defined in boot(8) and loader(8).
The ongoing development of the FreeBSD bootloader, and its
rapid deployment while still in the development phase, has
resulted in a large number of installations with outdated
configurations. Those installations actively tracking the
FreeBSD development should also ensure that their bootloader
configurations are updated. If you see files discussed here
that your system doesn't yet have, add them yourself.
This is an effort to give the currently correct method for
setting up your boot process. It includes information on
setting up screen savers and plug and play information, and
also on recording any changes you make in your kernel
configuration. This file is temporary, because as I noted,
the process is still undergoing development, and will still
change. Man pages are coming out, but they're still going
to be somewhat fragile for a while. If you note anything in
here that's broken, it would be a good idea to report it to
the FreeBSD-current list, or to Daniel C. Sobral
<dcs@FreeBSD.org> or Mike Smith <msmith@FreeBSD.org>.
After the first two stages in the booting process (described
in boot(8)), the last stage of the booting process, called
the loader (see loader(8)) reads in the /boot/loader.rc
file. The two lines you should have there are:
include /boot/loader.4th
start
This reads the ficl (forth) initialization files, then
/boot/default/loader.conf. This file, which strongly
resembles in form /etc/rc.conf but functions quite
differently, has spots for endless user customization but
isn't yet completely finished. For one thing, it used to
assume a /kernel.config instead of a /boot/kernel.conf.
Watch the first few lines of /boot/defaults/loader.conf to
see if the file name changes.
[See the section at the end on loader.conf syntax]
You don't actually want to make any changes to
/boot/defaults/loader.conf, the file that is a hacking-
target is:
/boot/loader.conf
and might very likely not exist yet on your system). You
should copy /boot/defaults/loader.conf to /boot/loader.conf,
and then cut out anything you didn't want changed.
The start command also loads your kernel for you, so don't
put any lines in there like "load kernel", they'll fail (but
really have already worked for you). Start also reads in
the file /boot/defaults/loader.conf and /boot/loader.conf.
If you don't have /boot/loader.conf, you'll see a message on
boot about it, but it's a warning only, no other effects.
See the section on loader.conf syntax at the end of this
document, for some more pointers on loader.conf syntax.
The best way to manage splash screens is with entries in
/boot/loader.conf, and this is very clearly illustrated in
/boot/defaults/loader.conf (which you could just copy over
to /boot/loader.conf). I'm going to illustrate here how you
*could* do it in /boot/loader.rc (for information only)
but I don't recommend you do this; use the
/boot/defaults/loader.conf syntax, it's easier to get it
correct.
You can load your splash screen by putting the following
lines into /boot/loader.rc:
load splash_bmp
load -t splash_image_data /path/to/file.bmp
The top line causes the splash_bmp module to get loaded.
The second line has the parameter "-t" which tells the
loader that the class of DATA being loaded is not a module,
but instead a splash_image_data located in file
/path/to/file.bmp.
To get your plug and play data correctly set, run kget,
redirecting the output to /boot/kernel.conf. Note that kget
right now adds an extra "q" to it's output (from the q for
quit you press when you exit config), and if you want, you
can remove that from the file. Kget reports data only, so
feel free to run it, just to see the output. Make certain
you have the kernel option USERCONFIG set in your kernel, so
that you can do a boot -c, to initially set your cards up.
Then, edit /boot/loader.conf so that the following line
shows up (overwriting, in effect, a similar line in
/boot/default/loader.conf):
userconfig_script_load="YES"
My own pnp line looks like:
pnp 1 0 os irq0 15 irq1 0 drq0 1 drq1 0 port0 1332
(kget changes numbers from hexadecimal to decimal). Note
that, at this moment, the change from using /kernel.config
to using /boot/kernel.conf as the storage place for kernel
config changes is going on. Take a look at your
/boot/defaults/loader.conf, see what's defined as
userconfig_script_name, and if you override, make sure the
file exists. Note that the loader only has access to the
root filesystem, so be careful where you tell it to read
from.
o If you interrupt autoboot, you'll engage interactive
mode with loader. Everything you type will have the
same effects as if it were lines in /boot/loader.rc.
o While in interactive mode, you can get help by typing
"?", "help [<topic> [<subtopic>]]" and "help index".
These are mostly commands one would expect a normal
user to use. I recommend you play with them a little,
to gain further familiarity with what's going on.
Note that it is not possible to damage or corrupt your
system while experimenting with the loader, as it
cannot write to any of your filesystems.
o The command "unload" will unload everything. This is
very useful. Once loader.rc has finished and the
system is in the autoboot count-down, you will usually
have the kernel and other modules loaded. Now, suppose
your new /kernel is broken, how do you load
/kernel.old? By typing:
unload
load kernel.old
[any other modules you wish to load]
boot
o If you use loader.conf, you can do:
unload
set kernel=kernel.old
boot-conf
this will then load all the modules you have
configured, using kernel.old as kernel, and boot.
o From loader, you can use the command "more" to read the
contents of /boot/loader.rc, if you wish. This is not
FreeBSD's more. It is one of loader's builtin commands.
Useful if you can't quite recall what you have there.
:-) Of course, you can use this command to read
anything else you want.
o "boot -flag" works, "boot kernelname" works, "boot
-flag kernelname" doesn't. "boot kernelname -flag"
might work, but I'm not sure. The problem is that these
flags are kernel's flags, not boot's flags.
o There are a number of variables that can be set. You
can see them in loader.conf, but you can get much more
detailed information using the "help" command, eg. help
set <variablename>.
o The variable root_disk_unit is particularly important,
as it solves a relatively common problem. This problem
shows when the BIOS assign disk units in a different
way than the kernel. For example, if you have two IDE
disks, one on the primary, the other on the secondary
controller, and both as master, the default in most
kernels is having the first as wd0, and the second as
wd2. If your root partition is in wd2, you'll get an
error, because the BIOS sees these disks as 0 and 1
(well, 1 and 2), and that's what loader tells the
kernel. In this case, "set root_disk_unit=2" solves the
problem. You use this whenever the kernel fails to
mount to root partition because it has a wrong unit
number.
FILE OVERVIEW
o /boot/defaults/loader.conf -- Master configuration
file, not to be edited. Overridden by
/boot/loader.conf.
o /boot/loader.conf -- local system customization file,
in form very much like /boot/defaults/loader.conf.
This file is meant to be used by local users and the
sysinstall process.
o /boot/loader.conf.local -- local installation override
file. This is intended for use by installations with
large numbers of systems, to allow global policy
overrides. No FreeBSD tools should ever write this
file.
o /kernel.config -- old location of kernel configuration
changes (like pnp changes).
o /boot/kernel.conf -- new location for kernel
configuration changes.
o /boot/loader.rc -- loader initial configuration file,
chiefly used to source in a forth file, and start the
configuration process.
NOTES ON LOADER.CONF SYNTAX
I'm copy here from the last 11 lines from
/boot/defaults/loader.conf:
##############################################################
### Module loading syntax example ##########################
##############################################################
#module_load="YES" # loads module "module"
#module_name="realname" # uses "realname" instead of "module"
#module_type="type" # passes "-t type" to load
#module_flags="flags" # passes "flags" to the module
#module_before="cmd" # executes "cmd" before loading module
#module_after="cmd" # executes "cmd" after loading module
#module_error="cmd" # executes "cmd" if load fails
The way this works, the command processor used by the loader
(which is a subset of forth) inspects these variables for
their suffix, and the 7 lines above illustrate all the
currently defined suffixes, and their use. Take the part
before the underscore, and customize it i(make it unique)
for your particular use, keeping the suffix to allow the
particular function you want to activate. Extra underscores
are fine, because it's only the sufixes that are scanned
for.
(authors Chuck Robey and Daniel Sobral).