Re: [RFC PATCH 1/2] random: Expose boot ID to other subsystems

From
Jason A. Donenfeld <Jason@zx2c4.com>
Date
2026-06-12 17:05:02
Also in
lkml
Reply to
Masami Hiramatsu (Google), 2026-05-21
On Thu, May 21, 2026 at 11:57:09PM +0900, Masami Hiramatsu (Google) wrote:
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

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?
quoted hunk ↗ jump to hunk
+/**
+ * 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?
Thread (10 messages) 10 messages, 4 authors, last reply 2026-06-22
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help