]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
MFC r359953, r359980, r359999: hostuuid preload
authorKyle Evans <kevans@FreeBSD.org>
Mon, 27 Apr 2020 22:29:24 +0000 (22:29 +0000)
committerKyle Evans <kevans@FreeBSD.org>
Mon, 27 Apr 2020 22:29:24 +0000 (22:29 +0000)
commit9db00827abd0991f97109c45afbf6d362548f912
treef309c57fc824c9ac87f0cdc518f29c60ea4b9994
parent1041e7c61ba46ffb071a323f1ec4c7888d3bb2db
MFC r359953, r359980, r359999: hostuuid preload

r359953:
kern uuid: break format validation out into a separate KPI

This new KPI, validate_uuid, strictly validates the formatting of the input
UUID and, optionally, populates a given struct uuid.

As noted in the header, the key differences are that the new KPI won't
recognize an empty string as a nil UUID and it won't do any kind of semantic
validation on it. Also key is that populating a struct uuid is optional, so
the caller doesn't necessarily need to allocate a bogus one on the stack
just to validate the string.

This KPI has specifically been broken out in support of D24288, which will
preload /etc/hostid in loader so that early boot hostuuid users (e.g.
anything that calls ether_gen_addr) can have a valid hostuuid to work with
once it's been stashed in /etc/hostid.

r359980:
validate_uuid: absorb the rest of parse_uuid with a flags arg

This makes the naming annoyance (validate_uuid vs. parse_uuid) less of an
issue and centralizes all of the functionality into the new KPI while still
making the extra validation optional. The end-result is all the same as far
as hostuuid validation-only goes.

r359999:
Preload hostuuid for early-boot use

prison0's hostuuid will get set by the hostid rc script, either after
generating it and saving it to /etc/hostid or by simply reading /etc/hostid.

Some things (e.g. arbitrary MAC address generation) may use the hostuuid as
a factor in early boot, so providing a way to read /etc/hostid (if it's
available) and using it before userland starts up is desirable. The code is
written such that the preload doesn't *have* to be /etc/hostid, thus not
assuming that there will be newline at the end of the buffer or even the
exact shape of the newline. White trailing whitespace/non-printables
trimmed, the result will be validated as a valid uuid before it's used for
early boot purposes.

The preload can be turned off with hostuuid_load="NO" in /boot/loader.conf,
just as other preloads; it's worth noting that this is a 37-byte file, the
overhead is believed to be generally minimal.

It doesn't seem necessary at this time to be concerned with kern.hostid.

One does wonder if we should consider validating hostuuids coming in
via jail_set(2); some bits seem to care about uuid form and we bother
validating format of smbios-provided uuid and in-fact whatever uuid comes
from /etc/hostid.
stand/defaults/loader.conf
sys/kern/kern_jail.c
sys/kern/kern_uuid.c
sys/sys/uuid.h