Re: [RFC PATCH 1/2] random: Expose boot ID to other subsystems
From: Google
Date: Mon Jun 22 2026 - 00:52:31 EST
On Fri, 12 Jun 2026 19:04:56 +0200
"Jason A. Donenfeld" <Jason@xxxxxxxxx> wrote:
> On Thu, May 21, 2026 at 11:57:09PM +0900, Masami Hiramatsu (Google) wrote:
> > From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
> >
> > Add get_boot_id() to expose current boot ID to other kernel subsystems.
> > Note that since this is only meaningful if user can access it via sysctl,
> > it returns NULL if CONFIG_SYSCTL=n.
>
> Wouldn't this be nice to have even on !SYSCTL systems? Why disable it for this
> case?
Unless user reads and records the boot_id, it is just a random number.
Thus it must be exposed to user space.
Anyway, this does not work as I expected, because to generate really
useful random number, user needs to ensure that enough entropy is
collected. If any component uses this from early boot or boot time,
we will generate less unique number.
Thanks,
>
> > +/**
> > + * get_boot_id - return the boot ID UUID
> > + *
> > + * This function returns a pointer to the boot ID UUID, which is generated on
> > + * demand the first time this function is called. The boot ID is a UUID that
> > + * is unique to each boot of the system.
> > + */
> > +const u8 *get_boot_id(void)
> > +{
> > + static DEFINE_SPINLOCK(bootid_spinlock);
> > +
> > + spin_lock(&bootid_spinlock);
> > + if (!sysctl_bootid[8])
> > + generate_random_uuid(sysctl_bootid);
> > + spin_unlock(&bootid_spinlock);
> > +
> > + return sysctl_bootid;
> > +}
> > +
> > /*
> > * This function is used to return both the bootid UUID, and random
> > * UUID. The difference is in whether table->data is NULL; if it is,
> > @@ -1638,12 +1657,8 @@ static int proc_do_uuid(const struct ctl_table *table, int write, void *buf,
> > uuid = tmp_uuid;
> > generate_random_uuid(uuid);
> > } else {
> > - static DEFINE_SPINLOCK(bootid_spinlock);
> > -
> > - spin_lock(&bootid_spinlock);
> > - if (!uuid[8])
> > - generate_random_uuid(uuid);
> > - spin_unlock(&bootid_spinlock);
> > + /* Ensure that the boot ID is initialized. */
> > + get_boot_id();
>
> I find this a little odd, this implicit behavior now that sysctl_bootid ==
> uuid. But perhaps that's the cleanest approach there is?
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>