2 * Linux interface for guarded module registration
4 * (c) Kyle C. Hale 2012
8 #include <linux/uaccess.h>
9 #include <linux/vmalloc.h>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/list.h>
13 #include <gears/guard_mods.h>
16 #include "linux-exts.h"
17 #include "iface-guard-mods.h"
21 vm_register_mod (struct v3_guest * guest,
27 struct v3_guard_mod arg_mod;
28 struct v3_guard_mod * gm;
31 gm = palacios_alloc(sizeof(struct v3_guard_mod));
33 ERROR("palacios: error allocating guarded module\n");
37 if (copy_from_user(&arg_mod, (void __user *)arg, sizeof(struct v3_guard_mod))) {
38 ERROR("palacios: error copying guarded module data from userspace\n");
42 memcpy(gm, &arg_mod, sizeof(struct v3_guard_mod));
45 gm->name = palacios_alloc(strnlen_user((char __user *)arg_mod.name, MAX_MOD_NAME_LEN)+1);
47 ERROR("Problem allocating space for mod name\n");
51 if (strncpy_from_user(gm->name, (char __user *)arg_mod.name, MAX_MOD_NAME_LEN) == -EFAULT) {
52 ERROR("problem copying from userspace\n");
56 /* get module content hash */
57 gm->content_hash = palacios_alloc(strnlen_user((char __user *)arg_mod.content_hash, MAX_HASH_LEN)+1);
58 if (!gm->content_hash) {
59 ERROR("Problem allocating space for content hash\n");
63 if (strncpy_from_user(gm->content_hash, (char __user *)arg_mod.content_hash, MAX_HASH_LEN) == -EFAULT) {
64 ERROR("problem copying from userspace\n");
68 /* get valid entry points */
69 gm->entry_points = palacios_alloc(sizeof(struct v3_guard_mod)*arg_mod.num_entries);
70 if (!gm->entry_points) {
71 ERROR("Problem allocating space for entry point array\n");
75 if (copy_from_user(gm->entry_points, (void __user *)arg_mod.entry_points, sizeof(struct v3_guard_mod)*arg_mod.num_entries)
77 ERROR("problem copying from userspace\n");
81 for (i = 0; i < gm->num_entries; i++) {
85 if ((len = strnlen_user((char __user *)gm->entry_points[i].name, MAX_MOD_NAME_LEN)+1) == -EFAULT) {
86 ERROR("problem getting strlen from userspace\n");
90 tmp = palacios_alloc(len);
92 ERROR("Problem allocating space for string\n");
96 if (strncpy_from_user(tmp, (char __user *)gm->entry_points[i].name, MAX_MOD_NAME_LEN) == -EFAULT) {
97 ERROR("problem copying from userspace\n");
101 gm->entry_points[i].name = tmp;
104 /* get list of privileges */
105 gm->priv_array = palacios_alloc(sizeof(char*)*arg_mod.num_privs);
106 if (!gm->priv_array) {
107 ERROR("Problem allocating space for privilege array\n");
111 if (copy_from_user(gm->priv_array, (void __user *)arg_mod.priv_array, sizeof(char*)*arg_mod.num_privs)
113 ERROR("problem copying privilege array from userspace\n");
117 for (i = 0; i < gm->num_privs; i++) {
120 if ((len = strlen_user((char __user*)gm->priv_array[i]) + 1) == -EFAULT) {
121 ERROR("problem getting strlen from userspace\n");
125 tmp = palacios_alloc(len);
127 ERROR("Problem allocating space for privilege name\n");
131 if (strncpy_from_user(tmp, (char __user *)gm->priv_array[i], MAX_MOD_NAME_LEN) == -EFAULT) {
132 ERROR("problem copying privilege from userspace\n");
136 gm->priv_array[i] = tmp;
139 INFO("Registering Guarded Module with Palacios\n");
140 ret = v3_register_gm(guest->v3_ctx,
149 (void*)gm->entry_points);
152 ERROR("palacios: could not register guarded module: %s\n", arg_mod.name);
158 if (copy_to_user((void __user *)arg, &arg_mod, sizeof(struct v3_guard_mod))) {
159 ERROR("palacios: error copying guarded module back to userspace\n");
164 kfree(gm->content_hash);
165 for (i = 0; i < gm->num_entries; i++) {
166 kfree(gm->entry_points[i].name);
168 kfree(gm->entry_points);
175 init_guard_mods (void)
182 deinit_guard_mods (void)
189 guest_init_guard_mods (struct v3_guest * guest, void ** vm_data)
191 add_guest_ctrl(guest, V3_VM_REGISTER_MOD, vm_register_mod, NULL);
197 guest_deinit_guard_mods (struct v3_guest * guest, void * vm_data)
203 static struct linux_ext guard_mods_ext = {
204 .name = "GUARDED_MODULES",
205 .init = init_guard_mods,
206 .deinit = deinit_guard_mods,
207 .guest_init = guest_init_guard_mods,
208 .guest_deinit = guest_deinit_guard_mods
211 register_extension(&guard_mods_ext);