From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Theodore Ts'o" <tytso@mit.edu>, Arnd Bergmann <arnd@arndb.de>,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 1/1] sysctl: introduce uuid_le and uuid_be
Date: Tue, 24 May 2016 20:27:27 +0300 [thread overview]
Message-ID: <1464110847-41097-1-git-send-email-andriy.shevchenko@linux.intel.com> (raw)
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
next reply other threads:[~2016-05-24 17:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-24 17:27 Andy Shevchenko [this message]
2016-05-24 20:15 ` [PATCH v1 1/1] sysctl: introduce uuid_le and uuid_be Andrew Morton
2016-05-24 20:25 ` Andy Shevchenko
2016-05-24 22:56 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1464110847-41097-1-git-send-email-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox