summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaes Nästén <pekdon@gmail.com>2021-04-06 22:11:21 +0200
committerGitHub <noreply@github.com>2021-04-06 16:11:21 -0400
commit307c10bceae0de25637bbcc688c2afb73dde01ff (patch)
tree2f84db8cbd4689a0bf1375b6757bff92c576c60e
parent43e43e05cd35925fd83121ffa94db7aa45725448 (diff)
downloadillumos-joyent-307c10bceae0de25637bbcc688c2afb73dde01ff.tar.gz
OS-8280 Add /proc/sys/kernel/random/uuid to LX brands
Reviewed-by: Mike Zeller <mike.zeller@joyent.com> Approved-by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/uts/common/brand/lx/procfs/lx_proc.h1
-rw-r--r--usr/src/uts/common/brand/lx/procfs/lx_prvnops.c74
-rw-r--r--usr/src/uts/common/brand/lx/sys/lx_brand.h6
3 files changed, 48 insertions, 33 deletions
diff --git a/usr/src/uts/common/brand/lx/procfs/lx_proc.h b/usr/src/uts/common/brand/lx/procfs/lx_proc.h
index 723dfff560..be95e7e471 100644
--- a/usr/src/uts/common/brand/lx/procfs/lx_proc.h
+++ b/usr/src/uts/common/brand/lx/procfs/lx_proc.h
@@ -225,6 +225,7 @@ typedef enum lxpr_nodetype {
LXPR_SYS_KERNEL_RANDDIR, /* /proc/sys/kernel/random */
LXPR_SYS_KERNEL_RAND_BOOTID, /* /proc/sys/kernel/random/boot_id */
LXPR_SYS_KERNEL_RAND_ENTAVL, /* /proc/sys/kernel/random/entropy_avail */
+ LXPR_SYS_KERNEL_RAND_UUID, /* /proc/sys/kernel/random/uuid */
LXPR_SYS_KERNEL_SEM, /* /proc/sys/kernel/sem */
LXPR_SYS_KERNEL_SHMALL, /* /proc/sys/kernel/shmall */
LXPR_SYS_KERNEL_SHMMAX, /* /proc/sys/kernel/shmmax */
diff --git a/usr/src/uts/common/brand/lx/procfs/lx_prvnops.c b/usr/src/uts/common/brand/lx/procfs/lx_prvnops.c
index 575acd59a2..d573825652 100644
--- a/usr/src/uts/common/brand/lx/procfs/lx_prvnops.c
+++ b/usr/src/uts/common/brand/lx/procfs/lx_prvnops.c
@@ -248,6 +248,7 @@ static void lxpr_read_sys_kernel_osrel(lxpr_node_t *, lxpr_uiobuf_t *);
static void lxpr_read_sys_kernel_pid_max(lxpr_node_t *, lxpr_uiobuf_t *);
static void lxpr_read_sys_kernel_rand_bootid(lxpr_node_t *, lxpr_uiobuf_t *);
static void lxpr_read_sys_kernel_rand_entavl(lxpr_node_t *, lxpr_uiobuf_t *);
+static void lxpr_read_sys_kernel_rand_uuid(lxpr_node_t *, lxpr_uiobuf_t *);
static void lxpr_read_sys_kernel_sem(lxpr_node_t *, lxpr_uiobuf_t *);
static void lxpr_read_sys_kernel_shmall(lxpr_node_t *, lxpr_uiobuf_t *);
static void lxpr_read_sys_kernel_shmmax(lxpr_node_t *, lxpr_uiobuf_t *);
@@ -590,6 +591,7 @@ static lxpr_dirent_t sys_kerneldir[] = {
static lxpr_dirent_t sys_randdir[] = {
{ LXPR_SYS_KERNEL_RAND_BOOTID, "boot_id" },
{ LXPR_SYS_KERNEL_RAND_ENTAVL, "entropy_avail" },
+ { LXPR_SYS_KERNEL_RAND_UUID, "uuid" },
};
#define SYS_RANDDIRFILES (sizeof (sys_randdir) / sizeof (sys_randdir[0]))
@@ -932,6 +934,7 @@ static void (*lxpr_read_function[])() = {
lxpr_read_invalid, /* /proc/sys/kernel/random */
lxpr_read_sys_kernel_rand_bootid, /* /proc/sys/kernel/random/boot_id */
lxpr_read_sys_kernel_rand_entavl, /* .../kernel/random/entropy_avail */
+ lxpr_read_sys_kernel_rand_uuid, /* .../kernel/random/uuid */
lxpr_read_sys_kernel_sem, /* /proc/sys/kernel/sem */
lxpr_read_sys_kernel_shmall, /* /proc/sys/kernel/shmall */
lxpr_read_sys_kernel_shmmax, /* /proc/sys/kernel/shmmax */
@@ -1101,6 +1104,7 @@ static vnode_t *(*lxpr_lookup_function[])() = {
lxpr_lookup_sys_kdir_randdir, /* /proc/sys/kernel/random */
lxpr_lookup_not_a_dir, /* /proc/sys/kernel/random/boot_id */
lxpr_lookup_not_a_dir, /* .../kernel/random/entropy_avail */
+ lxpr_lookup_not_a_dir, /* /proc/sys/kernel/random/uuid */
lxpr_lookup_not_a_dir, /* /proc/sys/kernel/sem */
lxpr_lookup_not_a_dir, /* /proc/sys/kernel/shmall */
lxpr_lookup_not_a_dir, /* /proc/sys/kernel/shmmax */
@@ -1270,6 +1274,7 @@ static int (*lxpr_readdir_function[])() = {
lxpr_readdir_sys_kdir_randdir, /* /proc/sys/kernel/random */
lxpr_readdir_not_a_dir, /* /proc/sys/kernel/random/boot_id */
lxpr_readdir_not_a_dir, /* .../kernel/random/entropy_avail */
+ lxpr_readdir_not_a_dir, /* /proc/sys/kernel/random/uuid */
lxpr_readdir_not_a_dir, /* /proc/sys/kernel/sem */
lxpr_readdir_not_a_dir, /* /proc/sys/kernel/shmall */
lxpr_readdir_not_a_dir, /* /proc/sys/kernel/shmmax */
@@ -4923,7 +4928,25 @@ lxpr_read_sys_kernel_pid_max(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
lxpr_uiobuf_printf(uiobuf, "%d\n", maxpid);
}
-/* ARGSUSED */
+static void
+lxpr_gen_uuid(char *uuid, size_t size)
+{
+ uint8_t r[16];
+ if (random_get_bytes(r, sizeof (r)) != 0) {
+ (void) random_get_pseudo_bytes(r, sizeof (r));
+ }
+ /* Set UUID version to 4 (random) */
+ r[6] = 0x40 | (r[6] & 0x0f);
+ /* Set UUID variant to 1 */
+ r[8] = 0x80 | (r[8] & 0x3f);
+
+ (void) snprintf(uuid, size,
+ "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x"
+ "-%02x%02x%02x%02x%02x%02x",
+ r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8],
+ r[9], r[10], r[11], r[12], r[13], r[14], r[15]);
+}
+
static void
lxpr_read_sys_kernel_rand_bootid(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
{
@@ -4937,13 +4960,11 @@ lxpr_read_sys_kernel_rand_bootid(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
* safe choice if you need to identify a specific boot on a specific
* booted kernel.
*
- * We'll just generate a random ID if necessary. On Linux the format
- * appears to resemble a uuid but since it is not documented to be a
- * uuid, we don't worry about that.
+ * On Linux the format appears to resemble a uuid so stick with that.
*/
zone_t *zone = LXPTOZ(lxpnp);
lx_zone_data_t *lxzd = ztolxzd(zone);
- char bootid[LX_BOOTID_LEN];
+ char bootid[UUID_PRINTABLE_STRING_LENGTH];
ASSERT(lxpnp->lxpr_type == LXPR_SYS_KERNEL_RAND_BOOTID);
ASSERT(zone->zone_brand == &lx_brand);
@@ -4951,30 +4972,7 @@ lxpr_read_sys_kernel_rand_bootid(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
mutex_enter(&lxzd->lxzd_lock);
if (lxzd->lxzd_bootid[0] == '\0') {
- int i;
-
- for (i = 0; i < 5; i++) {
- u_longlong_t n;
- char s[32];
-
- (void) random_get_bytes((uint8_t *)&n, sizeof (n));
- switch (i) {
- case 0: (void) snprintf(s, sizeof (s), "%08llx", n);
- s[8] = '\0';
- break;
- case 4: (void) snprintf(s, sizeof (s), "%012llx", n);
- s[12] = '\0';
- break;
- default: (void) snprintf(s, sizeof (s), "%04llx", n);
- s[4] = '\0';
- break;
- }
- if (i > 0)
- (void) strlcat(lxzd->lxzd_bootid, "-",
- sizeof (lxzd->lxzd_bootid));
- (void) strlcat(lxzd->lxzd_bootid, s,
- sizeof (lxzd->lxzd_bootid));
- }
+ lxpr_gen_uuid(lxzd->lxzd_bootid, sizeof (lxzd->lxzd_bootid));
}
(void) strlcpy(bootid, lxzd->lxzd_bootid, sizeof (bootid));
mutex_exit(&lxzd->lxzd_lock);
@@ -4995,6 +4993,24 @@ lxpr_read_sys_kernel_rand_entavl(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
lxpr_uiobuf_printf(uiobuf, "%d\n", swrand_stats.ss_entEst);
}
+static void
+lxpr_read_sys_kernel_rand_uuid(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
+{
+ /*
+ * Each read from this read-only file should return a new
+ * random 128-bit UUID string in the standard UUID format.
+ */
+ zone_t *zone = LXPTOZ(lxpnp);
+ char uuid[UUID_PRINTABLE_STRING_LENGTH];
+
+ ASSERT(lxpnp->lxpr_type == LXPR_SYS_KERNEL_RAND_UUID);
+ ASSERT(zone->zone_brand == &lx_brand);
+
+ lxpr_gen_uuid(uuid, sizeof (uuid));
+
+ lxpr_uiobuf_printf(uiobuf, "%s\n", uuid);
+}
+
/* ARGSUSED */
static void
lxpr_read_sys_kernel_sem(lxpr_node_t *lxpnp, lxpr_uiobuf_t *uiobuf)
diff --git a/usr/src/uts/common/brand/lx/sys/lx_brand.h b/usr/src/uts/common/brand/lx/sys/lx_brand.h
index 85aa5e34bd..35b1bddb03 100644
--- a/usr/src/uts/common/brand/lx/sys/lx_brand.h
+++ b/usr/src/uts/common/brand/lx/sys/lx_brand.h
@@ -41,6 +41,7 @@
#include <sys/cpuvar.h>
#include <sys/lx_futex.h>
#include <sys/lx_userhz.h>
+#include <sys/uuid.h>
#endif
#ifdef __cplusplus
@@ -397,9 +398,6 @@ typedef struct lx_proc_data {
#define LX_AFF_ULONGS (LX_NCPU / (8 * sizeof (ulong_t)))
typedef ulong_t lx_affmask_t[LX_AFF_ULONGS];
-/* Length of proc boot_id string */
-#define LX_BOOTID_LEN 37
-
/*
* Flag values for uc_brand_data[0] in the ucontext_t:
*/
@@ -637,7 +635,7 @@ typedef struct lx_zone_data {
char lxzd_kernel_release[LX_KERN_RELEASE_MAX];
char lxzd_kernel_version[LX_KERN_VERSION_MAX];
ksocket_t lxzd_ioctl_sock;
- char lxzd_bootid[LX_BOOTID_LEN]; /* procfs boot_id */
+ char lxzd_bootid[UUID_PRINTABLE_STRING_LENGTH]; /* procfs boot_id */
gid_t lxzd_ttygrp; /* tty gid for pty chown */
vfs_t *lxzd_cgroup; /* cgroup for this zone */
pid_t lxzd_lockd_pid; /* pid of NFS lockd */