Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1406299 > unrolled thread
| Started by | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| First post | 2016-05-24 19:30 +0200 |
| Last post | 2016-05-26 02:50 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v1 1/1] sysctl: introduce uuid_le and uuid_be Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-05-24 19:30 +0200
Re: [PATCH v1 1/1] sysctl: introduce uuid_le and uuid_be Andrew Morton <akpm@linux-foundation.org> - 2016-05-24 22:20 +0200
Re: [PATCH v1 1/1] sysctl: introduce uuid_le and uuid_be Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-05-24 22:30 +0200
Re: [PATCH v1 1/1] sysctl: introduce uuid_le and uuid_be Theodore Ts'o <tytso@mit.edu> - 2016-05-26 02:50 +0200
| From | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| Date | 2016-05-24 19:30 +0200 |
| Subject | [PATCH v1 1/1] sysctl: introduce uuid_le and uuid_be |
| Message-ID | <rCojv-6cC-7@gated-at.bofh.it> |
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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/char/random.c | 44 +++++++++++++++++++++++++++++++++++++++++
include/uapi/linux/sysctl.h | 4 +++-
kernel/sysctl_binary.c | 48 ++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 94 insertions(+), 2 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 0158d3b..a864013 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -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",
diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
index 0956373..db5fcf1 100644
--- a/include/uapi/linux/sysctl.h
+++ b/include/uapi/linux/sysctl.h
@@ -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 */
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index 6eb99c1..56b8c90 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -28,6 +28,8 @@ static bin_convert_t bin_string;
static bin_convert_t bin_intvec;
static bin_convert_t bin_ulongvec;
static bin_convert_t bin_uuid;
+static bin_convert_t bin_uuid_le;
+static bin_convert_t bin_uuid_be;
static bin_convert_t bin_dn_node_address;
#define CTL_DIR bin_dir
@@ -35,6 +37,8 @@ static bin_convert_t bin_dn_node_address;
#define CTL_INT bin_intvec
#define CTL_ULONG bin_ulongvec
#define CTL_UUID bin_uuid
+#define CTL_UUID_LE bin_uuid_le
+#define CTL_UUID_BE bin_uuid_be
#define CTL_DNADR bin_dn_node_address
#define BUFSZ 256
@@ -53,6 +57,8 @@ static const struct bin_table bin_random_table[] = {
{ CTL_INT, RANDOM_WRITE_THRESH, "write_wakeup_threshold" },
{ CTL_UUID, RANDOM_BOOT_ID, "boot_id" },
{ CTL_UUID, RANDOM_UUID, "uuid" },
+ { CTL_UUID_LE, RANDOM_UUID_LE, "uuid_le" },
+ { CTL_UUID_BE, RANDOM_UUID_BE, "uuid_be" },
{}
};
@@ -1111,7 +1117,7 @@ out:
return result;
}
-static ssize_t bin_uuid(struct file *file,
+static ssize_t bin_uuid_be(struct file *file,
void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
{
ssize_t result, copied = 0;
@@ -1145,6 +1151,46 @@ out:
return result;
}
+static ssize_t bin_uuid_le(struct file *file,
+ void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
+{
+ ssize_t result, copied = 0;
+
+ /* Only supports reads */
+ if (oldval && oldlen) {
+ char buf[UUID_STRING_LEN + 1];
+ uuid_le uuid;
+
+ result = kernel_read(file, 0, buf, sizeof(buf) - 1);
+ if (result < 0)
+ goto out;
+
+ buf[result] = '\0';
+
+ result = -EIO;
+ if (uuid_le_to_bin(buf, &uuid))
+ goto out;
+
+ if (oldlen > 16)
+ oldlen = 16;
+
+ result = -EFAULT;
+ if (copy_to_user(oldval, &uuid, oldlen))
+ goto out;
+
+ copied = oldlen;
+ }
+ result = copied;
+out:
+ return result;
+}
+
+static ssize_t bin_uuid(struct file *file,
+ void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
+{
+ return bin_uuid_be(file, oldval, oldlen, newval, newlen);
+}
+
static ssize_t bin_dn_node_address(struct file *file,
void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
{
--
2.8.1
[toc] | [next] | [standalone]
| From | Andrew Morton <akpm@linux-foundation.org> |
|---|---|
| Date | 2016-05-24 22:20 +0200 |
| Message-ID | <rCqY2-7Zt-23@gated-at.bofh.it> |
| In reply to | #1406299 |
On Tue, 24 May 2016 20:27:27 +0300 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > 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.
[toc] | [prev] | [next] | [standalone]
| From | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| Date | 2016-05-24 22:30 +0200 |
| Message-ID | <rCr7H-84g-5@gated-at.bofh.it> |
| In reply to | #1406435 |
On Tue, 2016-05-24 at 13:15 -0700, Andrew Morton wrote: > On Tue, 24 May 2016 20:27:27 +0300 Andy Shevchenko <andriy.shevchenko@ > linux.intel.com> wrote: > > > 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. 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. -- Andy Shevchenko <andriy.shevchenko@linux.intel.com> Intel Finland Oy
[toc] | [prev] | [next] | [standalone]
| From | Theodore Ts'o <tytso@mit.edu> |
|---|---|
| Date | 2016-05-26 02:50 +0200 |
| Message-ID | <rCRER-7LQ-3@gated-at.bofh.it> |
| In reply to | #1406439 |
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....
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web