mac_lomac.c (172953) | mac_lomac.c (172955) |
---|---|
1/*- 2 * Copyright (c) 1999-2002, 2007 Robert N. M. Watson 3 * Copyright (c) 2001-2005 Networks Associates Technology, Inc. 4 * Copyright (c) 2006 SPARTA, Inc. 5 * All rights reserved. 6 * 7 * This software was developed by Robert Watson for the TrustedBSD Project. 8 * --- 21 unchanged lines hidden (view full) --- 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * | 1/*- 2 * Copyright (c) 1999-2002, 2007 Robert N. M. Watson 3 * Copyright (c) 2001-2005 Networks Associates Technology, Inc. 4 * Copyright (c) 2006 SPARTA, Inc. 5 * All rights reserved. 6 * 7 * This software was developed by Robert Watson for the TrustedBSD Project. 8 * --- 21 unchanged lines hidden (view full) --- 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * |
38 * $FreeBSD: head/sys/security/mac_lomac/mac_lomac.c 172953 2007-10-25 07:49:47Z rwatson $ | 38 * $FreeBSD: head/sys/security/mac_lomac/mac_lomac.c 172955 2007-10-25 11:31:11Z rwatson $ |
39 */ 40 41/* 42 * Developed by the TrustedBSD Project. 43 * 44 * Low-watermark floating label mandatory integrity policy. 45 */ 46 --- 44 unchanged lines hidden (view full) --- 91 struct mtx mtx; 92}; 93 94SYSCTL_DECL(_security_mac); 95 96SYSCTL_NODE(_security_mac, OID_AUTO, lomac, CTLFLAG_RW, 0, 97 "TrustedBSD mac_lomac policy controls"); 98 | 39 */ 40 41/* 42 * Developed by the TrustedBSD Project. 43 * 44 * Low-watermark floating label mandatory integrity policy. 45 */ 46 --- 44 unchanged lines hidden (view full) --- 91 struct mtx mtx; 92}; 93 94SYSCTL_DECL(_security_mac); 95 96SYSCTL_NODE(_security_mac, OID_AUTO, lomac, CTLFLAG_RW, 0, 97 "TrustedBSD mac_lomac policy controls"); 98 |
99static int mac_lomac_label_size = sizeof(struct mac_lomac); | 99static int lomac_label_size = sizeof(struct mac_lomac); |
100SYSCTL_INT(_security_mac_lomac, OID_AUTO, label_size, CTLFLAG_RD, | 100SYSCTL_INT(_security_mac_lomac, OID_AUTO, label_size, CTLFLAG_RD, |
101 &mac_lomac_label_size, 0, "Size of struct mac_lomac"); | 101 &lomac_label_size, 0, "Size of struct mac_lomac"); |
102 | 102 |
103static int mac_lomac_enabled = 1; | 103static int lomac_enabled = 1; |
104SYSCTL_INT(_security_mac_lomac, OID_AUTO, enabled, CTLFLAG_RW, | 104SYSCTL_INT(_security_mac_lomac, OID_AUTO, enabled, CTLFLAG_RW, |
105 &mac_lomac_enabled, 0, "Enforce MAC/LOMAC policy"); 106TUNABLE_INT("security.mac.lomac.enabled", &mac_lomac_enabled); | 105 &lomac_enabled, 0, "Enforce MAC/LOMAC policy"); 106TUNABLE_INT("security.mac.lomac.enabled", &lomac_enabled); |
107 108static int destroyed_not_inited; 109SYSCTL_INT(_security_mac_lomac, OID_AUTO, destroyed_not_inited, CTLFLAG_RD, 110 &destroyed_not_inited, 0, "Count of labels destroyed but not inited"); 111 112static int trust_all_interfaces = 0; 113SYSCTL_INT(_security_mac_lomac, OID_AUTO, trust_all_interfaces, CTLFLAG_RD, 114 &trust_all_interfaces, 0, "Consider all interfaces 'trusted' by MAC/LOMAC"); --- 10 unchanged lines hidden (view full) --- 125 &ptys_equal, 0, "Label pty devices as lomac/equal on create"); 126TUNABLE_INT("security.mac.lomac.ptys_equal", &ptys_equal); 127 128static int revocation_enabled = 1; 129SYSCTL_INT(_security_mac_lomac, OID_AUTO, revocation_enabled, CTLFLAG_RW, 130 &revocation_enabled, 0, "Revoke access to objects on relabel"); 131TUNABLE_INT("security.mac.lomac.revocation_enabled", &revocation_enabled); 132 | 107 108static int destroyed_not_inited; 109SYSCTL_INT(_security_mac_lomac, OID_AUTO, destroyed_not_inited, CTLFLAG_RD, 110 &destroyed_not_inited, 0, "Count of labels destroyed but not inited"); 111 112static int trust_all_interfaces = 0; 113SYSCTL_INT(_security_mac_lomac, OID_AUTO, trust_all_interfaces, CTLFLAG_RD, 114 &trust_all_interfaces, 0, "Consider all interfaces 'trusted' by MAC/LOMAC"); --- 10 unchanged lines hidden (view full) --- 125 &ptys_equal, 0, "Label pty devices as lomac/equal on create"); 126TUNABLE_INT("security.mac.lomac.ptys_equal", &ptys_equal); 127 128static int revocation_enabled = 1; 129SYSCTL_INT(_security_mac_lomac, OID_AUTO, revocation_enabled, CTLFLAG_RW, 130 &revocation_enabled, 0, "Revoke access to objects on relabel"); 131TUNABLE_INT("security.mac.lomac.revocation_enabled", &revocation_enabled); 132 |
133static int mac_lomac_slot; 134#define SLOT(l) ((struct mac_lomac *)mac_label_get((l), mac_lomac_slot)) 135#define SLOT_SET(l, val) mac_label_set((l), mac_lomac_slot, (uintptr_t)(val)) | 133static int lomac_slot; 134#define SLOT(l) ((struct mac_lomac *)mac_label_get((l), lomac_slot)) 135#define SLOT_SET(l, val) mac_label_set((l), lomac_slot, (uintptr_t)(val)) |
136#define PSLOT(l) ((struct mac_lomac_proc *) \ | 136#define PSLOT(l) ((struct mac_lomac_proc *) \ |
137 mac_label_get((l), mac_lomac_slot)) 138#define PSLOT_SET(l, val) mac_label_set((l), mac_lomac_slot, (uintptr_t)(val)) | 137 mac_label_get((l), lomac_slot)) 138#define PSLOT_SET(l, val) mac_label_set((l), lomac_slot, (uintptr_t)(val)) |
139 | 139 |
140MALLOC_DEFINE(M_MACLOMAC, "mac_lomac_label", "MAC/LOMAC labels"); | 140MALLOC_DEFINE(M_LOMAC, "mac_lomac_label", "MAC/LOMAC labels"); |
141 142static struct mac_lomac * 143lomac_alloc(int flag) 144{ | 141 142static struct mac_lomac * 143lomac_alloc(int flag) 144{ |
145 struct mac_lomac *mac_lomac; | 145 struct mac_lomac *ml; |
146 | 146 |
147 mac_lomac = malloc(sizeof(struct mac_lomac), M_MACLOMAC, M_ZERO | flag); | 147 ml = malloc(sizeof(*ml), M_LOMAC, M_ZERO | flag); |
148 | 148 |
149 return (mac_lomac); | 149 return (ml); |
150} 151 152static void | 150} 151 152static void |
153lomac_free(struct mac_lomac *mac_lomac) | 153lomac_free(struct mac_lomac *ml) |
154{ 155 | 154{ 155 |
156 if (mac_lomac != NULL) 157 free(mac_lomac, M_MACLOMAC); | 156 if (ml != NULL) 157 free(ml, M_LOMAC); |
158 else 159 atomic_add_int(&destroyed_not_inited, 1); 160} 161 162static int | 158 else 159 atomic_add_int(&destroyed_not_inited, 1); 160} 161 162static int |
163lomac_atmostflags(struct mac_lomac *mac_lomac, int flags) | 163lomac_atmostflags(struct mac_lomac *ml, int flags) |
164{ 165 | 164{ 165 |
166 if ((mac_lomac->ml_flags & flags) != mac_lomac->ml_flags) | 166 if ((ml->ml_flags & flags) != ml->ml_flags) |
167 return (EINVAL); 168 return (0); 169} 170 171static int | 167 return (EINVAL); 168 return (0); 169} 170 171static int |
172mac_lomac_dominate_element(struct mac_lomac_element *a, | 172lomac_dominate_element(struct mac_lomac_element *a, |
173 struct mac_lomac_element *b) 174{ 175 176 switch (a->mle_type) { 177 case MAC_LOMAC_TYPE_EQUAL: 178 case MAC_LOMAC_TYPE_HIGH: 179 return (1); 180 181 case MAC_LOMAC_TYPE_LOW: 182 switch (b->mle_type) { 183 case MAC_LOMAC_TYPE_GRADE: 184 case MAC_LOMAC_TYPE_HIGH: 185 return (0); 186 187 case MAC_LOMAC_TYPE_EQUAL: 188 case MAC_LOMAC_TYPE_LOW: 189 return (1); 190 191 default: | 173 struct mac_lomac_element *b) 174{ 175 176 switch (a->mle_type) { 177 case MAC_LOMAC_TYPE_EQUAL: 178 case MAC_LOMAC_TYPE_HIGH: 179 return (1); 180 181 case MAC_LOMAC_TYPE_LOW: 182 switch (b->mle_type) { 183 case MAC_LOMAC_TYPE_GRADE: 184 case MAC_LOMAC_TYPE_HIGH: 185 return (0); 186 187 case MAC_LOMAC_TYPE_EQUAL: 188 case MAC_LOMAC_TYPE_LOW: 189 return (1); 190 191 default: |
192 panic("mac_lomac_dominate_element: b->mle_type invalid"); | 192 panic("lomac_dominate_element: b->mle_type invalid"); |
193 } 194 195 case MAC_LOMAC_TYPE_GRADE: 196 switch (b->mle_type) { 197 case MAC_LOMAC_TYPE_EQUAL: 198 case MAC_LOMAC_TYPE_LOW: 199 return (1); 200 201 case MAC_LOMAC_TYPE_HIGH: 202 return (0); 203 204 case MAC_LOMAC_TYPE_GRADE: 205 return (a->mle_grade >= b->mle_grade); 206 207 default: | 193 } 194 195 case MAC_LOMAC_TYPE_GRADE: 196 switch (b->mle_type) { 197 case MAC_LOMAC_TYPE_EQUAL: 198 case MAC_LOMAC_TYPE_LOW: 199 return (1); 200 201 case MAC_LOMAC_TYPE_HIGH: 202 return (0); 203 204 case MAC_LOMAC_TYPE_GRADE: 205 return (a->mle_grade >= b->mle_grade); 206 207 default: |
208 panic("mac_lomac_dominate_element: b->mle_type invalid"); | 208 panic("lomac_dominate_element: b->mle_type invalid"); |
209 } 210 211 default: | 209 } 210 211 default: |
212 panic("mac_lomac_dominate_element: a->mle_type invalid"); | 212 panic("lomac_dominate_element: a->mle_type invalid"); |
213 } 214} 215 216static int | 213 } 214} 215 216static int |
217mac_lomac_range_in_range(struct mac_lomac *rangea, struct mac_lomac *rangeb) | 217lomac_range_in_range(struct mac_lomac *rangea, struct mac_lomac *rangeb) |
218{ 219 | 218{ 219 |
220 return (mac_lomac_dominate_element(&rangeb->ml_rangehigh, | 220 return (lomac_dominate_element(&rangeb->ml_rangehigh, |
221 &rangea->ml_rangehigh) && | 221 &rangea->ml_rangehigh) && |
222 mac_lomac_dominate_element(&rangea->ml_rangelow, | 222 lomac_dominate_element(&rangea->ml_rangelow, |
223 &rangeb->ml_rangelow)); 224} 225 226static int | 223 &rangeb->ml_rangelow)); 224} 225 226static int |
227mac_lomac_single_in_range(struct mac_lomac *single, struct mac_lomac *range) | 227lomac_single_in_range(struct mac_lomac *single, struct mac_lomac *range) |
228{ 229 230 KASSERT((single->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, | 228{ 229 230 KASSERT((single->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, |
231 ("mac_lomac_single_in_range: a not single")); | 231 ("lomac_single_in_range: a not single")); |
232 KASSERT((range->ml_flags & MAC_LOMAC_FLAG_RANGE) != 0, | 232 KASSERT((range->ml_flags & MAC_LOMAC_FLAG_RANGE) != 0, |
233 ("mac_lomac_single_in_range: b not range")); | 233 ("lomac_single_in_range: b not range")); |
234 | 234 |
235 return (mac_lomac_dominate_element(&range->ml_rangehigh, 236 &single->ml_single) && 237 mac_lomac_dominate_element(&single->ml_single, | 235 return (lomac_dominate_element(&range->ml_rangehigh, 236 &single->ml_single) && lomac_dominate_element(&single->ml_single, |
238 &range->ml_rangelow)); 239} 240 241static int | 237 &range->ml_rangelow)); 238} 239 240static int |
242mac_lomac_auxsingle_in_range(struct mac_lomac *single, struct mac_lomac *range) | 241lomac_auxsingle_in_range(struct mac_lomac *single, struct mac_lomac *range) |
243{ 244 245 KASSERT((single->ml_flags & MAC_LOMAC_FLAG_AUX) != 0, | 242{ 243 244 KASSERT((single->ml_flags & MAC_LOMAC_FLAG_AUX) != 0, |
246 ("mac_lomac_single_in_range: a not auxsingle")); | 245 ("lomac_single_in_range: a not auxsingle")); |
247 KASSERT((range->ml_flags & MAC_LOMAC_FLAG_RANGE) != 0, | 246 KASSERT((range->ml_flags & MAC_LOMAC_FLAG_RANGE) != 0, |
248 ("mac_lomac_single_in_range: b not range")); | 247 ("lomac_single_in_range: b not range")); |
249 | 248 |
250 return (mac_lomac_dominate_element(&range->ml_rangehigh, | 249 return (lomac_dominate_element(&range->ml_rangehigh, |
251 &single->ml_auxsingle) && | 250 &single->ml_auxsingle) && |
252 mac_lomac_dominate_element(&single->ml_auxsingle, | 251 lomac_dominate_element(&single->ml_auxsingle, |
253 &range->ml_rangelow)); 254} 255 256static int | 252 &range->ml_rangelow)); 253} 254 255static int |
257mac_lomac_dominate_single(struct mac_lomac *a, struct mac_lomac *b) | 256lomac_dominate_single(struct mac_lomac *a, struct mac_lomac *b) |
258{ 259 KASSERT((a->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, | 257{ 258 KASSERT((a->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, |
260 ("mac_lomac_dominate_single: a not single")); | 259 ("lomac_dominate_single: a not single")); |
261 KASSERT((b->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, | 260 KASSERT((b->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, |
262 ("mac_lomac_dominate_single: b not single")); | 261 ("lomac_dominate_single: b not single")); |
263 | 262 |
264 return (mac_lomac_dominate_element(&a->ml_single, &b->ml_single)); | 263 return (lomac_dominate_element(&a->ml_single, &b->ml_single)); |
265} 266 267static int | 264} 265 266static int |
268mac_lomac_subject_dominate(struct mac_lomac *a, struct mac_lomac *b) | 267lomac_subject_dominate(struct mac_lomac *a, struct mac_lomac *b) |
269{ 270 KASSERT((~a->ml_flags & 271 (MAC_LOMAC_FLAG_SINGLE | MAC_LOMAC_FLAG_RANGE)) == 0, | 268{ 269 KASSERT((~a->ml_flags & 270 (MAC_LOMAC_FLAG_SINGLE | MAC_LOMAC_FLAG_RANGE)) == 0, |
272 ("mac_lomac_dominate_single: a not subject")); | 271 ("lomac_dominate_single: a not subject")); |
273 KASSERT((b->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, | 272 KASSERT((b->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, |
274 ("mac_lomac_dominate_single: b not single")); | 273 ("lomac_dominate_single: b not single")); |
275 | 274 |
276 return (mac_lomac_dominate_element(&a->ml_rangehigh, 277 &b->ml_single)); | 275 return (lomac_dominate_element(&a->ml_rangehigh, &b->ml_single)); |
278} 279 280static int | 276} 277 278static int |
281mac_lomac_equal_element(struct mac_lomac_element *a, struct mac_lomac_element *b) | 279lomac_equal_element(struct mac_lomac_element *a, struct mac_lomac_element *b) |
282{ 283 284 if (a->mle_type == MAC_LOMAC_TYPE_EQUAL || 285 b->mle_type == MAC_LOMAC_TYPE_EQUAL) 286 return (1); 287 288 return (a->mle_type == b->mle_type && a->mle_grade == b->mle_grade); 289} 290 291static int | 280{ 281 282 if (a->mle_type == MAC_LOMAC_TYPE_EQUAL || 283 b->mle_type == MAC_LOMAC_TYPE_EQUAL) 284 return (1); 285 286 return (a->mle_type == b->mle_type && a->mle_grade == b->mle_grade); 287} 288 289static int |
292mac_lomac_equal_single(struct mac_lomac *a, struct mac_lomac *b) | 290lomac_equal_single(struct mac_lomac *a, struct mac_lomac *b) |
293{ 294 295 KASSERT((a->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, | 291{ 292 293 KASSERT((a->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, |
296 ("mac_lomac_equal_single: a not single")); | 294 ("lomac_equal_single: a not single")); |
297 KASSERT((b->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, | 295 KASSERT((b->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, |
298 ("mac_lomac_equal_single: b not single")); | 296 ("lomac_equal_single: b not single")); |
299 | 297 |
300 return (mac_lomac_equal_element(&a->ml_single, &b->ml_single)); | 298 return (lomac_equal_element(&a->ml_single, &b->ml_single)); |
301} 302 303static int | 299} 300 301static int |
304mac_lomac_contains_equal(struct mac_lomac *mac_lomac) | 302lomac_contains_equal(struct mac_lomac *ml) |
305{ 306 | 303{ 304 |
307 if (mac_lomac->ml_flags & MAC_LOMAC_FLAG_SINGLE) 308 if (mac_lomac->ml_single.mle_type == MAC_LOMAC_TYPE_EQUAL) | 305 if (ml->ml_flags & MAC_LOMAC_FLAG_SINGLE) 306 if (ml->ml_single.mle_type == MAC_LOMAC_TYPE_EQUAL) |
309 return (1); | 307 return (1); |
310 if (mac_lomac->ml_flags & MAC_LOMAC_FLAG_AUX) 311 if (mac_lomac->ml_auxsingle.mle_type == MAC_LOMAC_TYPE_EQUAL) | 308 if (ml->ml_flags & MAC_LOMAC_FLAG_AUX) 309 if (ml->ml_auxsingle.mle_type == MAC_LOMAC_TYPE_EQUAL) |
312 return (1); 313 | 310 return (1); 311 |
314 if (mac_lomac->ml_flags & MAC_LOMAC_FLAG_RANGE) { 315 if (mac_lomac->ml_rangelow.mle_type == MAC_LOMAC_TYPE_EQUAL) | 312 if (ml->ml_flags & MAC_LOMAC_FLAG_RANGE) { 313 if (ml->ml_rangelow.mle_type == MAC_LOMAC_TYPE_EQUAL) |
316 return (1); | 314 return (1); |
317 if (mac_lomac->ml_rangehigh.mle_type == MAC_LOMAC_TYPE_EQUAL) | 315 if (ml->ml_rangehigh.mle_type == MAC_LOMAC_TYPE_EQUAL) |
318 return (1); 319 } 320 321 return (0); 322} 323 324static int | 316 return (1); 317 } 318 319 return (0); 320} 321 322static int |
325mac_lomac_subject_privileged(struct mac_lomac *mac_lomac) | 323lomac_subject_privileged(struct mac_lomac *ml) |
326{ 327 | 324{ 325 |
328 KASSERT((mac_lomac->ml_flags & MAC_LOMAC_FLAGS_BOTH) == | 326 KASSERT((ml->ml_flags & MAC_LOMAC_FLAGS_BOTH) == |
329 MAC_LOMAC_FLAGS_BOTH, | 327 MAC_LOMAC_FLAGS_BOTH, |
330 ("mac_lomac_subject_privileged: subject doesn't have both labels")); | 328 ("lomac_subject_privileged: subject doesn't have both labels")); |
331 332 /* If the single is EQUAL, it's ok. */ | 329 330 /* If the single is EQUAL, it's ok. */ |
333 if (mac_lomac->ml_single.mle_type == MAC_LOMAC_TYPE_EQUAL) | 331 if (ml->ml_single.mle_type == MAC_LOMAC_TYPE_EQUAL) |
334 return (0); 335 336 /* If either range endpoint is EQUAL, it's ok. */ | 332 return (0); 333 334 /* If either range endpoint is EQUAL, it's ok. */ |
337 if (mac_lomac->ml_rangelow.mle_type == MAC_LOMAC_TYPE_EQUAL || 338 mac_lomac->ml_rangehigh.mle_type == MAC_LOMAC_TYPE_EQUAL) | 335 if (ml->ml_rangelow.mle_type == MAC_LOMAC_TYPE_EQUAL || 336 ml->ml_rangehigh.mle_type == MAC_LOMAC_TYPE_EQUAL) |
339 return (0); 340 341 /* If the range is low-high, it's ok. */ | 337 return (0); 338 339 /* If the range is low-high, it's ok. */ |
342 if (mac_lomac->ml_rangelow.mle_type == MAC_LOMAC_TYPE_LOW && 343 mac_lomac->ml_rangehigh.mle_type == MAC_LOMAC_TYPE_HIGH) | 340 if (ml->ml_rangelow.mle_type == MAC_LOMAC_TYPE_LOW && 341 ml->ml_rangehigh.mle_type == MAC_LOMAC_TYPE_HIGH) |
344 return (0); 345 346 /* It's not ok. */ 347 return (EPERM); 348} 349 350static int | 342 return (0); 343 344 /* It's not ok. */ 345 return (EPERM); 346} 347 348static int |
351mac_lomac_high_single(struct mac_lomac *mac_lomac) | 349lomac_high_single(struct mac_lomac *ml) |
352{ 353 | 350{ 351 |
354 KASSERT((mac_lomac->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, 355 ("mac_lomac_high_single: mac_lomac not single")); | 352 KASSERT((ml->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, 353 ("lomac_high_single: mac_lomac not single")); |
356 | 354 |
357 return (mac_lomac->ml_single.mle_type == MAC_LOMAC_TYPE_HIGH); | 355 return (ml->ml_single.mle_type == MAC_LOMAC_TYPE_HIGH); |
358} 359 360static int | 356} 357 358static int |
361mac_lomac_valid(struct mac_lomac *mac_lomac) | 359lomac_valid(struct mac_lomac *ml) |
362{ 363 | 360{ 361 |
364 if (mac_lomac->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 365 switch (mac_lomac->ml_single.mle_type) { | 362 if (ml->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 363 switch (ml->ml_single.mle_type) { |
366 case MAC_LOMAC_TYPE_GRADE: 367 case MAC_LOMAC_TYPE_EQUAL: 368 case MAC_LOMAC_TYPE_HIGH: 369 case MAC_LOMAC_TYPE_LOW: 370 break; 371 372 default: 373 return (EINVAL); 374 } 375 } else { | 364 case MAC_LOMAC_TYPE_GRADE: 365 case MAC_LOMAC_TYPE_EQUAL: 366 case MAC_LOMAC_TYPE_HIGH: 367 case MAC_LOMAC_TYPE_LOW: 368 break; 369 370 default: 371 return (EINVAL); 372 } 373 } else { |
376 if (mac_lomac->ml_single.mle_type != MAC_LOMAC_TYPE_UNDEF) | 374 if (ml->ml_single.mle_type != MAC_LOMAC_TYPE_UNDEF) |
377 return (EINVAL); 378 } 379 | 375 return (EINVAL); 376 } 377 |
380 if (mac_lomac->ml_flags & MAC_LOMAC_FLAG_AUX) { 381 switch (mac_lomac->ml_auxsingle.mle_type) { | 378 if (ml->ml_flags & MAC_LOMAC_FLAG_AUX) { 379 switch (ml->ml_auxsingle.mle_type) { |
382 case MAC_LOMAC_TYPE_GRADE: 383 case MAC_LOMAC_TYPE_EQUAL: 384 case MAC_LOMAC_TYPE_HIGH: 385 case MAC_LOMAC_TYPE_LOW: 386 break; 387 388 default: 389 return (EINVAL); 390 } 391 } else { | 380 case MAC_LOMAC_TYPE_GRADE: 381 case MAC_LOMAC_TYPE_EQUAL: 382 case MAC_LOMAC_TYPE_HIGH: 383 case MAC_LOMAC_TYPE_LOW: 384 break; 385 386 default: 387 return (EINVAL); 388 } 389 } else { |
392 if (mac_lomac->ml_auxsingle.mle_type != MAC_LOMAC_TYPE_UNDEF) | 390 if (ml->ml_auxsingle.mle_type != MAC_LOMAC_TYPE_UNDEF) |
393 return (EINVAL); 394 } 395 | 391 return (EINVAL); 392 } 393 |
396 if (mac_lomac->ml_flags & MAC_LOMAC_FLAG_RANGE) { 397 switch (mac_lomac->ml_rangelow.mle_type) { | 394 if (ml->ml_flags & MAC_LOMAC_FLAG_RANGE) { 395 switch (ml->ml_rangelow.mle_type) { |
398 case MAC_LOMAC_TYPE_GRADE: 399 case MAC_LOMAC_TYPE_EQUAL: 400 case MAC_LOMAC_TYPE_HIGH: 401 case MAC_LOMAC_TYPE_LOW: 402 break; 403 404 default: 405 return (EINVAL); 406 } 407 | 396 case MAC_LOMAC_TYPE_GRADE: 397 case MAC_LOMAC_TYPE_EQUAL: 398 case MAC_LOMAC_TYPE_HIGH: 399 case MAC_LOMAC_TYPE_LOW: 400 break; 401 402 default: 403 return (EINVAL); 404 } 405 |
408 switch (mac_lomac->ml_rangehigh.mle_type) { | 406 switch (ml->ml_rangehigh.mle_type) { |
409 case MAC_LOMAC_TYPE_GRADE: 410 case MAC_LOMAC_TYPE_EQUAL: 411 case MAC_LOMAC_TYPE_HIGH: 412 case MAC_LOMAC_TYPE_LOW: 413 break; 414 415 default: 416 return (EINVAL); 417 } | 407 case MAC_LOMAC_TYPE_GRADE: 408 case MAC_LOMAC_TYPE_EQUAL: 409 case MAC_LOMAC_TYPE_HIGH: 410 case MAC_LOMAC_TYPE_LOW: 411 break; 412 413 default: 414 return (EINVAL); 415 } |
418 if (!mac_lomac_dominate_element(&mac_lomac->ml_rangehigh, 419 &mac_lomac->ml_rangelow)) | 416 if (!lomac_dominate_element(&ml->ml_rangehigh, 417 &ml->ml_rangelow)) |
420 return (EINVAL); 421 } else { | 418 return (EINVAL); 419 } else { |
422 if (mac_lomac->ml_rangelow.mle_type != MAC_LOMAC_TYPE_UNDEF || 423 mac_lomac->ml_rangehigh.mle_type != MAC_LOMAC_TYPE_UNDEF) | 420 if (ml->ml_rangelow.mle_type != MAC_LOMAC_TYPE_UNDEF || 421 ml->ml_rangehigh.mle_type != MAC_LOMAC_TYPE_UNDEF) |
424 return (EINVAL); 425 } 426 427 return (0); 428} 429 430static void | 422 return (EINVAL); 423 } 424 425 return (0); 426} 427 428static void |
431mac_lomac_set_range(struct mac_lomac *mac_lomac, u_short typelow, 432 u_short gradelow, u_short typehigh, u_short gradehigh) | 429lomac_set_range(struct mac_lomac *ml, u_short typelow, u_short gradelow, 430 u_short typehigh, u_short gradehigh) |
433{ 434 | 431{ 432 |
435 mac_lomac->ml_rangelow.mle_type = typelow; 436 mac_lomac->ml_rangelow.mle_grade = gradelow; 437 mac_lomac->ml_rangehigh.mle_type = typehigh; 438 mac_lomac->ml_rangehigh.mle_grade = gradehigh; 439 mac_lomac->ml_flags |= MAC_LOMAC_FLAG_RANGE; | 433 ml->ml_rangelow.mle_type = typelow; 434 ml->ml_rangelow.mle_grade = gradelow; 435 ml->ml_rangehigh.mle_type = typehigh; 436 ml->ml_rangehigh.mle_grade = gradehigh; 437 ml->ml_flags |= MAC_LOMAC_FLAG_RANGE; |
440} 441 442static void | 438} 439 440static void |
443mac_lomac_set_single(struct mac_lomac *mac_lomac, u_short type, u_short grade) | 441lomac_set_single(struct mac_lomac *ml, u_short type, u_short grade) |
444{ 445 | 442{ 443 |
446 mac_lomac->ml_single.mle_type = type; 447 mac_lomac->ml_single.mle_grade = grade; 448 mac_lomac->ml_flags |= MAC_LOMAC_FLAG_SINGLE; | 444 ml->ml_single.mle_type = type; 445 ml->ml_single.mle_grade = grade; 446 ml->ml_flags |= MAC_LOMAC_FLAG_SINGLE; |
449} 450 451static void | 447} 448 449static void |
452mac_lomac_copy_range(struct mac_lomac *labelfrom, struct mac_lomac *labelto) | 450lomac_copy_range(struct mac_lomac *labelfrom, struct mac_lomac *labelto) |
453{ 454 455 KASSERT((labelfrom->ml_flags & MAC_LOMAC_FLAG_RANGE) != 0, | 451{ 452 453 KASSERT((labelfrom->ml_flags & MAC_LOMAC_FLAG_RANGE) != 0, |
456 ("mac_lomac_copy_range: labelfrom not range")); | 454 ("lomac_copy_range: labelfrom not range")); |
457 458 labelto->ml_rangelow = labelfrom->ml_rangelow; 459 labelto->ml_rangehigh = labelfrom->ml_rangehigh; 460 labelto->ml_flags |= MAC_LOMAC_FLAG_RANGE; 461} 462 463static void | 455 456 labelto->ml_rangelow = labelfrom->ml_rangelow; 457 labelto->ml_rangehigh = labelfrom->ml_rangehigh; 458 labelto->ml_flags |= MAC_LOMAC_FLAG_RANGE; 459} 460 461static void |
464mac_lomac_copy_single(struct mac_lomac *labelfrom, struct mac_lomac *labelto) | 462lomac_copy_single(struct mac_lomac *labelfrom, struct mac_lomac *labelto) |
465{ 466 467 KASSERT((labelfrom->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, | 463{ 464 465 KASSERT((labelfrom->ml_flags & MAC_LOMAC_FLAG_SINGLE) != 0, |
468 ("mac_lomac_copy_single: labelfrom not single")); | 466 ("lomac_copy_single: labelfrom not single")); |
469 470 labelto->ml_single = labelfrom->ml_single; 471 labelto->ml_flags |= MAC_LOMAC_FLAG_SINGLE; 472} 473 474static void | 467 468 labelto->ml_single = labelfrom->ml_single; 469 labelto->ml_flags |= MAC_LOMAC_FLAG_SINGLE; 470} 471 472static void |
475mac_lomac_copy_auxsingle(struct mac_lomac *labelfrom, struct mac_lomac *labelto) | 473lomac_copy_auxsingle(struct mac_lomac *labelfrom, struct mac_lomac *labelto) |
476{ 477 478 KASSERT((labelfrom->ml_flags & MAC_LOMAC_FLAG_AUX) != 0, | 474{ 475 476 KASSERT((labelfrom->ml_flags & MAC_LOMAC_FLAG_AUX) != 0, |
479 ("mac_lomac_copy_auxsingle: labelfrom not auxsingle")); | 477 ("lomac_copy_auxsingle: labelfrom not auxsingle")); |
480 481 labelto->ml_auxsingle = labelfrom->ml_auxsingle; 482 labelto->ml_flags |= MAC_LOMAC_FLAG_AUX; 483} 484 485static void | 478 479 labelto->ml_auxsingle = labelfrom->ml_auxsingle; 480 labelto->ml_flags |= MAC_LOMAC_FLAG_AUX; 481} 482 483static void |
486mac_lomac_copy(struct mac_lomac *source, struct mac_lomac *dest) | 484lomac_copy(struct mac_lomac *source, struct mac_lomac *dest) |
487{ 488 489 if (source->ml_flags & MAC_LOMAC_FLAG_SINGLE) | 485{ 486 487 if (source->ml_flags & MAC_LOMAC_FLAG_SINGLE) |
490 mac_lomac_copy_single(source, dest); | 488 lomac_copy_single(source, dest); |
491 if (source->ml_flags & MAC_LOMAC_FLAG_AUX) | 489 if (source->ml_flags & MAC_LOMAC_FLAG_AUX) |
492 mac_lomac_copy_auxsingle(source, dest); | 490 lomac_copy_auxsingle(source, dest); |
493 if (source->ml_flags & MAC_LOMAC_FLAG_RANGE) | 491 if (source->ml_flags & MAC_LOMAC_FLAG_RANGE) |
494 mac_lomac_copy_range(source, dest); | 492 lomac_copy_range(source, dest); |
495} 496 | 493} 494 |
497static int mac_lomac_to_string(struct sbuf *sb, 498 struct mac_lomac *mac_lomac); | 495static int lomac_to_string(struct sbuf *sb, struct mac_lomac *ml); |
499 500static int 501maybe_demote(struct mac_lomac *subjlabel, struct mac_lomac *objlabel, 502 const char *actionname, const char *objname, struct vnode *vp) 503{ 504 struct sbuf subjlabel_sb, subjtext_sb, objlabel_sb; 505 char *subjlabeltext, *objlabeltext, *subjtext; 506 struct mac_lomac cached_subjlabel; 507 struct mac_lomac_proc *subj; 508 struct vattr va; 509 struct proc *p; 510 pid_t pgid; 511 512 subj = PSLOT(curthread->td_proc->p_label); 513 514 p = curthread->td_proc; 515 mtx_lock(&subj->mtx); 516 if (subj->mac_lomac.ml_flags & MAC_LOMAC_FLAG_UPDATE) { 517 /* | 496 497static int 498maybe_demote(struct mac_lomac *subjlabel, struct mac_lomac *objlabel, 499 const char *actionname, const char *objname, struct vnode *vp) 500{ 501 struct sbuf subjlabel_sb, subjtext_sb, objlabel_sb; 502 char *subjlabeltext, *objlabeltext, *subjtext; 503 struct mac_lomac cached_subjlabel; 504 struct mac_lomac_proc *subj; 505 struct vattr va; 506 struct proc *p; 507 pid_t pgid; 508 509 subj = PSLOT(curthread->td_proc->p_label); 510 511 p = curthread->td_proc; 512 mtx_lock(&subj->mtx); 513 if (subj->mac_lomac.ml_flags & MAC_LOMAC_FLAG_UPDATE) { 514 /* |
518 * Check to see if the pending demotion would be more or 519 * less severe than this one, and keep the more severe. 520 * This can only happen for a multi-threaded application. | 515 * Check to see if the pending demotion would be more or less 516 * severe than this one, and keep the more severe. This can 517 * only happen for a multi-threaded application. |
521 */ | 518 */ |
522 if (mac_lomac_dominate_single(objlabel, &subj->mac_lomac)) { | 519 if (lomac_dominate_single(objlabel, &subj->mac_lomac)) { |
523 mtx_unlock(&subj->mtx); 524 return (0); 525 } 526 } 527 bzero(&subj->mac_lomac, sizeof(subj->mac_lomac)); 528 /* 529 * Always demote the single label. 530 */ | 520 mtx_unlock(&subj->mtx); 521 return (0); 522 } 523 } 524 bzero(&subj->mac_lomac, sizeof(subj->mac_lomac)); 525 /* 526 * Always demote the single label. 527 */ |
531 mac_lomac_copy_single(objlabel, &subj->mac_lomac); | 528 lomac_copy_single(objlabel, &subj->mac_lomac); |
532 /* | 529 /* |
533 * Start with the original range, then minimize each side of 534 * the range to the point of not dominating the object. The 535 * high side will always be demoted, of course. | 530 * Start with the original range, then minimize each side of the 531 * range to the point of not dominating the object. The high side 532 * will always be demoted, of course. |
536 */ | 533 */ |
537 mac_lomac_copy_range(subjlabel, &subj->mac_lomac); 538 if (!mac_lomac_dominate_element(&objlabel->ml_single, | 534 lomac_copy_range(subjlabel, &subj->mac_lomac); 535 if (!lomac_dominate_element(&objlabel->ml_single, |
539 &subj->mac_lomac.ml_rangelow)) 540 subj->mac_lomac.ml_rangelow = objlabel->ml_single; 541 subj->mac_lomac.ml_rangehigh = objlabel->ml_single; 542 subj->mac_lomac.ml_flags |= MAC_LOMAC_FLAG_UPDATE; 543 thread_lock(curthread); 544 curthread->td_flags |= TDF_ASTPENDING | TDF_MACPEND; 545 thread_unlock(curthread); 546 547 /* | 536 &subj->mac_lomac.ml_rangelow)) 537 subj->mac_lomac.ml_rangelow = objlabel->ml_single; 538 subj->mac_lomac.ml_rangehigh = objlabel->ml_single; 539 subj->mac_lomac.ml_flags |= MAC_LOMAC_FLAG_UPDATE; 540 thread_lock(curthread); 541 curthread->td_flags |= TDF_ASTPENDING | TDF_MACPEND; 542 thread_unlock(curthread); 543 544 /* |
548 * Avoid memory allocation while holding a mutex; cache the 549 * label. | 545 * Avoid memory allocation while holding a mutex; cache the label. |
550 */ | 546 */ |
551 mac_lomac_copy_single(&subj->mac_lomac, &cached_subjlabel); | 547 lomac_copy_single(&subj->mac_lomac, &cached_subjlabel); |
552 mtx_unlock(&subj->mtx); 553 554 sbuf_new(&subjlabel_sb, NULL, 0, SBUF_AUTOEXTEND); | 548 mtx_unlock(&subj->mtx); 549 550 sbuf_new(&subjlabel_sb, NULL, 0, SBUF_AUTOEXTEND); |
555 mac_lomac_to_string(&subjlabel_sb, subjlabel); | 551 lomac_to_string(&subjlabel_sb, subjlabel); |
556 sbuf_finish(&subjlabel_sb); 557 subjlabeltext = sbuf_data(&subjlabel_sb); 558 559 sbuf_new(&subjtext_sb, NULL, 0, SBUF_AUTOEXTEND); | 552 sbuf_finish(&subjlabel_sb); 553 subjlabeltext = sbuf_data(&subjlabel_sb); 554 555 sbuf_new(&subjtext_sb, NULL, 0, SBUF_AUTOEXTEND); |
560 mac_lomac_to_string(&subjtext_sb, &subj->mac_lomac); | 556 lomac_to_string(&subjtext_sb, &subj->mac_lomac); |
561 sbuf_finish(&subjtext_sb); 562 subjtext = sbuf_data(&subjtext_sb); 563 564 sbuf_new(&objlabel_sb, NULL, 0, SBUF_AUTOEXTEND); | 557 sbuf_finish(&subjtext_sb); 558 subjtext = sbuf_data(&subjtext_sb); 559 560 sbuf_new(&objlabel_sb, NULL, 0, SBUF_AUTOEXTEND); |
565 mac_lomac_to_string(&objlabel_sb, objlabel); | 561 lomac_to_string(&objlabel_sb, objlabel); |
566 sbuf_finish(&objlabel_sb); 567 objlabeltext = sbuf_data(&objlabel_sb); 568 569 pgid = p->p_pgrp->pg_id; /* XXX could be stale? */ 570 if (vp != NULL && VOP_GETATTR(vp, &va, curthread->td_ucred, 571 curthread) == 0) { 572 log(LOG_INFO, "LOMAC: level-%s subject p%dg%du%d:%s demoted to" 573 " level %s after %s a level-%s %s (inode=%ld, " --- 11 unchanged lines hidden (view full) --- 585 sbuf_delete(&subjlabel_sb); 586 sbuf_delete(&subjtext_sb); 587 sbuf_delete(&objlabel_sb); 588 589 return (0); 590} 591 592/* | 562 sbuf_finish(&objlabel_sb); 563 objlabeltext = sbuf_data(&objlabel_sb); 564 565 pgid = p->p_pgrp->pg_id; /* XXX could be stale? */ 566 if (vp != NULL && VOP_GETATTR(vp, &va, curthread->td_ucred, 567 curthread) == 0) { 568 log(LOG_INFO, "LOMAC: level-%s subject p%dg%du%d:%s demoted to" 569 " level %s after %s a level-%s %s (inode=%ld, " --- 11 unchanged lines hidden (view full) --- 581 sbuf_delete(&subjlabel_sb); 582 sbuf_delete(&subjtext_sb); 583 sbuf_delete(&objlabel_sb); 584 585 return (0); 586} 587 588/* |
593 * Relabel "to" to "from" only if "from" is a valid label (contains 594 * at least a single), as for a relabel operation which may or may 595 * not involve a relevant label. | 589 * Relabel "to" to "from" only if "from" is a valid label (contains at least 590 * a single), as for a relabel operation which may or may not involve a 591 * relevant label. |
596 */ 597static void 598try_relabel(struct mac_lomac *from, struct mac_lomac *to) 599{ 600 601 if (from->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 602 bzero(to, sizeof(*to)); | 592 */ 593static void 594try_relabel(struct mac_lomac *from, struct mac_lomac *to) 595{ 596 597 if (from->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 598 bzero(to, sizeof(*to)); |
603 mac_lomac_copy(from, to); | 599 lomac_copy(from, to); |
604 } 605} 606 607/* 608 * Policy module operations. 609 */ 610static void | 600 } 601} 602 603/* 604 * Policy module operations. 605 */ 606static void |
611mac_lomac_init(struct mac_policy_conf *conf) | 607lomac_init(struct mac_policy_conf *conf) |
612{ 613 614} 615 616/* 617 * Label operations. 618 */ 619static void | 608{ 609 610} 611 612/* 613 * Label operations. 614 */ 615static void |
620mac_lomac_init_label(struct label *label) | 616lomac_init_label(struct label *label) |
621{ 622 623 SLOT_SET(label, lomac_alloc(M_WAITOK)); 624} 625 626static int | 617{ 618 619 SLOT_SET(label, lomac_alloc(M_WAITOK)); 620} 621 622static int |
627mac_lomac_init_label_waitcheck(struct label *label, int flag) | 623lomac_init_label_waitcheck(struct label *label, int flag) |
628{ 629 630 SLOT_SET(label, lomac_alloc(flag)); 631 if (SLOT(label) == NULL) 632 return (ENOMEM); 633 634 return (0); 635} 636 637static void | 624{ 625 626 SLOT_SET(label, lomac_alloc(flag)); 627 if (SLOT(label) == NULL) 628 return (ENOMEM); 629 630 return (0); 631} 632 633static void |
638mac_lomac_proc_init_label(struct label *label) | 634lomac_proc_init_label(struct label *label) |
639{ 640 | 635{ 636 |
641 PSLOT_SET(label, malloc(sizeof(struct mac_lomac_proc), M_MACLOMAC, | 637 PSLOT_SET(label, malloc(sizeof(struct mac_lomac_proc), M_LOMAC, |
642 M_ZERO | M_WAITOK)); 643 mtx_init(&PSLOT(label)->mtx, "MAC/Lomac proc lock", NULL, MTX_DEF); 644} 645 646static void | 638 M_ZERO | M_WAITOK)); 639 mtx_init(&PSLOT(label)->mtx, "MAC/Lomac proc lock", NULL, MTX_DEF); 640} 641 642static void |
647mac_lomac_destroy_label(struct label *label) | 643lomac_destroy_label(struct label *label) |
648{ 649 650 lomac_free(SLOT(label)); 651 SLOT_SET(label, NULL); 652} 653 654static void | 644{ 645 646 lomac_free(SLOT(label)); 647 SLOT_SET(label, NULL); 648} 649 650static void |
655mac_lomac_proc_destroy_label(struct label *label) | 651lomac_proc_destroy_label(struct label *label) |
656{ 657 658 mtx_destroy(&PSLOT(label)->mtx); | 652{ 653 654 mtx_destroy(&PSLOT(label)->mtx); |
659 FREE(PSLOT(label), M_MACLOMAC); | 655 FREE(PSLOT(label), M_LOMAC); |
660 PSLOT_SET(label, NULL); 661} 662 663static int | 656 PSLOT_SET(label, NULL); 657} 658 659static int |
664mac_lomac_element_to_string(struct sbuf *sb, struct mac_lomac_element *element) | 660lomac_element_to_string(struct sbuf *sb, struct mac_lomac_element *element) |
665{ 666 667 switch (element->mle_type) { 668 case MAC_LOMAC_TYPE_HIGH: 669 return (sbuf_printf(sb, "high")); 670 671 case MAC_LOMAC_TYPE_LOW: 672 return (sbuf_printf(sb, "low")); 673 674 case MAC_LOMAC_TYPE_EQUAL: 675 return (sbuf_printf(sb, "equal")); 676 677 case MAC_LOMAC_TYPE_GRADE: 678 return (sbuf_printf(sb, "%d", element->mle_grade)); 679 680 default: | 661{ 662 663 switch (element->mle_type) { 664 case MAC_LOMAC_TYPE_HIGH: 665 return (sbuf_printf(sb, "high")); 666 667 case MAC_LOMAC_TYPE_LOW: 668 return (sbuf_printf(sb, "low")); 669 670 case MAC_LOMAC_TYPE_EQUAL: 671 return (sbuf_printf(sb, "equal")); 672 673 case MAC_LOMAC_TYPE_GRADE: 674 return (sbuf_printf(sb, "%d", element->mle_grade)); 675 676 default: |
681 panic("mac_lomac_element_to_string: invalid type (%d)", | 677 panic("lomac_element_to_string: invalid type (%d)", |
682 element->mle_type); 683 } 684} 685 686static int | 678 element->mle_type); 679 } 680} 681 682static int |
687mac_lomac_to_string(struct sbuf *sb, struct mac_lomac *mac_lomac) | 683lomac_to_string(struct sbuf *sb, struct mac_lomac *ml) |
688{ 689 | 684{ 685 |
690 if (mac_lomac->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 691 if (mac_lomac_element_to_string(sb, &mac_lomac->ml_single) 692 == -1) | 686 if (ml->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 687 if (lomac_element_to_string(sb, &ml->ml_single) == -1) |
693 return (EINVAL); 694 } 695 | 688 return (EINVAL); 689 } 690 |
696 if (mac_lomac->ml_flags & MAC_LOMAC_FLAG_AUX) { | 691 if (ml->ml_flags & MAC_LOMAC_FLAG_AUX) { |
697 if (sbuf_putc(sb, '[') == -1) 698 return (EINVAL); 699 | 692 if (sbuf_putc(sb, '[') == -1) 693 return (EINVAL); 694 |
700 if (mac_lomac_element_to_string(sb, &mac_lomac->ml_auxsingle) 701 == -1) | 695 if (lomac_element_to_string(sb, &ml->ml_auxsingle) == -1) |
702 return (EINVAL); 703 704 if (sbuf_putc(sb, ']') == -1) 705 return (EINVAL); 706 } 707 | 696 return (EINVAL); 697 698 if (sbuf_putc(sb, ']') == -1) 699 return (EINVAL); 700 } 701 |
708 if (mac_lomac->ml_flags & MAC_LOMAC_FLAG_RANGE) { | 702 if (ml->ml_flags & MAC_LOMAC_FLAG_RANGE) { |
709 if (sbuf_putc(sb, '(') == -1) 710 return (EINVAL); 711 | 703 if (sbuf_putc(sb, '(') == -1) 704 return (EINVAL); 705 |
712 if (mac_lomac_element_to_string(sb, &mac_lomac->ml_rangelow) 713 == -1) | 706 if (lomac_element_to_string(sb, &ml->ml_rangelow) == -1) |
714 return (EINVAL); 715 716 if (sbuf_putc(sb, '-') == -1) 717 return (EINVAL); 718 | 707 return (EINVAL); 708 709 if (sbuf_putc(sb, '-') == -1) 710 return (EINVAL); 711 |
719 if (mac_lomac_element_to_string(sb, &mac_lomac->ml_rangehigh) 720 == -1) | 712 if (lomac_element_to_string(sb, &ml->ml_rangehigh) == -1) |
721 return (EINVAL); 722 723 if (sbuf_putc(sb, ')') == -1) 724 return (EINVAL); 725 } 726 727 return (0); 728} 729 730static int | 713 return (EINVAL); 714 715 if (sbuf_putc(sb, ')') == -1) 716 return (EINVAL); 717 } 718 719 return (0); 720} 721 722static int |
731mac_lomac_externalize_label(struct label *label, char *element_name, | 723lomac_externalize_label(struct label *label, char *element_name, |
732 struct sbuf *sb, int *claimed) 733{ | 724 struct sbuf *sb, int *claimed) 725{ |
734 struct mac_lomac *mac_lomac; | 726 struct mac_lomac *ml; |
735 736 if (strcmp(MAC_LOMAC_LABEL_NAME, element_name) != 0) 737 return (0); 738 739 (*claimed)++; 740 | 727 728 if (strcmp(MAC_LOMAC_LABEL_NAME, element_name) != 0) 729 return (0); 730 731 (*claimed)++; 732 |
741 mac_lomac = SLOT(label); | 733 ml = SLOT(label); |
742 | 734 |
743 return (mac_lomac_to_string(sb, mac_lomac)); | 735 return (lomac_to_string(sb, ml)); |
744} 745 746static int | 736} 737 738static int |
747mac_lomac_parse_element(struct mac_lomac_element *element, char *string) | 739lomac_parse_element(struct mac_lomac_element *element, char *string) |
748{ 749 | 740{ 741 |
750 if (strcmp(string, "high") == 0 || 751 strcmp(string, "hi") == 0) { | 742 if (strcmp(string, "high") == 0 || strcmp(string, "hi") == 0) { |
752 element->mle_type = MAC_LOMAC_TYPE_HIGH; 753 element->mle_grade = MAC_LOMAC_TYPE_UNDEF; | 743 element->mle_type = MAC_LOMAC_TYPE_HIGH; 744 element->mle_grade = MAC_LOMAC_TYPE_UNDEF; |
754 } else if (strcmp(string, "low") == 0 || 755 strcmp(string, "lo") == 0) { | 745 } else if (strcmp(string, "low") == 0 || strcmp(string, "lo") == 0) { |
756 element->mle_type = MAC_LOMAC_TYPE_LOW; 757 element->mle_grade = MAC_LOMAC_TYPE_UNDEF; | 746 element->mle_type = MAC_LOMAC_TYPE_LOW; 747 element->mle_grade = MAC_LOMAC_TYPE_UNDEF; |
758 } else if (strcmp(string, "equal") == 0 || 759 strcmp(string, "eq") == 0) { | 748 } else if (strcmp(string, "equal") == 0 || strcmp(string, "eq") == 0) 749 { |
760 element->mle_type = MAC_LOMAC_TYPE_EQUAL; 761 element->mle_grade = MAC_LOMAC_TYPE_UNDEF; 762 } else { 763 char *p0, *p1; 764 int d; 765 766 p0 = string; 767 d = strtol(p0, &p1, 10); --- 6 unchanged lines hidden (view full) --- 774 if (p1 == p0 || *p1 != '\0') 775 return (EINVAL); 776 } 777 778 return (0); 779} 780 781/* | 750 element->mle_type = MAC_LOMAC_TYPE_EQUAL; 751 element->mle_grade = MAC_LOMAC_TYPE_UNDEF; 752 } else { 753 char *p0, *p1; 754 int d; 755 756 p0 = string; 757 d = strtol(p0, &p1, 10); --- 6 unchanged lines hidden (view full) --- 764 if (p1 == p0 || *p1 != '\0') 765 return (EINVAL); 766 } 767 768 return (0); 769} 770 771/* |
782 * Note: destructively consumes the string, make a local copy before 783 * calling if that's a problem. | 772 * Note: destructively consumes the string, make a local copy before calling 773 * if that's a problem. |
784 */ 785static int | 774 */ 775static int |
786mac_lomac_parse(struct mac_lomac *mac_lomac, char *string) | 776lomac_parse(struct mac_lomac *ml, char *string) |
787{ 788 char *range, *rangeend, *rangehigh, *rangelow, *single, *auxsingle, 789 *auxsingleend; 790 int error; 791 792 /* Do we have a range? */ 793 single = string; 794 range = index(string, '('); --- 22 unchanged lines hidden (view full) --- 817 if (*(rangeend + 1) != '\0') 818 return (EINVAL); 819 /* Nul terminate the ends of the ranges. */ 820 *(rangehigh - 1) = '\0'; 821 *rangeend = '\0'; 822 } 823 KASSERT((rangelow != NULL && rangehigh != NULL) || 824 (rangelow == NULL && rangehigh == NULL), | 777{ 778 char *range, *rangeend, *rangehigh, *rangelow, *single, *auxsingle, 779 *auxsingleend; 780 int error; 781 782 /* Do we have a range? */ 783 single = string; 784 range = index(string, '('); --- 22 unchanged lines hidden (view full) --- 807 if (*(rangeend + 1) != '\0') 808 return (EINVAL); 809 /* Nul terminate the ends of the ranges. */ 810 *(rangehigh - 1) = '\0'; 811 *rangeend = '\0'; 812 } 813 KASSERT((rangelow != NULL && rangehigh != NULL) || 814 (rangelow == NULL && rangehigh == NULL), |
825 ("mac_lomac_internalize_label: range mismatch")); | 815 ("lomac_internalize_label: range mismatch")); |
826 if (auxsingle != NULL) { 827 /* Nul terminate the end of the single string. */ 828 *auxsingle = '\0'; 829 auxsingle++; 830 auxsingleend = index(auxsingle, ']'); 831 if (auxsingleend == NULL) 832 return (EINVAL); 833 if (*(auxsingleend + 1) != '\0') 834 return (EINVAL); 835 /* Nul terminate the end of the auxsingle. */ 836 *auxsingleend = '\0'; 837 } 838 | 816 if (auxsingle != NULL) { 817 /* Nul terminate the end of the single string. */ 818 *auxsingle = '\0'; 819 auxsingle++; 820 auxsingleend = index(auxsingle, ']'); 821 if (auxsingleend == NULL) 822 return (EINVAL); 823 if (*(auxsingleend + 1) != '\0') 824 return (EINVAL); 825 /* Nul terminate the end of the auxsingle. */ 826 *auxsingleend = '\0'; 827 } 828 |
839 bzero(mac_lomac, sizeof(*mac_lomac)); | 829 bzero(ml, sizeof(*ml)); |
840 if (single != NULL) { | 830 if (single != NULL) { |
841 error = mac_lomac_parse_element(&mac_lomac->ml_single, single); | 831 error = lomac_parse_element(&ml->ml_single, single); |
842 if (error) 843 return (error); | 832 if (error) 833 return (error); |
844 mac_lomac->ml_flags |= MAC_LOMAC_FLAG_SINGLE; | 834 ml->ml_flags |= MAC_LOMAC_FLAG_SINGLE; |
845 } 846 847 if (auxsingle != NULL) { | 835 } 836 837 if (auxsingle != NULL) { |
848 error = mac_lomac_parse_element(&mac_lomac->ml_auxsingle, | 838 error = lomac_parse_element(&ml->ml_auxsingle, |
849 auxsingle); 850 if (error) 851 return (error); | 839 auxsingle); 840 if (error) 841 return (error); |
852 mac_lomac->ml_flags |= MAC_LOMAC_FLAG_AUX; | 842 ml->ml_flags |= MAC_LOMAC_FLAG_AUX; |
853 } 854 855 if (rangelow != NULL) { | 843 } 844 845 if (rangelow != NULL) { |
856 error = mac_lomac_parse_element(&mac_lomac->ml_rangelow, 857 rangelow); | 846 error = lomac_parse_element(&ml->ml_rangelow, rangelow); |
858 if (error) 859 return (error); | 847 if (error) 848 return (error); |
860 error = mac_lomac_parse_element(&mac_lomac->ml_rangehigh, 861 rangehigh); | 849 error = lomac_parse_element(&ml->ml_rangehigh, rangehigh); |
862 if (error) 863 return (error); | 850 if (error) 851 return (error); |
864 mac_lomac->ml_flags |= MAC_LOMAC_FLAG_RANGE; | 852 ml->ml_flags |= MAC_LOMAC_FLAG_RANGE; |
865 } 866 | 853 } 854 |
867 error = mac_lomac_valid(mac_lomac); | 855 error = lomac_valid(ml); |
868 if (error) 869 return (error); 870 871 return (0); 872} 873 874static int | 856 if (error) 857 return (error); 858 859 return (0); 860} 861 862static int |
875mac_lomac_internalize_label(struct label *label, char *element_name, | 863lomac_internalize_label(struct label *label, char *element_name, |
876 char *element_data, int *claimed) 877{ | 864 char *element_data, int *claimed) 865{ |
878 struct mac_lomac *mac_lomac, mac_lomac_temp; | 866 struct mac_lomac *ml, ml_temp; |
879 int error; 880 881 if (strcmp(MAC_LOMAC_LABEL_NAME, element_name) != 0) 882 return (0); 883 884 (*claimed)++; 885 | 867 int error; 868 869 if (strcmp(MAC_LOMAC_LABEL_NAME, element_name) != 0) 870 return (0); 871 872 (*claimed)++; 873 |
886 error = mac_lomac_parse(&mac_lomac_temp, element_data); | 874 error = lomac_parse(&ml_temp, element_data); |
887 if (error) 888 return (error); 889 | 875 if (error) 876 return (error); 877 |
890 mac_lomac = SLOT(label); 891 *mac_lomac = mac_lomac_temp; | 878 ml = SLOT(label); 879 *ml = ml_temp; |
892 893 return (0); 894} 895 896static void | 880 881 return (0); 882} 883 884static void |
897mac_lomac_copy_label(struct label *src, struct label *dest) | 885lomac_copy_label(struct label *src, struct label *dest) |
898{ 899 900 *SLOT(dest) = *SLOT(src); 901} 902 903/* | 886{ 887 888 *SLOT(dest) = *SLOT(src); 889} 890 891/* |
904 * Labeling event operations: file system objects, and things that look 905 * a lot like file system objects. | 892 * Labeling event operations: file system objects, and things that look a lot 893 * like file system objects. |
906 */ 907static void | 894 */ 895static void |
908mac_lomac_devfs_create_device(struct ucred *cred, struct mount *mp, | 896lomac_devfs_create_device(struct ucred *cred, struct mount *mp, |
909 struct cdev *dev, struct devfs_dirent *de, struct label *delabel) 910{ | 897 struct cdev *dev, struct devfs_dirent *de, struct label *delabel) 898{ |
911 struct mac_lomac *mac_lomac; | 899 struct mac_lomac *ml; |
912 int lomac_type; 913 | 900 int lomac_type; 901 |
914 mac_lomac = SLOT(delabel); | 902 ml = SLOT(delabel); |
915 if (strcmp(dev->si_name, "null") == 0 || 916 strcmp(dev->si_name, "zero") == 0 || 917 strcmp(dev->si_name, "random") == 0 || 918 strncmp(dev->si_name, "fd/", strlen("fd/")) == 0 || 919 strncmp(dev->si_name, "ttyv", strlen("ttyv")) == 0) 920 lomac_type = MAC_LOMAC_TYPE_EQUAL; 921 else if (ptys_equal && 922 (strncmp(dev->si_name, "ttyp", strlen("ttyp")) == 0 || 923 strncmp(dev->si_name, "ptyp", strlen("ptyp")) == 0)) 924 lomac_type = MAC_LOMAC_TYPE_EQUAL; 925 else 926 lomac_type = MAC_LOMAC_TYPE_HIGH; | 903 if (strcmp(dev->si_name, "null") == 0 || 904 strcmp(dev->si_name, "zero") == 0 || 905 strcmp(dev->si_name, "random") == 0 || 906 strncmp(dev->si_name, "fd/", strlen("fd/")) == 0 || 907 strncmp(dev->si_name, "ttyv", strlen("ttyv")) == 0) 908 lomac_type = MAC_LOMAC_TYPE_EQUAL; 909 else if (ptys_equal && 910 (strncmp(dev->si_name, "ttyp", strlen("ttyp")) == 0 || 911 strncmp(dev->si_name, "ptyp", strlen("ptyp")) == 0)) 912 lomac_type = MAC_LOMAC_TYPE_EQUAL; 913 else 914 lomac_type = MAC_LOMAC_TYPE_HIGH; |
927 mac_lomac_set_single(mac_lomac, lomac_type, 0); | 915 lomac_set_single(ml, lomac_type, 0); |
928} 929 930static void | 916} 917 918static void |
931mac_lomac_devfs_create_directory(struct mount *mp, char *dirname, 932 int dirnamelen, struct devfs_dirent *de, struct label *delabel) | 919lomac_devfs_create_directory(struct mount *mp, char *dirname, int dirnamelen, 920 struct devfs_dirent *de, struct label *delabel) |
933{ | 921{ |
934 struct mac_lomac *mac_lomac; | 922 struct mac_lomac *ml; |
935 | 923 |
936 mac_lomac = SLOT(delabel); 937 mac_lomac_set_single(mac_lomac, MAC_LOMAC_TYPE_HIGH, 0); | 924 ml = SLOT(delabel); 925 lomac_set_single(ml, MAC_LOMAC_TYPE_HIGH, 0); |
938} 939 940static void | 926} 927 928static void |
941mac_lomac_devfs_create_symlink(struct ucred *cred, struct mount *mp, | 929lomac_devfs_create_symlink(struct ucred *cred, struct mount *mp, |
942 struct devfs_dirent *dd, struct label *ddlabel, struct devfs_dirent *de, 943 struct label *delabel) 944{ 945 struct mac_lomac *source, *dest; 946 947 source = SLOT(cred->cr_label); 948 dest = SLOT(delabel); 949 | 930 struct devfs_dirent *dd, struct label *ddlabel, struct devfs_dirent *de, 931 struct label *delabel) 932{ 933 struct mac_lomac *source, *dest; 934 935 source = SLOT(cred->cr_label); 936 dest = SLOT(delabel); 937 |
950 mac_lomac_copy_single(source, dest); | 938 lomac_copy_single(source, dest); |
951} 952 953static void | 939} 940 941static void |
954mac_lomac_mount_create(struct ucred *cred, struct mount *mp, | 942lomac_mount_create(struct ucred *cred, struct mount *mp, |
955 struct label *mplabel) 956{ 957 struct mac_lomac *source, *dest; 958 959 source = SLOT(cred->cr_label); 960 dest = SLOT(mplabel); | 943 struct label *mplabel) 944{ 945 struct mac_lomac *source, *dest; 946 947 source = SLOT(cred->cr_label); 948 dest = SLOT(mplabel); |
961 mac_lomac_copy_single(source, dest); | 949 lomac_copy_single(source, dest); |
962} 963 964static void | 950} 951 952static void |
965mac_lomac_vnode_relabel(struct ucred *cred, struct vnode *vp, | 953lomac_vnode_relabel(struct ucred *cred, struct vnode *vp, |
966 struct label *vplabel, struct label *newlabel) 967{ 968 struct mac_lomac *source, *dest; 969 970 source = SLOT(newlabel); 971 dest = SLOT(vplabel); 972 973 try_relabel(source, dest); 974} 975 976static void | 954 struct label *vplabel, struct label *newlabel) 955{ 956 struct mac_lomac *source, *dest; 957 958 source = SLOT(newlabel); 959 dest = SLOT(vplabel); 960 961 try_relabel(source, dest); 962} 963 964static void |
977mac_lomac_devfs_update(struct mount *mp, struct devfs_dirent *de, | 965lomac_devfs_update(struct mount *mp, struct devfs_dirent *de, |
978 struct label *delabel, struct vnode *vp, struct label *vplabel) 979{ 980 struct mac_lomac *source, *dest; 981 982 source = SLOT(vplabel); 983 dest = SLOT(delabel); 984 | 966 struct label *delabel, struct vnode *vp, struct label *vplabel) 967{ 968 struct mac_lomac *source, *dest; 969 970 source = SLOT(vplabel); 971 dest = SLOT(delabel); 972 |
985 mac_lomac_copy(source, dest); | 973 lomac_copy(source, dest); |
986} 987 988static void | 974} 975 976static void |
989mac_lomac_devfs_vnode_associate(struct mount *mp, struct label *mplabel, | 977lomac_devfs_vnode_associate(struct mount *mp, struct label *mplabel, |
990 struct devfs_dirent *de, struct label *delabel, struct vnode *vp, 991 struct label *vplabel) 992{ 993 struct mac_lomac *source, *dest; 994 995 source = SLOT(delabel); 996 dest = SLOT(vplabel); 997 | 978 struct devfs_dirent *de, struct label *delabel, struct vnode *vp, 979 struct label *vplabel) 980{ 981 struct mac_lomac *source, *dest; 982 983 source = SLOT(delabel); 984 dest = SLOT(vplabel); 985 |
998 mac_lomac_copy_single(source, dest); | 986 lomac_copy_single(source, dest); |
999} 1000 1001static int | 987} 988 989static int |
1002mac_lomac_vnode_associate_extattr(struct mount *mp, struct label *mplabel, | 990lomac_vnode_associate_extattr(struct mount *mp, struct label *mplabel, |
1003 struct vnode *vp, struct label *vplabel) 1004{ | 991 struct vnode *vp, struct label *vplabel) 992{ |
1005 struct mac_lomac temp, *source, *dest; | 993 struct mac_lomac ml_temp, *source, *dest; |
1006 int buflen, error; 1007 1008 source = SLOT(mplabel); 1009 dest = SLOT(vplabel); 1010 | 994 int buflen, error; 995 996 source = SLOT(mplabel); 997 dest = SLOT(vplabel); 998 |
1011 buflen = sizeof(temp); 1012 bzero(&temp, buflen); | 999 buflen = sizeof(ml_temp); 1000 bzero(&ml_temp, buflen); |
1013 1014 error = vn_extattr_get(vp, IO_NODELOCKED, MAC_LOMAC_EXTATTR_NAMESPACE, | 1001 1002 error = vn_extattr_get(vp, IO_NODELOCKED, MAC_LOMAC_EXTATTR_NAMESPACE, |
1015 MAC_LOMAC_EXTATTR_NAME, &buflen, (char *)&temp, curthread); | 1003 MAC_LOMAC_EXTATTR_NAME, &buflen, (char *)&ml_temp, curthread); |
1016 if (error == ENOATTR || error == EOPNOTSUPP) { 1017 /* Fall back to the mntlabel. */ | 1004 if (error == ENOATTR || error == EOPNOTSUPP) { 1005 /* Fall back to the mntlabel. */ |
1018 mac_lomac_copy_single(source, dest); | 1006 lomac_copy_single(source, dest); |
1019 return (0); 1020 } else if (error) 1021 return (error); 1022 | 1007 return (0); 1008 } else if (error) 1009 return (error); 1010 |
1023 if (buflen != sizeof(temp)) { 1024 if (buflen != sizeof(temp) - sizeof(temp.ml_auxsingle)) { 1025 printf("mac_lomac_vnode_associate_extattr: bad size %d\n", | 1011 if (buflen != sizeof(ml_temp)) { 1012 if (buflen != sizeof(ml_temp) - sizeof(ml_temp.ml_auxsingle)) { 1013 printf("lomac_vnode_associate_extattr: bad size %d\n", |
1026 buflen); 1027 return (EPERM); 1028 } | 1014 buflen); 1015 return (EPERM); 1016 } |
1029 bzero(&temp.ml_auxsingle, sizeof(temp.ml_auxsingle)); 1030 buflen = sizeof(temp); | 1017 bzero(&ml_temp.ml_auxsingle, sizeof(ml_temp.ml_auxsingle)); 1018 buflen = sizeof(ml_temp); |
1031 (void)vn_extattr_set(vp, IO_NODELOCKED, 1032 MAC_LOMAC_EXTATTR_NAMESPACE, MAC_LOMAC_EXTATTR_NAME, | 1019 (void)vn_extattr_set(vp, IO_NODELOCKED, 1020 MAC_LOMAC_EXTATTR_NAMESPACE, MAC_LOMAC_EXTATTR_NAME, |
1033 buflen, (char *)&temp, curthread); | 1021 buflen, (char *)&ml_temp, curthread); |
1034 } | 1022 } |
1035 if (mac_lomac_valid(&temp) != 0) { 1036 printf("mac_lomac_vnode_associate_extattr: invalid\n"); | 1023 if (lomac_valid(&ml_temp) != 0) { 1024 printf("lomac_vnode_associate_extattr: invalid\n"); |
1037 return (EPERM); 1038 } | 1025 return (EPERM); 1026 } |
1039 if ((temp.ml_flags & MAC_LOMAC_FLAGS_BOTH) != MAC_LOMAC_FLAG_SINGLE) { 1040 printf("mac_lomac_vnode_associate_extattr: not single\n"); | 1027 if ((ml_temp.ml_flags & MAC_LOMAC_FLAGS_BOTH) != 1028 MAC_LOMAC_FLAG_SINGLE) { 1029 printf("lomac_vnode_associate_extattr: not single\n"); |
1041 return (EPERM); 1042 } 1043 | 1030 return (EPERM); 1031 } 1032 |
1044 mac_lomac_copy_single(&temp, dest); | 1033 lomac_copy_single(&ml_temp, dest); |
1045 return (0); 1046} 1047 1048static void | 1034 return (0); 1035} 1036 1037static void |
1049mac_lomac_vnode_associate_singlelabel(struct mount *mp, 1050 struct label *mplabel, struct vnode *vp, struct label *vplabel) | 1038lomac_vnode_associate_singlelabel(struct mount *mp, struct label *mplabel, 1039 struct vnode *vp, struct label *vplabel) |
1051{ 1052 struct mac_lomac *source, *dest; 1053 1054 source = SLOT(mplabel); 1055 dest = SLOT(vplabel); 1056 | 1040{ 1041 struct mac_lomac *source, *dest; 1042 1043 source = SLOT(mplabel); 1044 dest = SLOT(vplabel); 1045 |
1057 mac_lomac_copy_single(source, dest); | 1046 lomac_copy_single(source, dest); |
1058} 1059 1060static int | 1047} 1048 1049static int |
1061mac_lomac_vnode_create_extattr(struct ucred *cred, struct mount *mp, | 1050lomac_vnode_create_extattr(struct ucred *cred, struct mount *mp, |
1062 struct label *mplabel, struct vnode *dvp, struct label *dvplabel, 1063 struct vnode *vp, struct label *vplabel, struct componentname *cnp) 1064{ 1065 struct mac_lomac *source, *dest, *dir, temp; 1066 size_t buflen; 1067 int error; 1068 1069 buflen = sizeof(temp); 1070 bzero(&temp, buflen); 1071 1072 source = SLOT(cred->cr_label); 1073 dest = SLOT(vplabel); 1074 dir = SLOT(dvplabel); 1075 if (dir->ml_flags & MAC_LOMAC_FLAG_AUX) { | 1051 struct label *mplabel, struct vnode *dvp, struct label *dvplabel, 1052 struct vnode *vp, struct label *vplabel, struct componentname *cnp) 1053{ 1054 struct mac_lomac *source, *dest, *dir, temp; 1055 size_t buflen; 1056 int error; 1057 1058 buflen = sizeof(temp); 1059 bzero(&temp, buflen); 1060 1061 source = SLOT(cred->cr_label); 1062 dest = SLOT(vplabel); 1063 dir = SLOT(dvplabel); 1064 if (dir->ml_flags & MAC_LOMAC_FLAG_AUX) { |
1076 mac_lomac_copy_auxsingle(dir, &temp); 1077 mac_lomac_set_single(&temp, dir->ml_auxsingle.mle_type, | 1065 lomac_copy_auxsingle(dir, &temp); 1066 lomac_set_single(&temp, dir->ml_auxsingle.mle_type, |
1078 dir->ml_auxsingle.mle_grade); 1079 } else { | 1067 dir->ml_auxsingle.mle_grade); 1068 } else { |
1080 mac_lomac_copy_single(source, &temp); | 1069 lomac_copy_single(source, &temp); |
1081 } 1082 1083 error = vn_extattr_set(vp, IO_NODELOCKED, MAC_LOMAC_EXTATTR_NAMESPACE, 1084 MAC_LOMAC_EXTATTR_NAME, buflen, (char *)&temp, curthread); 1085 if (error == 0) | 1070 } 1071 1072 error = vn_extattr_set(vp, IO_NODELOCKED, MAC_LOMAC_EXTATTR_NAMESPACE, 1073 MAC_LOMAC_EXTATTR_NAME, buflen, (char *)&temp, curthread); 1074 if (error == 0) |
1086 mac_lomac_copy(&temp, dest); | 1075 lomac_copy(&temp, dest); |
1087 return (error); 1088} 1089 1090static int | 1076 return (error); 1077} 1078 1079static int |
1091mac_lomac_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp, | 1080lomac_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp, |
1092 struct label *vplabel, struct label *intlabel) 1093{ 1094 struct mac_lomac *source, temp; 1095 size_t buflen; 1096 int error; 1097 1098 buflen = sizeof(temp); 1099 bzero(&temp, buflen); 1100 1101 source = SLOT(intlabel); 1102 if ((source->ml_flags & MAC_LOMAC_FLAG_SINGLE) == 0) 1103 return (0); 1104 | 1081 struct label *vplabel, struct label *intlabel) 1082{ 1083 struct mac_lomac *source, temp; 1084 size_t buflen; 1085 int error; 1086 1087 buflen = sizeof(temp); 1088 bzero(&temp, buflen); 1089 1090 source = SLOT(intlabel); 1091 if ((source->ml_flags & MAC_LOMAC_FLAG_SINGLE) == 0) 1092 return (0); 1093 |
1105 mac_lomac_copy_single(source, &temp); | 1094 lomac_copy_single(source, &temp); |
1106 error = vn_extattr_set(vp, IO_NODELOCKED, MAC_LOMAC_EXTATTR_NAMESPACE, 1107 MAC_LOMAC_EXTATTR_NAME, buflen, (char *)&temp, curthread); 1108 return (error); 1109} 1110 1111/* 1112 * Labeling event operations: IPC object. 1113 */ 1114static void | 1095 error = vn_extattr_set(vp, IO_NODELOCKED, MAC_LOMAC_EXTATTR_NAMESPACE, 1096 MAC_LOMAC_EXTATTR_NAME, buflen, (char *)&temp, curthread); 1097 return (error); 1098} 1099 1100/* 1101 * Labeling event operations: IPC object. 1102 */ 1103static void |
1115mac_lomac_inpcb_create(struct socket *so, struct label *solabel, | 1104lomac_inpcb_create(struct socket *so, struct label *solabel, |
1116 struct inpcb *inp, struct label *inplabel) 1117{ 1118 struct mac_lomac *source, *dest; 1119 1120 source = SLOT(solabel); 1121 dest = SLOT(inplabel); 1122 | 1105 struct inpcb *inp, struct label *inplabel) 1106{ 1107 struct mac_lomac *source, *dest; 1108 1109 source = SLOT(solabel); 1110 dest = SLOT(inplabel); 1111 |
1123 mac_lomac_copy_single(source, dest); | 1112 lomac_copy_single(source, dest); |
1124} 1125 1126static void | 1113} 1114 1115static void |
1127mac_lomac_socket_create_mbuf(struct socket *so, struct label *solabel, | 1116lomac_socket_create_mbuf(struct socket *so, struct label *solabel, |
1128 struct mbuf *m, struct label *mlabel) 1129{ 1130 struct mac_lomac *source, *dest; 1131 1132 source = SLOT(solabel); 1133 dest = SLOT(mlabel); 1134 | 1117 struct mbuf *m, struct label *mlabel) 1118{ 1119 struct mac_lomac *source, *dest; 1120 1121 source = SLOT(solabel); 1122 dest = SLOT(mlabel); 1123 |
1135 mac_lomac_copy_single(source, dest); | 1124 lomac_copy_single(source, dest); |
1136} 1137 1138static void | 1125} 1126 1127static void |
1139mac_lomac_socket_create(struct ucred *cred, struct socket *so, | 1128lomac_socket_create(struct ucred *cred, struct socket *so, |
1140 struct label *solabel) 1141{ 1142 struct mac_lomac *source, *dest; 1143 1144 source = SLOT(cred->cr_label); 1145 dest = SLOT(solabel); 1146 | 1129 struct label *solabel) 1130{ 1131 struct mac_lomac *source, *dest; 1132 1133 source = SLOT(cred->cr_label); 1134 dest = SLOT(solabel); 1135 |
1147 mac_lomac_copy_single(source, dest); | 1136 lomac_copy_single(source, dest); |
1148} 1149 1150static void | 1137} 1138 1139static void |
1151mac_lomac_pipe_create(struct ucred *cred, struct pipepair *pp, | 1140lomac_pipe_create(struct ucred *cred, struct pipepair *pp, |
1152 struct label *pplabel) 1153{ 1154 struct mac_lomac *source, *dest; 1155 1156 source = SLOT(cred->cr_label); 1157 dest = SLOT(pplabel); 1158 | 1141 struct label *pplabel) 1142{ 1143 struct mac_lomac *source, *dest; 1144 1145 source = SLOT(cred->cr_label); 1146 dest = SLOT(pplabel); 1147 |
1159 mac_lomac_copy_single(source, dest); | 1148 lomac_copy_single(source, dest); |
1160} 1161 1162static void | 1149} 1150 1151static void |
1163mac_lomac_socket_newconn(struct socket *oldso, struct label *oldsolabel, | 1152lomac_socket_newconn(struct socket *oldso, struct label *oldsolabel, |
1164 struct socket *newso, struct label *newsolabel) 1165{ 1166 struct mac_lomac *source, *dest; 1167 1168 source = SLOT(oldsolabel); 1169 dest = SLOT(newsolabel); 1170 | 1153 struct socket *newso, struct label *newsolabel) 1154{ 1155 struct mac_lomac *source, *dest; 1156 1157 source = SLOT(oldsolabel); 1158 dest = SLOT(newsolabel); 1159 |
1171 mac_lomac_copy_single(source, dest); | 1160 lomac_copy_single(source, dest); |
1172} 1173 1174static void | 1161} 1162 1163static void |
1175mac_lomac_socket_relabel(struct ucred *cred, struct socket *so, | 1164lomac_socket_relabel(struct ucred *cred, struct socket *so, |
1176 struct label *solabel, struct label *newlabel) 1177{ 1178 struct mac_lomac *source, *dest; 1179 1180 source = SLOT(newlabel); 1181 dest = SLOT(solabel); 1182 1183 try_relabel(source, dest); 1184} 1185 1186static void | 1165 struct label *solabel, struct label *newlabel) 1166{ 1167 struct mac_lomac *source, *dest; 1168 1169 source = SLOT(newlabel); 1170 dest = SLOT(solabel); 1171 1172 try_relabel(source, dest); 1173} 1174 1175static void |
1187mac_lomac_pipe_relabel(struct ucred *cred, struct pipepair *pp, | 1176lomac_pipe_relabel(struct ucred *cred, struct pipepair *pp, |
1188 struct label *pplabel, struct label *newlabel) 1189{ 1190 struct mac_lomac *source, *dest; 1191 1192 source = SLOT(newlabel); 1193 dest = SLOT(pplabel); 1194 1195 try_relabel(source, dest); 1196} 1197 1198static void | 1177 struct label *pplabel, struct label *newlabel) 1178{ 1179 struct mac_lomac *source, *dest; 1180 1181 source = SLOT(newlabel); 1182 dest = SLOT(pplabel); 1183 1184 try_relabel(source, dest); 1185} 1186 1187static void |
1199mac_lomac_socketpeer_set_from_mbuf(struct mbuf *m, struct label *mlabel, | 1188lomac_socketpeer_set_from_mbuf(struct mbuf *m, struct label *mlabel, |
1200 struct socket *so, struct label *sopeerlabel) 1201{ 1202 struct mac_lomac *source, *dest; 1203 1204 source = SLOT(mlabel); 1205 dest = SLOT(sopeerlabel); 1206 | 1189 struct socket *so, struct label *sopeerlabel) 1190{ 1191 struct mac_lomac *source, *dest; 1192 1193 source = SLOT(mlabel); 1194 dest = SLOT(sopeerlabel); 1195 |
1207 mac_lomac_copy_single(source, dest); | 1196 lomac_copy_single(source, dest); |
1208} 1209 1210/* 1211 * Labeling event operations: network objects. 1212 */ 1213static void | 1197} 1198 1199/* 1200 * Labeling event operations: network objects. 1201 */ 1202static void |
1214mac_lomac_socketpeer_set_from_socket(struct socket *oldso, | 1203lomac_socketpeer_set_from_socket(struct socket *oldso, |
1215 struct label *oldsolabel, struct socket *newso, 1216 struct label *newsopeerlabel) 1217{ 1218 struct mac_lomac *source, *dest; 1219 1220 source = SLOT(oldsolabel); 1221 dest = SLOT(newsopeerlabel); 1222 | 1204 struct label *oldsolabel, struct socket *newso, 1205 struct label *newsopeerlabel) 1206{ 1207 struct mac_lomac *source, *dest; 1208 1209 source = SLOT(oldsolabel); 1210 dest = SLOT(newsopeerlabel); 1211 |
1223 mac_lomac_copy_single(source, dest); | 1212 lomac_copy_single(source, dest); |
1224} 1225 1226static void | 1213} 1214 1215static void |
1227mac_lomac_bpfdesc_create(struct ucred *cred, struct bpf_d *d, | 1216lomac_bpfdesc_create(struct ucred *cred, struct bpf_d *d, |
1228 struct label *dlabel) 1229{ 1230 struct mac_lomac *source, *dest; 1231 1232 source = SLOT(cred->cr_label); 1233 dest = SLOT(dlabel); 1234 | 1217 struct label *dlabel) 1218{ 1219 struct mac_lomac *source, *dest; 1220 1221 source = SLOT(cred->cr_label); 1222 dest = SLOT(dlabel); 1223 |
1235 mac_lomac_copy_single(source, dest); | 1224 lomac_copy_single(source, dest); |
1236} 1237 1238static void | 1225} 1226 1227static void |
1239mac_lomac_ifnet_create(struct ifnet *ifp, struct label *ifplabel) | 1228lomac_ifnet_create(struct ifnet *ifp, struct label *ifplabel) |
1240{ 1241 char tifname[IFNAMSIZ], *p, *q; 1242 char tiflist[sizeof(trusted_interfaces)]; 1243 struct mac_lomac *dest; 1244 int len, grade; 1245 1246 dest = SLOT(ifplabel); 1247 --- 36 unchanged lines hidden (view full) --- 1284 q, IFNAMSIZ); 1285 } 1286 if (*p == '\0') 1287 break; 1288 q = p + 1; 1289 } 1290 } 1291set: | 1229{ 1230 char tifname[IFNAMSIZ], *p, *q; 1231 char tiflist[sizeof(trusted_interfaces)]; 1232 struct mac_lomac *dest; 1233 int len, grade; 1234 1235 dest = SLOT(ifplabel); 1236 --- 36 unchanged lines hidden (view full) --- 1273 q, IFNAMSIZ); 1274 } 1275 if (*p == '\0') 1276 break; 1277 q = p + 1; 1278 } 1279 } 1280set: |
1292 mac_lomac_set_single(dest, grade, 0); 1293 mac_lomac_set_range(dest, grade, 0, grade, 0); | 1281 lomac_set_single(dest, grade, 0); 1282 lomac_set_range(dest, grade, 0, grade, 0); |
1294} 1295 1296static void | 1283} 1284 1285static void |
1297mac_lomac_ipq_create(struct mbuf *m, struct label *mlabel, struct ipq *ipq, | 1286lomac_ipq_create(struct mbuf *m, struct label *mlabel, struct ipq *ipq, |
1298 struct label *ipqlabel) 1299{ 1300 struct mac_lomac *source, *dest; 1301 1302 source = SLOT(mlabel); 1303 dest = SLOT(ipqlabel); 1304 | 1287 struct label *ipqlabel) 1288{ 1289 struct mac_lomac *source, *dest; 1290 1291 source = SLOT(mlabel); 1292 dest = SLOT(ipqlabel); 1293 |
1305 mac_lomac_copy_single(source, dest); | 1294 lomac_copy_single(source, dest); |
1306} 1307 1308static void | 1295} 1296 1297static void |
1309mac_lomac_ipq_reassemble(struct ipq *ipq, struct label *ipqlabel, | 1298lomac_ipq_reassemble(struct ipq *ipq, struct label *ipqlabel, |
1310 struct mbuf *m, struct label *mlabel) 1311{ 1312 struct mac_lomac *source, *dest; 1313 1314 source = SLOT(ipqlabel); 1315 dest = SLOT(mlabel); 1316 1317 /* Just use the head, since we require them all to match. */ | 1299 struct mbuf *m, struct label *mlabel) 1300{ 1301 struct mac_lomac *source, *dest; 1302 1303 source = SLOT(ipqlabel); 1304 dest = SLOT(mlabel); 1305 1306 /* Just use the head, since we require them all to match. */ |
1318 mac_lomac_copy_single(source, dest); | 1307 lomac_copy_single(source, dest); |
1319} 1320 1321static void | 1308} 1309 1310static void |
1322mac_lomac_netinet_fragment(struct mbuf *m, struct label *mlabel, | 1311lomac_netinet_fragment(struct mbuf *m, struct label *mlabel, |
1323 struct mbuf *frag, struct label *fraglabel) 1324{ 1325 struct mac_lomac *source, *dest; 1326 1327 source = SLOT(mlabel); 1328 dest = SLOT(fraglabel); 1329 | 1312 struct mbuf *frag, struct label *fraglabel) 1313{ 1314 struct mac_lomac *source, *dest; 1315 1316 source = SLOT(mlabel); 1317 dest = SLOT(fraglabel); 1318 |
1330 mac_lomac_copy_single(source, dest); | 1319 lomac_copy_single(source, dest); |
1331} 1332 1333static void | 1320} 1321 1322static void |
1334mac_lomac_inpcb_create_mbuf(struct inpcb *inp, struct label *inplabel, | 1323lomac_inpcb_create_mbuf(struct inpcb *inp, struct label *inplabel, |
1335 struct mbuf *m, struct label *mlabel) 1336{ 1337 struct mac_lomac *source, *dest; 1338 1339 source = SLOT(inplabel); 1340 dest = SLOT(mlabel); 1341 | 1324 struct mbuf *m, struct label *mlabel) 1325{ 1326 struct mac_lomac *source, *dest; 1327 1328 source = SLOT(inplabel); 1329 dest = SLOT(mlabel); 1330 |
1342 mac_lomac_copy_single(source, dest); | 1331 lomac_copy_single(source, dest); |
1343} 1344 1345static void | 1332} 1333 1334static void |
1346mac_lomac_create_mbuf_linklayer(struct ifnet *ifp, struct label *ifplabel, | 1335lomac_create_mbuf_linklayer(struct ifnet *ifp, struct label *ifplabel, |
1347 struct mbuf *m, struct label *mlabel) 1348{ 1349 struct mac_lomac *dest; 1350 1351 dest = SLOT(mlabel); 1352 | 1336 struct mbuf *m, struct label *mlabel) 1337{ 1338 struct mac_lomac *dest; 1339 1340 dest = SLOT(mlabel); 1341 |
1353 mac_lomac_set_single(dest, MAC_LOMAC_TYPE_EQUAL, 0); | 1342 lomac_set_single(dest, MAC_LOMAC_TYPE_EQUAL, 0); |
1354} 1355 1356static void | 1343} 1344 1345static void |
1357mac_lomac_bpfdesc_create_mbuf(struct bpf_d *d, struct label *dlabel, | 1346lomac_bpfdesc_create_mbuf(struct bpf_d *d, struct label *dlabel, |
1358 struct mbuf *m, struct label *mlabel) 1359{ 1360 struct mac_lomac *source, *dest; 1361 1362 source = SLOT(dlabel); 1363 dest = SLOT(mlabel); 1364 | 1347 struct mbuf *m, struct label *mlabel) 1348{ 1349 struct mac_lomac *source, *dest; 1350 1351 source = SLOT(dlabel); 1352 dest = SLOT(mlabel); 1353 |
1365 mac_lomac_copy_single(source, dest); | 1354 lomac_copy_single(source, dest); |
1366} 1367 1368static void | 1355} 1356 1357static void |
1369mac_lomac_ifnet_create_mbuf(struct ifnet *ifp, struct label *ifplabel, | 1358lomac_ifnet_create_mbuf(struct ifnet *ifp, struct label *ifplabel, |
1370 struct mbuf *m, struct label *mlabel) 1371{ 1372 struct mac_lomac *source, *dest; 1373 1374 source = SLOT(ifplabel); 1375 dest = SLOT(mlabel); 1376 | 1359 struct mbuf *m, struct label *mlabel) 1360{ 1361 struct mac_lomac *source, *dest; 1362 1363 source = SLOT(ifplabel); 1364 dest = SLOT(mlabel); 1365 |
1377 mac_lomac_copy_single(source, dest); | 1366 lomac_copy_single(source, dest); |
1378} 1379 1380static void | 1367} 1368 1369static void |
1381mac_lomac_mbuf_create_multicast_encap(struct mbuf *m, struct label *mlabel, | 1370lomac_mbuf_create_multicast_encap(struct mbuf *m, struct label *mlabel, |
1382 struct ifnet *ifp, struct label *ifplabel, struct mbuf *mnew, 1383 struct label *mnewlabel) 1384{ 1385 struct mac_lomac *source, *dest; 1386 1387 source = SLOT(mlabel); 1388 dest = SLOT(mnewlabel); 1389 | 1371 struct ifnet *ifp, struct label *ifplabel, struct mbuf *mnew, 1372 struct label *mnewlabel) 1373{ 1374 struct mac_lomac *source, *dest; 1375 1376 source = SLOT(mlabel); 1377 dest = SLOT(mnewlabel); 1378 |
1390 mac_lomac_copy_single(source, dest); | 1379 lomac_copy_single(source, dest); |
1391} 1392 1393static void | 1380} 1381 1382static void |
1394mac_lomac_mbuf_create_netlayer(struct mbuf *m, struct label *mlabel, | 1383lomac_mbuf_create_netlayer(struct mbuf *m, struct label *mlabel, |
1395 struct mbuf *mnew, struct label *mnewlabel) 1396{ 1397 struct mac_lomac *source, *dest; 1398 1399 source = SLOT(mlabel); 1400 dest = SLOT(mnewlabel); 1401 | 1384 struct mbuf *mnew, struct label *mnewlabel) 1385{ 1386 struct mac_lomac *source, *dest; 1387 1388 source = SLOT(mlabel); 1389 dest = SLOT(mnewlabel); 1390 |
1402 mac_lomac_copy_single(source, dest); | 1391 lomac_copy_single(source, dest); |
1403} 1404 1405static int | 1392} 1393 1394static int |
1406mac_lomac_ipq_match(struct mbuf *m, struct label *mlabel, struct ipq *ipq, | 1395lomac_ipq_match(struct mbuf *m, struct label *mlabel, struct ipq *ipq, |
1407 struct label *ipqlabel) 1408{ 1409 struct mac_lomac *a, *b; 1410 1411 a = SLOT(ipqlabel); 1412 b = SLOT(mlabel); 1413 | 1396 struct label *ipqlabel) 1397{ 1398 struct mac_lomac *a, *b; 1399 1400 a = SLOT(ipqlabel); 1401 b = SLOT(mlabel); 1402 |
1414 return (mac_lomac_equal_single(a, b)); | 1403 return (lomac_equal_single(a, b)); |
1415} 1416 1417static void | 1404} 1405 1406static void |
1418mac_lomac_ifnet_relabel(struct ucred *cred, struct ifnet *ifp, | 1407lomac_ifnet_relabel(struct ucred *cred, struct ifnet *ifp, |
1419 struct label *ifplabel, struct label *newlabel) 1420{ 1421 struct mac_lomac *source, *dest; 1422 1423 source = SLOT(newlabel); 1424 dest = SLOT(ifplabel); 1425 1426 try_relabel(source, dest); 1427} 1428 1429static void | 1408 struct label *ifplabel, struct label *newlabel) 1409{ 1410 struct mac_lomac *source, *dest; 1411 1412 source = SLOT(newlabel); 1413 dest = SLOT(ifplabel); 1414 1415 try_relabel(source, dest); 1416} 1417 1418static void |
1430mac_lomac_ipq_update(struct mbuf *m, struct label *mlabel, struct ipq *ipq, | 1419lomac_ipq_update(struct mbuf *m, struct label *mlabel, struct ipq *ipq, |
1431 struct label *ipqlabel) 1432{ 1433 1434 /* NOOP: we only accept matching labels, so no need to update */ 1435} 1436 1437static void | 1420 struct label *ipqlabel) 1421{ 1422 1423 /* NOOP: we only accept matching labels, so no need to update */ 1424} 1425 1426static void |
1438mac_lomac_inpcb_sosetlabel(struct socket *so, struct label *solabel, | 1427lomac_inpcb_sosetlabel(struct socket *so, struct label *solabel, |
1439 struct inpcb *inp, struct label *inplabel) 1440{ 1441 struct mac_lomac *source, *dest; 1442 1443 source = SLOT(solabel); 1444 dest = SLOT(inplabel); 1445 | 1428 struct inpcb *inp, struct label *inplabel) 1429{ 1430 struct mac_lomac *source, *dest; 1431 1432 source = SLOT(solabel); 1433 dest = SLOT(inplabel); 1434 |
1446 mac_lomac_copy_single(source, dest); | 1435 lomac_copy_single(source, dest); |
1447} 1448 1449static void | 1436} 1437 1438static void |
1450mac_lomac_init_syncache_from_inpcb(struct label *label, struct inpcb *inp) | 1439lomac_init_syncache_from_inpcb(struct label *label, struct inpcb *inp) |
1451{ 1452 struct mac_lomac *source, *dest; 1453 1454 source = SLOT(inp->inp_label); 1455 dest = SLOT(label); | 1440{ 1441 struct mac_lomac *source, *dest; 1442 1443 source = SLOT(inp->inp_label); 1444 dest = SLOT(label); |
1456 mac_lomac_copy(source, dest); | 1445 lomac_copy(source, dest); |
1457} 1458 1459static void | 1446} 1447 1448static void |
1460mac_lomac_create_mbuf_from_syncache(struct label *sc_label, struct mbuf *m, | 1449lomac_create_mbuf_from_syncache(struct label *sc_label, struct mbuf *m, |
1461 struct label *mlabel) 1462{ 1463 struct mac_lomac *source, *dest; 1464 1465 source = SLOT(sc_label); 1466 dest = SLOT(mlabel); | 1450 struct label *mlabel) 1451{ 1452 struct mac_lomac *source, *dest; 1453 1454 source = SLOT(sc_label); 1455 dest = SLOT(mlabel); |
1467 mac_lomac_copy(source, dest); | 1456 lomac_copy(source, dest); |
1468} 1469 1470static void | 1457} 1458 1459static void |
1471mac_lomac_mbuf_create_from_firewall(struct mbuf *m, struct label *mlabel) | 1460lomac_mbuf_create_from_firewall(struct mbuf *m, struct label *mlabel) |
1472{ 1473 struct mac_lomac *dest; 1474 1475 dest = SLOT(mlabel); 1476 1477 /* XXX: where is the label for the firewall really comming from? */ | 1461{ 1462 struct mac_lomac *dest; 1463 1464 dest = SLOT(mlabel); 1465 1466 /* XXX: where is the label for the firewall really comming from? */ |
1478 mac_lomac_set_single(dest, MAC_LOMAC_TYPE_EQUAL, 0); | 1467 lomac_set_single(dest, MAC_LOMAC_TYPE_EQUAL, 0); |
1479} 1480 1481/* 1482 * Labeling event operations: processes. 1483 */ 1484static void | 1468} 1469 1470/* 1471 * Labeling event operations: processes. 1472 */ 1473static void |
1485mac_lomac_vnode_execve_transition(struct ucred *old, struct ucred *new, | 1474lomac_vnode_execve_transition(struct ucred *old, struct ucred *new, |
1486 struct vnode *vp, struct label *vplabel, struct label *interpvplabel, 1487 struct image_params *imgp, struct label *execlabel) 1488{ 1489 struct mac_lomac *source, *dest, *obj, *robj; 1490 1491 source = SLOT(old->cr_label); 1492 dest = SLOT(new->cr_label); 1493 obj = SLOT(vplabel); 1494 robj = interpvplabel != NULL ? SLOT(interpvplabel) : obj; 1495 | 1475 struct vnode *vp, struct label *vplabel, struct label *interpvplabel, 1476 struct image_params *imgp, struct label *execlabel) 1477{ 1478 struct mac_lomac *source, *dest, *obj, *robj; 1479 1480 source = SLOT(old->cr_label); 1481 dest = SLOT(new->cr_label); 1482 obj = SLOT(vplabel); 1483 robj = interpvplabel != NULL ? SLOT(interpvplabel) : obj; 1484 |
1496 mac_lomac_copy(source, dest); | 1485 lomac_copy(source, dest); |
1497 /* | 1486 /* |
1498 * If there's an auxiliary label on the real object, respect it 1499 * and assume that this level should be assumed immediately if 1500 * a higher level is currently in place. | 1487 * If there's an auxiliary label on the real object, respect it and 1488 * assume that this level should be assumed immediately if a higher 1489 * level is currently in place. |
1501 */ 1502 if (robj->ml_flags & MAC_LOMAC_FLAG_AUX && | 1490 */ 1491 if (robj->ml_flags & MAC_LOMAC_FLAG_AUX && |
1503 !mac_lomac_dominate_element(&robj->ml_auxsingle, &dest->ml_single) 1504 && mac_lomac_auxsingle_in_range(robj, dest)) 1505 mac_lomac_set_single(dest, robj->ml_auxsingle.mle_type, | 1492 !lomac_dominate_element(&robj->ml_auxsingle, &dest->ml_single) 1493 && lomac_auxsingle_in_range(robj, dest)) 1494 lomac_set_single(dest, robj->ml_auxsingle.mle_type, |
1506 robj->ml_auxsingle.mle_grade); 1507 /* | 1495 robj->ml_auxsingle.mle_grade); 1496 /* |
1508 * Restructuring to use the execve transitioning mechanism 1509 * instead of the normal demotion mechanism here would be 1510 * difficult, so just copy the label over and perform standard 1511 * demotion. This is also non-optimal because it will result 1512 * in the intermediate label "new" being created and immediately 1513 * recycled. | 1497 * Restructuring to use the execve transitioning mechanism instead of 1498 * the normal demotion mechanism here would be difficult, so just 1499 * copy the label over and perform standard demotion. This is also 1500 * non-optimal because it will result in the intermediate label "new" 1501 * being created and immediately recycled. |
1514 */ | 1502 */ |
1515 if (mac_lomac_enabled && revocation_enabled && 1516 !mac_lomac_dominate_single(obj, source)) | 1503 if (lomac_enabled && revocation_enabled && 1504 !lomac_dominate_single(obj, source)) |
1517 (void)maybe_demote(source, obj, "executing", "file", vp); 1518} 1519 1520static int | 1505 (void)maybe_demote(source, obj, "executing", "file", vp); 1506} 1507 1508static int |
1521mac_lomac_vnode_execve_will_transition(struct ucred *old, struct vnode *vp, | 1509lomac_vnode_execve_will_transition(struct ucred *old, struct vnode *vp, |
1522 struct label *vplabel, struct label *interpvplabel, 1523 struct image_params *imgp, struct label *execlabel) 1524{ 1525 struct mac_lomac *subj, *obj, *robj; 1526 | 1510 struct label *vplabel, struct label *interpvplabel, 1511 struct image_params *imgp, struct label *execlabel) 1512{ 1513 struct mac_lomac *subj, *obj, *robj; 1514 |
1527 if (!mac_lomac_enabled || !revocation_enabled) | 1515 if (!lomac_enabled || !revocation_enabled) |
1528 return (0); 1529 1530 subj = SLOT(old->cr_label); 1531 obj = SLOT(vplabel); 1532 robj = interpvplabel != NULL ? SLOT(interpvplabel) : obj; 1533 1534 return ((robj->ml_flags & MAC_LOMAC_FLAG_AUX && | 1516 return (0); 1517 1518 subj = SLOT(old->cr_label); 1519 obj = SLOT(vplabel); 1520 robj = interpvplabel != NULL ? SLOT(interpvplabel) : obj; 1521 1522 return ((robj->ml_flags & MAC_LOMAC_FLAG_AUX && |
1535 !mac_lomac_dominate_element(&robj->ml_auxsingle, &subj->ml_single) 1536 && mac_lomac_auxsingle_in_range(robj, subj)) || 1537 !mac_lomac_dominate_single(obj, subj)); | 1523 !lomac_dominate_element(&robj->ml_auxsingle, &subj->ml_single) 1524 && lomac_auxsingle_in_range(robj, subj)) || 1525 !lomac_dominate_single(obj, subj)); |
1538} 1539 1540static void | 1526} 1527 1528static void |
1541mac_lomac_proc_create_swapper(struct ucred *cred) | 1529lomac_proc_create_swapper(struct ucred *cred) |
1542{ 1543 struct mac_lomac *dest; 1544 1545 dest = SLOT(cred->cr_label); 1546 | 1530{ 1531 struct mac_lomac *dest; 1532 1533 dest = SLOT(cred->cr_label); 1534 |
1547 mac_lomac_set_single(dest, MAC_LOMAC_TYPE_EQUAL, 0); 1548 mac_lomac_set_range(dest, MAC_LOMAC_TYPE_LOW, 0, MAC_LOMAC_TYPE_HIGH, 1549 0); | 1535 lomac_set_single(dest, MAC_LOMAC_TYPE_EQUAL, 0); 1536 lomac_set_range(dest, MAC_LOMAC_TYPE_LOW, 0, MAC_LOMAC_TYPE_HIGH, 0); |
1550} 1551 1552static void | 1537} 1538 1539static void |
1553mac_lomac_proc_create_init(struct ucred *cred) | 1540lomac_proc_create_init(struct ucred *cred) |
1554{ 1555 struct mac_lomac *dest; 1556 1557 dest = SLOT(cred->cr_label); 1558 | 1541{ 1542 struct mac_lomac *dest; 1543 1544 dest = SLOT(cred->cr_label); 1545 |
1559 mac_lomac_set_single(dest, MAC_LOMAC_TYPE_HIGH, 0); 1560 mac_lomac_set_range(dest, MAC_LOMAC_TYPE_LOW, 0, MAC_LOMAC_TYPE_HIGH, 1561 0); | 1546 lomac_set_single(dest, MAC_LOMAC_TYPE_HIGH, 0); 1547 lomac_set_range(dest, MAC_LOMAC_TYPE_LOW, 0, MAC_LOMAC_TYPE_HIGH, 0); |
1562} 1563 1564static void | 1548} 1549 1550static void |
1565mac_lomac_cred_relabel(struct ucred *cred, struct label *newlabel) | 1551lomac_cred_relabel(struct ucred *cred, struct label *newlabel) |
1566{ 1567 struct mac_lomac *source, *dest; 1568 1569 source = SLOT(newlabel); 1570 dest = SLOT(cred->cr_label); 1571 1572 try_relabel(source, dest); 1573} 1574 1575/* 1576 * Access control checks. 1577 */ 1578static int | 1552{ 1553 struct mac_lomac *source, *dest; 1554 1555 source = SLOT(newlabel); 1556 dest = SLOT(cred->cr_label); 1557 1558 try_relabel(source, dest); 1559} 1560 1561/* 1562 * Access control checks. 1563 */ 1564static int |
1579mac_lomac_bpfdesc_check_receive(struct bpf_d *d, struct label *dlabel, | 1565lomac_bpfdesc_check_receive(struct bpf_d *d, struct label *dlabel, |
1580 struct ifnet *ifp, struct label *ifplabel) 1581{ 1582 struct mac_lomac *a, *b; 1583 | 1566 struct ifnet *ifp, struct label *ifplabel) 1567{ 1568 struct mac_lomac *a, *b; 1569 |
1584 if (!mac_lomac_enabled) | 1570 if (!lomac_enabled) |
1585 return (0); 1586 1587 a = SLOT(dlabel); 1588 b = SLOT(ifplabel); 1589 | 1571 return (0); 1572 1573 a = SLOT(dlabel); 1574 b = SLOT(ifplabel); 1575 |
1590 if (mac_lomac_equal_single(a, b)) | 1576 if (lomac_equal_single(a, b)) |
1591 return (0); 1592 return (EACCES); 1593} 1594 1595static int | 1577 return (0); 1578 return (EACCES); 1579} 1580 1581static int |
1596mac_lomac_cred_check_relabel(struct ucred *cred, struct label *newlabel) | 1582lomac_cred_check_relabel(struct ucred *cred, struct label *newlabel) |
1597{ 1598 struct mac_lomac *subj, *new; 1599 int error; 1600 1601 subj = SLOT(cred->cr_label); 1602 new = SLOT(newlabel); 1603 1604 /* | 1583{ 1584 struct mac_lomac *subj, *new; 1585 int error; 1586 1587 subj = SLOT(cred->cr_label); 1588 new = SLOT(newlabel); 1589 1590 /* |
1605 * If there is a LOMAC label update for the credential, it may 1606 * be an update of the single, range, or both. | 1591 * If there is a LOMAC label update for the credential, it may be an 1592 * update of the single, range, or both. |
1607 */ 1608 error = lomac_atmostflags(new, MAC_LOMAC_FLAGS_BOTH); 1609 if (error) 1610 return (error); 1611 1612 /* 1613 * If the LOMAC label is to be changed, authorize as appropriate. 1614 */ 1615 if (new->ml_flags & MAC_LOMAC_FLAGS_BOTH) { 1616 /* 1617 * Fill in the missing parts from the previous label. 1618 */ 1619 if ((new->ml_flags & MAC_LOMAC_FLAG_SINGLE) == 0) | 1593 */ 1594 error = lomac_atmostflags(new, MAC_LOMAC_FLAGS_BOTH); 1595 if (error) 1596 return (error); 1597 1598 /* 1599 * If the LOMAC label is to be changed, authorize as appropriate. 1600 */ 1601 if (new->ml_flags & MAC_LOMAC_FLAGS_BOTH) { 1602 /* 1603 * Fill in the missing parts from the previous label. 1604 */ 1605 if ((new->ml_flags & MAC_LOMAC_FLAG_SINGLE) == 0) |
1620 mac_lomac_copy_single(subj, new); | 1606 lomac_copy_single(subj, new); |
1621 if ((new->ml_flags & MAC_LOMAC_FLAG_RANGE) == 0) | 1607 if ((new->ml_flags & MAC_LOMAC_FLAG_RANGE) == 0) |
1622 mac_lomac_copy_range(subj, new); | 1608 lomac_copy_range(subj, new); |
1623 1624 /* | 1609 1610 /* |
1625 * To change the LOMAC range on a credential, the new 1626 * range label must be in the current range. | 1611 * To change the LOMAC range on a credential, the new range 1612 * label must be in the current range. |
1627 */ | 1613 */ |
1628 if (!mac_lomac_range_in_range(new, subj)) | 1614 if (!lomac_range_in_range(new, subj)) |
1629 return (EPERM); 1630 1631 /* | 1615 return (EPERM); 1616 1617 /* |
1632 * To change the LOMAC single label on a credential, the 1633 * new single label must be in the new range. Implicitly 1634 * from the previous check, the new single is in the old 1635 * range. | 1618 * To change the LOMAC single label on a credential, the new 1619 * single label must be in the new range. Implicitly from 1620 * the previous check, the new single is in the old range. |
1636 */ | 1621 */ |
1637 if (!mac_lomac_single_in_range(new, new)) | 1622 if (!lomac_single_in_range(new, new)) |
1638 return (EPERM); 1639 1640 /* | 1623 return (EPERM); 1624 1625 /* |
1641 * To have EQUAL in any component of the new credential 1642 * LOMAC label, the subject must already have EQUAL in 1643 * their label. | 1626 * To have EQUAL in any component of the new credential LOMAC 1627 * label, the subject must already have EQUAL in their label. |
1644 */ | 1628 */ |
1645 if (mac_lomac_contains_equal(new)) { 1646 error = mac_lomac_subject_privileged(subj); | 1629 if (lomac_contains_equal(new)) { 1630 error = lomac_subject_privileged(subj); |
1647 if (error) 1648 return (error); 1649 } 1650 1651 /* | 1631 if (error) 1632 return (error); 1633 } 1634 1635 /* |
1652 * XXXMAC: Additional consistency tests regarding the 1653 * single and range of the new label might be performed 1654 * here. | 1636 * XXXMAC: Additional consistency tests regarding the single 1637 * and range of the new label might be performed here. |
1655 */ 1656 } 1657 1658 return (0); 1659} 1660 1661static int | 1638 */ 1639 } 1640 1641 return (0); 1642} 1643 1644static int |
1662mac_lomac_cred_check_visible(struct ucred *cr1, struct ucred *cr2) | 1645lomac_cred_check_visible(struct ucred *cr1, struct ucred *cr2) |
1663{ 1664 struct mac_lomac *subj, *obj; 1665 | 1646{ 1647 struct mac_lomac *subj, *obj; 1648 |
1666 if (!mac_lomac_enabled) | 1649 if (!lomac_enabled) |
1667 return (0); 1668 1669 subj = SLOT(cr1->cr_label); 1670 obj = SLOT(cr2->cr_label); 1671 1672 /* XXX: range */ | 1650 return (0); 1651 1652 subj = SLOT(cr1->cr_label); 1653 obj = SLOT(cr2->cr_label); 1654 1655 /* XXX: range */ |
1673 if (!mac_lomac_dominate_single(obj, subj)) | 1656 if (!lomac_dominate_single(obj, subj)) |
1674 return (ESRCH); 1675 1676 return (0); 1677} 1678 1679static int | 1657 return (ESRCH); 1658 1659 return (0); 1660} 1661 1662static int |
1680mac_lomac_ifnet_check_relabel(struct ucred *cred, struct ifnet *ifp, | 1663lomac_ifnet_check_relabel(struct ucred *cred, struct ifnet *ifp, |
1681 struct label *ifplabel, struct label *newlabel) 1682{ 1683 struct mac_lomac *subj, *new; 1684 int error; 1685 1686 subj = SLOT(cred->cr_label); 1687 new = SLOT(newlabel); 1688 1689 /* | 1664 struct label *ifplabel, struct label *newlabel) 1665{ 1666 struct mac_lomac *subj, *new; 1667 int error; 1668 1669 subj = SLOT(cred->cr_label); 1670 new = SLOT(newlabel); 1671 1672 /* |
1690 * If there is a LOMAC label update for the interface, it may 1691 * be an update of the single, range, or both. | 1673 * If there is a LOMAC label update for the interface, it may be an 1674 * update of the single, range, or both. |
1692 */ 1693 error = lomac_atmostflags(new, MAC_LOMAC_FLAGS_BOTH); 1694 if (error) 1695 return (error); 1696 1697 /* 1698 * Relabling network interfaces requires LOMAC privilege. 1699 */ | 1675 */ 1676 error = lomac_atmostflags(new, MAC_LOMAC_FLAGS_BOTH); 1677 if (error) 1678 return (error); 1679 1680 /* 1681 * Relabling network interfaces requires LOMAC privilege. 1682 */ |
1700 error = mac_lomac_subject_privileged(subj); | 1683 error = lomac_subject_privileged(subj); |
1701 if (error) 1702 return (error); 1703 1704 /* 1705 * If the LOMAC label is to be changed, authorize as appropriate. 1706 */ 1707 if (new->ml_flags & MAC_LOMAC_FLAGS_BOTH) { 1708 /* 1709 * Fill in the missing parts from the previous label. 1710 */ 1711 if ((new->ml_flags & MAC_LOMAC_FLAG_SINGLE) == 0) | 1684 if (error) 1685 return (error); 1686 1687 /* 1688 * If the LOMAC label is to be changed, authorize as appropriate. 1689 */ 1690 if (new->ml_flags & MAC_LOMAC_FLAGS_BOTH) { 1691 /* 1692 * Fill in the missing parts from the previous label. 1693 */ 1694 if ((new->ml_flags & MAC_LOMAC_FLAG_SINGLE) == 0) |
1712 mac_lomac_copy_single(subj, new); | 1695 lomac_copy_single(subj, new); |
1713 if ((new->ml_flags & MAC_LOMAC_FLAG_RANGE) == 0) | 1696 if ((new->ml_flags & MAC_LOMAC_FLAG_RANGE) == 0) |
1714 mac_lomac_copy_range(subj, new); | 1697 lomac_copy_range(subj, new); |
1715 1716 /* 1717 * Rely on the traditional superuser status for the LOMAC 1718 * interface relabel requirements. XXXMAC: This will go 1719 * away. 1720 * 1721 * XXXRW: This is also redundant to a higher layer check. 1722 */ --- 6 unchanged lines hidden (view full) --- 1729 * and the range of the new label might be performed here. 1730 */ 1731 } 1732 1733 return (0); 1734} 1735 1736static int | 1698 1699 /* 1700 * Rely on the traditional superuser status for the LOMAC 1701 * interface relabel requirements. XXXMAC: This will go 1702 * away. 1703 * 1704 * XXXRW: This is also redundant to a higher layer check. 1705 */ --- 6 unchanged lines hidden (view full) --- 1712 * and the range of the new label might be performed here. 1713 */ 1714 } 1715 1716 return (0); 1717} 1718 1719static int |
1737mac_lomac_ifnet_check_transmit(struct ifnet *ifp, struct label *ifplabel, | 1720lomac_ifnet_check_transmit(struct ifnet *ifp, struct label *ifplabel, |
1738 struct mbuf *m, struct label *mlabel) 1739{ 1740 struct mac_lomac *p, *i; 1741 | 1721 struct mbuf *m, struct label *mlabel) 1722{ 1723 struct mac_lomac *p, *i; 1724 |
1742 if (!mac_lomac_enabled) | 1725 if (!lomac_enabled) |
1743 return (0); 1744 1745 p = SLOT(mlabel); 1746 i = SLOT(ifplabel); 1747 | 1726 return (0); 1727 1728 p = SLOT(mlabel); 1729 i = SLOT(ifplabel); 1730 |
1748 return (mac_lomac_single_in_range(p, i) ? 0 : EACCES); | 1731 return (lomac_single_in_range(p, i) ? 0 : EACCES); |
1749} 1750 1751static int | 1732} 1733 1734static int |
1752mac_lomac_inpcb_check_deliver(struct inpcb *inp, struct label *inplabel, | 1735lomac_inpcb_check_deliver(struct inpcb *inp, struct label *inplabel, |
1753 struct mbuf *m, struct label *mlabel) 1754{ 1755 struct mac_lomac *p, *i; 1756 | 1736 struct mbuf *m, struct label *mlabel) 1737{ 1738 struct mac_lomac *p, *i; 1739 |
1757 if (!mac_lomac_enabled) | 1740 if (!lomac_enabled) |
1758 return (0); 1759 1760 p = SLOT(mlabel); 1761 i = SLOT(inplabel); 1762 | 1741 return (0); 1742 1743 p = SLOT(mlabel); 1744 i = SLOT(inplabel); 1745 |
1763 return (mac_lomac_equal_single(p, i) ? 0 : EACCES); | 1746 return (lomac_equal_single(p, i) ? 0 : EACCES); |
1764} 1765 1766static int | 1747} 1748 1749static int |
1767mac_lomac_kld_check_load(struct ucred *cred, struct vnode *vp, | 1750lomac_kld_check_load(struct ucred *cred, struct vnode *vp, |
1768 struct label *vplabel) 1769{ 1770 struct mac_lomac *subj, *obj; 1771 | 1751 struct label *vplabel) 1752{ 1753 struct mac_lomac *subj, *obj; 1754 |
1772 if (!mac_lomac_enabled) | 1755 if (!lomac_enabled) |
1773 return (0); 1774 1775 subj = SLOT(cred->cr_label); 1776 obj = SLOT(vplabel); 1777 | 1756 return (0); 1757 1758 subj = SLOT(cred->cr_label); 1759 obj = SLOT(vplabel); 1760 |
1778 if (mac_lomac_subject_privileged(subj)) | 1761 if (lomac_subject_privileged(subj)) |
1779 return (EPERM); 1780 | 1762 return (EPERM); 1763 |
1781 if (!mac_lomac_high_single(obj)) | 1764 if (!lomac_high_single(obj)) |
1782 return (EACCES); 1783 1784 return (0); 1785} 1786 1787static int | 1765 return (EACCES); 1766 1767 return (0); 1768} 1769 1770static int |
1788mac_lomac_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp, | 1771lomac_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp, |
1789 struct label *pplabel, unsigned long cmd, void /* caddr_t */ *data) 1790{ 1791 | 1772 struct label *pplabel, unsigned long cmd, void /* caddr_t */ *data) 1773{ 1774 |
1792 if (!mac_lomac_enabled) | 1775 if (!lomac_enabled) |
1793 return (0); 1794 1795 /* XXX: This will be implemented soon... */ 1796 1797 return (0); 1798} 1799 1800static int | 1776 return (0); 1777 1778 /* XXX: This will be implemented soon... */ 1779 1780 return (0); 1781} 1782 1783static int |
1801mac_lomac_pipe_check_read(struct ucred *cred, struct pipepair *pp, | 1784lomac_pipe_check_read(struct ucred *cred, struct pipepair *pp, |
1802 struct label *pplabel) 1803{ 1804 struct mac_lomac *subj, *obj; 1805 | 1785 struct label *pplabel) 1786{ 1787 struct mac_lomac *subj, *obj; 1788 |
1806 if (!mac_lomac_enabled) | 1789 if (!lomac_enabled) |
1807 return (0); 1808 1809 subj = SLOT(cred->cr_label); 1810 obj = SLOT(pplabel); 1811 | 1790 return (0); 1791 1792 subj = SLOT(cred->cr_label); 1793 obj = SLOT(pplabel); 1794 |
1812 if (!mac_lomac_dominate_single(obj, subj)) | 1795 if (!lomac_dominate_single(obj, subj)) |
1813 return (maybe_demote(subj, obj, "reading", "pipe", NULL)); 1814 1815 return (0); 1816} 1817 1818static int | 1796 return (maybe_demote(subj, obj, "reading", "pipe", NULL)); 1797 1798 return (0); 1799} 1800 1801static int |
1819mac_lomac_pipe_check_relabel(struct ucred *cred, struct pipepair *pp, | 1802lomac_pipe_check_relabel(struct ucred *cred, struct pipepair *pp, |
1820 struct label *pplabel, struct label *newlabel) 1821{ 1822 struct mac_lomac *subj, *obj, *new; 1823 int error; 1824 1825 new = SLOT(newlabel); 1826 subj = SLOT(cred->cr_label); 1827 obj = SLOT(pplabel); 1828 1829 /* | 1803 struct label *pplabel, struct label *newlabel) 1804{ 1805 struct mac_lomac *subj, *obj, *new; 1806 int error; 1807 1808 new = SLOT(newlabel); 1809 subj = SLOT(cred->cr_label); 1810 obj = SLOT(pplabel); 1811 1812 /* |
1830 * If there is a LOMAC label update for a pipe, it must be a 1831 * single update. | 1813 * If there is a LOMAC label update for a pipe, it must be a single 1814 * update. |
1832 */ 1833 error = lomac_atmostflags(new, MAC_LOMAC_FLAG_SINGLE); 1834 if (error) 1835 return (error); 1836 1837 /* 1838 * To perform a relabel of a pipe (LOMAC label or not), LOMAC must 1839 * authorize the relabel. 1840 */ | 1815 */ 1816 error = lomac_atmostflags(new, MAC_LOMAC_FLAG_SINGLE); 1817 if (error) 1818 return (error); 1819 1820 /* 1821 * To perform a relabel of a pipe (LOMAC label or not), LOMAC must 1822 * authorize the relabel. 1823 */ |
1841 if (!mac_lomac_single_in_range(obj, subj)) | 1824 if (!lomac_single_in_range(obj, subj)) |
1842 return (EPERM); 1843 1844 /* 1845 * If the LOMAC label is to be changed, authorize as appropriate. 1846 */ 1847 if (new->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 1848 /* 1849 * To change the LOMAC label on a pipe, the new pipe label 1850 * must be in the subject range. 1851 */ | 1825 return (EPERM); 1826 1827 /* 1828 * If the LOMAC label is to be changed, authorize as appropriate. 1829 */ 1830 if (new->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 1831 /* 1832 * To change the LOMAC label on a pipe, the new pipe label 1833 * must be in the subject range. 1834 */ |
1852 if (!mac_lomac_single_in_range(new, subj)) | 1835 if (!lomac_single_in_range(new, subj)) |
1853 return (EPERM); 1854 1855 /* 1856 * To change the LOMAC label on a pipe to be EQUAL, the 1857 * subject must have appropriate privilege. 1858 */ | 1836 return (EPERM); 1837 1838 /* 1839 * To change the LOMAC label on a pipe to be EQUAL, the 1840 * subject must have appropriate privilege. 1841 */ |
1859 if (mac_lomac_contains_equal(new)) { 1860 error = mac_lomac_subject_privileged(subj); | 1842 if (lomac_contains_equal(new)) { 1843 error = lomac_subject_privileged(subj); |
1861 if (error) 1862 return (error); 1863 } 1864 } 1865 1866 return (0); 1867} 1868 1869static int | 1844 if (error) 1845 return (error); 1846 } 1847 } 1848 1849 return (0); 1850} 1851 1852static int |
1870mac_lomac_pipe_check_write(struct ucred *cred, struct pipepair *pp, | 1853lomac_pipe_check_write(struct ucred *cred, struct pipepair *pp, |
1871 struct label *pplabel) 1872{ 1873 struct mac_lomac *subj, *obj; 1874 | 1854 struct label *pplabel) 1855{ 1856 struct mac_lomac *subj, *obj; 1857 |
1875 if (!mac_lomac_enabled) | 1858 if (!lomac_enabled) |
1876 return (0); 1877 1878 subj = SLOT(cred->cr_label); 1879 obj = SLOT(pplabel); 1880 | 1859 return (0); 1860 1861 subj = SLOT(cred->cr_label); 1862 obj = SLOT(pplabel); 1863 |
1881 if (!mac_lomac_subject_dominate(subj, obj)) | 1864 if (!lomac_subject_dominate(subj, obj)) |
1882 return (EACCES); 1883 1884 return (0); 1885} 1886 1887static int | 1865 return (EACCES); 1866 1867 return (0); 1868} 1869 1870static int |
1888mac_lomac_proc_check_debug(struct ucred *cred, struct proc *p) | 1871lomac_proc_check_debug(struct ucred *cred, struct proc *p) |
1889{ 1890 struct mac_lomac *subj, *obj; 1891 | 1872{ 1873 struct mac_lomac *subj, *obj; 1874 |
1892 if (!mac_lomac_enabled) | 1875 if (!lomac_enabled) |
1893 return (0); 1894 1895 subj = SLOT(cred->cr_label); 1896 obj = SLOT(p->p_ucred->cr_label); 1897 1898 /* XXX: range checks */ | 1876 return (0); 1877 1878 subj = SLOT(cred->cr_label); 1879 obj = SLOT(p->p_ucred->cr_label); 1880 1881 /* XXX: range checks */ |
1899 if (!mac_lomac_dominate_single(obj, subj)) | 1882 if (!lomac_dominate_single(obj, subj)) |
1900 return (ESRCH); | 1883 return (ESRCH); |
1901 if (!mac_lomac_subject_dominate(subj, obj)) | 1884 if (!lomac_subject_dominate(subj, obj)) |
1902 return (EACCES); 1903 1904 return (0); 1905} 1906 1907static int | 1885 return (EACCES); 1886 1887 return (0); 1888} 1889 1890static int |
1908mac_lomac_proc_check_sched(struct ucred *cred, struct proc *p) | 1891lomac_proc_check_sched(struct ucred *cred, struct proc *p) |
1909{ 1910 struct mac_lomac *subj, *obj; 1911 | 1892{ 1893 struct mac_lomac *subj, *obj; 1894 |
1912 if (!mac_lomac_enabled) | 1895 if (!lomac_enabled) |
1913 return (0); 1914 1915 subj = SLOT(cred->cr_label); 1916 obj = SLOT(p->p_ucred->cr_label); 1917 1918 /* XXX: range checks */ | 1896 return (0); 1897 1898 subj = SLOT(cred->cr_label); 1899 obj = SLOT(p->p_ucred->cr_label); 1900 1901 /* XXX: range checks */ |
1919 if (!mac_lomac_dominate_single(obj, subj)) | 1902 if (!lomac_dominate_single(obj, subj)) |
1920 return (ESRCH); | 1903 return (ESRCH); |
1921 if (!mac_lomac_subject_dominate(subj, obj)) | 1904 if (!lomac_subject_dominate(subj, obj)) |
1922 return (EACCES); 1923 1924 return (0); 1925} 1926 1927static int | 1905 return (EACCES); 1906 1907 return (0); 1908} 1909 1910static int |
1928mac_lomac_proc_check_signal(struct ucred *cred, struct proc *p, int signum) | 1911lomac_proc_check_signal(struct ucred *cred, struct proc *p, int signum) |
1929{ 1930 struct mac_lomac *subj, *obj; 1931 | 1912{ 1913 struct mac_lomac *subj, *obj; 1914 |
1932 if (!mac_lomac_enabled) | 1915 if (!lomac_enabled) |
1933 return (0); 1934 1935 subj = SLOT(cred->cr_label); 1936 obj = SLOT(p->p_ucred->cr_label); 1937 1938 /* XXX: range checks */ | 1916 return (0); 1917 1918 subj = SLOT(cred->cr_label); 1919 obj = SLOT(p->p_ucred->cr_label); 1920 1921 /* XXX: range checks */ |
1939 if (!mac_lomac_dominate_single(obj, subj)) | 1922 if (!lomac_dominate_single(obj, subj)) |
1940 return (ESRCH); | 1923 return (ESRCH); |
1941 if (!mac_lomac_subject_dominate(subj, obj)) | 1924 if (!lomac_subject_dominate(subj, obj)) |
1942 return (EACCES); 1943 1944 return (0); 1945} 1946 1947static int | 1925 return (EACCES); 1926 1927 return (0); 1928} 1929 1930static int |
1948mac_lomac_socket_check_deliver(struct socket *so, struct label *solabel, | 1931lomac_socket_check_deliver(struct socket *so, struct label *solabel, |
1949 struct mbuf *m, struct label *mlabel) 1950{ 1951 struct mac_lomac *p, *s; 1952 | 1932 struct mbuf *m, struct label *mlabel) 1933{ 1934 struct mac_lomac *p, *s; 1935 |
1953 if (!mac_lomac_enabled) | 1936 if (!lomac_enabled) |
1954 return (0); 1955 1956 p = SLOT(mlabel); 1957 s = SLOT(solabel); 1958 | 1937 return (0); 1938 1939 p = SLOT(mlabel); 1940 s = SLOT(solabel); 1941 |
1959 return (mac_lomac_equal_single(p, s) ? 0 : EACCES); | 1942 return (lomac_equal_single(p, s) ? 0 : EACCES); |
1960} 1961 1962static int | 1943} 1944 1945static int |
1963mac_lomac_socket_check_relabel(struct ucred *cred, struct socket *so, | 1946lomac_socket_check_relabel(struct ucred *cred, struct socket *so, |
1964 struct label *solabel, struct label *newlabel) 1965{ 1966 struct mac_lomac *subj, *obj, *new; 1967 int error; 1968 1969 new = SLOT(newlabel); 1970 subj = SLOT(cred->cr_label); 1971 obj = SLOT(solabel); 1972 1973 /* | 1947 struct label *solabel, struct label *newlabel) 1948{ 1949 struct mac_lomac *subj, *obj, *new; 1950 int error; 1951 1952 new = SLOT(newlabel); 1953 subj = SLOT(cred->cr_label); 1954 obj = SLOT(solabel); 1955 1956 /* |
1974 * If there is a LOMAC label update for the socket, it may be 1975 * an update of single. | 1957 * If there is a LOMAC label update for the socket, it may be an 1958 * update of single. |
1976 */ 1977 error = lomac_atmostflags(new, MAC_LOMAC_FLAG_SINGLE); 1978 if (error) 1979 return (error); 1980 1981 /* 1982 * To relabel a socket, the old socket single must be in the subject 1983 * range. 1984 */ | 1959 */ 1960 error = lomac_atmostflags(new, MAC_LOMAC_FLAG_SINGLE); 1961 if (error) 1962 return (error); 1963 1964 /* 1965 * To relabel a socket, the old socket single must be in the subject 1966 * range. 1967 */ |
1985 if (!mac_lomac_single_in_range(obj, subj)) | 1968 if (!lomac_single_in_range(obj, subj)) |
1986 return (EPERM); 1987 1988 /* 1989 * If the LOMAC label is to be changed, authorize as appropriate. 1990 */ 1991 if (new->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 1992 /* | 1969 return (EPERM); 1970 1971 /* 1972 * If the LOMAC label is to be changed, authorize as appropriate. 1973 */ 1974 if (new->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 1975 /* |
1993 * To relabel a socket, the new socket single must be in 1994 * the subject range. | 1976 * To relabel a socket, the new socket single must be in the 1977 * subject range. |
1995 */ | 1978 */ |
1996 if (!mac_lomac_single_in_range(new, subj)) | 1979 if (!lomac_single_in_range(new, subj)) |
1997 return (EPERM); 1998 1999 /* 2000 * To change the LOMAC label on the socket to contain EQUAL, 2001 * the subject must have appropriate privilege. 2002 */ | 1980 return (EPERM); 1981 1982 /* 1983 * To change the LOMAC label on the socket to contain EQUAL, 1984 * the subject must have appropriate privilege. 1985 */ |
2003 if (mac_lomac_contains_equal(new)) { 2004 error = mac_lomac_subject_privileged(subj); | 1986 if (lomac_contains_equal(new)) { 1987 error = lomac_subject_privileged(subj); |
2005 if (error) 2006 return (error); 2007 } 2008 } 2009 2010 return (0); 2011} 2012 2013static int | 1988 if (error) 1989 return (error); 1990 } 1991 } 1992 1993 return (0); 1994} 1995 1996static int |
2014mac_lomac_socket_check_visible(struct ucred *cred, struct socket *so, | 1997lomac_socket_check_visible(struct ucred *cred, struct socket *so, |
2015 struct label *solabel) 2016{ 2017 struct mac_lomac *subj, *obj; 2018 | 1998 struct label *solabel) 1999{ 2000 struct mac_lomac *subj, *obj; 2001 |
2019 if (!mac_lomac_enabled) | 2002 if (!lomac_enabled) |
2020 return (0); 2021 2022 subj = SLOT(cred->cr_label); 2023 obj = SLOT(solabel); 2024 | 2003 return (0); 2004 2005 subj = SLOT(cred->cr_label); 2006 obj = SLOT(solabel); 2007 |
2025 if (!mac_lomac_dominate_single(obj, subj)) | 2008 if (!lomac_dominate_single(obj, subj)) |
2026 return (ENOENT); 2027 2028 return (0); 2029} 2030 2031/* 2032 * Some system privileges are allowed regardless of integrity grade; others 2033 * are allowed only when running with privilege with respect to the LOMAC 2034 * policy as they might otherwise allow bypassing of the integrity policy. 2035 */ 2036static int | 2009 return (ENOENT); 2010 2011 return (0); 2012} 2013 2014/* 2015 * Some system privileges are allowed regardless of integrity grade; others 2016 * are allowed only when running with privilege with respect to the LOMAC 2017 * policy as they might otherwise allow bypassing of the integrity policy. 2018 */ 2019static int |
2037mac_lomac_priv_check(struct ucred *cred, int priv) | 2020lomac_priv_check(struct ucred *cred, int priv) |
2038{ 2039 struct mac_lomac *subj; 2040 int error; 2041 | 2021{ 2022 struct mac_lomac *subj; 2023 int error; 2024 |
2042 if (!mac_lomac_enabled) | 2025 if (!lomac_enabled) |
2043 return (0); 2044 2045 /* 2046 * Exempt only specific privileges from the LOMAC integrity policy. 2047 */ 2048 switch (priv) { 2049 case PRIV_KTRACE: 2050 case PRIV_MSGBUF: --- 154 unchanged lines hidden (view full) --- 2205 break; 2206 2207 /* 2208 * All remaining system privileges are allow only if the process 2209 * holds privilege with respect to the LOMAC policy. 2210 */ 2211 default: 2212 subj = SLOT(cred->cr_label); | 2026 return (0); 2027 2028 /* 2029 * Exempt only specific privileges from the LOMAC integrity policy. 2030 */ 2031 switch (priv) { 2032 case PRIV_KTRACE: 2033 case PRIV_MSGBUF: --- 154 unchanged lines hidden (view full) --- 2188 break; 2189 2190 /* 2191 * All remaining system privileges are allow only if the process 2192 * holds privilege with respect to the LOMAC policy. 2193 */ 2194 default: 2195 subj = SLOT(cred->cr_label); |
2213 error = mac_lomac_subject_privileged(subj); | 2196 error = lomac_subject_privileged(subj); |
2214 if (error) 2215 return (error); 2216 } 2217 return (0); 2218} 2219 2220 2221static int | 2197 if (error) 2198 return (error); 2199 } 2200 return (0); 2201} 2202 2203 2204static int |
2222mac_lomac_system_check_acct(struct ucred *cred, struct vnode *vp, | 2205lomac_system_check_acct(struct ucred *cred, struct vnode *vp, |
2223 struct label *vplabel) 2224{ 2225 struct mac_lomac *subj, *obj; 2226 | 2206 struct label *vplabel) 2207{ 2208 struct mac_lomac *subj, *obj; 2209 |
2227 if (!mac_lomac_enabled) | 2210 if (!lomac_enabled) |
2228 return (0); 2229 2230 subj = SLOT(cred->cr_label); 2231 obj = SLOT(vplabel); 2232 | 2211 return (0); 2212 2213 subj = SLOT(cred->cr_label); 2214 obj = SLOT(vplabel); 2215 |
2233 if (mac_lomac_subject_privileged(subj)) | 2216 if (lomac_subject_privileged(subj)) |
2234 return (EPERM); 2235 | 2217 return (EPERM); 2218 |
2236 if (!mac_lomac_high_single(obj)) | 2219 if (!lomac_high_single(obj)) |
2237 return (EACCES); 2238 2239 return (0); 2240} 2241 2242static int | 2220 return (EACCES); 2221 2222 return (0); 2223} 2224 2225static int |
2243mac_lomac_system_check_auditctl(struct ucred *cred, struct vnode *vp, | 2226lomac_system_check_auditctl(struct ucred *cred, struct vnode *vp, |
2244 struct label *vplabel) 2245{ 2246 struct mac_lomac *subj, *obj; 2247 | 2227 struct label *vplabel) 2228{ 2229 struct mac_lomac *subj, *obj; 2230 |
2248 if (!mac_lomac_enabled) | 2231 if (!lomac_enabled) |
2249 return (0); 2250 2251 subj = SLOT(cred->cr_label); 2252 obj = SLOT(vplabel); 2253 | 2232 return (0); 2233 2234 subj = SLOT(cred->cr_label); 2235 obj = SLOT(vplabel); 2236 |
2254 if (mac_lomac_subject_privileged(subj)) | 2237 if (lomac_subject_privileged(subj)) |
2255 return (EPERM); 2256 | 2238 return (EPERM); 2239 |
2257 if (!mac_lomac_high_single(obj)) | 2240 if (!lomac_high_single(obj)) |
2258 return (EACCES); 2259 2260 return (0); 2261} 2262 2263static int | 2241 return (EACCES); 2242 2243 return (0); 2244} 2245 2246static int |
2264mac_lomac_system_check_swapoff(struct ucred *cred, struct vnode *vp, | 2247lomac_system_check_swapoff(struct ucred *cred, struct vnode *vp, |
2265 struct label *vplabel) 2266{ 2267 struct mac_lomac *subj; 2268 | 2248 struct label *vplabel) 2249{ 2250 struct mac_lomac *subj; 2251 |
2269 if (!mac_lomac_enabled) | 2252 if (!lomac_enabled) |
2270 return (0); 2271 2272 subj = SLOT(cred->cr_label); 2273 | 2253 return (0); 2254 2255 subj = SLOT(cred->cr_label); 2256 |
2274 if (mac_lomac_subject_privileged(subj)) | 2257 if (lomac_subject_privileged(subj)) |
2275 return (EPERM); 2276 2277 return (0); 2278} 2279 2280static int | 2258 return (EPERM); 2259 2260 return (0); 2261} 2262 2263static int |
2281mac_lomac_system_check_swapon(struct ucred *cred, struct vnode *vp, | 2264lomac_system_check_swapon(struct ucred *cred, struct vnode *vp, |
2282 struct label *vplabel) 2283{ 2284 struct mac_lomac *subj, *obj; 2285 | 2265 struct label *vplabel) 2266{ 2267 struct mac_lomac *subj, *obj; 2268 |
2286 if (!mac_lomac_enabled) | 2269 if (!lomac_enabled) |
2287 return (0); 2288 2289 subj = SLOT(cred->cr_label); 2290 obj = SLOT(vplabel); 2291 | 2270 return (0); 2271 2272 subj = SLOT(cred->cr_label); 2273 obj = SLOT(vplabel); 2274 |
2292 if (mac_lomac_subject_privileged(subj)) | 2275 if (lomac_subject_privileged(subj)) |
2293 return (EPERM); 2294 | 2276 return (EPERM); 2277 |
2295 if (!mac_lomac_high_single(obj)) | 2278 if (!lomac_high_single(obj)) |
2296 return (EACCES); 2297 2298 return (0); 2299} 2300 2301static int | 2279 return (EACCES); 2280 2281 return (0); 2282} 2283 2284static int |
2302mac_lomac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp, | 2285lomac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp, |
2303 void *arg1, int arg2, struct sysctl_req *req) 2304{ 2305 struct mac_lomac *subj; 2306 | 2286 void *arg1, int arg2, struct sysctl_req *req) 2287{ 2288 struct mac_lomac *subj; 2289 |
2307 if (!mac_lomac_enabled) | 2290 if (!lomac_enabled) |
2308 return (0); 2309 2310 subj = SLOT(cred->cr_label); 2311 2312 /* | 2291 return (0); 2292 2293 subj = SLOT(cred->cr_label); 2294 2295 /* |
2313 * Treat sysctl variables without CTLFLAG_ANYBODY flag as 2314 * lomac/high, but also require privilege to change them. | 2296 * Treat sysctl variables without CTLFLAG_ANYBODY flag as lomac/high, 2297 * but also require privilege to change them. |
2315 */ 2316 if (req->newptr != NULL && (oidp->oid_kind & CTLFLAG_ANYBODY) == 0) { 2317#ifdef notdef | 2298 */ 2299 if (req->newptr != NULL && (oidp->oid_kind & CTLFLAG_ANYBODY) == 0) { 2300#ifdef notdef |
2318 if (!mac_lomac_subject_dominate_high(subj)) | 2301 if (!lomac_subject_dominate_high(subj)) |
2319 return (EACCES); 2320#endif 2321 | 2302 return (EACCES); 2303#endif 2304 |
2322 if (mac_lomac_subject_privileged(subj)) | 2305 if (lomac_subject_privileged(subj)) |
2323 return (EPERM); 2324 } 2325 2326 return (0); 2327} 2328 2329static int | 2306 return (EPERM); 2307 } 2308 2309 return (0); 2310} 2311 2312static int |
2330mac_lomac_vnode_check_create(struct ucred *cred, struct vnode *dvp, | 2313lomac_vnode_check_create(struct ucred *cred, struct vnode *dvp, |
2331 struct label *dvplabel, struct componentname *cnp, struct vattr *vap) 2332{ 2333 struct mac_lomac *subj, *obj; 2334 | 2314 struct label *dvplabel, struct componentname *cnp, struct vattr *vap) 2315{ 2316 struct mac_lomac *subj, *obj; 2317 |
2335 if (!mac_lomac_enabled) | 2318 if (!lomac_enabled) |
2336 return (0); 2337 2338 subj = SLOT(cred->cr_label); 2339 obj = SLOT(dvplabel); 2340 | 2319 return (0); 2320 2321 subj = SLOT(cred->cr_label); 2322 obj = SLOT(dvplabel); 2323 |
2341 if (!mac_lomac_subject_dominate(subj, obj)) | 2324 if (!lomac_subject_dominate(subj, obj)) |
2342 return (EACCES); 2343 if (obj->ml_flags & MAC_LOMAC_FLAG_AUX && | 2325 return (EACCES); 2326 if (obj->ml_flags & MAC_LOMAC_FLAG_AUX && |
2344 !mac_lomac_dominate_element(&subj->ml_single, &obj->ml_auxsingle)) | 2327 !lomac_dominate_element(&subj->ml_single, &obj->ml_auxsingle)) |
2345 return (EACCES); 2346 2347 return (0); 2348} 2349 2350static int | 2328 return (EACCES); 2329 2330 return (0); 2331} 2332 2333static int |
2351mac_lomac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp, | 2334lomac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp, |
2352 struct label *vplabel, acl_type_t type) 2353{ 2354 struct mac_lomac *subj, *obj; 2355 | 2335 struct label *vplabel, acl_type_t type) 2336{ 2337 struct mac_lomac *subj, *obj; 2338 |
2356 if (!mac_lomac_enabled) | 2339 if (!lomac_enabled) |
2357 return (0); 2358 2359 subj = SLOT(cred->cr_label); 2360 obj = SLOT(vplabel); 2361 | 2340 return (0); 2341 2342 subj = SLOT(cred->cr_label); 2343 obj = SLOT(vplabel); 2344 |
2362 if (!mac_lomac_subject_dominate(subj, obj)) | 2345 if (!lomac_subject_dominate(subj, obj)) |
2363 return (EACCES); 2364 2365 return (0); 2366} 2367 2368static int | 2346 return (EACCES); 2347 2348 return (0); 2349} 2350 2351static int |
2369mac_lomac_vnode_check_link(struct ucred *cred, struct vnode *dvp, | 2352lomac_vnode_check_link(struct ucred *cred, struct vnode *dvp, |
2370 struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2371 struct componentname *cnp) 2372{ 2373 struct mac_lomac *subj, *obj; 2374 | 2353 struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2354 struct componentname *cnp) 2355{ 2356 struct mac_lomac *subj, *obj; 2357 |
2375 if (!mac_lomac_enabled) | 2358 if (!lomac_enabled) |
2376 return (0); 2377 2378 subj = SLOT(cred->cr_label); 2379 obj = SLOT(dvplabel); 2380 | 2359 return (0); 2360 2361 subj = SLOT(cred->cr_label); 2362 obj = SLOT(dvplabel); 2363 |
2381 if (!mac_lomac_subject_dominate(subj, obj)) | 2364 if (!lomac_subject_dominate(subj, obj)) |
2382 return (EACCES); 2383 2384 obj = SLOT(vplabel); 2385 | 2365 return (EACCES); 2366 2367 obj = SLOT(vplabel); 2368 |
2386 if (!mac_lomac_subject_dominate(subj, obj)) | 2369 if (!lomac_subject_dominate(subj, obj)) |
2387 return (EACCES); 2388 2389 return (0); 2390} 2391 2392static int | 2370 return (EACCES); 2371 2372 return (0); 2373} 2374 2375static int |
2393mac_lomac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, | 2376lomac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, |
2394 struct label *vplabel, int prot, int flags) 2395{ 2396 struct mac_lomac *subj, *obj; 2397 2398 /* 2399 * Rely on the use of open()-time protections to handle 2400 * non-revocation cases. 2401 */ | 2377 struct label *vplabel, int prot, int flags) 2378{ 2379 struct mac_lomac *subj, *obj; 2380 2381 /* 2382 * Rely on the use of open()-time protections to handle 2383 * non-revocation cases. 2384 */ |
2402 if (!mac_lomac_enabled) | 2385 if (!lomac_enabled) |
2403 return (0); 2404 2405 subj = SLOT(cred->cr_label); 2406 obj = SLOT(vplabel); 2407 2408 if (((prot & VM_PROT_WRITE) != 0) && ((flags & MAP_SHARED) != 0)) { | 2386 return (0); 2387 2388 subj = SLOT(cred->cr_label); 2389 obj = SLOT(vplabel); 2390 2391 if (((prot & VM_PROT_WRITE) != 0) && ((flags & MAP_SHARED) != 0)) { |
2409 if (!mac_lomac_subject_dominate(subj, obj)) | 2392 if (!lomac_subject_dominate(subj, obj)) |
2410 return (EACCES); 2411 } 2412 if (prot & (VM_PROT_READ | VM_PROT_EXECUTE)) { | 2393 return (EACCES); 2394 } 2395 if (prot & (VM_PROT_READ | VM_PROT_EXECUTE)) { |
2413 if (!mac_lomac_dominate_single(obj, subj)) | 2396 if (!lomac_dominate_single(obj, subj)) |
2414 return (maybe_demote(subj, obj, "mapping", "file", vp)); 2415 } 2416 2417 return (0); 2418} 2419 2420static void | 2397 return (maybe_demote(subj, obj, "mapping", "file", vp)); 2398 } 2399 2400 return (0); 2401} 2402 2403static void |
2421mac_lomac_vnode_check_mmap_downgrade(struct ucred *cred, struct vnode *vp, | 2404lomac_vnode_check_mmap_downgrade(struct ucred *cred, struct vnode *vp, |
2422 struct label *vplabel, /* XXX vm_prot_t */ int *prot) 2423{ 2424 struct mac_lomac *subj, *obj; 2425 2426 /* 2427 * Rely on the use of open()-time protections to handle 2428 * non-revocation cases. 2429 */ | 2405 struct label *vplabel, /* XXX vm_prot_t */ int *prot) 2406{ 2407 struct mac_lomac *subj, *obj; 2408 2409 /* 2410 * Rely on the use of open()-time protections to handle 2411 * non-revocation cases. 2412 */ |
2430 if (!mac_lomac_enabled || !revocation_enabled) | 2413 if (!lomac_enabled || !revocation_enabled) |
2431 return; 2432 2433 subj = SLOT(cred->cr_label); 2434 obj = SLOT(vplabel); 2435 | 2414 return; 2415 2416 subj = SLOT(cred->cr_label); 2417 obj = SLOT(vplabel); 2418 |
2436 if (!mac_lomac_subject_dominate(subj, obj)) | 2419 if (!lomac_subject_dominate(subj, obj)) |
2437 *prot &= ~VM_PROT_WRITE; 2438} 2439 2440static int | 2420 *prot &= ~VM_PROT_WRITE; 2421} 2422 2423static int |
2441mac_lomac_vnode_check_open(struct ucred *cred, struct vnode *vp, | 2424lomac_vnode_check_open(struct ucred *cred, struct vnode *vp, |
2442 struct label *vplabel, int acc_mode) 2443{ 2444 struct mac_lomac *subj, *obj; 2445 | 2425 struct label *vplabel, int acc_mode) 2426{ 2427 struct mac_lomac *subj, *obj; 2428 |
2446 if (!mac_lomac_enabled) | 2429 if (!lomac_enabled) |
2447 return (0); 2448 2449 subj = SLOT(cred->cr_label); 2450 obj = SLOT(vplabel); 2451 2452 /* XXX privilege override for admin? */ 2453 if (acc_mode & (VWRITE | VAPPEND | VADMIN)) { | 2430 return (0); 2431 2432 subj = SLOT(cred->cr_label); 2433 obj = SLOT(vplabel); 2434 2435 /* XXX privilege override for admin? */ 2436 if (acc_mode & (VWRITE | VAPPEND | VADMIN)) { |
2454 if (!mac_lomac_subject_dominate(subj, obj)) | 2437 if (!lomac_subject_dominate(subj, obj)) |
2455 return (EACCES); 2456 } 2457 2458 return (0); 2459} 2460 2461static int | 2438 return (EACCES); 2439 } 2440 2441 return (0); 2442} 2443 2444static int |
2462mac_lomac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred, | 2445lomac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred, |
2463 struct vnode *vp, struct label *vplabel) 2464{ 2465 struct mac_lomac *subj, *obj; 2466 | 2446 struct vnode *vp, struct label *vplabel) 2447{ 2448 struct mac_lomac *subj, *obj; 2449 |
2467 if (!mac_lomac_enabled || !revocation_enabled) | 2450 if (!lomac_enabled || !revocation_enabled) |
2468 return (0); 2469 2470 subj = SLOT(active_cred->cr_label); 2471 obj = SLOT(vplabel); 2472 | 2451 return (0); 2452 2453 subj = SLOT(active_cred->cr_label); 2454 obj = SLOT(vplabel); 2455 |
2473 if (!mac_lomac_dominate_single(obj, subj)) | 2456 if (!lomac_dominate_single(obj, subj)) |
2474 return (maybe_demote(subj, obj, "reading", "file", vp)); 2475 2476 return (0); 2477} 2478 2479static int | 2457 return (maybe_demote(subj, obj, "reading", "file", vp)); 2458 2459 return (0); 2460} 2461 2462static int |
2480mac_lomac_vnode_check_relabel(struct ucred *cred, struct vnode *vp, | 2463lomac_vnode_check_relabel(struct ucred *cred, struct vnode *vp, |
2481 struct label *vplabel, struct label *newlabel) 2482{ 2483 struct mac_lomac *old, *new, *subj; 2484 int error; 2485 2486 old = SLOT(vplabel); 2487 new = SLOT(newlabel); 2488 subj = SLOT(cred->cr_label); --- 6 unchanged lines hidden (view full) --- 2495 MAC_LOMAC_FLAG_SINGLE | MAC_LOMAC_FLAG_AUX); 2496 if (error) 2497 return (error); 2498 2499 /* 2500 * To perform a relabel of the vnode (LOMAC label or not), LOMAC must 2501 * authorize the relabel. 2502 */ | 2464 struct label *vplabel, struct label *newlabel) 2465{ 2466 struct mac_lomac *old, *new, *subj; 2467 int error; 2468 2469 old = SLOT(vplabel); 2470 new = SLOT(newlabel); 2471 subj = SLOT(cred->cr_label); --- 6 unchanged lines hidden (view full) --- 2478 MAC_LOMAC_FLAG_SINGLE | MAC_LOMAC_FLAG_AUX); 2479 if (error) 2480 return (error); 2481 2482 /* 2483 * To perform a relabel of the vnode (LOMAC label or not), LOMAC must 2484 * authorize the relabel. 2485 */ |
2503 if (!mac_lomac_single_in_range(old, subj)) | 2486 if (!lomac_single_in_range(old, subj)) |
2504 return (EPERM); 2505 2506 /* 2507 * If the LOMAC label is to be changed, authorize as appropriate. 2508 */ 2509 if (new->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 2510 /* 2511 * To change the LOMAC label on a vnode, the new vnode label 2512 * must be in the subject range. 2513 */ | 2487 return (EPERM); 2488 2489 /* 2490 * If the LOMAC label is to be changed, authorize as appropriate. 2491 */ 2492 if (new->ml_flags & MAC_LOMAC_FLAG_SINGLE) { 2493 /* 2494 * To change the LOMAC label on a vnode, the new vnode label 2495 * must be in the subject range. 2496 */ |
2514 if (!mac_lomac_single_in_range(new, subj)) | 2497 if (!lomac_single_in_range(new, subj)) |
2515 return (EPERM); 2516 2517 /* | 2498 return (EPERM); 2499 2500 /* |
2518 * To change the LOMAC label on the vnode to be EQUAL, 2519 * the subject must have appropriate privilege. | 2501 * To change the LOMAC label on the vnode to be EQUAL, the 2502 * subject must have appropriate privilege. |
2520 */ | 2503 */ |
2521 if (mac_lomac_contains_equal(new)) { 2522 error = mac_lomac_subject_privileged(subj); | 2504 if (lomac_contains_equal(new)) { 2505 error = lomac_subject_privileged(subj); |
2523 if (error) 2524 return (error); 2525 } 2526 } 2527 if (new->ml_flags & MAC_LOMAC_FLAG_AUX) { 2528 /* 2529 * Fill in the missing parts from the previous label. 2530 */ 2531 if ((new->ml_flags & MAC_LOMAC_FLAG_SINGLE) == 0) | 2506 if (error) 2507 return (error); 2508 } 2509 } 2510 if (new->ml_flags & MAC_LOMAC_FLAG_AUX) { 2511 /* 2512 * Fill in the missing parts from the previous label. 2513 */ 2514 if ((new->ml_flags & MAC_LOMAC_FLAG_SINGLE) == 0) |
2532 mac_lomac_copy_single(subj, new); | 2515 lomac_copy_single(subj, new); |
2533 2534 /* 2535 * To change the auxiliary LOMAC label on a vnode, the new 2536 * vnode label must be in the subject range. 2537 */ | 2516 2517 /* 2518 * To change the auxiliary LOMAC label on a vnode, the new 2519 * vnode label must be in the subject range. 2520 */ |
2538 if (!mac_lomac_auxsingle_in_range(new, subj)) | 2521 if (!lomac_auxsingle_in_range(new, subj)) |
2539 return (EPERM); 2540 2541 /* 2542 * To change the auxiliary LOMAC label on the vnode to be 2543 * EQUAL, the subject must have appropriate privilege. 2544 */ | 2522 return (EPERM); 2523 2524 /* 2525 * To change the auxiliary LOMAC label on the vnode to be 2526 * EQUAL, the subject must have appropriate privilege. 2527 */ |
2545 if (mac_lomac_contains_equal(new)) { 2546 error = mac_lomac_subject_privileged(subj); | 2528 if (lomac_contains_equal(new)) { 2529 error = lomac_subject_privileged(subj); |
2547 if (error) 2548 return (error); 2549 } 2550 } 2551 2552 return (0); 2553} 2554 2555static int | 2530 if (error) 2531 return (error); 2532 } 2533 } 2534 2535 return (0); 2536} 2537 2538static int |
2556mac_lomac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp, | 2539lomac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp, |
2557 struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2558 struct componentname *cnp) 2559{ 2560 struct mac_lomac *subj, *obj; 2561 | 2540 struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2541 struct componentname *cnp) 2542{ 2543 struct mac_lomac *subj, *obj; 2544 |
2562 if (!mac_lomac_enabled) | 2545 if (!lomac_enabled) |
2563 return (0); 2564 2565 subj = SLOT(cred->cr_label); 2566 obj = SLOT(dvplabel); 2567 | 2546 return (0); 2547 2548 subj = SLOT(cred->cr_label); 2549 obj = SLOT(dvplabel); 2550 |
2568 if (!mac_lomac_subject_dominate(subj, obj)) | 2551 if (!lomac_subject_dominate(subj, obj)) |
2569 return (EACCES); 2570 2571 obj = SLOT(vplabel); 2572 | 2552 return (EACCES); 2553 2554 obj = SLOT(vplabel); 2555 |
2573 if (!mac_lomac_subject_dominate(subj, obj)) | 2556 if (!lomac_subject_dominate(subj, obj)) |
2574 return (EACCES); 2575 2576 return (0); 2577} 2578 2579static int | 2557 return (EACCES); 2558 2559 return (0); 2560} 2561 2562static int |
2580mac_lomac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp, | 2563lomac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp, |
2581 struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2582 int samedir, struct componentname *cnp) 2583{ 2584 struct mac_lomac *subj, *obj; 2585 | 2564 struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2565 int samedir, struct componentname *cnp) 2566{ 2567 struct mac_lomac *subj, *obj; 2568 |
2586 if (!mac_lomac_enabled) | 2569 if (!lomac_enabled) |
2587 return (0); 2588 2589 subj = SLOT(cred->cr_label); 2590 obj = SLOT(dvplabel); 2591 | 2570 return (0); 2571 2572 subj = SLOT(cred->cr_label); 2573 obj = SLOT(dvplabel); 2574 |
2592 if (!mac_lomac_subject_dominate(subj, obj)) | 2575 if (!lomac_subject_dominate(subj, obj)) |
2593 return (EACCES); 2594 2595 if (vp != NULL) { 2596 obj = SLOT(vplabel); 2597 | 2576 return (EACCES); 2577 2578 if (vp != NULL) { 2579 obj = SLOT(vplabel); 2580 |
2598 if (!mac_lomac_subject_dominate(subj, obj)) | 2581 if (!lomac_subject_dominate(subj, obj)) |
2599 return (EACCES); 2600 } 2601 2602 return (0); 2603} 2604 2605static int | 2582 return (EACCES); 2583 } 2584 2585 return (0); 2586} 2587 2588static int |
2606mac_lomac_vnode_check_revoke(struct ucred *cred, struct vnode *vp, | 2589lomac_vnode_check_revoke(struct ucred *cred, struct vnode *vp, |
2607 struct label *vplabel) 2608{ 2609 struct mac_lomac *subj, *obj; 2610 | 2590 struct label *vplabel) 2591{ 2592 struct mac_lomac *subj, *obj; 2593 |
2611 if (!mac_lomac_enabled) | 2594 if (!lomac_enabled) |
2612 return (0); 2613 2614 subj = SLOT(cred->cr_label); 2615 obj = SLOT(vplabel); 2616 | 2595 return (0); 2596 2597 subj = SLOT(cred->cr_label); 2598 obj = SLOT(vplabel); 2599 |
2617 if (!mac_lomac_subject_dominate(subj, obj)) | 2600 if (!lomac_subject_dominate(subj, obj)) |
2618 return (EACCES); 2619 2620 return (0); 2621} 2622 2623static int | 2601 return (EACCES); 2602 2603 return (0); 2604} 2605 2606static int |
2624mac_lomac_vnode_check_setacl(struct ucred *cred, struct vnode *vp, | 2607lomac_vnode_check_setacl(struct ucred *cred, struct vnode *vp, |
2625 struct label *vplabel, acl_type_t type, struct acl *acl) 2626{ 2627 struct mac_lomac *subj, *obj; 2628 | 2608 struct label *vplabel, acl_type_t type, struct acl *acl) 2609{ 2610 struct mac_lomac *subj, *obj; 2611 |
2629 if (!mac_lomac_enabled) | 2612 if (!lomac_enabled) |
2630 return (0); 2631 2632 subj = SLOT(cred->cr_label); 2633 obj = SLOT(vplabel); 2634 | 2613 return (0); 2614 2615 subj = SLOT(cred->cr_label); 2616 obj = SLOT(vplabel); 2617 |
2635 if (!mac_lomac_subject_dominate(subj, obj)) | 2618 if (!lomac_subject_dominate(subj, obj)) |
2636 return (EACCES); 2637 2638 return (0); 2639} 2640 2641static int | 2619 return (EACCES); 2620 2621 return (0); 2622} 2623 2624static int |
2642mac_lomac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp, | 2625lomac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp, |
2643 struct label *vplabel, int attrnamespace, const char *name, 2644 struct uio *uio) 2645{ 2646 struct mac_lomac *subj, *obj; 2647 | 2626 struct label *vplabel, int attrnamespace, const char *name, 2627 struct uio *uio) 2628{ 2629 struct mac_lomac *subj, *obj; 2630 |
2648 if (!mac_lomac_enabled) | 2631 if (!lomac_enabled) |
2649 return (0); 2650 2651 subj = SLOT(cred->cr_label); 2652 obj = SLOT(vplabel); 2653 | 2632 return (0); 2633 2634 subj = SLOT(cred->cr_label); 2635 obj = SLOT(vplabel); 2636 |
2654 if (!mac_lomac_subject_dominate(subj, obj)) | 2637 if (!lomac_subject_dominate(subj, obj)) |
2655 return (EACCES); 2656 2657 /* XXX: protect the MAC EA in a special way? */ 2658 2659 return (0); 2660} 2661 2662static int | 2638 return (EACCES); 2639 2640 /* XXX: protect the MAC EA in a special way? */ 2641 2642 return (0); 2643} 2644 2645static int |
2663mac_lomac_vnode_check_setflags(struct ucred *cred, struct vnode *vp, | 2646lomac_vnode_check_setflags(struct ucred *cred, struct vnode *vp, |
2664 struct label *vplabel, u_long flags) 2665{ 2666 struct mac_lomac *subj, *obj; 2667 | 2647 struct label *vplabel, u_long flags) 2648{ 2649 struct mac_lomac *subj, *obj; 2650 |
2668 if (!mac_lomac_enabled) | 2651 if (!lomac_enabled) |
2669 return (0); 2670 2671 subj = SLOT(cred->cr_label); 2672 obj = SLOT(vplabel); 2673 | 2652 return (0); 2653 2654 subj = SLOT(cred->cr_label); 2655 obj = SLOT(vplabel); 2656 |
2674 if (!mac_lomac_subject_dominate(subj, obj)) | 2657 if (!lomac_subject_dominate(subj, obj)) |
2675 return (EACCES); 2676 2677 return (0); 2678} 2679 2680static int | 2658 return (EACCES); 2659 2660 return (0); 2661} 2662 2663static int |
2681mac_lomac_vnode_check_setmode(struct ucred *cred, struct vnode *vp, | 2664lomac_vnode_check_setmode(struct ucred *cred, struct vnode *vp, |
2682 struct label *vplabel, mode_t mode) 2683{ 2684 struct mac_lomac *subj, *obj; 2685 | 2665 struct label *vplabel, mode_t mode) 2666{ 2667 struct mac_lomac *subj, *obj; 2668 |
2686 if (!mac_lomac_enabled) | 2669 if (!lomac_enabled) |
2687 return (0); 2688 2689 subj = SLOT(cred->cr_label); 2690 obj = SLOT(vplabel); 2691 | 2670 return (0); 2671 2672 subj = SLOT(cred->cr_label); 2673 obj = SLOT(vplabel); 2674 |
2692 if (!mac_lomac_subject_dominate(subj, obj)) | 2675 if (!lomac_subject_dominate(subj, obj)) |
2693 return (EACCES); 2694 2695 return (0); 2696} 2697 2698static int | 2676 return (EACCES); 2677 2678 return (0); 2679} 2680 2681static int |
2699mac_lomac_vnode_check_setowner(struct ucred *cred, struct vnode *vp, | 2682lomac_vnode_check_setowner(struct ucred *cred, struct vnode *vp, |
2700 struct label *vplabel, uid_t uid, gid_t gid) 2701{ 2702 struct mac_lomac *subj, *obj; 2703 | 2683 struct label *vplabel, uid_t uid, gid_t gid) 2684{ 2685 struct mac_lomac *subj, *obj; 2686 |
2704 if (!mac_lomac_enabled) | 2687 if (!lomac_enabled) |
2705 return (0); 2706 2707 subj = SLOT(cred->cr_label); 2708 obj = SLOT(vplabel); 2709 | 2688 return (0); 2689 2690 subj = SLOT(cred->cr_label); 2691 obj = SLOT(vplabel); 2692 |
2710 if (!mac_lomac_subject_dominate(subj, obj)) | 2693 if (!lomac_subject_dominate(subj, obj)) |
2711 return (EACCES); 2712 2713 return (0); 2714} 2715 2716static int | 2694 return (EACCES); 2695 2696 return (0); 2697} 2698 2699static int |
2717mac_lomac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp, | 2700lomac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp, |
2718 struct label *vplabel, struct timespec atime, struct timespec mtime) 2719{ 2720 struct mac_lomac *subj, *obj; 2721 | 2701 struct label *vplabel, struct timespec atime, struct timespec mtime) 2702{ 2703 struct mac_lomac *subj, *obj; 2704 |
2722 if (!mac_lomac_enabled) | 2705 if (!lomac_enabled) |
2723 return (0); 2724 2725 subj = SLOT(cred->cr_label); 2726 obj = SLOT(vplabel); 2727 | 2706 return (0); 2707 2708 subj = SLOT(cred->cr_label); 2709 obj = SLOT(vplabel); 2710 |
2728 if (!mac_lomac_subject_dominate(subj, obj)) | 2711 if (!lomac_subject_dominate(subj, obj)) |
2729 return (EACCES); 2730 2731 return (0); 2732} 2733 2734static int | 2712 return (EACCES); 2713 2714 return (0); 2715} 2716 2717static int |
2735mac_lomac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp, | 2718lomac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp, |
2736 struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2737 struct componentname *cnp) 2738{ 2739 struct mac_lomac *subj, *obj; 2740 | 2719 struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2720 struct componentname *cnp) 2721{ 2722 struct mac_lomac *subj, *obj; 2723 |
2741 if (!mac_lomac_enabled) | 2724 if (!lomac_enabled) |
2742 return (0); 2743 2744 subj = SLOT(cred->cr_label); 2745 obj = SLOT(dvplabel); 2746 | 2725 return (0); 2726 2727 subj = SLOT(cred->cr_label); 2728 obj = SLOT(dvplabel); 2729 |
2747 if (!mac_lomac_subject_dominate(subj, obj)) | 2730 if (!lomac_subject_dominate(subj, obj)) |
2748 return (EACCES); 2749 2750 obj = SLOT(vplabel); 2751 | 2731 return (EACCES); 2732 2733 obj = SLOT(vplabel); 2734 |
2752 if (!mac_lomac_subject_dominate(subj, obj)) | 2735 if (!lomac_subject_dominate(subj, obj)) |
2753 return (EACCES); 2754 2755 return (0); 2756} 2757 2758static int | 2736 return (EACCES); 2737 2738 return (0); 2739} 2740 2741static int |
2759mac_lomac_vnode_check_write(struct ucred *active_cred, | 2742lomac_vnode_check_write(struct ucred *active_cred, |
2760 struct ucred *file_cred, struct vnode *vp, struct label *vplabel) 2761{ 2762 struct mac_lomac *subj, *obj; 2763 | 2743 struct ucred *file_cred, struct vnode *vp, struct label *vplabel) 2744{ 2745 struct mac_lomac *subj, *obj; 2746 |
2764 if (!mac_lomac_enabled || !revocation_enabled) | 2747 if (!lomac_enabled || !revocation_enabled) |
2765 return (0); 2766 2767 subj = SLOT(active_cred->cr_label); 2768 obj = SLOT(vplabel); 2769 | 2748 return (0); 2749 2750 subj = SLOT(active_cred->cr_label); 2751 obj = SLOT(vplabel); 2752 |
2770 if (!mac_lomac_subject_dominate(subj, obj)) | 2753 if (!lomac_subject_dominate(subj, obj)) |
2771 return (EACCES); 2772 2773 return (0); 2774} 2775 2776static void | 2754 return (EACCES); 2755 2756 return (0); 2757} 2758 2759static void |
2777mac_lomac_thread_userret(struct thread *td) | 2760lomac_thread_userret(struct thread *td) |
2778{ 2779 struct proc *p = td->td_proc; 2780 struct mac_lomac_proc *subj = PSLOT(p->p_label); 2781 struct ucred *newcred, *oldcred; 2782 int dodrop; 2783 2784 mtx_lock(&subj->mtx); 2785 if (subj->mac_lomac.ml_flags & MAC_LOMAC_FLAG_UPDATE) { 2786 dodrop = 0; 2787 mtx_unlock(&subj->mtx); 2788 newcred = crget(); 2789 /* 2790 * Prevent a lock order reversal in | 2761{ 2762 struct proc *p = td->td_proc; 2763 struct mac_lomac_proc *subj = PSLOT(p->p_label); 2764 struct ucred *newcred, *oldcred; 2765 int dodrop; 2766 2767 mtx_lock(&subj->mtx); 2768 if (subj->mac_lomac.ml_flags & MAC_LOMAC_FLAG_UPDATE) { 2769 dodrop = 0; 2770 mtx_unlock(&subj->mtx); 2771 newcred = crget(); 2772 /* 2773 * Prevent a lock order reversal in |
2791 * mac_cred_mmapped_drop_perms; ideally, the other 2792 * user of subj->mtx wouldn't be holding Giant. | 2774 * mac_cred_mmapped_drop_perms; ideally, the other user of 2775 * subj->mtx wouldn't be holding Giant. |
2793 */ 2794 mtx_lock(&Giant); 2795 PROC_LOCK(p); 2796 mtx_lock(&subj->mtx); 2797 /* 2798 * Check if we lost the race while allocating the cred. 2799 */ 2800 if ((subj->mac_lomac.ml_flags & MAC_LOMAC_FLAG_UPDATE) == 0) { 2801 crfree(newcred); 2802 goto out; 2803 } 2804 oldcred = p->p_ucred; 2805 crcopy(newcred, oldcred); 2806 crhold(newcred); | 2776 */ 2777 mtx_lock(&Giant); 2778 PROC_LOCK(p); 2779 mtx_lock(&subj->mtx); 2780 /* 2781 * Check if we lost the race while allocating the cred. 2782 */ 2783 if ((subj->mac_lomac.ml_flags & MAC_LOMAC_FLAG_UPDATE) == 0) { 2784 crfree(newcred); 2785 goto out; 2786 } 2787 oldcred = p->p_ucred; 2788 crcopy(newcred, oldcred); 2789 crhold(newcred); |
2807 mac_lomac_copy(&subj->mac_lomac, SLOT(newcred->cr_label)); | 2790 lomac_copy(&subj->mac_lomac, SLOT(newcred->cr_label)); |
2808 p->p_ucred = newcred; 2809 crfree(oldcred); 2810 dodrop = 1; 2811 out: 2812 mtx_unlock(&subj->mtx); 2813 PROC_UNLOCK(p); 2814 if (dodrop) 2815 mac_cred_mmapped_drop_perms(curthread, newcred); 2816 mtx_unlock(&Giant); 2817 } else { 2818 mtx_unlock(&subj->mtx); 2819 } 2820} 2821 | 2791 p->p_ucred = newcred; 2792 crfree(oldcred); 2793 dodrop = 1; 2794 out: 2795 mtx_unlock(&subj->mtx); 2796 PROC_UNLOCK(p); 2797 if (dodrop) 2798 mac_cred_mmapped_drop_perms(curthread, newcred); 2799 mtx_unlock(&Giant); 2800 } else { 2801 mtx_unlock(&subj->mtx); 2802 } 2803} 2804 |
2822static struct mac_policy_ops mac_lomac_ops = | 2805static struct mac_policy_ops lomac_ops = |
2823{ | 2806{ |
2824 .mpo_init = mac_lomac_init, 2825 .mpo_bpfdesc_init_label = mac_lomac_init_label, 2826 .mpo_cred_init_label = mac_lomac_init_label, 2827 .mpo_devfs_init_label = mac_lomac_init_label, 2828 .mpo_ifnet_init_label = mac_lomac_init_label, 2829 .mpo_init_syncache_label = mac_lomac_init_label_waitcheck, 2830 .mpo_inpcb_init_label = mac_lomac_init_label_waitcheck, 2831 .mpo_ipq_init_label = mac_lomac_init_label_waitcheck, 2832 .mpo_mbuf_init_label = mac_lomac_init_label_waitcheck, 2833 .mpo_mount_init_label = mac_lomac_init_label, 2834 .mpo_pipe_init_label = mac_lomac_init_label, 2835 .mpo_proc_init_label = mac_lomac_proc_init_label, 2836 .mpo_socket_init_label = mac_lomac_init_label_waitcheck, 2837 .mpo_socketpeer_init_label = mac_lomac_init_label_waitcheck, 2838 .mpo_vnode_init_label = mac_lomac_init_label, 2839 .mpo_init_syncache_from_inpcb = mac_lomac_init_syncache_from_inpcb, 2840 .mpo_bpfdesc_destroy_label = mac_lomac_destroy_label, 2841 .mpo_cred_destroy_label = mac_lomac_destroy_label, 2842 .mpo_devfs_destroy_label = mac_lomac_destroy_label, 2843 .mpo_ifnet_destroy_label = mac_lomac_destroy_label, 2844 .mpo_inpcb_destroy_label = mac_lomac_destroy_label, 2845 .mpo_ipq_destroy_label = mac_lomac_destroy_label, 2846 .mpo_mbuf_destroy_label = mac_lomac_destroy_label, 2847 .mpo_mount_destroy_label = mac_lomac_destroy_label, 2848 .mpo_pipe_destroy_label = mac_lomac_destroy_label, 2849 .mpo_proc_destroy_label = mac_lomac_proc_destroy_label, 2850 .mpo_destroy_syncache_label = mac_lomac_destroy_label, 2851 .mpo_socket_destroy_label = mac_lomac_destroy_label, 2852 .mpo_socketpeer_destroy_label = mac_lomac_destroy_label, 2853 .mpo_vnode_destroy_label = mac_lomac_destroy_label, 2854 .mpo_cred_copy_label = mac_lomac_copy_label, 2855 .mpo_ifnet_copy_label = mac_lomac_copy_label, 2856 .mpo_mbuf_copy_label = mac_lomac_copy_label, 2857 .mpo_pipe_copy_label = mac_lomac_copy_label, 2858 .mpo_socket_copy_label = mac_lomac_copy_label, 2859 .mpo_vnode_copy_label = mac_lomac_copy_label, 2860 .mpo_cred_externalize_label = mac_lomac_externalize_label, 2861 .mpo_ifnet_externalize_label = mac_lomac_externalize_label, 2862 .mpo_pipe_externalize_label = mac_lomac_externalize_label, 2863 .mpo_socket_externalize_label = mac_lomac_externalize_label, 2864 .mpo_socketpeer_externalize_label = mac_lomac_externalize_label, 2865 .mpo_vnode_externalize_label = mac_lomac_externalize_label, 2866 .mpo_cred_internalize_label = mac_lomac_internalize_label, 2867 .mpo_ifnet_internalize_label = mac_lomac_internalize_label, 2868 .mpo_pipe_internalize_label = mac_lomac_internalize_label, 2869 .mpo_socket_internalize_label = mac_lomac_internalize_label, 2870 .mpo_vnode_internalize_label = mac_lomac_internalize_label, 2871 .mpo_devfs_create_device = mac_lomac_devfs_create_device, 2872 .mpo_devfs_create_directory = mac_lomac_devfs_create_directory, 2873 .mpo_devfs_create_symlink = mac_lomac_devfs_create_symlink, 2874 .mpo_mount_create = mac_lomac_mount_create, 2875 .mpo_vnode_relabel = mac_lomac_vnode_relabel, 2876 .mpo_devfs_update = mac_lomac_devfs_update, 2877 .mpo_devfs_vnode_associate = mac_lomac_devfs_vnode_associate, 2878 .mpo_vnode_associate_extattr = mac_lomac_vnode_associate_extattr, 2879 .mpo_vnode_associate_singlelabel = 2880 mac_lomac_vnode_associate_singlelabel, 2881 .mpo_vnode_create_extattr = mac_lomac_vnode_create_extattr, 2882 .mpo_vnode_setlabel_extattr = mac_lomac_vnode_setlabel_extattr, 2883 .mpo_socket_create_mbuf = mac_lomac_socket_create_mbuf, 2884 .mpo_create_mbuf_from_syncache = mac_lomac_create_mbuf_from_syncache, 2885 .mpo_pipe_create = mac_lomac_pipe_create, 2886 .mpo_socket_create = mac_lomac_socket_create, 2887 .mpo_socket_newconn = mac_lomac_socket_newconn, 2888 .mpo_pipe_relabel = mac_lomac_pipe_relabel, 2889 .mpo_socket_relabel = mac_lomac_socket_relabel, 2890 .mpo_socketpeer_set_from_mbuf = mac_lomac_socketpeer_set_from_mbuf, 2891 .mpo_socketpeer_set_from_socket = 2892 mac_lomac_socketpeer_set_from_socket, 2893 .mpo_bpfdesc_create = mac_lomac_bpfdesc_create, 2894 .mpo_ipq_reassemble = mac_lomac_ipq_reassemble, 2895 .mpo_netinet_fragment = mac_lomac_netinet_fragment, 2896 .mpo_ifnet_create = mac_lomac_ifnet_create, 2897 .mpo_inpcb_create = mac_lomac_inpcb_create, 2898 .mpo_ipq_create = mac_lomac_ipq_create, 2899 .mpo_inpcb_create_mbuf = mac_lomac_inpcb_create_mbuf, 2900 .mpo_create_mbuf_linklayer = mac_lomac_create_mbuf_linklayer, 2901 .mpo_bpfdesc_create_mbuf = mac_lomac_bpfdesc_create_mbuf, 2902 .mpo_ifnet_create_mbuf = mac_lomac_ifnet_create_mbuf, 2903 .mpo_mbuf_create_multicast_encap = 2904 mac_lomac_mbuf_create_multicast_encap, 2905 .mpo_mbuf_create_netlayer = mac_lomac_mbuf_create_netlayer, 2906 .mpo_ipq_match = mac_lomac_ipq_match, 2907 .mpo_ifnet_relabel = mac_lomac_ifnet_relabel, 2908 .mpo_ipq_update = mac_lomac_ipq_update, 2909 .mpo_inpcb_sosetlabel = mac_lomac_inpcb_sosetlabel, 2910 .mpo_vnode_execve_transition = mac_lomac_vnode_execve_transition, | 2807 .mpo_init = lomac_init, 2808 .mpo_bpfdesc_init_label = lomac_init_label, 2809 .mpo_cred_init_label = lomac_init_label, 2810 .mpo_devfs_init_label = lomac_init_label, 2811 .mpo_ifnet_init_label = lomac_init_label, 2812 .mpo_init_syncache_label = lomac_init_label_waitcheck, 2813 .mpo_inpcb_init_label = lomac_init_label_waitcheck, 2814 .mpo_ipq_init_label = lomac_init_label_waitcheck, 2815 .mpo_mbuf_init_label = lomac_init_label_waitcheck, 2816 .mpo_mount_init_label = lomac_init_label, 2817 .mpo_pipe_init_label = lomac_init_label, 2818 .mpo_proc_init_label = lomac_proc_init_label, 2819 .mpo_socket_init_label = lomac_init_label_waitcheck, 2820 .mpo_socketpeer_init_label = lomac_init_label_waitcheck, 2821 .mpo_vnode_init_label = lomac_init_label, 2822 .mpo_init_syncache_from_inpcb = lomac_init_syncache_from_inpcb, 2823 .mpo_bpfdesc_destroy_label = lomac_destroy_label, 2824 .mpo_cred_destroy_label = lomac_destroy_label, 2825 .mpo_devfs_destroy_label = lomac_destroy_label, 2826 .mpo_ifnet_destroy_label = lomac_destroy_label, 2827 .mpo_inpcb_destroy_label = lomac_destroy_label, 2828 .mpo_ipq_destroy_label = lomac_destroy_label, 2829 .mpo_mbuf_destroy_label = lomac_destroy_label, 2830 .mpo_mount_destroy_label = lomac_destroy_label, 2831 .mpo_pipe_destroy_label = lomac_destroy_label, 2832 .mpo_proc_destroy_label = lomac_proc_destroy_label, 2833 .mpo_destroy_syncache_label = lomac_destroy_label, 2834 .mpo_socket_destroy_label = lomac_destroy_label, 2835 .mpo_socketpeer_destroy_label = lomac_destroy_label, 2836 .mpo_vnode_destroy_label = lomac_destroy_label, 2837 .mpo_cred_copy_label = lomac_copy_label, 2838 .mpo_ifnet_copy_label = lomac_copy_label, 2839 .mpo_mbuf_copy_label = lomac_copy_label, 2840 .mpo_pipe_copy_label = lomac_copy_label, 2841 .mpo_socket_copy_label = lomac_copy_label, 2842 .mpo_vnode_copy_label = lomac_copy_label, 2843 .mpo_cred_externalize_label = lomac_externalize_label, 2844 .mpo_ifnet_externalize_label = lomac_externalize_label, 2845 .mpo_pipe_externalize_label = lomac_externalize_label, 2846 .mpo_socket_externalize_label = lomac_externalize_label, 2847 .mpo_socketpeer_externalize_label = lomac_externalize_label, 2848 .mpo_vnode_externalize_label = lomac_externalize_label, 2849 .mpo_cred_internalize_label = lomac_internalize_label, 2850 .mpo_ifnet_internalize_label = lomac_internalize_label, 2851 .mpo_pipe_internalize_label = lomac_internalize_label, 2852 .mpo_socket_internalize_label = lomac_internalize_label, 2853 .mpo_vnode_internalize_label = lomac_internalize_label, 2854 .mpo_devfs_create_device = lomac_devfs_create_device, 2855 .mpo_devfs_create_directory = lomac_devfs_create_directory, 2856 .mpo_devfs_create_symlink = lomac_devfs_create_symlink, 2857 .mpo_mount_create = lomac_mount_create, 2858 .mpo_vnode_relabel = lomac_vnode_relabel, 2859 .mpo_devfs_update = lomac_devfs_update, 2860 .mpo_devfs_vnode_associate = lomac_devfs_vnode_associate, 2861 .mpo_vnode_associate_extattr = lomac_vnode_associate_extattr, 2862 .mpo_vnode_associate_singlelabel = lomac_vnode_associate_singlelabel, 2863 .mpo_vnode_create_extattr = lomac_vnode_create_extattr, 2864 .mpo_vnode_setlabel_extattr = lomac_vnode_setlabel_extattr, 2865 .mpo_socket_create_mbuf = lomac_socket_create_mbuf, 2866 .mpo_create_mbuf_from_syncache = lomac_create_mbuf_from_syncache, 2867 .mpo_pipe_create = lomac_pipe_create, 2868 .mpo_socket_create = lomac_socket_create, 2869 .mpo_socket_newconn = lomac_socket_newconn, 2870 .mpo_pipe_relabel = lomac_pipe_relabel, 2871 .mpo_socket_relabel = lomac_socket_relabel, 2872 .mpo_socketpeer_set_from_mbuf = lomac_socketpeer_set_from_mbuf, 2873 .mpo_socketpeer_set_from_socket = lomac_socketpeer_set_from_socket, 2874 .mpo_bpfdesc_create = lomac_bpfdesc_create, 2875 .mpo_ipq_reassemble = lomac_ipq_reassemble, 2876 .mpo_netinet_fragment = lomac_netinet_fragment, 2877 .mpo_ifnet_create = lomac_ifnet_create, 2878 .mpo_inpcb_create = lomac_inpcb_create, 2879 .mpo_ipq_create = lomac_ipq_create, 2880 .mpo_inpcb_create_mbuf = lomac_inpcb_create_mbuf, 2881 .mpo_create_mbuf_linklayer = lomac_create_mbuf_linklayer, 2882 .mpo_bpfdesc_create_mbuf = lomac_bpfdesc_create_mbuf, 2883 .mpo_ifnet_create_mbuf = lomac_ifnet_create_mbuf, 2884 .mpo_mbuf_create_multicast_encap = lomac_mbuf_create_multicast_encap, 2885 .mpo_mbuf_create_netlayer = lomac_mbuf_create_netlayer, 2886 .mpo_ipq_match = lomac_ipq_match, 2887 .mpo_ifnet_relabel = lomac_ifnet_relabel, 2888 .mpo_ipq_update = lomac_ipq_update, 2889 .mpo_inpcb_sosetlabel = lomac_inpcb_sosetlabel, 2890 .mpo_vnode_execve_transition = lomac_vnode_execve_transition, |
2911 .mpo_vnode_execve_will_transition = | 2891 .mpo_vnode_execve_will_transition = |
2912 mac_lomac_vnode_execve_will_transition, 2913 .mpo_proc_create_swapper = mac_lomac_proc_create_swapper, 2914 .mpo_proc_create_init = mac_lomac_proc_create_init, 2915 .mpo_cred_relabel = mac_lomac_cred_relabel, 2916 .mpo_bpfdesc_check_receive = mac_lomac_bpfdesc_check_receive, 2917 .mpo_cred_check_relabel = mac_lomac_cred_check_relabel, 2918 .mpo_cred_check_visible = mac_lomac_cred_check_visible, 2919 .mpo_ifnet_check_relabel = mac_lomac_ifnet_check_relabel, 2920 .mpo_ifnet_check_transmit = mac_lomac_ifnet_check_transmit, 2921 .mpo_inpcb_check_deliver = mac_lomac_inpcb_check_deliver, 2922 .mpo_kld_check_load = mac_lomac_kld_check_load, 2923 .mpo_pipe_check_ioctl = mac_lomac_pipe_check_ioctl, 2924 .mpo_pipe_check_read = mac_lomac_pipe_check_read, 2925 .mpo_pipe_check_relabel = mac_lomac_pipe_check_relabel, 2926 .mpo_pipe_check_write = mac_lomac_pipe_check_write, 2927 .mpo_proc_check_debug = mac_lomac_proc_check_debug, 2928 .mpo_proc_check_sched = mac_lomac_proc_check_sched, 2929 .mpo_proc_check_signal = mac_lomac_proc_check_signal, 2930 .mpo_socket_check_deliver = mac_lomac_socket_check_deliver, 2931 .mpo_socket_check_relabel = mac_lomac_socket_check_relabel, 2932 .mpo_socket_check_visible = mac_lomac_socket_check_visible, 2933 .mpo_system_check_acct = mac_lomac_system_check_acct, 2934 .mpo_system_check_auditctl = mac_lomac_system_check_auditctl, 2935 .mpo_system_check_swapoff = mac_lomac_system_check_swapoff, 2936 .mpo_system_check_swapon = mac_lomac_system_check_swapon, 2937 .mpo_system_check_sysctl = mac_lomac_system_check_sysctl, 2938 .mpo_vnode_check_access = mac_lomac_vnode_check_open, 2939 .mpo_vnode_check_create = mac_lomac_vnode_check_create, 2940 .mpo_vnode_check_deleteacl = mac_lomac_vnode_check_deleteacl, 2941 .mpo_vnode_check_link = mac_lomac_vnode_check_link, 2942 .mpo_vnode_check_mmap = mac_lomac_vnode_check_mmap, 2943 .mpo_vnode_check_mmap_downgrade = mac_lomac_vnode_check_mmap_downgrade, 2944 .mpo_vnode_check_open = mac_lomac_vnode_check_open, 2945 .mpo_vnode_check_read = mac_lomac_vnode_check_read, 2946 .mpo_vnode_check_relabel = mac_lomac_vnode_check_relabel, 2947 .mpo_vnode_check_rename_from = mac_lomac_vnode_check_rename_from, 2948 .mpo_vnode_check_rename_to = mac_lomac_vnode_check_rename_to, 2949 .mpo_vnode_check_revoke = mac_lomac_vnode_check_revoke, 2950 .mpo_vnode_check_setacl = mac_lomac_vnode_check_setacl, 2951 .mpo_vnode_check_setextattr = mac_lomac_vnode_check_setextattr, 2952 .mpo_vnode_check_setflags = mac_lomac_vnode_check_setflags, 2953 .mpo_vnode_check_setmode = mac_lomac_vnode_check_setmode, 2954 .mpo_vnode_check_setowner = mac_lomac_vnode_check_setowner, 2955 .mpo_vnode_check_setutimes = mac_lomac_vnode_check_setutimes, 2956 .mpo_vnode_check_unlink = mac_lomac_vnode_check_unlink, 2957 .mpo_vnode_check_write = mac_lomac_vnode_check_write, 2958 .mpo_thread_userret = mac_lomac_thread_userret, 2959 .mpo_mbuf_create_from_firewall = mac_lomac_mbuf_create_from_firewall, 2960 .mpo_priv_check = mac_lomac_priv_check, | 2892 lomac_vnode_execve_will_transition, 2893 .mpo_proc_create_swapper = lomac_proc_create_swapper, 2894 .mpo_proc_create_init = lomac_proc_create_init, 2895 .mpo_cred_relabel = lomac_cred_relabel, 2896 .mpo_bpfdesc_check_receive = lomac_bpfdesc_check_receive, 2897 .mpo_cred_check_relabel = lomac_cred_check_relabel, 2898 .mpo_cred_check_visible = lomac_cred_check_visible, 2899 .mpo_ifnet_check_relabel = lomac_ifnet_check_relabel, 2900 .mpo_ifnet_check_transmit = lomac_ifnet_check_transmit, 2901 .mpo_inpcb_check_deliver = lomac_inpcb_check_deliver, 2902 .mpo_kld_check_load = lomac_kld_check_load, 2903 .mpo_pipe_check_ioctl = lomac_pipe_check_ioctl, 2904 .mpo_pipe_check_read = lomac_pipe_check_read, 2905 .mpo_pipe_check_relabel = lomac_pipe_check_relabel, 2906 .mpo_pipe_check_write = lomac_pipe_check_write, 2907 .mpo_proc_check_debug = lomac_proc_check_debug, 2908 .mpo_proc_check_sched = lomac_proc_check_sched, 2909 .mpo_proc_check_signal = lomac_proc_check_signal, 2910 .mpo_socket_check_deliver = lomac_socket_check_deliver, 2911 .mpo_socket_check_relabel = lomac_socket_check_relabel, 2912 .mpo_socket_check_visible = lomac_socket_check_visible, 2913 .mpo_system_check_acct = lomac_system_check_acct, 2914 .mpo_system_check_auditctl = lomac_system_check_auditctl, 2915 .mpo_system_check_swapoff = lomac_system_check_swapoff, 2916 .mpo_system_check_swapon = lomac_system_check_swapon, 2917 .mpo_system_check_sysctl = lomac_system_check_sysctl, 2918 .mpo_vnode_check_access = lomac_vnode_check_open, 2919 .mpo_vnode_check_create = lomac_vnode_check_create, 2920 .mpo_vnode_check_deleteacl = lomac_vnode_check_deleteacl, 2921 .mpo_vnode_check_link = lomac_vnode_check_link, 2922 .mpo_vnode_check_mmap = lomac_vnode_check_mmap, 2923 .mpo_vnode_check_mmap_downgrade = lomac_vnode_check_mmap_downgrade, 2924 .mpo_vnode_check_open = lomac_vnode_check_open, 2925 .mpo_vnode_check_read = lomac_vnode_check_read, 2926 .mpo_vnode_check_relabel = lomac_vnode_check_relabel, 2927 .mpo_vnode_check_rename_from = lomac_vnode_check_rename_from, 2928 .mpo_vnode_check_rename_to = lomac_vnode_check_rename_to, 2929 .mpo_vnode_check_revoke = lomac_vnode_check_revoke, 2930 .mpo_vnode_check_setacl = lomac_vnode_check_setacl, 2931 .mpo_vnode_check_setextattr = lomac_vnode_check_setextattr, 2932 .mpo_vnode_check_setflags = lomac_vnode_check_setflags, 2933 .mpo_vnode_check_setmode = lomac_vnode_check_setmode, 2934 .mpo_vnode_check_setowner = lomac_vnode_check_setowner, 2935 .mpo_vnode_check_setutimes = lomac_vnode_check_setutimes, 2936 .mpo_vnode_check_unlink = lomac_vnode_check_unlink, 2937 .mpo_vnode_check_write = lomac_vnode_check_write, 2938 .mpo_thread_userret = lomac_thread_userret, 2939 .mpo_mbuf_create_from_firewall = lomac_mbuf_create_from_firewall, 2940 .mpo_priv_check = lomac_priv_check, |
2961}; 2962 | 2941}; 2942 |
2963MAC_POLICY_SET(&mac_lomac_ops, mac_lomac, "TrustedBSD MAC/LOMAC", | 2943MAC_POLICY_SET(&lomac_ops, mac_lomac, "TrustedBSD MAC/LOMAC", |
2964 MPC_LOADTIME_FLAG_NOTLATE | MPC_LOADTIME_FLAG_LABELMBUFS, | 2944 MPC_LOADTIME_FLAG_NOTLATE | MPC_LOADTIME_FLAG_LABELMBUFS, |
2965 &mac_lomac_slot); | 2945 &lomac_slot); |