]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
UBUNTU: Add ubuntu-host module
authorSeth Forshee <seth.forshee@canonical.com>
Wed, 30 Sep 2020 01:01:09 +0000 (20:01 -0500)
committerPaolo Pisati <paolo.pisati@canonical.com>
Tue, 2 Nov 2021 07:24:50 +0000 (08:24 +0100)
ubuntu-host is a module for providing data to containers via proc.
Initially it is populated with a single file, esm-token, for
supplying ESM access tokens.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
ubuntu/Kconfig
ubuntu/Makefile
ubuntu/ubuntu-host/Kconfig [new file with mode: 0644]
ubuntu/ubuntu-host/Makefile [new file with mode: 0644]
ubuntu/ubuntu-host/ubuntu-host.c [new file with mode: 0644]

index 8cea998f29a325470667d856ef8e95febe463d25..5056671223bbe3f9b05b6178eb6f04041c2eaf5b 100644 (file)
@@ -14,6 +14,10 @@ source "ubuntu/hio/Kconfig"
 ##
 ##
 ##
+source "ubuntu/ubuntu-host/Kconfig"
+##
+##
+##
 ##
 ##
 ##
index 67c6d5b98b53b4ec257e9e3a98cf8e95bb07a1c7..2363b219072f56ad91753bc68445be22e1bf51bc 100644 (file)
@@ -19,6 +19,10 @@ obj-$(CONFIG_HIO)             += hio/
 ##
 ##
 ##
+obj-$(CONFIG_UBUNTU_HOST)      += ubuntu-host/
+##
+##
+##
 ifeq ($(ARCH),x86)
 obj-y                          += xr-usb-serial/
 endif
diff --git a/ubuntu/ubuntu-host/Kconfig b/ubuntu/ubuntu-host/Kconfig
new file mode 100644 (file)
index 0000000..1989da6
--- /dev/null
@@ -0,0 +1,5 @@
+config UBUNTU_HOST
+       tristate "proc dir for exporting host data to containers"
+       help
+         Creates an ubuntu-host directory in proc for providing data from
+         Ubuntu hosts to containers.
diff --git a/ubuntu/ubuntu-host/Makefile b/ubuntu/ubuntu-host/Makefile
new file mode 100644 (file)
index 0000000..fef3c13
--- /dev/null
@@ -0,0 +1 @@
+obj-$(CONFIG_UBUNTU_HOST) += ubuntu-host.o
diff --git a/ubuntu/ubuntu-host/ubuntu-host.c b/ubuntu/ubuntu-host/ubuntu-host.c
new file mode 100644 (file)
index 0000000..1abd402
--- /dev/null
@@ -0,0 +1,68 @@
+#include <linux/uaccess.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/proc_fs.h>
+#include <asm/uaccess.h>
+
+#define PROC_DIR               "ubuntu-host"
+
+#define ESM_TOKEN_FILE         "esm-token"
+#define ESM_TOKEN_MAX_SIZE             64
+
+static struct proc_dir_entry *proc_dir;
+static char esm_token_buffer[ESM_TOKEN_MAX_SIZE];
+
+static ssize_t esm_token_read(struct file *f, char __user *buf, size_t len,
+                             loff_t *off)
+{
+       return simple_read_from_buffer(buf, len, off, esm_token_buffer,
+                                      strlen(esm_token_buffer));
+}
+
+static ssize_t esm_token_write(struct file *f, const char __user *buf,
+                              size_t len, loff_t *off)
+{
+       ssize_t ret;
+
+       if (len >= ESM_TOKEN_MAX_SIZE - 1)
+               return -EINVAL;
+
+       ret = simple_write_to_buffer(esm_token_buffer, ESM_TOKEN_MAX_SIZE - 1,
+                                    off, buf, len);
+       if (ret >= 0)
+               esm_token_buffer[ret] = '\0';
+
+       return ret;
+}
+
+static const struct proc_ops esm_token_fops = {
+       .proc_read = esm_token_read,
+       .proc_write = esm_token_write,
+};
+
+static void ubuntu_host_cleanup(void)
+{
+       remove_proc_entry(ESM_TOKEN_FILE, proc_dir);
+       proc_remove(proc_dir);
+}
+
+static int __init ubuntu_host_init(void)
+{
+       proc_dir = proc_mkdir(PROC_DIR, NULL);
+       if (!proc_dir) {
+               pr_err("Failed to create ubuntu-host dir\n");
+               return -ENOMEM;
+       }
+
+       if (!proc_create_data(ESM_TOKEN_FILE, 0644, proc_dir, &esm_token_fops, NULL)) {
+               pr_err("Failed to create esm-tokan file\n");
+               ubuntu_host_cleanup();
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+module_init(ubuntu_host_init);
+module_exit(ubuntu_host_cleanup);
+MODULE_LICENSE("GPL");