mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-01 06:33:07 +00:00
random: cleanup UUID handling
Rather than hard coding various lengths, we can use the right constants.
Strings should be `char *` while buffers should be `u8 *`. Rather than
have a nonsensical and unused maxlength, just remove it. Finally, use
snprintf instead of sprintf, just out of good hygiene.
As well, remove the old comment about returning a binary UUID via the
binary sysctl syscall. That syscall was removed from the kernel in 5.5,
and actually, the "uuid_strategy" function and related infrastructure
for even serving it via the binary sysctl syscall was removed with
894d249115
("sysctl drivers: Remove dead binary sysctl support") back
in 2.6.33.
Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
a3f9e8910e
commit
64276a9939
1 changed files with 13 additions and 16 deletions
|
@ -1661,22 +1661,25 @@ const struct file_operations urandom_fops = {
|
||||||
static int sysctl_random_min_urandom_seed = 60;
|
static int sysctl_random_min_urandom_seed = 60;
|
||||||
static int sysctl_random_write_wakeup_bits = POOL_MIN_BITS;
|
static int sysctl_random_write_wakeup_bits = POOL_MIN_BITS;
|
||||||
static int sysctl_poolsize = POOL_BITS;
|
static int sysctl_poolsize = POOL_BITS;
|
||||||
static char sysctl_bootid[16];
|
static u8 sysctl_bootid[UUID_SIZE];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function is used to return both the bootid UUID, and random
|
* 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,
|
* UUID. The difference is in whether table->data is NULL; if it is,
|
||||||
* then a new UUID is generated and returned to the user.
|
* then a new UUID is generated and returned to the user.
|
||||||
*
|
|
||||||
* If the user accesses this via the proc interface, the UUID will be
|
|
||||||
* returned as an ASCII string in the standard UUID format; if via the
|
|
||||||
* sysctl system call, as 16 bytes of binary data.
|
|
||||||
*/
|
*/
|
||||||
static int proc_do_uuid(struct ctl_table *table, int write, void *buffer,
|
static int proc_do_uuid(struct ctl_table *table, int write, void *buffer,
|
||||||
size_t *lenp, loff_t *ppos)
|
size_t *lenp, loff_t *ppos)
|
||||||
{
|
{
|
||||||
struct ctl_table fake_table;
|
u8 tmp_uuid[UUID_SIZE], *uuid;
|
||||||
unsigned char buf[64], tmp_uuid[16], *uuid;
|
char uuid_string[UUID_STRING_LEN + 1];
|
||||||
|
struct ctl_table fake_table = {
|
||||||
|
.data = uuid_string,
|
||||||
|
.maxlen = UUID_STRING_LEN
|
||||||
|
};
|
||||||
|
|
||||||
|
if (write)
|
||||||
|
return -EPERM;
|
||||||
|
|
||||||
uuid = table->data;
|
uuid = table->data;
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
|
@ -1691,12 +1694,8 @@ static int proc_do_uuid(struct ctl_table *table, int write, void *buffer,
|
||||||
spin_unlock(&bootid_spinlock);
|
spin_unlock(&bootid_spinlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buf, "%pU", uuid);
|
snprintf(uuid_string, sizeof(uuid_string), "%pU", uuid);
|
||||||
|
return proc_dostring(&fake_table, 0, buffer, lenp, ppos);
|
||||||
fake_table.data = buf;
|
|
||||||
fake_table.maxlen = sizeof(buf);
|
|
||||||
|
|
||||||
return proc_dostring(&fake_table, write, buffer, lenp, ppos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ctl_table random_table[] = {
|
static struct ctl_table random_table[] = {
|
||||||
|
@ -1731,13 +1730,11 @@ static struct ctl_table random_table[] = {
|
||||||
{
|
{
|
||||||
.procname = "boot_id",
|
.procname = "boot_id",
|
||||||
.data = &sysctl_bootid,
|
.data = &sysctl_bootid,
|
||||||
.maxlen = 16,
|
|
||||||
.mode = 0444,
|
.mode = 0444,
|
||||||
.proc_handler = proc_do_uuid,
|
.proc_handler = proc_do_uuid,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.procname = "uuid",
|
.procname = "uuid",
|
||||||
.maxlen = 16,
|
|
||||||
.mode = 0444,
|
.mode = 0444,
|
||||||
.proc_handler = proc_do_uuid,
|
.proc_handler = proc_do_uuid,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue