HomeFreeBSD

MFC fixes to hostuuid handling

Description

MFC fixes to hostuuid handling

330f110b:
Fix 'hostuuid: preload data malformed' warning

If the preloaded hostuuid value is invalid and verbose booting is
enabled, a warning is printed. This printf had two bugs:

  1. It was missing a trailing \n character.
  2. The malformed UUID is printed with %s even though it is not known

to be NUL-terminated.

This commit adds the missing \n and uses %.*s with the (already known)
length of the preloaded UUID to ensure that we don't read past the end
of the buffer.

Reported by: kevans
Fixes: c3188289 Preload hostuuid for early-boot use

b6be9566:
Fix buffer overflow in preloaded hostuuid cleaning

When a module of type "hostuuid" is provided by the loader,
prison0_init strips any trailing whitespace and ASCII control
characters by (a) adjusting the buffer length, and (b) zeroing out
the characters in question, before storing it as the system's
hostuuid.

The buffer length adjustment was correct, but the zeroing overwrote
one byte higher in memory than intended -- in the typical case,
zeroing one byte past the end of the hostuuid buffer. Due to the
layout of buffers passed by the boot loader to the kernel, this will
be the first byte of a subsequent buffer.

This was *probably* harmless; prison0_init runs after preloaded kernel
modules have been linked and after the preloaded /boot/entropy cache
has been processed, so in both cases having the first byte overwritten
will not cause problems. We cannot however rule out the possibility
that other objects which are preloaded by the loader could suffer from
having the first byte overwritten.

Since the zeroing does not in fact serve any purpose, remove it and
trim trailing whitespace and ASCII control characters by adjusting
the buffer length alone.

Fixes: c3188289 Preload hostuuid for early-boot use
Reviewed by: kevans, markj

(cherry picked from commit 330f110bf1e420dc8d8ddadc4030e0ae1f1c52bd)
(cherry picked from commit b6be9566d236f83ad1a44170a64b9a34e382eafa)

Details

Provenance
cpercivaAuthored on May 15 2021, 5:57 AM
Parents
rGc910e015ba8b: Correct assert added to dump program.
Branches
Unknown
Tags
Unknown