ugidfw_system.c revision 166531
1/*- 2 * Copyright (c) 2005 Tom Rhodes 3 * Copyright (c) 1999-2002 Robert N. M. Watson 4 * Copyright (c) 2001-2005 Networks Associates Technology, Inc. 5 * All rights reserved. 6 * 7 * This software was developed by Robert Watson for the TrustedBSD Project. 8 * It was later enhanced by Tom Rhodes for the TrustedBSD Project. 9 * 10 * This software was developed for the FreeBSD Project in part by Network 11 * Associates Laboratories, the Security Research Division of Network 12 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), 13 * as part of the DARPA CHATS research program. 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * $FreeBSD: head/sys/security/mac_bsdextended/mac_bsdextended.c 166531 2007-02-06 10:59:23Z rwatson $ 37 */ 38 39/* 40 * Developed by the TrustedBSD Project. 41 * "BSD Extended" MAC policy, allowing the administrator to impose 42 * mandatory rules regarding users and some system objects. 43 */ 44 45#include <sys/types.h> 46#include <sys/param.h> 47#include <sys/acl.h> 48#include <sys/conf.h> 49#include <sys/kernel.h> 50#include <sys/jail.h> 51#include <sys/lock.h> 52#include <sys/malloc.h> 53#include <sys/mount.h> 54#include <sys/mutex.h> 55#include <sys/proc.h> 56#include <sys/systm.h> 57#include <sys/sysproto.h> 58#include <sys/sysent.h> 59#include <sys/vnode.h> 60#include <sys/file.h> 61#include <sys/socket.h> 62#include <sys/socketvar.h> 63#include <sys/sysctl.h> 64#include <sys/syslog.h> 65#include <sys/ucred.h> 66 67#include <net/bpfdesc.h> 68#include <net/if.h> 69#include <net/if_types.h> 70#include <net/if_var.h> 71 72#include <vm/vm.h> 73 74#include <security/mac/mac_policy.h> 75#include <security/mac_bsdextended/mac_bsdextended.h> 76 77static struct mtx mac_bsdextended_mtx; 78 79SYSCTL_DECL(_security_mac); 80 81SYSCTL_NODE(_security_mac, OID_AUTO, bsdextended, CTLFLAG_RW, 0, 82 "TrustedBSD extended BSD MAC policy controls"); 83 84static int mac_bsdextended_enabled = 1; 85SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, enabled, CTLFLAG_RW, 86 &mac_bsdextended_enabled, 0, "Enforce extended BSD policy"); 87TUNABLE_INT("security.mac.bsdextended.enabled", &mac_bsdextended_enabled); 88 89MALLOC_DEFINE(M_MACBSDEXTENDED, "mac_bsdextended", "BSD Extended MAC rule"); 90 91#define MAC_BSDEXTENDED_MAXRULES 250 92static struct mac_bsdextended_rule *rules[MAC_BSDEXTENDED_MAXRULES]; 93static int rule_count = 0; 94static int rule_slots = 0; 95static int rule_version = MB_VERSION; 96 97SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, rule_count, CTLFLAG_RD, 98 &rule_count, 0, "Number of defined rules\n"); 99SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, rule_slots, CTLFLAG_RD, 100 &rule_slots, 0, "Number of used rule slots\n"); 101SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, rule_version, CTLFLAG_RD, 102 &rule_version, 0, "Version number for API\n"); 103 104/* 105 * This is just used for logging purposes, eventually we would like 106 * to log much more then failed requests. 107 */ 108static int mac_bsdextended_logging; 109SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, logging, CTLFLAG_RW, 110 &mac_bsdextended_logging, 0, "Log failed authorization requests"); 111 112/* 113 * This tunable is here for compatibility. It will allow the user 114 * to switch between the new mode (first rule matches) and the old 115 * functionality (all rules match). 116 */ 117static int 118mac_bsdextended_firstmatch_enabled; 119SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, firstmatch_enabled, 120 CTLFLAG_RW, &mac_bsdextended_firstmatch_enabled, 1, 121 "Disable/enable match first rule functionality"); 122 123static int 124mac_bsdextended_rule_valid(struct mac_bsdextended_rule *rule) 125{ 126 127 if ((rule->mbr_subject.mbs_flags | MBS_ALL_FLAGS) != MBS_ALL_FLAGS) 128 return (EINVAL); 129 130 if ((rule->mbr_subject.mbs_neg | MBS_ALL_FLAGS) != MBS_ALL_FLAGS) 131 return (EINVAL); 132 133 if ((rule->mbr_object.mbo_flags | MBO_ALL_FLAGS) != MBO_ALL_FLAGS) 134 return (EINVAL); 135 136 if ((rule->mbr_object.mbo_neg | MBO_ALL_FLAGS) != MBO_ALL_FLAGS) 137 return (EINVAL); 138 139 if ((rule->mbr_object.mbo_neg | MBO_TYPE_DEFINED) && 140 (rule->mbr_object.mbo_type | MBO_ALL_TYPE) != MBO_ALL_TYPE) 141 return (EINVAL); 142 143 if ((rule->mbr_mode | MBI_ALLPERM) != MBI_ALLPERM) 144 return (EINVAL); 145 146 return (0); 147} 148 149static int 150sysctl_rule(SYSCTL_HANDLER_ARGS) 151{ 152 struct mac_bsdextended_rule temprule, *ruleptr; 153 u_int namelen; 154 int error, index, *name; 155 156 error = 0; 157 name = (int *)arg1; 158 namelen = arg2; 159 160 /* printf("bsdextended sysctl handler (namelen %d)\n", namelen); */ 161 162 if (namelen != 1) 163 return (EINVAL); 164 165 index = name[0]; 166 if (index >= MAC_BSDEXTENDED_MAXRULES) 167 return (ENOENT); 168 169 ruleptr = NULL; 170 if (req->newptr && req->newlen != 0) { 171 error = SYSCTL_IN(req, &temprule, sizeof(temprule)); 172 if (error) 173 return (error); 174 MALLOC(ruleptr, struct mac_bsdextended_rule *, 175 sizeof(*ruleptr), M_MACBSDEXTENDED, M_WAITOK | M_ZERO); 176 } 177 178 mtx_lock(&mac_bsdextended_mtx); 179 180 if (req->oldptr) { 181 if (index < 0 || index > rule_slots + 1) { 182 error = ENOENT; 183 goto out; 184 } 185 if (rules[index] == NULL) { 186 error = ENOENT; 187 goto out; 188 } 189 temprule = *rules[index]; 190 } 191 192 if (req->newptr && req->newlen == 0) { 193 /* printf("deletion\n"); */ 194 KASSERT(ruleptr == NULL, ("sysctl_rule: ruleptr != NULL")); 195 ruleptr = rules[index]; 196 if (ruleptr == NULL) { 197 error = ENOENT; 198 goto out; 199 } 200 rule_count--; 201 rules[index] = NULL; 202 } else if (req->newptr) { 203 error = mac_bsdextended_rule_valid(&temprule); 204 if (error) 205 goto out; 206 207 if (rules[index] == NULL) { 208 /* printf("addition\n"); */ 209 *ruleptr = temprule; 210 rules[index] = ruleptr; 211 ruleptr = NULL; 212 if (index + 1 > rule_slots) 213 rule_slots = index + 1; 214 rule_count++; 215 } else { 216 /* printf("replacement\n"); */ 217 *rules[index] = temprule; 218 } 219 } 220 221out: 222 mtx_unlock(&mac_bsdextended_mtx); 223 if (ruleptr != NULL) 224 FREE(ruleptr, M_MACBSDEXTENDED); 225 if (req->oldptr && error == 0) 226 error = SYSCTL_OUT(req, &temprule, sizeof(temprule)); 227 228 return (error); 229} 230 231SYSCTL_NODE(_security_mac_bsdextended, OID_AUTO, rules, 232 CTLFLAG_RW, sysctl_rule, "BSD extended MAC rules"); 233 234static void 235mac_bsdextended_init(struct mac_policy_conf *mpc) 236{ 237 238 /* Initialize ruleset lock. */ 239 mtx_init(&mac_bsdextended_mtx, "mac_bsdextended lock", NULL, MTX_DEF); 240 241 /* Register dynamic sysctl's for rules. */ 242} 243 244static void 245mac_bsdextended_destroy(struct mac_policy_conf *mpc) 246{ 247 248 /* Destroy ruleset lock. */ 249 mtx_destroy(&mac_bsdextended_mtx); 250 251 /* Tear down sysctls. */ 252} 253 254static int 255mac_bsdextended_rulecheck(struct mac_bsdextended_rule *rule, 256 struct ucred *cred, struct vnode *vp, struct vattr *vap, int acc_mode) 257{ 258 int match; 259 int i; 260 261 /* 262 * Is there a subject match? 263 */ 264 mtx_assert(&mac_bsdextended_mtx, MA_OWNED); 265 if (rule->mbr_subject.mbs_flags & MBS_UID_DEFINED) { 266 match = ((cred->cr_uid <= rule->mbr_subject.mbs_uid_max && 267 cred->cr_uid >= rule->mbr_subject.mbs_uid_min) || 268 (cred->cr_ruid <= rule->mbr_subject.mbs_uid_max && 269 cred->cr_ruid >= rule->mbr_subject.mbs_uid_min) || 270 (cred->cr_svuid <= rule->mbr_subject.mbs_uid_max && 271 cred->cr_svuid >= rule->mbr_subject.mbs_uid_min)); 272 273 if (rule->mbr_subject.mbs_neg & MBS_UID_DEFINED) 274 match = !match; 275 276 if (!match) 277 return (0); 278 } 279 280 if (rule->mbr_subject.mbs_flags & MBS_GID_DEFINED) { 281 match = ((cred->cr_rgid <= rule->mbr_subject.mbs_gid_max && 282 cred->cr_rgid >= rule->mbr_subject.mbs_gid_min) || 283 (cred->cr_svgid <= rule->mbr_subject.mbs_gid_max && 284 cred->cr_svgid >= rule->mbr_subject.mbs_gid_min)); 285 286 if (!match) { 287 for (i = 0; i < cred->cr_ngroups; i++) 288 if (cred->cr_groups[i] 289 <= rule->mbr_subject.mbs_gid_max && 290 cred->cr_groups[i] 291 >= rule->mbr_subject.mbs_gid_min) { 292 match = 1; 293 break; 294 } 295 } 296 297 if (rule->mbr_subject.mbs_neg & MBS_GID_DEFINED) 298 match = !match; 299 300 if (!match) 301 return (0); 302 } 303 304 if (rule->mbr_subject.mbs_flags & MBS_PRISON_DEFINED) { 305 match = (cred->cr_prison != NULL && 306 cred->cr_prison->pr_id == rule->mbr_subject.mbs_prison); 307 308 if (rule->mbr_subject.mbs_neg & MBS_PRISON_DEFINED) 309 match = !match; 310 311 if (!match) 312 return (0); 313 } 314 315 /* 316 * Is there an object match? 317 */ 318 if (rule->mbr_object.mbo_flags & MBO_UID_DEFINED) { 319 match = (vap->va_uid <= rule->mbr_object.mbo_uid_max && 320 vap->va_uid >= rule->mbr_object.mbo_uid_min); 321 322 if (rule->mbr_object.mbo_neg & MBO_UID_DEFINED) 323 match = !match; 324 325 if (!match) 326 return (0); 327 } 328 329 if (rule->mbr_object.mbo_flags & MBO_GID_DEFINED) { 330 match = (vap->va_gid <= rule->mbr_object.mbo_gid_max && 331 vap->va_gid >= rule->mbr_object.mbo_gid_min); 332 333 if (rule->mbr_object.mbo_neg & MBO_GID_DEFINED) 334 match = !match; 335 336 if (!match) 337 return (0); 338 } 339 340 if (rule->mbr_object.mbo_flags & MBO_FSID_DEFINED) { 341 match = (bcmp(&(vp->v_mount->mnt_stat.f_fsid), 342 &(rule->mbr_object.mbo_fsid), 343 sizeof(rule->mbr_object.mbo_fsid)) == 0); 344 345 if (rule->mbr_object.mbo_neg & MBO_FSID_DEFINED) 346 match = !match; 347 348 if (!match) 349 return 0; 350 } 351 352 if (rule->mbr_object.mbo_flags & MBO_SUID) { 353 match = (vap->va_mode & VSUID); 354 355 if (rule->mbr_object.mbo_neg & MBO_SUID) 356 match = !match; 357 358 if (!match) 359 return 0; 360 } 361 362 if (rule->mbr_object.mbo_flags & MBO_SGID) { 363 match = (vap->va_mode & VSGID); 364 365 if (rule->mbr_object.mbo_neg & MBO_SGID) 366 match = !match; 367 368 if (!match) 369 return 0; 370 } 371 372 if (rule->mbr_object.mbo_flags & MBO_UID_SUBJECT) { 373 match = (vap->va_uid == cred->cr_uid || 374 vap->va_uid == cred->cr_ruid || 375 vap->va_uid == cred->cr_svuid); 376 377 if (rule->mbr_object.mbo_neg & MBO_UID_SUBJECT) 378 match = !match; 379 380 if (!match) 381 return 0; 382 } 383 384 if (rule->mbr_object.mbo_flags & MBO_GID_SUBJECT) { 385 match = (groupmember(vap->va_gid, cred) || 386 vap->va_gid == cred->cr_rgid || 387 vap->va_gid == cred->cr_svgid); 388 389 if (rule->mbr_object.mbo_neg & MBO_GID_SUBJECT) 390 match = !match; 391 392 if (!match) 393 return 0; 394 } 395 396 if (rule->mbr_object.mbo_flags & MBO_TYPE_DEFINED) { 397 switch (vap->va_type) { 398 case VREG: 399 match = (rule->mbr_object.mbo_type & MBO_TYPE_REG); 400 break; 401 case VDIR: 402 match = (rule->mbr_object.mbo_type & MBO_TYPE_DIR); 403 break; 404 case VBLK: 405 match = (rule->mbr_object.mbo_type & MBO_TYPE_BLK); 406 break; 407 case VCHR: 408 match = (rule->mbr_object.mbo_type & MBO_TYPE_CHR); 409 break; 410 case VLNK: 411 match = (rule->mbr_object.mbo_type & MBO_TYPE_LNK); 412 break; 413 case VSOCK: 414 match = (rule->mbr_object.mbo_type & MBO_TYPE_SOCK); 415 break; 416 case VFIFO: 417 match = (rule->mbr_object.mbo_type & MBO_TYPE_FIFO); 418 break; 419 default: 420 match = 0; 421 } 422 423 if (rule->mbr_object.mbo_neg & MBO_TYPE_DEFINED) 424 match = !match; 425 426 if (!match) 427 return 0; 428 } 429 430 /* 431 * Is the access permitted? 432 */ 433 if ((rule->mbr_mode & acc_mode) != acc_mode) { 434 if (mac_bsdextended_logging) 435 log(LOG_AUTHPRIV, "mac_bsdextended: %d:%d request %d" 436 " on %d:%d failed. \n", cred->cr_ruid, 437 cred->cr_rgid, acc_mode, vap->va_uid, vap->va_gid); 438 return (EACCES); /* Matching rule denies access */ 439 } 440 441 /* 442 * If the rule matched, permits access, and first match is enabled, 443 * return success. 444 */ 445 if (mac_bsdextended_firstmatch_enabled) 446 return (EJUSTRETURN); 447 else 448 return(0); 449} 450 451static int 452mac_bsdextended_check(struct ucred *cred, struct vnode *vp, struct vattr *vap, 453 int acc_mode) 454{ 455 int error, i; 456 457 /* 458 * XXXRW: More specific privilege selection needed? 459 */ 460 if (suser_cred(cred, 0) == 0) 461 return (0); 462 463 mtx_lock(&mac_bsdextended_mtx); 464 for (i = 0; i < rule_slots; i++) { 465 if (rules[i] == NULL) 466 continue; 467 468 /* 469 * Since we do not separately handle append, map append to 470 * write. 471 */ 472 if (acc_mode & MBI_APPEND) { 473 acc_mode &= ~MBI_APPEND; 474 acc_mode |= MBI_WRITE; 475 } 476 477 error = mac_bsdextended_rulecheck(rules[i], cred, 478 vp, vap, acc_mode); 479 if (error == EJUSTRETURN) 480 break; 481 if (error) { 482 mtx_unlock(&mac_bsdextended_mtx); 483 return (error); 484 } 485 } 486 mtx_unlock(&mac_bsdextended_mtx); 487 return (0); 488} 489 490static int 491mac_bsdextended_check_vp(struct ucred *cred, struct vnode *vp, int acc_mode) 492{ 493 int error; 494 struct vattr vap; 495 496 if (!mac_bsdextended_enabled) 497 return (0); 498 499 error = VOP_GETATTR(vp, &vap, cred, curthread); 500 if (error) 501 return (error); 502 503 return (mac_bsdextended_check(cred, vp, &vap, acc_mode)); 504} 505 506static int 507mac_bsdextended_check_system_swapon(struct ucred *cred, struct vnode *vp, 508 struct label *label) 509{ 510 511 return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE)); 512} 513 514static int 515mac_bsdextended_check_vnode_access(struct ucred *cred, struct vnode *vp, 516 struct label *label, int acc_mode) 517{ 518 519 return (mac_bsdextended_check_vp(cred, vp, acc_mode)); 520} 521 522static int 523mac_bsdextended_check_vnode_chdir(struct ucred *cred, struct vnode *dvp, 524 struct label *dlabel) 525{ 526 527 return (mac_bsdextended_check_vp(cred, dvp, MBI_EXEC)); 528} 529 530static int 531mac_bsdextended_check_vnode_chroot(struct ucred *cred, struct vnode *dvp, 532 struct label *dlabel) 533{ 534 535 return (mac_bsdextended_check_vp(cred, dvp, MBI_EXEC)); 536} 537 538static int 539mac_bsdextended_check_create_vnode(struct ucred *cred, struct vnode *dvp, 540 struct label *dlabel, struct componentname *cnp, struct vattr *vap) 541{ 542 543 return (mac_bsdextended_check_vp(cred, dvp, MBI_WRITE)); 544} 545 546static int 547mac_bsdextended_check_vnode_delete(struct ucred *cred, struct vnode *dvp, 548 struct label *dlabel, struct vnode *vp, struct label *label, 549 struct componentname *cnp) 550{ 551 int error; 552 553 error = mac_bsdextended_check_vp(cred, dvp, MBI_WRITE); 554 if (error) 555 return (error); 556 557 return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE)); 558} 559 560static int 561mac_bsdextended_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, 562 struct label *label, acl_type_t type) 563{ 564 565 return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN)); 566} 567 568static int 569mac_bsdextended_check_vnode_deleteextattr(struct ucred *cred, struct vnode *vp, 570 struct label *label, int attrnamespace, const char *name) 571{ 572 573 return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE)); 574} 575 576static int 577mac_bsdextended_check_vnode_exec(struct ucred *cred, struct vnode *vp, 578 struct label *label, struct image_params *imgp, 579 struct label *execlabel) 580{ 581 582 return (mac_bsdextended_check_vp(cred, vp, MBI_READ|MBI_EXEC)); 583} 584 585static int 586mac_bsdextended_check_vnode_getacl(struct ucred *cred, struct vnode *vp, 587 struct label *label, acl_type_t type) 588{ 589 590 return (mac_bsdextended_check_vp(cred, vp, MBI_STAT)); 591} 592 593static int 594mac_bsdextended_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, 595 struct label *label, int attrnamespace, const char *name, struct uio *uio) 596{ 597 598 return (mac_bsdextended_check_vp(cred, vp, MBI_READ)); 599} 600 601static int 602mac_bsdextended_check_vnode_link(struct ucred *cred, struct vnode *dvp, 603 struct label *dlabel, struct vnode *vp, struct label *label, 604 struct componentname *cnp) 605{ 606 int error; 607 608 error = mac_bsdextended_check_vp(cred, dvp, MBI_WRITE); 609 if (error) 610 return (error); 611 612 error = mac_bsdextended_check_vp(cred, vp, MBI_WRITE); 613 if (error) 614 return (error); 615 return (0); 616} 617 618static int 619mac_bsdextended_check_vnode_listextattr(struct ucred *cred, struct vnode *vp, 620 struct label *label, int attrnamespace) 621{ 622 623 return (mac_bsdextended_check_vp(cred, vp, MBI_READ)); 624} 625 626static int 627mac_bsdextended_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, 628 struct label *dlabel, struct componentname *cnp) 629{ 630 631 return (mac_bsdextended_check_vp(cred, dvp, MBI_EXEC)); 632} 633 634static int 635mac_bsdextended_check_vnode_open(struct ucred *cred, struct vnode *vp, 636 struct label *filelabel, int acc_mode) 637{ 638 639 return (mac_bsdextended_check_vp(cred, vp, acc_mode)); 640} 641 642static int 643mac_bsdextended_check_vnode_readdir(struct ucred *cred, struct vnode *dvp, 644 struct label *dlabel) 645{ 646 647 return (mac_bsdextended_check_vp(cred, dvp, MBI_READ)); 648} 649 650static int 651mac_bsdextended_check_vnode_readdlink(struct ucred *cred, struct vnode *vp, 652 struct label *label) 653{ 654 655 return (mac_bsdextended_check_vp(cred, vp, MBI_READ)); 656} 657 658static int 659mac_bsdextended_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, 660 struct label *dlabel, struct vnode *vp, struct label *label, 661 struct componentname *cnp) 662{ 663 int error; 664 665 error = mac_bsdextended_check_vp(cred, dvp, MBI_WRITE); 666 if (error) 667 return (error); 668 error = mac_bsdextended_check_vp(cred, vp, MBI_WRITE); 669 670 return (error); 671} 672 673static int 674mac_bsdextended_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, 675 struct label *dlabel, struct vnode *vp, struct label *label, int samedir, 676 struct componentname *cnp) 677{ 678 int error; 679 680 error = mac_bsdextended_check_vp(cred, dvp, MBI_WRITE); 681 if (error) 682 return (error); 683 684 if (vp != NULL) 685 error = mac_bsdextended_check_vp(cred, vp, MBI_WRITE); 686 687 return (error); 688} 689 690static int 691mac_bsdextended_check_vnode_revoke(struct ucred *cred, struct vnode *vp, 692 struct label *label) 693{ 694 695 return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN)); 696} 697 698static int 699mac_bsdextended_check_setacl_vnode(struct ucred *cred, struct vnode *vp, 700 struct label *label, acl_type_t type, struct acl *acl) 701{ 702 703 return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN)); 704} 705 706static int 707mac_bsdextended_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, 708 struct label *label, int attrnamespace, const char *name, struct uio *uio) 709{ 710 711 return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE)); 712} 713 714static int 715mac_bsdextended_check_vnode_setflags(struct ucred *cred, struct vnode *vp, 716 struct label *label, u_long flags) 717{ 718 719 return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN)); 720} 721 722static int 723mac_bsdextended_check_vnode_setmode(struct ucred *cred, struct vnode *vp, 724 struct label *label, mode_t mode) 725{ 726 727 return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN)); 728} 729 730static int 731mac_bsdextended_check_vnode_setowner(struct ucred *cred, struct vnode *vp, 732 struct label *label, uid_t uid, gid_t gid) 733{ 734 735 return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN)); 736} 737 738static int 739mac_bsdextended_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, 740 struct label *label, struct timespec atime, struct timespec utime) 741{ 742 743 return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN)); 744} 745 746static int 747mac_bsdextended_check_vnode_stat(struct ucred *active_cred, 748 struct ucred *file_cred, struct vnode *vp, struct label *label) 749{ 750 751 return (mac_bsdextended_check_vp(active_cred, vp, MBI_STAT)); 752} 753 754static struct mac_policy_ops mac_bsdextended_ops = 755{ 756 .mpo_destroy = mac_bsdextended_destroy, 757 .mpo_init = mac_bsdextended_init, 758 .mpo_check_system_swapon = mac_bsdextended_check_system_swapon, 759 .mpo_check_vnode_access = mac_bsdextended_check_vnode_access, 760 .mpo_check_vnode_chdir = mac_bsdextended_check_vnode_chdir, 761 .mpo_check_vnode_chroot = mac_bsdextended_check_vnode_chroot, 762 .mpo_check_vnode_create = mac_bsdextended_check_create_vnode, 763 .mpo_check_vnode_delete = mac_bsdextended_check_vnode_delete, 764 .mpo_check_vnode_deleteacl = mac_bsdextended_check_vnode_deleteacl, 765 .mpo_check_vnode_deleteextattr = mac_bsdextended_check_vnode_deleteextattr, 766 .mpo_check_vnode_exec = mac_bsdextended_check_vnode_exec, 767 .mpo_check_vnode_getacl = mac_bsdextended_check_vnode_getacl, 768 .mpo_check_vnode_getextattr = mac_bsdextended_check_vnode_getextattr, 769 .mpo_check_vnode_link = mac_bsdextended_check_vnode_link, 770 .mpo_check_vnode_listextattr = mac_bsdextended_check_vnode_listextattr, 771 .mpo_check_vnode_lookup = mac_bsdextended_check_vnode_lookup, 772 .mpo_check_vnode_open = mac_bsdextended_check_vnode_open, 773 .mpo_check_vnode_readdir = mac_bsdextended_check_vnode_readdir, 774 .mpo_check_vnode_readlink = mac_bsdextended_check_vnode_readdlink, 775 .mpo_check_vnode_rename_from = mac_bsdextended_check_vnode_rename_from, 776 .mpo_check_vnode_rename_to = mac_bsdextended_check_vnode_rename_to, 777 .mpo_check_vnode_revoke = mac_bsdextended_check_vnode_revoke, 778 .mpo_check_vnode_setacl = mac_bsdextended_check_setacl_vnode, 779 .mpo_check_vnode_setextattr = mac_bsdextended_check_vnode_setextattr, 780 .mpo_check_vnode_setflags = mac_bsdextended_check_vnode_setflags, 781 .mpo_check_vnode_setmode = mac_bsdextended_check_vnode_setmode, 782 .mpo_check_vnode_setowner = mac_bsdextended_check_vnode_setowner, 783 .mpo_check_vnode_setutimes = mac_bsdextended_check_vnode_setutimes, 784 .mpo_check_vnode_stat = mac_bsdextended_check_vnode_stat, 785}; 786 787MAC_POLICY_SET(&mac_bsdextended_ops, mac_bsdextended, 788 "TrustedBSD MAC/BSD Extended", MPC_LOADTIME_FLAG_UNLOADOK, NULL); 789