Skip to contentSkip to conversation

sysctl: introduce uuid_le and uuid_be

PATCH In review Andy Shevchenko 3 participants 4 messages May 24, 2016 – May 26, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sysctl: introduce uuid_le and uuid_be

By default the sysctl interface returns random UUID in big endian format. Sometimes it's not suitable, e.g. using generated UUID for EFI variable name. Provide uuid_le and uuid_be to comprehence that interface.

---
 drivers/char/random.c       | 44 +++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/sysctl.h |  4 +++-
 kernel/sysctl_binary.c      | 48 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 94 insertions(+), 2 deletions(-)
drivers/char/random.c +44 -0
index 0158d3b..a864013 100644
@@ -1673,6 +1673,38 @@ static int proc_do_uuid(struct ctl_table *table, int write,
 	return proc_dostring(&fake_table, write, buffer, lenp, ppos);
 }
 
+static int proc_do_uuid_le(struct ctl_table *table, int write,
+			   void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	struct ctl_table fake_table;
+	unsigned char buf[64];
+	uuid_le uuid;
+
+	uuid_le_gen(&uuid);
+	sprintf(buf, "%pUl", &uuid);
+
+	fake_table.data = buf;
+	fake_table.maxlen = sizeof(buf);
+
+	return proc_dostring(&fake_table, write, buffer, lenp, ppos);
+}
+
+static int proc_do_uuid_be(struct ctl_table *table, int write,
+			   void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	struct ctl_table fake_table;
+	unsigned char buf[64];
+	uuid_be uuid;
+
+	uuid_be_gen(&uuid);
+	sprintf(buf, "%pUb", &uuid);
+
+	fake_table.data = buf;
+	fake_table.maxlen = sizeof(buf);
+
+	return proc_dostring(&fake_table, write, buffer, lenp, ppos);
+}
+
 /*
  * Return entropy available scaled to integral bits
  */
@@ -1745,6 +1777,18 @@ struct ctl_table random_table[] = {
 		.mode		= 0444,
 		.proc_handler	= proc_do_uuid,
 	},
+	{
+		.procname	= "uuid_le",
+		.maxlen		= 16,
+		.mode		= 0444,
+		.proc_handler	= proc_do_uuid_le,
+	},
+	{
+		.procname	= "uuid_be",
+		.maxlen		= 16,
+		.mode		= 0444,
+		.proc_handler	= proc_do_uuid_be,
+	},
 #ifdef ADD_INTERRUPT_BENCH
 	{
 		.procname	= "add_interrupt_avg_cycles",
include/uapi/linux/sysctl.h +3 -1
index 0956373..db5fcf1 100644
@@ -233,7 +233,9 @@ enum
 	RANDOM_READ_THRESH=3,
 	RANDOM_WRITE_THRESH=4,
 	RANDOM_BOOT_ID=5,
-	RANDOM_UUID=6
+	RANDOM_UUID=6,
+	RANDOM_UUID_LE=7,
+	RANDOM_UUID_BE=8,
 };
 
 /* /proc/sys/kernel/pty */
kernel/sysctl_binary.c +47 -1

78 lines not on this page · raw message

Signature · 1 line
2.8.1
#1 lore raw
Quoted 9 lines · On Tue, 24 May 2016 20:27:27 +0300 Andy Shevchenko…

By default the sysctl interface returns random UUID in big endian format. Sometimes it's not suitable, e.g. using generated UUID for EFI variable name. Provide uuid_le and uuid_be to comprehence that interface.

...

 drivers/char/random.c       | 44 +++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/sysctl.h |  4 +++-
 kernel/sysctl_binary.c      | 48 ++++++++++++++++++++++++++++++++++++++++++++

Why does the kernel need to do this? If userspace wants a random uuid then it can grab a random number and cook up the UUID itself.

#2 lore raw
Quoted 11 lines · Andrew Morton
Quoted 8 lines · On Tue, 24 May 2016 20:27:27 +0300 Andy Shevchenko <andriy.shevchenko@…

By default the sysctl interface returns random UUID in big endian format.
Sometimes it's not suitable, e.g. using generated UUID for EFI variable name.
Provide uuid_le and uuid_be to comprehence that interface.

...

Quoted 8 lines
Quoted 5 lines

 drivers/char/random.c       | 44
+++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/sysctl.h |  4 +++-
 kernel/sysctl_binary.c      | 48
++++++++++++++++++++++++++++++++++++++++++++

Why does the kernel need to do this?  If userspace wants a random uuid then it can grab a random number and cook up the UUID itself.

Good question. I dunno why we have uuid in the first place there. At some point I noticed people who recommend to use that file to get a random UUID(s), but apparently they don't aware that endianess matters.

P.S. I thought to send this as RFC, but decided to drop the notation in last minute. So, it's okay to drop it.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
maintainer
#3 lore raw

I'm also curious what !@#!? idiot came up with the concept of Little Endian UUID's. UUID's, and how to transform them from a printed representation to a binary presentation, were well defined in a very specific way in RFC-4122, which came from HP's Apollo/Domain OS, and was adopted by the OSF/DCE, as well as later by Microsoft. In all cases, there was never any such thing as little endian versus big endian UUID's. Might as well talk about big-endian and little endian IP addresses. This way lies madness.

It's also the case that if all you need is a random UUID's, that *technically* the endianness matters, but in actual practice, it really won't matter.

- Ted

P.S. Let me guess, it was some clueless Intel engineer when they were drafting the EFI spec? Sigh....