ia64/xen-unstable

view xen/acm/acm_core.c @ 5704:9b73afea874e

Certain types of event channel are now auto-bound to vcpu0 by Xen.
Make sure that xenolinux agrees with this.
author sos22@douglas.cl.cam.ac.uk
date Fri Jul 08 15:35:43 2005 +0000 (2005-07-08)
parents 68de76620c9c
children ecb17ef5a587 b53a65034532
line source
1 /****************************************************************
2 * acm_core.c
3 *
4 * Copyright (C) 2005 IBM Corporation
5 *
6 * Author:
7 * Reiner Sailer <sailer@watson.ibm.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2 of the
12 * License.
13 *
14 * sHype access control module (ACM)
15 * This file handles initialization of the ACM
16 * as well as initializing/freeing security
17 * identifiers for domains (it calls on active
18 * policy hook functions).
19 *
20 */
22 #include <xen/config.h>
23 #include <xen/errno.h>
24 #include <xen/types.h>
25 #include <xen/lib.h>
26 #include <xen/delay.h>
27 #include <xen/sched.h>
28 #include <acm/acm_hooks.h>
29 #include <acm/acm_endian.h>
31 /* debug:
32 * include/acm/acm_hooks.h defines a constant ACM_TRACE_MODE;
33 * define/undefine this constant to receive / suppress any
34 * security hook debug output of sHype
35 *
36 * include/public/acm.h defines a constant ACM_DEBUG
37 * define/undefine this constant to receive non-hook-related
38 * debug output.
39 */
41 /* function prototypes */
42 void acm_init_chwall_policy(void);
43 void acm_init_ste_policy(void);
45 extern struct acm_operations acm_chinesewall_ops,
46 acm_simple_type_enforcement_ops, acm_null_ops;
48 /* global ops structs called by the hooks */
49 struct acm_operations *acm_primary_ops = NULL;
50 /* called in hook if-and-only-if primary succeeds */
51 struct acm_operations *acm_secondary_ops = NULL;
53 /* acm global binary policy (points to 'local' primary and secondary policies */
54 struct acm_binary_policy acm_bin_pol;
55 /* acm binary policy lock */
56 rwlock_t acm_bin_pol_rwlock = RW_LOCK_UNLOCKED;
58 /* until we have endian support in Xen, we discover it at runtime */
59 u8 little_endian = 1;
60 void acm_set_endian(void)
61 {
62 u32 test = 1;
63 if (*((u8 *)&test) == 1) {
64 printk("ACM module running in LITTLE ENDIAN.\n");
65 little_endian = 1;
66 } else {
67 printk("ACM module running in BIG ENDIAN.\n");
68 little_endian = 0;
69 }
70 }
72 #if (ACM_USE_SECURITY_POLICY != ACM_NULL_POLICY)
74 /* initialize global security policy for Xen; policy write-locked already */
75 static void
76 acm_init_binary_policy(void *primary, void *secondary)
77 {
78 acm_bin_pol.primary_policy_code = 0;
79 acm_bin_pol.secondary_policy_code = 0;
80 acm_bin_pol.primary_binary_policy = primary;
81 acm_bin_pol.secondary_binary_policy = secondary;
82 }
85 int
86 acm_init(void)
87 {
88 int ret = -EINVAL;
90 acm_set_endian();
91 write_lock(&acm_bin_pol_rwlock);
93 if (ACM_USE_SECURITY_POLICY == ACM_CHINESE_WALL_POLICY) {
94 acm_init_binary_policy(NULL, NULL);
95 acm_init_chwall_policy();
96 acm_bin_pol.primary_policy_code = ACM_CHINESE_WALL_POLICY;
97 acm_primary_ops = &acm_chinesewall_ops;
98 acm_bin_pol.secondary_policy_code = ACM_NULL_POLICY;
99 acm_secondary_ops = &acm_null_ops;
100 ret = ACM_OK;
101 } else if (ACM_USE_SECURITY_POLICY == ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) {
102 acm_init_binary_policy(NULL, NULL);
103 acm_init_ste_policy();
104 acm_bin_pol.primary_policy_code = ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY;
105 acm_primary_ops = &acm_simple_type_enforcement_ops;
106 acm_bin_pol.secondary_policy_code = ACM_NULL_POLICY;
107 acm_secondary_ops = &acm_null_ops;
108 ret = ACM_OK;
109 } else if (ACM_USE_SECURITY_POLICY == ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY) {
110 acm_init_binary_policy(NULL, NULL);
111 acm_init_chwall_policy();
112 acm_init_ste_policy();
113 acm_bin_pol.primary_policy_code = ACM_CHINESE_WALL_POLICY;
114 acm_primary_ops = &acm_chinesewall_ops;
115 acm_bin_pol.secondary_policy_code = ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY;
116 acm_secondary_ops = &acm_simple_type_enforcement_ops;
117 ret = ACM_OK;
118 } else if (ACM_USE_SECURITY_POLICY == ACM_NULL_POLICY) {
119 acm_init_binary_policy(NULL, NULL);
120 acm_bin_pol.primary_policy_code = ACM_NULL_POLICY;
121 acm_primary_ops = &acm_null_ops;
122 acm_bin_pol.secondary_policy_code = ACM_NULL_POLICY;
123 acm_secondary_ops = &acm_null_ops;
124 ret = ACM_OK;
125 }
126 write_unlock(&acm_bin_pol_rwlock);
128 if (ret != ACM_OK)
129 return -EINVAL;
130 printk("%s: Enforcing Primary %s, Secondary %s.\n", __func__,
131 ACM_POLICY_NAME(acm_bin_pol.primary_policy_code), ACM_POLICY_NAME(acm_bin_pol.secondary_policy_code));
132 return ACM_OK;
133 }
135 #endif
137 int
138 acm_init_domain_ssid(domid_t id, ssidref_t ssidref)
139 {
140 struct acm_ssid_domain *ssid;
141 struct domain *subj = find_domain_by_id(id);
142 int ret1, ret2;
144 if (subj == NULL) {
145 printk("%s: ACM_NULL_POINTER ERROR (id=%x).\n", __func__, id);
146 return ACM_NULL_POINTER_ERROR;
147 }
148 if ((ssid = xmalloc(struct acm_ssid_domain)) == NULL)
149 return ACM_INIT_SSID_ERROR;
151 ssid->datatype = DOMAIN;
152 ssid->subject = subj;
153 ssid->domainid = subj->domain_id;
154 ssid->primary_ssid = NULL;
155 ssid->secondary_ssid = NULL;
157 if (ACM_USE_SECURITY_POLICY != ACM_NULL_POLICY)
158 ssid->ssidref = ssidref;
159 else
160 ssid->ssidref = ACM_DEFAULT_SSID;
162 subj->ssid = ssid;
163 /* now fill in primary and secondary parts; we only get here through hooks */
164 if (acm_primary_ops->init_domain_ssid != NULL)
165 ret1 = acm_primary_ops->init_domain_ssid(&(ssid->primary_ssid), ssidref);
166 else
167 ret1 = ACM_OK;
169 if (acm_secondary_ops->init_domain_ssid != NULL)
170 ret2 = acm_secondary_ops->init_domain_ssid(&(ssid->secondary_ssid), ssidref);
171 else
172 ret2 = ACM_OK;
174 if ((ret1 != ACM_OK) || (ret2 != ACM_OK)) {
175 printk("%s: ERROR instantiating individual ssids for domain 0x%02x.\n",
176 __func__, subj->domain_id);
177 acm_free_domain_ssid(ssid);
178 put_domain(subj);
179 return ACM_INIT_SSID_ERROR;
180 }
181 printk("%s: assigned domain %x the ssidref=%x.\n", __func__, id, ssid->ssidref);
182 put_domain(subj);
183 return ACM_OK;
184 }
187 int
188 acm_free_domain_ssid(struct acm_ssid_domain *ssid)
189 {
190 domid_t id;
192 /* domain is already gone, just ssid is left */
193 if (ssid == NULL) {
194 printk("%s: ACM_NULL_POINTER ERROR.\n", __func__);
195 return ACM_NULL_POINTER_ERROR;
196 }
197 id = ssid->domainid;
198 ssid->subject = NULL;
200 if (acm_primary_ops->free_domain_ssid != NULL) /* null policy */
201 acm_primary_ops->free_domain_ssid(ssid->primary_ssid);
202 ssid->primary_ssid = NULL;
203 if (acm_secondary_ops->free_domain_ssid != NULL)
204 acm_secondary_ops->free_domain_ssid(ssid->secondary_ssid);
205 ssid->secondary_ssid = NULL;
206 xfree(ssid);
207 printkd("%s: Freed individual domain ssid (domain=%02x).\n",__func__, id);
208 return ACM_OK;
209 }