2 * Linux interface for guarded module registration
4 * (c) Kyle C. Hale 2012
8 #include <linux/uaccess.h>
9 #include <linux/module.h>
10 #include <linux/types.h>
11 #include <linux/list.h>
12 #include <gears/guard_mods.h>
15 #include "linux-exts.h"
16 #include "iface-guard-mods.h"
20 vm_register_mod (struct v3_guest * guest,
26 struct v3_guard_mod arg_mod;
27 struct v3_guard_mod * gm;
30 gm = palacios_alloc(sizeof(struct v3_guard_mod));
32 ERROR("palacios: error allocating guarded module\n");
36 if (copy_from_user(&arg_mod, (void __user *)arg, sizeof(struct v3_guard_mod))) {
37 ERROR("palacios: error copying guarded module data from userspace\n");
41 memcpy(gm, &arg_mod, sizeof(struct v3_guard_mod));
44 gm->name = palacios_alloc(strnlen_user((char __user *)arg_mod.name, MAX_MOD_NAME_LEN)+1);
46 ERROR("Problem allocating space for mod name\n");
50 if (strncpy_from_user(gm->name, (char __user *)arg_mod.name, MAX_MOD_NAME_LEN) == -EFAULT) {
51 ERROR("problem copying from userspace\n");
55 /* get module content hash */
56 gm->content_hash = palacios_alloc(strnlen_user((char __user *)arg_mod.content_hash, MAX_HASH_LEN)+1);
57 if (!gm->content_hash) {
58 ERROR("Problem allocating space for content hash\n");
62 if (strncpy_from_user(gm->content_hash, (char __user *)arg_mod.content_hash, MAX_HASH_LEN) == -EFAULT) {
63 ERROR("problem copying from userspace\n");
67 /* get valid entry points */
68 gm->entry_points = palacios_alloc(sizeof(struct v3_guard_mod)*arg_mod.num_entries);
69 if (!gm->entry_points) {
70 ERROR("Problem allocating space for entry point array\n");
74 if (copy_from_user(gm->entry_points, (void __user *)arg_mod.entry_points, sizeof(struct v3_guard_mod)*arg_mod.num_entries)
76 ERROR("problem copying from userspace\n");
80 for (i = 0; i < gm->num_entries; i++) {
84 if ((len = strnlen_user((char __user *)gm->entry_points[i].name, MAX_MOD_NAME_LEN)+1) == -EFAULT) {
85 ERROR("problem getting strlen from userspace\n");
89 tmp = palacios_alloc(len);
91 ERROR("Problem allocating space for string\n");
95 if (strncpy_from_user(tmp, (char __user *)gm->entry_points[i].name, MAX_MOD_NAME_LEN) == -EFAULT) {
96 ERROR("problem copying from userspace\n");
100 gm->entry_points[i].name = tmp;
103 /* get list of privileges */
104 gm->priv_array = palacios_alloc(sizeof(char*)*arg_mod.num_privs);
105 if (!gm->priv_array) {
106 ERROR("Problem allocating space for privilege array\n");
110 if (copy_from_user(gm->priv_array, (void __user *)arg_mod.priv_array, sizeof(char*)*arg_mod.num_privs)
112 ERROR("problem copying privilege array from userspace\n");
116 for (i = 0; i < gm->num_privs; i++) {
119 if ((len = strlen_user((char __user*)gm->priv_array[i]) + 1) == -EFAULT) {
120 ERROR("problem getting strlen from userspace\n");
124 tmp = palacios_alloc(len);
126 ERROR("Problem allocating space for privilege name\n");
130 if (strncpy_from_user(tmp, (char __user *)gm->priv_array[i], MAX_MOD_NAME_LEN) == -EFAULT) {
131 ERROR("problem copying privilege from userspace\n");
135 gm->priv_array[i] = tmp;
138 INFO("Registering Guarded Module with Palacios\n");
139 ret = v3_register_gm(guest->v3_ctx,
148 (void*)gm->entry_points);
151 ERROR("palacios: could not register guarded module: %s\n", arg_mod.name);
157 if (copy_to_user((void __user *)arg, &arg_mod, sizeof(struct v3_guard_mod))) {
158 ERROR("palacios: error copying guarded module back to userspace\n");
162 palacios_free(gm->name);
163 palacios_free(gm->content_hash);
164 for (i = 0; i < gm->num_entries; i++) {
165 palacios_free(gm->entry_points[i].name);
167 palacios_free(gm->entry_points);
174 init_guard_mods (void)
181 deinit_guard_mods (void)
188 guest_init_guard_mods (struct v3_guest * guest, void ** vm_data)
190 add_guest_ctrl(guest, V3_VM_REGISTER_MOD, vm_register_mod, NULL);
196 guest_deinit_guard_mods (struct v3_guest * guest, void * vm_data)
202 static struct linux_ext guard_mods_ext = {
203 .name = "GUARDED_MODULES",
204 .init = init_guard_mods,
205 .deinit = deinit_guard_mods,
206 .guest_init = guest_init_guard_mods,
207 .guest_deinit = guest_deinit_guard_mods
210 register_extension(&guard_mods_ext);