8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / uts / common / os / policy.c
blobd6821c83b05a03adfae36932bd21261856ea613c
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2016 Joyent, Inc.
24 * Copyright (c) 2016 by Delphix. All rights reserved.
27 #include <sys/types.h>
28 #include <sys/sysmacros.h>
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/cred_impl.h>
32 #include <sys/vnode.h>
33 #include <sys/vfs.h>
34 #include <sys/stat.h>
35 #include <sys/errno.h>
36 #include <sys/kmem.h>
37 #include <sys/user.h>
38 #include <sys/proc.h>
39 #include <sys/acct.h>
40 #include <sys/ipc_impl.h>
41 #include <sys/cmn_err.h>
42 #include <sys/debug.h>
43 #include <sys/policy.h>
44 #include <sys/kobj.h>
45 #include <sys/msg.h>
46 #include <sys/devpolicy.h>
47 #include <c2/audit.h>
48 #include <sys/varargs.h>
49 #include <sys/klpd.h>
50 #include <sys/modctl.h>
51 #include <sys/disp.h>
52 #include <sys/zone.h>
53 #include <inet/optcom.h>
54 #include <sys/sdt.h>
55 #include <sys/vfs.h>
56 #include <sys/mntent.h>
57 #include <sys/contract_impl.h>
58 #include <sys/dld_ioc.h>
61 * There are two possible layers of privilege routines and two possible
62 * levels of secpolicy. Plus one other we may not be interested in, so
63 * we may need as many as 6 but no more.
65 #define MAXPRIVSTACK 6
67 int priv_debug = 0;
68 int priv_basic_test = -1;
71 * This file contains the majority of the policy routines.
72 * Since the policy routines are defined by function and not
73 * by privilege, there is quite a bit of duplication of
74 * functions.
76 * The secpolicy functions must not make assumptions about
77 * locks held or not held as any lock can be held while they're
78 * being called.
80 * Credentials are read-only so no special precautions need to
81 * be taken while locking them.
83 * When a new policy check needs to be added to the system the
84 * following procedure should be followed:
86 * Pick an appropriate secpolicy_*() function
87 * -> done if one exists.
88 * Create a new secpolicy function, preferably with
89 * a descriptive name using the standard template.
90 * Pick an appropriate privilege for the policy.
91 * If no appropraite privilege exists, define new one
92 * (this should be done with extreme care; in most cases
93 * little is gained by adding another privilege)
95 * WHY ROOT IS STILL SPECIAL.
97 * In a number of the policy functions, there are still explicit
98 * checks for uid 0. The rationale behind these is that many root
99 * owned files/objects hold configuration information which can give full
100 * privileges to the user once written to. To prevent escalation
101 * of privilege by allowing just a single privilege to modify root owned
102 * objects, we've added these root specific checks where we considered
103 * them necessary: modifying root owned files, changing uids to 0, etc.
105 * PRIVILEGE ESCALATION AND ZONES.
107 * A number of operations potentially allow the caller to achieve
108 * privileges beyond the ones normally required to perform the operation.
109 * For example, if allowed to create a setuid 0 executable, a process can
110 * gain privileges beyond PRIV_FILE_SETID. Zones, however, place
111 * restrictions on the ability to gain privileges beyond those available
112 * within the zone through file and process manipulation. Hence, such
113 * operations require that the caller have an effective set that includes
114 * all privileges available within the current zone, or all privileges
115 * if executing in the global zone.
117 * This is indicated in the priv_policy* policy checking functions
118 * through a combination of parameters. The "priv" parameter indicates
119 * the privilege that is required, and the "allzone" parameter indicates
120 * whether or not all privileges in the zone are required. In addition,
121 * priv can be set to PRIV_ALL to indicate that all privileges are
122 * required (regardless of zone). There are three scenarios of interest:
123 * (1) operation requires a specific privilege
124 * (2) operation requires a specific privilege, and requires all
125 * privileges available within the zone (or all privileges if in
126 * the global zone)
127 * (3) operation requires all privileges, regardless of zone
129 * For (1), priv should be set to the specific privilege, and allzone
130 * should be set to B_FALSE.
131 * For (2), priv should be set to the specific privilege, and allzone
132 * should be set to B_TRUE.
133 * For (3), priv should be set to PRIV_ALL, and allzone should be set
134 * to B_FALSE.
139 * The privileges are checked against the Effective set for
140 * ordinary processes and checked against the Limit set
141 * for euid 0 processes that haven't manipulated their privilege
142 * sets.
144 #define HAS_ALLPRIVS(cr) priv_isfullset(&CR_OEPRIV(cr))
145 #define ZONEPRIVS(cr) ((cr)->cr_zone->zone_privset)
146 #define HAS_ALLZONEPRIVS(cr) priv_issubset(ZONEPRIVS(cr), &CR_OEPRIV(cr))
147 #define HAS_PRIVILEGE(cr, pr) ((pr) == PRIV_ALL ? \
148 HAS_ALLPRIVS(cr) : \
149 PRIV_ISASSERT(&CR_OEPRIV(cr), pr))
151 #define FAST_BASIC_CHECK(cr, priv) \
152 if (PRIV_ISASSERT(&CR_OEPRIV(cr), priv)) { \
153 DTRACE_PROBE2(priv__ok, int, priv, boolean_t, B_FALSE); \
154 return (0); \
158 * Policy checking functions.
160 * All of the system's policy should be implemented here.
164 * Private functions which take an additional va_list argument to
165 * implement an object specific policy override.
167 static int priv_policy_ap(const cred_t *, int, boolean_t, int,
168 const char *, va_list);
169 static int priv_policy_va(const cred_t *, int, boolean_t, int,
170 const char *, ...);
173 * Generic policy calls
175 * The "bottom" functions of policy control
177 static char *
178 mprintf(const char *fmt, ...)
180 va_list args;
181 char *buf;
182 size_t len;
184 va_start(args, fmt);
185 len = vsnprintf(NULL, 0, fmt, args) + 1;
186 va_end(args);
188 buf = kmem_alloc(len, KM_NOSLEEP);
190 if (buf == NULL)
191 return (NULL);
193 va_start(args, fmt);
194 (void) vsnprintf(buf, len, fmt, args);
195 va_end(args);
197 return (buf);
201 * priv_policy_errmsg()
203 * Generate an error message if privilege debugging is enabled system wide
204 * or for this particular process.
207 #define FMTHDR "%s[%d]: missing privilege \"%s\" (euid = %d, syscall = %d)"
208 #define FMTMSG " for \"%s\""
209 #define FMTFUN " needed at %s+0x%lx"
211 /* The maximum size privilege format: the concatenation of the above */
212 #define FMTMAX FMTHDR FMTMSG FMTFUN "\n"
214 static void
215 priv_policy_errmsg(const cred_t *cr, int priv, const char *msg)
217 struct proc *me;
218 pc_t stack[MAXPRIVSTACK];
219 int depth;
220 int i;
221 char *sym;
222 ulong_t off;
223 const char *pname;
225 char *cmd;
226 char fmt[sizeof (FMTMAX)];
228 if ((me = curproc) == &p0)
229 return;
231 /* Privileges must be defined */
232 ASSERT(priv == PRIV_ALL || priv == PRIV_MULTIPLE ||
233 priv == PRIV_ALLZONE || priv == PRIV_GLOBAL ||
234 priv_getbynum(priv) != NULL);
236 if (priv == PRIV_ALLZONE && INGLOBALZONE(me))
237 priv = PRIV_ALL;
239 if (curthread->t_pre_sys)
240 ttolwp(curthread)->lwp_badpriv = (short)priv;
242 if (priv_debug == 0 && (CR_FLAGS(cr) & PRIV_DEBUG) == 0)
243 return;
245 (void) strcpy(fmt, FMTHDR);
247 if (me->p_user.u_comm[0])
248 cmd = &me->p_user.u_comm[0];
249 else
250 cmd = "priv_policy";
252 if (msg != NULL && *msg != '\0') {
253 (void) strcat(fmt, FMTMSG);
254 } else {
255 (void) strcat(fmt, "%s");
256 msg = "";
259 sym = NULL;
261 depth = getpcstack(stack, MAXPRIVSTACK);
264 * Try to find the first interesting function on the stack.
265 * priv_policy* that's us, so completely uninteresting.
266 * suser(), drv_priv(), secpolicy_* are also called from
267 * too many locations to convey useful information.
269 for (i = 0; i < depth; i++) {
270 sym = kobj_getsymname((uintptr_t)stack[i], &off);
271 if (sym != NULL &&
272 strstr(sym, "hasprocperm") == 0 &&
273 strcmp("suser", sym) != 0 &&
274 strcmp("ipcaccess", sym) != 0 &&
275 strcmp("drv_priv", sym) != 0 &&
276 strncmp("secpolicy_", sym, 10) != 0 &&
277 strncmp("priv_policy", sym, 11) != 0)
278 break;
281 if (sym != NULL)
282 (void) strcat(fmt, FMTFUN);
284 (void) strcat(fmt, "\n");
286 switch (priv) {
287 case PRIV_ALL:
288 pname = "ALL";
289 break;
290 case PRIV_MULTIPLE:
291 pname = "MULTIPLE";
292 break;
293 case PRIV_ALLZONE:
294 pname = "ZONE";
295 break;
296 case PRIV_GLOBAL:
297 pname = "GLOBAL";
298 break;
299 default:
300 pname = priv_getbynum(priv);
301 break;
304 if (CR_FLAGS(cr) & PRIV_DEBUG) {
305 /* Remember last message, just like lwp_badpriv. */
306 if (curthread->t_pdmsg != NULL) {
307 kmem_free(curthread->t_pdmsg,
308 strlen(curthread->t_pdmsg) + 1);
311 curthread->t_pdmsg = mprintf(fmt, cmd, me->p_pid, pname,
312 cr->cr_uid, curthread->t_sysnum, msg, sym, off);
314 curthread->t_post_sys = 1;
316 if (priv_debug) {
317 cmn_err(CE_NOTE, fmt, cmd, me->p_pid, pname, cr->cr_uid,
318 curthread->t_sysnum, msg, sym, off);
323 * Override the policy, if appropriate. Return 0 if the external
324 * policy engine approves.
326 static int
327 priv_policy_override(const cred_t *cr, int priv, boolean_t allzone, va_list ap)
329 priv_set_t set;
330 int ret;
332 if (!(CR_FLAGS(cr) & PRIV_XPOLICY))
333 return (-1);
335 if (priv == PRIV_ALL) {
336 priv_fillset(&set);
337 } else if (allzone) {
338 set = *ZONEPRIVS(cr);
339 } else {
340 priv_emptyset(&set);
341 priv_addset(&set, priv);
343 ret = klpd_call(cr, &set, ap);
344 return (ret);
347 static int
348 priv_policy_override_set(const cred_t *cr, const priv_set_t *req, va_list ap)
350 if (CR_FLAGS(cr) & PRIV_PFEXEC)
351 return (check_user_privs(cr, req));
352 if (CR_FLAGS(cr) & PRIV_XPOLICY) {
353 return (klpd_call(cr, req, ap));
355 return (-1);
358 static int
359 priv_policy_override_set_va(const cred_t *cr, const priv_set_t *req, ...)
361 va_list ap;
362 int ret;
364 va_start(ap, req);
365 ret = priv_policy_override_set(cr, req, ap);
366 va_end(ap);
367 return (ret);
371 * Audit failure, log error message.
373 static void
374 priv_policy_err(const cred_t *cr, int priv, boolean_t allzone, const char *msg)
377 if (AU_AUDITING())
378 audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 0);
379 DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone);
381 if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) ||
382 curthread->t_pre_sys) {
383 if (allzone && !HAS_ALLZONEPRIVS(cr)) {
384 priv_policy_errmsg(cr, PRIV_ALLZONE, msg);
385 } else {
386 ASSERT(!HAS_PRIVILEGE(cr, priv));
387 priv_policy_errmsg(cr, priv, msg);
393 * priv_policy_ap()
394 * return 0 or error.
395 * See block comment above for a description of "priv" and "allzone" usage.
397 static int
398 priv_policy_ap(const cred_t *cr, int priv, boolean_t allzone, int err,
399 const char *msg, va_list ap)
401 if ((HAS_PRIVILEGE(cr, priv) && (!allzone || HAS_ALLZONEPRIVS(cr))) ||
402 (!servicing_interrupt() &&
403 priv_policy_override(cr, priv, allzone, ap) == 0)) {
404 if ((allzone || priv == PRIV_ALL ||
405 !PRIV_ISASSERT(priv_basic, priv)) &&
406 !servicing_interrupt()) {
407 PTOU(curproc)->u_acflag |= ASU; /* Needed for SVVS */
408 if (AU_AUDITING())
409 audit_priv(priv,
410 allzone ? ZONEPRIVS(cr) : NULL, 1);
412 err = 0;
413 DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone);
414 } else if (!servicing_interrupt()) {
415 /* Failure audited in this procedure */
416 priv_policy_err(cr, priv, allzone, msg);
418 return (err);
422 priv_policy_va(const cred_t *cr, int priv, boolean_t allzone, int err,
423 const char *msg, ...)
425 int ret;
426 va_list ap;
428 va_start(ap, msg);
429 ret = priv_policy_ap(cr, priv, allzone, err, msg, ap);
430 va_end(ap);
432 return (ret);
436 priv_policy(const cred_t *cr, int priv, boolean_t allzone, int err,
437 const char *msg)
439 return (priv_policy_va(cr, priv, allzone, err, msg, KLPDARG_NONE));
443 * Return B_TRUE for sufficient privileges, B_FALSE for insufficient privileges.
445 boolean_t
446 priv_policy_choice(const cred_t *cr, int priv, boolean_t allzone)
448 boolean_t res = HAS_PRIVILEGE(cr, priv) &&
449 (!allzone || HAS_ALLZONEPRIVS(cr));
451 /* Audit success only */
452 if (res && AU_AUDITING() &&
453 (allzone || priv == PRIV_ALL || !PRIV_ISASSERT(priv_basic, priv)) &&
454 !servicing_interrupt()) {
455 audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 1);
457 if (res) {
458 DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone);
459 } else {
460 DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone);
462 return (res);
466 * Non-auditing variant of priv_policy_choice().
468 boolean_t
469 priv_policy_only(const cred_t *cr, int priv, boolean_t allzone)
471 boolean_t res = HAS_PRIVILEGE(cr, priv) &&
472 (!allzone || HAS_ALLZONEPRIVS(cr));
474 if (res) {
475 DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone);
476 } else {
477 DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone);
479 return (res);
483 * Check whether all privileges in the required set are present.
485 static int
486 secpolicy_require_set(const cred_t *cr, const priv_set_t *req,
487 const char *msg, ...)
489 int priv;
490 int pfound = -1;
491 priv_set_t pset;
492 va_list ap;
493 int ret;
495 if (req == PRIV_FULLSET ? HAS_ALLPRIVS(cr) : priv_issubset(req,
496 &CR_OEPRIV(cr))) {
497 return (0);
500 va_start(ap, msg);
501 ret = priv_policy_override_set(cr, req, ap);
502 va_end(ap);
503 if (ret == 0)
504 return (0);
506 if (req == PRIV_FULLSET || priv_isfullset(req)) {
507 priv_policy_err(cr, PRIV_ALL, B_FALSE, msg);
508 return (EACCES);
511 pset = CR_OEPRIV(cr); /* present privileges */
512 priv_inverse(&pset); /* all non present privileges */
513 priv_intersect(req, &pset); /* the actual missing privs */
515 if (AU_AUDITING())
516 audit_priv(PRIV_NONE, &pset, 0);
518 * Privilege debugging; special case "one privilege in set".
520 if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || curthread->t_pre_sys) {
521 for (priv = 0; priv < nprivs; priv++) {
522 if (priv_ismember(&pset, priv)) {
523 if (pfound != -1) {
524 /* Multiple missing privs */
525 priv_policy_errmsg(cr, PRIV_MULTIPLE,
526 msg);
527 return (EACCES);
529 pfound = priv;
532 ASSERT(pfound != -1);
533 /* Just the one missing privilege */
534 priv_policy_errmsg(cr, pfound, msg);
537 return (EACCES);
541 * Called when an operation requires that the caller be in the
542 * global zone, regardless of privilege.
544 static int
545 priv_policy_global(const cred_t *cr)
547 if (crgetzoneid(cr) == GLOBAL_ZONEID)
548 return (0); /* success */
550 if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) ||
551 curthread->t_pre_sys) {
552 priv_policy_errmsg(cr, PRIV_GLOBAL, NULL);
554 return (EPERM);
558 * Raising process priority
561 secpolicy_raisepriority(const cred_t *cr)
563 if (PRIV_POLICY(cr, PRIV_PROC_PRIOUP, B_FALSE, EPERM, NULL) == 0)
564 return (0);
565 return (secpolicy_setpriority(cr));
569 * Changing process priority or scheduling class
572 secpolicy_setpriority(const cred_t *cr)
574 return (PRIV_POLICY(cr, PRIV_PROC_PRIOCNTL, B_FALSE, EPERM, NULL));
578 * Binding to a privileged port, port must be specified in host byte
579 * order.
580 * When adding a new privilege which allows binding to currently privileged
581 * ports, then you MUST also allow processes with PRIV_NET_PRIVADDR bind
582 * to these ports because of backward compatibility.
585 secpolicy_net_privaddr(const cred_t *cr, in_port_t port, int proto)
587 char *reason;
588 int priv;
590 switch (port) {
591 case 137:
592 case 138:
593 case 139:
594 case 445:
596 * NBT and SMB ports, these are normal privileged ports,
597 * allow bind only if the SYS_SMB or NET_PRIVADDR privilege
598 * is present.
599 * Try both, if neither is present return an error for
600 * priv SYS_SMB.
602 if (PRIV_POLICY_ONLY(cr, PRIV_NET_PRIVADDR, B_FALSE))
603 priv = PRIV_NET_PRIVADDR;
604 else
605 priv = PRIV_SYS_SMB;
606 reason = "NBT or SMB port";
607 break;
609 case 2049:
610 case 4045:
612 * NFS ports, these are extra privileged ports, allow bind
613 * only if the SYS_NFS privilege is present.
615 priv = PRIV_SYS_NFS;
616 reason = "NFS port";
617 break;
619 default:
620 priv = PRIV_NET_PRIVADDR;
621 reason = NULL;
622 break;
626 return (priv_policy_va(cr, priv, B_FALSE, EACCES, reason,
627 KLPDARG_PORT, (int)proto, (int)port, KLPDARG_NOMORE));
631 * Binding to a multilevel port on a trusted (labeled) system.
634 secpolicy_net_bindmlp(const cred_t *cr)
636 return (PRIV_POLICY(cr, PRIV_NET_BINDMLP, B_FALSE, EACCES, NULL));
640 * Allow a communication between a zone and an unlabeled host when their
641 * labels don't match.
644 secpolicy_net_mac_aware(const cred_t *cr)
646 return (PRIV_POLICY(cr, PRIV_NET_MAC_AWARE, B_FALSE, EACCES, NULL));
650 * Allow a privileged process to transmit traffic without explicit labels
653 secpolicy_net_mac_implicit(const cred_t *cr)
655 return (PRIV_POLICY(cr, PRIV_NET_MAC_IMPLICIT, B_FALSE, EACCES, NULL));
659 * Common routine which determines whether a given credential can
660 * act on a given mount.
661 * When called through mount, the parameter needoptcheck is a pointer
662 * to a boolean variable which will be set to either true or false,
663 * depending on whether the mount policy should change the mount options.
664 * In all other cases, needoptcheck should be a NULL pointer.
666 static int
667 secpolicy_fs_common(cred_t *cr, vnode_t *mvp, const vfs_t *vfsp,
668 boolean_t *needoptcheck)
670 boolean_t allzone = B_FALSE;
671 boolean_t mounting = needoptcheck != NULL;
674 * Short circuit the following cases:
675 * vfsp == NULL or mvp == NULL (pure privilege check)
676 * have all privileges - no further checks required
677 * and no mount options need to be set.
679 if (vfsp == NULL || mvp == NULL || HAS_ALLPRIVS(cr)) {
680 if (mounting)
681 *needoptcheck = B_FALSE;
683 return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM,
684 NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE));
688 * When operating on an existing mount (either we're not mounting
689 * or we're doing a remount and VFS_REMOUNT will be set), zones
690 * can operate only on mounts established by the zone itself.
692 if (!mounting || (vfsp->vfs_flag & VFS_REMOUNT) != 0) {
693 zoneid_t zoneid = crgetzoneid(cr);
695 if (zoneid != GLOBAL_ZONEID &&
696 vfsp->vfs_zone->zone_id != zoneid) {
697 return (EPERM);
701 if (mounting)
702 *needoptcheck = B_TRUE;
705 * Overlay mounts may hide important stuff; if you can't write to a
706 * mount point but would be able to mount on top of it, you can
707 * escalate your privileges.
708 * So we go about asking the same questions namefs does when it
709 * decides whether you can mount over a file or not but with the
710 * added restriction that you can only mount on top of a regular
711 * file or directory.
712 * If we have all the zone's privileges, we skip all other checks,
713 * or else we may actually get in trouble inside the automounter.
715 if ((mvp->v_flag & VROOT) != 0 ||
716 (mvp->v_type != VDIR && mvp->v_type != VREG) ||
717 HAS_ALLZONEPRIVS(cr)) {
718 allzone = B_TRUE;
719 } else {
720 vattr_t va;
721 int err;
723 va.va_mask = AT_UID|AT_MODE;
724 err = VOP_GETATTR(mvp, &va, 0, cr, NULL);
725 if (err != 0)
726 return (err);
728 if ((err = secpolicy_vnode_owner(cr, va.va_uid)) != 0)
729 return (err);
731 if (secpolicy_vnode_access2(cr, mvp, va.va_uid, va.va_mode,
732 VWRITE) != 0) {
733 return (EACCES);
736 return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM,
737 NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE));
740 void
741 secpolicy_fs_mount_clearopts(cred_t *cr, struct vfs *vfsp)
743 boolean_t amsuper = HAS_ALLZONEPRIVS(cr);
746 * check; if we don't have either "nosuid" or
747 * both "nosetuid" and "nodevices", then we add
748 * "nosuid"; this depends on how the current
749 * implementation works (it first checks nosuid). In a
750 * zone, a user with all zone privileges can mount with
751 * "setuid" but never with "devices".
753 if (!vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL) &&
754 (!vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL) ||
755 !vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL))) {
756 if (crgetzoneid(cr) == GLOBAL_ZONEID || !amsuper)
757 vfs_setmntopt(vfsp, MNTOPT_NOSUID, NULL, 0);
758 else
759 vfs_setmntopt(vfsp, MNTOPT_NODEVICES, NULL, 0);
762 * If we're not the local super user, we set the "restrict"
763 * option to indicate to automountd that this mount should
764 * be handled with care.
766 if (!amsuper)
767 vfs_setmntopt(vfsp, MNTOPT_RESTRICT, NULL, 0);
772 secpolicy_fs_allowed_mount(const char *fsname)
774 struct vfssw *vswp;
775 const char *p;
776 size_t len;
778 ASSERT(fsname != NULL);
779 ASSERT(fsname[0] != '\0');
781 if (INGLOBALZONE(curproc))
782 return (0);
784 vswp = vfs_getvfssw(fsname);
785 if (vswp == NULL)
786 return (ENOENT);
788 if ((vswp->vsw_flag & VSW_ZMOUNT) != 0) {
789 vfs_unrefvfssw(vswp);
790 return (0);
793 vfs_unrefvfssw(vswp);
795 p = curzone->zone_fs_allowed;
796 len = strlen(fsname);
798 while (p != NULL && *p != '\0') {
799 if (strncmp(p, fsname, len) == 0) {
800 char c = *(p + len);
801 if (c == '\0' || c == ',')
802 return (0);
805 /* skip to beyond the next comma */
806 if ((p = strchr(p, ',')) != NULL)
807 p++;
810 return (EPERM);
813 extern vnode_t *rootvp;
814 extern vfs_t *rootvfs;
817 secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct vfs *vfsp)
819 boolean_t needoptchk;
820 int error;
823 * If it's a remount, get the underlying mount point,
824 * except for the root where we use the rootvp.
826 if ((vfsp->vfs_flag & VFS_REMOUNT) != 0) {
827 if (vfsp == rootvfs)
828 mvp = rootvp;
829 else
830 mvp = vfsp->vfs_vnodecovered;
833 error = secpolicy_fs_common(cr, mvp, vfsp, &needoptchk);
835 if (error == 0 && needoptchk) {
836 secpolicy_fs_mount_clearopts(cr, vfsp);
839 return (error);
843 * Does the policy computations for "ownership" of a mount;
844 * here ownership is defined as the ability to "mount"
845 * the filesystem originally. The rootvfs doesn't cover any
846 * vnodes; we attribute its ownership to the rootvp.
848 static int
849 secpolicy_fs_owner(cred_t *cr, const struct vfs *vfsp)
851 vnode_t *mvp;
853 if (vfsp == NULL)
854 mvp = NULL;
855 else if (vfsp == rootvfs)
856 mvp = rootvp;
857 else
858 mvp = vfsp->vfs_vnodecovered;
860 return (secpolicy_fs_common(cr, mvp, vfsp, NULL));
864 secpolicy_fs_unmount(cred_t *cr, struct vfs *vfsp)
866 return (secpolicy_fs_owner(cr, vfsp));
870 * Quotas are a resource, but if one has the ability to mount a filesystem,
871 * they should be able to modify quotas on it.
874 secpolicy_fs_quota(const cred_t *cr, const vfs_t *vfsp)
876 return (secpolicy_fs_owner((cred_t *)cr, vfsp));
880 * Exceeding minfree: also a per-mount resource constraint.
883 secpolicy_fs_minfree(const cred_t *cr, const vfs_t *vfsp)
885 return (secpolicy_fs_owner((cred_t *)cr, vfsp));
889 secpolicy_fs_config(const cred_t *cr, const vfs_t *vfsp)
891 return (secpolicy_fs_owner((cred_t *)cr, vfsp));
894 /* ARGSUSED */
896 secpolicy_fs_linkdir(const cred_t *cr, const vfs_t *vfsp)
898 return (PRIV_POLICY(cr, PRIV_SYS_LINKDIR, B_FALSE, EPERM, NULL));
902 * Name: secpolicy_vnode_access()
904 * Parameters: Process credential
905 * vnode
906 * uid of owner of vnode
907 * permission bits not granted to the caller when examining
908 * file mode bits (i.e., when a process wants to open a
909 * mode 444 file for VREAD|VWRITE, this function should be
910 * called only with a VWRITE argument).
912 * Normal: Verifies that cred has the appropriate privileges to
913 * override the mode bits that were denied.
915 * Override: file_dac_execute - if VEXEC bit was denied and vnode is
916 * not a directory.
917 * file_dac_read - if VREAD bit was denied.
918 * file_dac_search - if VEXEC bit was denied and vnode is
919 * a directory.
920 * file_dac_write - if VWRITE bit was denied.
922 * Root owned files are special cased to protect system
923 * configuration files and such.
925 * Output: EACCES - if privilege check fails.
929 secpolicy_vnode_access(const cred_t *cr, vnode_t *vp, uid_t owner, mode_t mode)
931 if ((mode & VREAD) && priv_policy_va(cr, PRIV_FILE_DAC_READ, B_FALSE,
932 EACCES, NULL, KLPDARG_VNODE, vp, (char *)NULL,
933 KLPDARG_NOMORE) != 0) {
934 return (EACCES);
937 if (mode & VWRITE) {
938 boolean_t allzone;
940 if (owner == 0 && cr->cr_uid != 0)
941 allzone = B_TRUE;
942 else
943 allzone = B_FALSE;
944 if (priv_policy_va(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES,
945 NULL, KLPDARG_VNODE, vp, (char *)NULL,
946 KLPDARG_NOMORE) != 0) {
947 return (EACCES);
951 if (mode & VEXEC) {
953 * Directories use file_dac_search to override the execute bit.
955 int p = vp->v_type == VDIR ? PRIV_FILE_DAC_SEARCH :
956 PRIV_FILE_DAC_EXECUTE;
958 return (priv_policy_va(cr, p, B_FALSE, EACCES, NULL,
959 KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE));
961 return (0);
965 * Like secpolicy_vnode_access() but we get the actual wanted mode and the
966 * current mode of the file, not the missing bits.
969 secpolicy_vnode_access2(const cred_t *cr, vnode_t *vp, uid_t owner,
970 mode_t curmode, mode_t wantmode)
972 mode_t mode;
974 /* Inline the basic privileges tests. */
975 if ((wantmode & VREAD) &&
976 !PRIV_ISASSERT(&CR_OEPRIV(cr), PRIV_FILE_READ) &&
977 priv_policy_va(cr, PRIV_FILE_READ, B_FALSE, EACCES, NULL,
978 KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE) != 0) {
979 return (EACCES);
982 if ((wantmode & VWRITE) &&
983 !PRIV_ISASSERT(&CR_OEPRIV(cr), PRIV_FILE_WRITE) &&
984 priv_policy_va(cr, PRIV_FILE_WRITE, B_FALSE, EACCES, NULL,
985 KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE) != 0) {
986 return (EACCES);
989 mode = ~curmode & wantmode;
991 if (mode == 0)
992 return (0);
994 if ((mode & VREAD) && priv_policy_va(cr, PRIV_FILE_DAC_READ, B_FALSE,
995 EACCES, NULL, KLPDARG_VNODE, vp, (char *)NULL,
996 KLPDARG_NOMORE) != 0) {
997 return (EACCES);
1000 if (mode & VWRITE) {
1001 boolean_t allzone;
1003 if (owner == 0 && cr->cr_uid != 0)
1004 allzone = B_TRUE;
1005 else
1006 allzone = B_FALSE;
1007 if (priv_policy_va(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES,
1008 NULL, KLPDARG_VNODE, vp, (char *)NULL,
1009 KLPDARG_NOMORE) != 0) {
1010 return (EACCES);
1014 if (mode & VEXEC) {
1016 * Directories use file_dac_search to override the execute bit.
1018 int p = vp->v_type == VDIR ? PRIV_FILE_DAC_SEARCH :
1019 PRIV_FILE_DAC_EXECUTE;
1021 return (priv_policy_va(cr, p, B_FALSE, EACCES, NULL,
1022 KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE));
1024 return (0);
1028 * This is a special routine for ZFS; it is used to determine whether
1029 * any of the privileges in effect allow any form of access to the
1030 * file. There's no reason to audit this or any reason to record
1031 * this. More work is needed to do the "KPLD" stuff.
1034 secpolicy_vnode_any_access(const cred_t *cr, vnode_t *vp, uid_t owner)
1036 static int privs[] = {
1037 PRIV_FILE_OWNER,
1038 PRIV_FILE_CHOWN,
1039 PRIV_FILE_DAC_READ,
1040 PRIV_FILE_DAC_WRITE,
1041 PRIV_FILE_DAC_EXECUTE,
1042 PRIV_FILE_DAC_SEARCH,
1044 int i;
1046 /* Same as secpolicy_vnode_setdac */
1047 if (owner == cr->cr_uid)
1048 return (0);
1050 for (i = 0; i < sizeof (privs)/sizeof (int); i++) {
1051 boolean_t allzone = B_FALSE;
1052 int priv;
1054 switch (priv = privs[i]) {
1055 case PRIV_FILE_DAC_EXECUTE:
1056 if (vp->v_type == VDIR)
1057 continue;
1058 break;
1059 case PRIV_FILE_DAC_SEARCH:
1060 if (vp->v_type != VDIR)
1061 continue;
1062 break;
1063 case PRIV_FILE_DAC_WRITE:
1064 case PRIV_FILE_OWNER:
1065 case PRIV_FILE_CHOWN:
1066 /* We know here that if owner == 0, that cr_uid != 0 */
1067 allzone = owner == 0;
1068 break;
1070 if (PRIV_POLICY_CHOICE(cr, priv, allzone))
1071 return (0);
1073 return (EPERM);
1077 * Name: secpolicy_vnode_setid_modify()
1079 * Normal: verify that subject can set the file setid flags.
1081 * Output: EPERM - if not privileged.
1084 static int
1085 secpolicy_vnode_setid_modify(const cred_t *cr, uid_t owner)
1087 /* If changing to suid root, must have all zone privs */
1088 boolean_t allzone = B_TRUE;
1090 if (owner != 0) {
1091 if (owner == cr->cr_uid)
1092 return (0);
1093 allzone = B_FALSE;
1095 return (PRIV_POLICY(cr, PRIV_FILE_SETID, allzone, EPERM, NULL));
1099 * Are we allowed to retain the set-uid/set-gid bits when
1100 * changing ownership or when writing to a file?
1101 * "issuid" should be true when set-uid; only in that case
1102 * root ownership is checked (setgid is assumed).
1105 secpolicy_vnode_setid_retain(const cred_t *cred, boolean_t issuidroot)
1107 if (issuidroot && !HAS_ALLZONEPRIVS(cred))
1108 return (EPERM);
1110 return (!PRIV_POLICY_CHOICE(cred, PRIV_FILE_SETID, B_FALSE));
1114 * Name: secpolicy_vnode_setids_setgids()
1116 * Normal: verify that subject can set the file setgid flag.
1118 * Output: EPERM - if not privileged
1122 secpolicy_vnode_setids_setgids(const cred_t *cred, gid_t gid)
1124 if (!groupmember(gid, cred))
1125 return (PRIV_POLICY(cred, PRIV_FILE_SETID, B_FALSE, EPERM,
1126 NULL));
1127 return (0);
1131 * Name: secpolicy_vnode_chown
1133 * Normal: Determine if subject can chown owner of a file.
1135 * Output: EPERM - if access denied
1139 secpolicy_vnode_chown(const cred_t *cred, uid_t owner)
1141 boolean_t is_owner = (owner == crgetuid(cred));
1142 boolean_t allzone = B_FALSE;
1143 int priv;
1145 if (!is_owner) {
1146 allzone = (owner == 0);
1147 priv = PRIV_FILE_CHOWN;
1148 } else {
1149 priv = HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN) ?
1150 PRIV_FILE_CHOWN : PRIV_FILE_CHOWN_SELF;
1153 return (PRIV_POLICY(cred, priv, allzone, EPERM, NULL));
1157 * Name: secpolicy_vnode_create_gid
1159 * Normal: Determine if subject can change group ownership of a file.
1161 * Output: EPERM - if access denied
1164 secpolicy_vnode_create_gid(const cred_t *cred)
1166 if (HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN))
1167 return (PRIV_POLICY(cred, PRIV_FILE_CHOWN, B_FALSE, EPERM,
1168 NULL));
1169 else
1170 return (PRIV_POLICY(cred, PRIV_FILE_CHOWN_SELF, B_FALSE, EPERM,
1171 NULL));
1175 * Name: secpolicy_vnode_utime_modify()
1177 * Normal: verify that subject can modify the utime on a file.
1179 * Output: EPERM - if access denied.
1182 static int
1183 secpolicy_vnode_utime_modify(const cred_t *cred)
1185 return (PRIV_POLICY(cred, PRIV_FILE_OWNER, B_FALSE, EPERM,
1186 "modify file times"));
1191 * Name: secpolicy_vnode_setdac()
1193 * Normal: verify that subject can modify the mode of a file.
1194 * allzone privilege needed when modifying root owned object.
1196 * Output: EPERM - if access denied.
1200 secpolicy_vnode_setdac(const cred_t *cred, uid_t owner)
1202 if (owner == cred->cr_uid)
1203 return (0);
1205 return (PRIV_POLICY(cred, PRIV_FILE_OWNER, owner == 0, EPERM, NULL));
1208 * Name: secpolicy_vnode_stky_modify()
1210 * Normal: verify that subject can make a file a "sticky".
1212 * Output: EPERM - if access denied.
1216 secpolicy_vnode_stky_modify(const cred_t *cred)
1218 return (PRIV_POLICY(cred, PRIV_SYS_CONFIG, B_FALSE, EPERM,
1219 "set file sticky"));
1223 * Policy determines whether we can remove an entry from a directory,
1224 * regardless of permission bits.
1227 secpolicy_vnode_remove(const cred_t *cr)
1229 return (PRIV_POLICY(cr, PRIV_FILE_OWNER, B_FALSE, EACCES,
1230 "sticky directory"));
1234 secpolicy_vnode_owner(const cred_t *cr, uid_t owner)
1236 boolean_t allzone = (owner == 0);
1238 if (owner == cr->cr_uid)
1239 return (0);
1241 return (PRIV_POLICY(cr, PRIV_FILE_OWNER, allzone, EPERM, NULL));
1244 void
1245 secpolicy_setid_clear(vattr_t *vap, cred_t *cr)
1247 if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0 &&
1248 secpolicy_vnode_setid_retain(cr,
1249 (vap->va_mode & S_ISUID) != 0 &&
1250 (vap->va_mask & AT_UID) != 0 && vap->va_uid == 0) != 0) {
1251 vap->va_mask |= AT_MODE;
1252 vap->va_mode &= ~(S_ISUID|S_ISGID);
1257 secpolicy_setid_setsticky_clear(vnode_t *vp, vattr_t *vap, const vattr_t *ovap,
1258 cred_t *cr)
1260 int error;
1262 if ((vap->va_mode & S_ISUID) != 0 &&
1263 (error = secpolicy_vnode_setid_modify(cr,
1264 ovap->va_uid)) != 0) {
1265 return (error);
1269 * Check privilege if attempting to set the
1270 * sticky bit on a non-directory.
1272 if (vp->v_type != VDIR && (vap->va_mode & S_ISVTX) != 0 &&
1273 secpolicy_vnode_stky_modify(cr) != 0) {
1274 vap->va_mode &= ~S_ISVTX;
1278 * Check for privilege if attempting to set the
1279 * group-id bit.
1281 if ((vap->va_mode & S_ISGID) != 0 &&
1282 secpolicy_vnode_setids_setgids(cr, ovap->va_gid) != 0) {
1283 vap->va_mode &= ~S_ISGID;
1286 return (0);
1289 #define ATTR_FLAG_PRIV(attr, value, cr) \
1290 PRIV_POLICY(cr, value ? PRIV_FILE_FLAG_SET : PRIV_ALL, \
1291 B_FALSE, EPERM, NULL)
1294 * Check privileges for setting xvattr attributes
1297 secpolicy_xvattr(xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype)
1299 xoptattr_t *xoap;
1300 int error = 0;
1302 if ((xoap = xva_getxoptattr(xvap)) == NULL)
1303 return (EINVAL);
1306 * First process the DOS bits
1308 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE) ||
1309 XVA_ISSET_REQ(xvap, XAT_HIDDEN) ||
1310 XVA_ISSET_REQ(xvap, XAT_READONLY) ||
1311 XVA_ISSET_REQ(xvap, XAT_SYSTEM) ||
1312 XVA_ISSET_REQ(xvap, XAT_CREATETIME) ||
1313 XVA_ISSET_REQ(xvap, XAT_OFFLINE) ||
1314 XVA_ISSET_REQ(xvap, XAT_SPARSE)) {
1315 if ((error = secpolicy_vnode_owner(cr, owner)) != 0)
1316 return (error);
1320 * Now handle special attributes
1323 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
1324 error = ATTR_FLAG_PRIV(XAT_IMMUTABLE,
1325 xoap->xoa_immutable, cr);
1326 if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
1327 error = ATTR_FLAG_PRIV(XAT_NOUNLINK,
1328 xoap->xoa_nounlink, cr);
1329 if (error == 0 && XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
1330 error = ATTR_FLAG_PRIV(XAT_APPENDONLY,
1331 xoap->xoa_appendonly, cr);
1332 if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NODUMP))
1333 error = ATTR_FLAG_PRIV(XAT_NODUMP,
1334 xoap->xoa_nodump, cr);
1335 if (error == 0 && XVA_ISSET_REQ(xvap, XAT_OPAQUE))
1336 error = EPERM;
1337 if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
1338 error = ATTR_FLAG_PRIV(XAT_AV_QUARANTINED,
1339 xoap->xoa_av_quarantined, cr);
1340 if (error == 0 && vtype != VREG && xoap->xoa_av_quarantined)
1341 error = EINVAL;
1343 if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
1344 error = ATTR_FLAG_PRIV(XAT_AV_MODIFIED,
1345 xoap->xoa_av_modified, cr);
1346 if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
1347 error = ATTR_FLAG_PRIV(XAT_AV_SCANSTAMP,
1348 xoap->xoa_av_scanstamp, cr);
1349 if (error == 0 && vtype != VREG)
1350 error = EINVAL;
1352 return (error);
1356 * This function checks the policy decisions surrounding the
1357 * vop setattr call.
1359 * It should be called after sufficient locks have been established
1360 * on the underlying data structures. No concurrent modifications
1361 * should be allowed.
1363 * The caller must pass in unlocked version of its vaccess function
1364 * this is required because vop_access function should lock the
1365 * node for reading. A three argument function should be defined
1366 * which accepts the following argument:
1367 * A pointer to the internal "node" type (inode *)
1368 * vnode access bits (VREAD|VWRITE|VEXEC)
1369 * a pointer to the credential
1371 * This function makes the following policy decisions:
1373 * - change permissions
1374 * - permission to change file mode if not owner
1375 * - permission to add sticky bit to non-directory
1376 * - permission to add set-gid bit
1378 * The ovap argument should include AT_MODE|AT_UID|AT_GID.
1380 * If the vap argument does not include AT_MODE, the mode will be copied from
1381 * ovap. In certain situations set-uid/set-gid bits need to be removed;
1382 * this is done by marking vap->va_mask to include AT_MODE and va_mode
1383 * is updated to the newly computed mode.
1387 secpolicy_vnode_setattr(cred_t *cr, struct vnode *vp, struct vattr *vap,
1388 const struct vattr *ovap, int flags,
1389 int unlocked_access(void *, int, cred_t *),
1390 void *node)
1392 int mask = vap->va_mask;
1393 int error = 0;
1394 boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
1396 if (mask & AT_SIZE) {
1397 if (vp->v_type == VDIR) {
1398 error = EISDIR;
1399 goto out;
1403 * If ATTR_NOACLCHECK is set in the flags, then we don't
1404 * perform the secondary unlocked_access() call since the
1405 * ACL (if any) is being checked there.
1407 if (skipaclchk == B_FALSE) {
1408 error = unlocked_access(node, VWRITE, cr);
1409 if (error)
1410 goto out;
1413 if (mask & AT_MODE) {
1415 * If not the owner of the file then check privilege
1416 * for two things: the privilege to set the mode at all
1417 * and, if we're setting setuid, we also need permissions
1418 * to add the set-uid bit, if we're not the owner.
1419 * In the specific case of creating a set-uid root
1420 * file, we need even more permissions.
1422 if ((error = secpolicy_vnode_setdac(cr, ovap->va_uid)) != 0)
1423 goto out;
1425 if ((error = secpolicy_setid_setsticky_clear(vp, vap,
1426 ovap, cr)) != 0)
1427 goto out;
1428 } else
1429 vap->va_mode = ovap->va_mode;
1431 if (mask & (AT_UID|AT_GID)) {
1432 boolean_t checkpriv = B_FALSE;
1435 * Chowning files.
1437 * If you are the file owner:
1438 * chown to other uid FILE_CHOWN_SELF
1439 * chown to gid (non-member) FILE_CHOWN_SELF
1440 * chown to gid (member) <none>
1442 * Instead of PRIV_FILE_CHOWN_SELF, FILE_CHOWN is also
1443 * acceptable but the first one is reported when debugging.
1445 * If you are not the file owner:
1446 * chown from root PRIV_FILE_CHOWN + zone
1447 * chown from other to any PRIV_FILE_CHOWN
1450 if (cr->cr_uid != ovap->va_uid) {
1451 checkpriv = B_TRUE;
1452 } else {
1453 if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) ||
1454 ((mask & AT_GID) && vap->va_gid != ovap->va_gid &&
1455 !groupmember(vap->va_gid, cr))) {
1456 checkpriv = B_TRUE;
1460 * If necessary, check privilege to see if update can be done.
1462 if (checkpriv &&
1463 (error = secpolicy_vnode_chown(cr, ovap->va_uid)) != 0) {
1464 goto out;
1468 * If the file has either the set UID or set GID bits
1469 * set and the caller can set the bits, then leave them.
1471 secpolicy_setid_clear(vap, cr);
1473 if (mask & (AT_ATIME|AT_MTIME)) {
1475 * If not the file owner and not otherwise privileged,
1476 * always return an error when setting the
1477 * time other than the current (ATTR_UTIME flag set).
1478 * If setting the current time (ATTR_UTIME not set) then
1479 * unlocked_access will check permissions according to policy.
1481 if (cr->cr_uid != ovap->va_uid) {
1482 if (flags & ATTR_UTIME)
1483 error = secpolicy_vnode_utime_modify(cr);
1484 else if (skipaclchk == B_FALSE) {
1485 error = unlocked_access(node, VWRITE, cr);
1486 if (error == EACCES &&
1487 secpolicy_vnode_utime_modify(cr) == 0)
1488 error = 0;
1490 if (error)
1491 goto out;
1496 * Check for optional attributes here by checking the following:
1498 if (mask & AT_XVATTR)
1499 error = secpolicy_xvattr((xvattr_t *)vap, ovap->va_uid, cr,
1500 vp->v_type);
1501 out:
1502 return (error);
1506 * Name: secpolicy_pcfs_modify_bootpartition()
1508 * Normal: verify that subject can modify a pcfs boot partition.
1510 * Output: EACCES - if privilege check failed.
1512 /*ARGSUSED*/
1514 secpolicy_pcfs_modify_bootpartition(const cred_t *cred)
1516 return (PRIV_POLICY(cred, PRIV_ALL, B_FALSE, EACCES,
1517 "modify pcfs boot partition"));
1521 * System V IPC routines
1524 secpolicy_ipc_owner(const cred_t *cr, const struct kipc_perm *ip)
1526 if (crgetzoneid(cr) != ip->ipc_zoneid ||
1527 (cr->cr_uid != ip->ipc_uid && cr->cr_uid != ip->ipc_cuid)) {
1528 boolean_t allzone = B_FALSE;
1529 if (ip->ipc_uid == 0 || ip->ipc_cuid == 0)
1530 allzone = B_TRUE;
1531 return (PRIV_POLICY(cr, PRIV_IPC_OWNER, allzone, EPERM, NULL));
1533 return (0);
1537 secpolicy_ipc_config(const cred_t *cr)
1539 return (PRIV_POLICY(cr, PRIV_SYS_IPC_CONFIG, B_FALSE, EPERM, NULL));
1543 secpolicy_ipc_access(const cred_t *cr, const struct kipc_perm *ip, mode_t mode)
1546 boolean_t allzone = B_FALSE;
1548 ASSERT((mode & (MSG_R|MSG_W)) != 0);
1550 if ((mode & MSG_R) &&
1551 PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0)
1552 return (EACCES);
1554 if (mode & MSG_W) {
1555 if (cr->cr_uid != 0 && (ip->ipc_uid == 0 || ip->ipc_cuid == 0))
1556 allzone = B_TRUE;
1558 return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES,
1559 NULL));
1561 return (0);
1565 secpolicy_rsm_access(const cred_t *cr, uid_t owner, mode_t mode)
1567 boolean_t allzone = B_FALSE;
1569 ASSERT((mode & (MSG_R|MSG_W)) != 0);
1571 if ((mode & MSG_R) &&
1572 PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0)
1573 return (EACCES);
1575 if (mode & MSG_W) {
1576 if (cr->cr_uid != 0 && owner == 0)
1577 allzone = B_TRUE;
1579 return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES,
1580 NULL));
1582 return (0);
1586 * Audit configuration.
1589 secpolicy_audit_config(const cred_t *cr)
1591 return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL));
1595 * Audit record generation.
1598 secpolicy_audit_modify(const cred_t *cr)
1600 return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, NULL));
1604 * Get audit attributes.
1605 * Either PRIV_SYS_AUDIT or PRIV_PROC_AUDIT required; report the
1606 * "Least" of the two privileges on error.
1609 secpolicy_audit_getattr(const cred_t *cr, boolean_t checkonly)
1611 int priv;
1613 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_AUDIT, B_FALSE))
1614 priv = PRIV_SYS_AUDIT;
1615 else
1616 priv = PRIV_PROC_AUDIT;
1618 if (checkonly)
1619 return (!PRIV_POLICY_ONLY(cr, priv, B_FALSE));
1620 else
1621 return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL));
1626 * Locking physical memory
1629 secpolicy_lock_memory(const cred_t *cr)
1631 return (PRIV_POLICY(cr, PRIV_PROC_LOCK_MEMORY, B_FALSE, EPERM, NULL));
1635 * Accounting (both acct(2) and exacct).
1638 secpolicy_acct(const cred_t *cr)
1640 return (PRIV_POLICY(cr, PRIV_SYS_ACCT, B_FALSE, EPERM, NULL));
1644 * Is this process privileged to change its uids at will?
1645 * Uid 0 is still considered "special" and having the SETID
1646 * privilege is not sufficient to get uid 0.
1647 * Files are owned by root, so the privilege would give
1648 * full access and euid 0 is still effective.
1650 * If you have the privilege and euid 0 only then do you
1651 * get the powers of root wrt uid 0.
1653 * For gid manipulations, this is should be called with an
1654 * uid of -1.
1658 secpolicy_allow_setid(const cred_t *cr, uid_t newuid, boolean_t checkonly)
1660 boolean_t allzone = B_FALSE;
1662 if (newuid == 0 && cr->cr_uid != 0 && cr->cr_suid != 0 &&
1663 cr->cr_ruid != 0) {
1664 allzone = B_TRUE;
1667 return (checkonly ? !PRIV_POLICY_ONLY(cr, PRIV_PROC_SETID, allzone) :
1668 PRIV_POLICY(cr, PRIV_PROC_SETID, allzone, EPERM, NULL));
1673 * Acting on a different process: if the mode is for writing,
1674 * the restrictions are more severe. This is called after
1675 * we've verified that the uids do not match.
1678 secpolicy_proc_owner(const cred_t *scr, const cred_t *tcr, int mode)
1680 boolean_t allzone = B_FALSE;
1682 if ((mode & VWRITE) && scr->cr_uid != 0 &&
1683 (tcr->cr_uid == 0 || tcr->cr_ruid == 0 || tcr->cr_suid == 0))
1684 allzone = B_TRUE;
1686 return (PRIV_POLICY(scr, PRIV_PROC_OWNER, allzone, EPERM, NULL));
1690 secpolicy_proc_access(const cred_t *scr)
1692 return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EACCES, NULL));
1696 secpolicy_proc_excl_open(const cred_t *scr)
1698 return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EBUSY, NULL));
1702 secpolicy_proc_zone(const cred_t *scr)
1704 return (PRIV_POLICY(scr, PRIV_PROC_ZONE, B_FALSE, EPERM, NULL));
1708 * Destroying the system
1712 secpolicy_kmdb(const cred_t *scr)
1714 return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL));
1718 secpolicy_error_inject(const cred_t *scr)
1720 return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL));
1724 * Processor sets, cpu configuration, resource pools.
1727 secpolicy_pset(const cred_t *cr)
1729 return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
1732 /* Process security flags */
1734 secpolicy_psecflags(const cred_t *cr, proc_t *tp, proc_t *sp)
1736 if (PRIV_POLICY(cr, PRIV_PROC_SECFLAGS, B_FALSE, EPERM, NULL) != 0)
1737 return (EPERM);
1739 if (!prochasprocperm(tp, sp, cr))
1740 return (EPERM);
1742 return (0);
1746 * Processor set binding.
1749 secpolicy_pbind(const cred_t *cr)
1751 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_RES_CONFIG, B_FALSE))
1752 return (secpolicy_pset(cr));
1753 return (PRIV_POLICY(cr, PRIV_SYS_RES_BIND, B_FALSE, EPERM, NULL));
1757 secpolicy_ponline(const cred_t *cr)
1759 return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
1763 secpolicy_pool(const cred_t *cr)
1765 return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
1769 secpolicy_blacklist(const cred_t *cr)
1771 return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
1775 * Catch all system configuration.
1778 secpolicy_sys_config(const cred_t *cr, boolean_t checkonly)
1780 if (checkonly) {
1781 return (PRIV_POLICY_ONLY(cr, PRIV_SYS_CONFIG, B_FALSE) ? 0 :
1782 EPERM);
1783 } else {
1784 return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
1789 * Zone administration (halt, reboot, etc.) from within zone.
1792 secpolicy_zone_admin(const cred_t *cr, boolean_t checkonly)
1794 if (checkonly) {
1795 return (PRIV_POLICY_ONLY(cr, PRIV_SYS_ADMIN, B_FALSE) ? 0 :
1796 EPERM);
1797 } else {
1798 return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM,
1799 NULL));
1804 * Zone configuration (create, halt, enter).
1807 secpolicy_zone_config(const cred_t *cr)
1810 * Require all privileges to avoid possibility of privilege
1811 * escalation.
1813 return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE));
1817 * Various other system configuration calls
1820 secpolicy_coreadm(const cred_t *cr)
1822 return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL));
1826 secpolicy_systeminfo(const cred_t *cr)
1828 return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL));
1832 secpolicy_dispadm(const cred_t *cr)
1834 return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
1838 secpolicy_settime(const cred_t *cr)
1840 return (PRIV_POLICY(cr, PRIV_SYS_TIME, B_FALSE, EPERM, NULL));
1844 * For realtime users: high resolution clock.
1847 secpolicy_clock_highres(const cred_t *cr)
1849 return (PRIV_POLICY(cr, PRIV_PROC_CLOCK_HIGHRES, B_FALSE, EPERM,
1850 NULL));
1854 * drv_priv() is documented as callable from interrupt context, not that
1855 * anyone ever does, but still. No debugging or auditing can be done when
1856 * it is called from interrupt context.
1857 * returns 0 on succes, EPERM on failure.
1860 drv_priv(cred_t *cr)
1862 return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
1866 secpolicy_sys_devices(const cred_t *cr)
1868 return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
1872 secpolicy_excl_open(const cred_t *cr)
1874 return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EBUSY, NULL));
1878 secpolicy_rctlsys(const cred_t *cr, boolean_t is_zone_rctl)
1880 /* zone.* rctls can only be set from the global zone */
1881 if (is_zone_rctl && priv_policy_global(cr) != 0)
1882 return (EPERM);
1883 return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL));
1887 secpolicy_resource(const cred_t *cr)
1889 return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL));
1893 secpolicy_resource_anon_mem(const cred_t *cr)
1895 return (PRIV_POLICY_ONLY(cr, PRIV_SYS_RESOURCE, B_FALSE));
1899 * Processes with a real uid of 0 escape any form of accounting, much
1900 * like before.
1903 secpolicy_newproc(const cred_t *cr)
1905 if (cr->cr_ruid == 0)
1906 return (0);
1908 return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL));
1912 * Networking
1915 secpolicy_net_rawaccess(const cred_t *cr)
1917 return (PRIV_POLICY(cr, PRIV_NET_RAWACCESS, B_FALSE, EACCES, NULL));
1921 secpolicy_net_observability(const cred_t *cr)
1923 return (PRIV_POLICY(cr, PRIV_NET_OBSERVABILITY, B_FALSE, EACCES, NULL));
1927 * Need this privilege for accessing the ICMP device
1930 secpolicy_net_icmpaccess(const cred_t *cr)
1932 return (PRIV_POLICY(cr, PRIV_NET_ICMPACCESS, B_FALSE, EACCES, NULL));
1936 * There are a few rare cases where the kernel generates ioctls() from
1937 * interrupt context with a credential of kcred rather than NULL.
1938 * In those cases, we take the safe and cheap test.
1941 secpolicy_net_config(const cred_t *cr, boolean_t checkonly)
1943 if (checkonly) {
1944 return (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE) ?
1945 0 : EPERM);
1946 } else {
1947 return (PRIV_POLICY(cr, PRIV_SYS_NET_CONFIG, B_FALSE, EPERM,
1948 NULL));
1954 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG.
1956 * There are a few rare cases where the kernel generates ioctls() from
1957 * interrupt context with a credential of kcred rather than NULL.
1958 * In those cases, we take the safe and cheap test.
1961 secpolicy_ip_config(const cred_t *cr, boolean_t checkonly)
1963 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
1964 return (secpolicy_net_config(cr, checkonly));
1966 if (checkonly) {
1967 return (PRIV_POLICY_ONLY(cr, PRIV_SYS_IP_CONFIG, B_FALSE) ?
1968 0 : EPERM);
1969 } else {
1970 return (PRIV_POLICY(cr, PRIV_SYS_IP_CONFIG, B_FALSE, EPERM,
1971 NULL));
1976 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_DL_CONFIG.
1979 secpolicy_dl_config(const cred_t *cr)
1981 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
1982 return (secpolicy_net_config(cr, B_FALSE));
1983 return (PRIV_POLICY(cr, PRIV_SYS_DL_CONFIG, B_FALSE, EPERM, NULL));
1987 * PRIV_SYS_DL_CONFIG is a superset of PRIV_SYS_IPTUN_CONFIG.
1990 secpolicy_iptun_config(const cred_t *cr)
1992 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
1993 return (secpolicy_net_config(cr, B_FALSE));
1994 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_DL_CONFIG, B_FALSE))
1995 return (secpolicy_dl_config(cr));
1996 return (PRIV_POLICY(cr, PRIV_SYS_IPTUN_CONFIG, B_FALSE, EPERM, NULL));
2000 * Map IP pseudo privileges to actual privileges.
2001 * So we don't need to recompile IP when we change the privileges.
2004 secpolicy_ip(const cred_t *cr, int netpriv, boolean_t checkonly)
2006 int priv = PRIV_ALL;
2008 switch (netpriv) {
2009 case OP_CONFIG:
2010 priv = PRIV_SYS_IP_CONFIG;
2011 break;
2012 case OP_RAW:
2013 priv = PRIV_NET_RAWACCESS;
2014 break;
2015 case OP_PRIVPORT:
2016 priv = PRIV_NET_PRIVADDR;
2017 break;
2019 ASSERT(priv != PRIV_ALL);
2020 if (checkonly)
2021 return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM);
2022 else
2023 return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL));
2027 * Map network pseudo privileges to actual privileges.
2028 * So we don't need to recompile IP when we change the privileges.
2031 secpolicy_net(const cred_t *cr, int netpriv, boolean_t checkonly)
2033 int priv = PRIV_ALL;
2035 switch (netpriv) {
2036 case OP_CONFIG:
2037 priv = PRIV_SYS_NET_CONFIG;
2038 break;
2039 case OP_RAW:
2040 priv = PRIV_NET_RAWACCESS;
2041 break;
2042 case OP_PRIVPORT:
2043 priv = PRIV_NET_PRIVADDR;
2044 break;
2046 ASSERT(priv != PRIV_ALL);
2047 if (checkonly)
2048 return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM);
2049 else
2050 return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL));
2054 * Checks for operations that are either client-only or are used by
2055 * both clients and servers.
2058 secpolicy_nfs(const cred_t *cr)
2060 return (PRIV_POLICY(cr, PRIV_SYS_NFS, B_FALSE, EPERM, NULL));
2064 * Special case for opening rpcmod: have NFS privileges or network
2065 * config privileges.
2068 secpolicy_rpcmod_open(const cred_t *cr)
2070 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NFS, B_FALSE))
2071 return (secpolicy_nfs(cr));
2072 else
2073 return (secpolicy_net_config(cr, NULL));
2077 secpolicy_chroot(const cred_t *cr)
2079 return (PRIV_POLICY(cr, PRIV_PROC_CHROOT, B_FALSE, EPERM, NULL));
2083 secpolicy_tasksys(const cred_t *cr)
2085 return (PRIV_POLICY(cr, PRIV_PROC_TASKID, B_FALSE, EPERM, NULL));
2089 secpolicy_meminfo(const cred_t *cr)
2091 return (PRIV_POLICY(cr, PRIV_PROC_MEMINFO, B_FALSE, EPERM, NULL));
2095 secpolicy_pfexec_register(const cred_t *cr)
2097 return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_TRUE, EPERM, NULL));
2101 * Basic privilege checks.
2104 secpolicy_basic_exec(const cred_t *cr, vnode_t *vp)
2106 FAST_BASIC_CHECK(cr, PRIV_PROC_EXEC);
2108 return (priv_policy_va(cr, PRIV_PROC_EXEC, B_FALSE, EPERM, NULL,
2109 KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE));
2113 secpolicy_basic_fork(const cred_t *cr)
2115 FAST_BASIC_CHECK(cr, PRIV_PROC_FORK);
2117 return (PRIV_POLICY(cr, PRIV_PROC_FORK, B_FALSE, EPERM, NULL));
2121 secpolicy_basic_proc(const cred_t *cr)
2123 FAST_BASIC_CHECK(cr, PRIV_PROC_SESSION);
2125 return (PRIV_POLICY(cr, PRIV_PROC_SESSION, B_FALSE, EPERM, NULL));
2129 * Slightly complicated because we don't want to trigger the policy too
2130 * often. First we shortcircuit access to "self" (tp == sp) or if
2131 * we don't have the privilege but if we have permission
2132 * just return (0) and we don't flag the privilege as needed.
2133 * Else, we test for the privilege because we either have it or need it.
2136 secpolicy_basic_procinfo(const cred_t *cr, proc_t *tp, proc_t *sp)
2138 if (tp == sp ||
2139 !HAS_PRIVILEGE(cr, PRIV_PROC_INFO) && prochasprocperm(tp, sp, cr)) {
2140 return (0);
2141 } else {
2142 return (PRIV_POLICY(cr, PRIV_PROC_INFO, B_FALSE, EPERM, NULL));
2147 secpolicy_basic_link(const cred_t *cr)
2149 FAST_BASIC_CHECK(cr, PRIV_FILE_LINK_ANY);
2151 return (PRIV_POLICY(cr, PRIV_FILE_LINK_ANY, B_FALSE, EPERM, NULL));
2155 secpolicy_basic_net_access(const cred_t *cr)
2157 FAST_BASIC_CHECK(cr, PRIV_NET_ACCESS);
2159 return (PRIV_POLICY(cr, PRIV_NET_ACCESS, B_FALSE, EACCES, NULL));
2162 /* ARGSUSED */
2164 secpolicy_basic_file_read(const cred_t *cr, vnode_t *vp, const char *pn)
2166 FAST_BASIC_CHECK(cr, PRIV_FILE_READ);
2168 return (priv_policy_va(cr, PRIV_FILE_READ, B_FALSE, EACCES, NULL,
2169 KLPDARG_VNODE, vp, (char *)pn, KLPDARG_NOMORE));
2172 /* ARGSUSED */
2174 secpolicy_basic_file_write(const cred_t *cr, vnode_t *vp, const char *pn)
2176 FAST_BASIC_CHECK(cr, PRIV_FILE_WRITE);
2178 return (priv_policy_va(cr, PRIV_FILE_WRITE, B_FALSE, EACCES, NULL,
2179 KLPDARG_VNODE, vp, (char *)pn, KLPDARG_NOMORE));
2183 * Additional device protection.
2185 * Traditionally, a device has specific permissions on the node in
2186 * the filesystem which govern which devices can be opened by what
2187 * processes. In certain cases, it is desirable to add extra
2188 * restrictions, as writing to certain devices is identical to
2189 * having a complete run of the system.
2191 * This mechanism is called the device policy.
2193 * When a device is opened, its policy entry is looked up in the
2194 * policy cache and checked.
2197 secpolicy_spec_open(const cred_t *cr, struct vnode *vp, int oflag)
2199 devplcy_t *plcy;
2200 int err;
2201 struct snode *csp = VTOS(common_specvp(vp));
2202 priv_set_t pset;
2204 mutex_enter(&csp->s_lock);
2206 if (csp->s_plcy == NULL || csp->s_plcy->dp_gen != devplcy_gen) {
2207 plcy = devpolicy_find(vp);
2208 if (csp->s_plcy)
2209 dpfree(csp->s_plcy);
2210 csp->s_plcy = plcy;
2211 ASSERT(plcy != NULL);
2212 } else
2213 plcy = csp->s_plcy;
2215 if (plcy == nullpolicy) {
2216 mutex_exit(&csp->s_lock);
2217 return (0);
2220 dphold(plcy);
2222 mutex_exit(&csp->s_lock);
2224 if (oflag & FWRITE)
2225 pset = plcy->dp_wrp;
2226 else
2227 pset = plcy->dp_rdp;
2229 * Special case:
2230 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG.
2231 * If PRIV_SYS_NET_CONFIG is present and PRIV_SYS_IP_CONFIG is
2232 * required, replace PRIV_SYS_IP_CONFIG with PRIV_SYS_NET_CONFIG
2233 * in the required privilege set before doing the check.
2235 if (priv_ismember(&pset, PRIV_SYS_IP_CONFIG) &&
2236 priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_NET_CONFIG) &&
2237 !priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_IP_CONFIG)) {
2238 priv_delset(&pset, PRIV_SYS_IP_CONFIG);
2239 priv_addset(&pset, PRIV_SYS_NET_CONFIG);
2242 err = secpolicy_require_set(cr, &pset, "devpolicy", KLPDARG_NONE);
2243 dpfree(plcy);
2245 return (err);
2249 secpolicy_modctl(const cred_t *cr, int cmd)
2251 switch (cmd) {
2252 case MODINFO:
2253 case MODGETMAJBIND:
2254 case MODGETPATH:
2255 case MODGETPATHLEN:
2256 case MODGETNAME:
2257 case MODGETFBNAME:
2258 case MODGETDEVPOLICY:
2259 case MODGETDEVPOLICYBYNAME:
2260 case MODDEVT2INSTANCE:
2261 case MODSIZEOF_DEVID:
2262 case MODGETDEVID:
2263 case MODSIZEOF_MINORNAME:
2264 case MODGETMINORNAME:
2265 case MODGETDEVFSPATH_LEN:
2266 case MODGETDEVFSPATH:
2267 case MODGETDEVFSPATH_MI_LEN:
2268 case MODGETDEVFSPATH_MI:
2269 /* Unprivileged */
2270 return (0);
2271 case MODLOAD:
2272 case MODSETDEVPOLICY:
2273 return (secpolicy_require_set(cr, PRIV_FULLSET, NULL,
2274 KLPDARG_NONE));
2275 default:
2276 return (secpolicy_sys_config(cr, B_FALSE));
2281 secpolicy_console(const cred_t *cr)
2283 return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
2287 secpolicy_power_mgmt(const cred_t *cr)
2289 return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
2293 * Simulate terminal input; another escalation of privileges avenue.
2297 secpolicy_sti(const cred_t *cr)
2299 return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE));
2302 boolean_t
2303 secpolicy_net_reply_equal(const cred_t *cr)
2305 return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
2309 secpolicy_swapctl(const cred_t *cr)
2311 return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
2315 secpolicy_cpc_cpu(const cred_t *cr)
2317 return (PRIV_POLICY(cr, PRIV_CPC_CPU, B_FALSE, EACCES, NULL));
2321 * secpolicy_contract_identity
2323 * Determine if the subject may set the process contract FMRI value
2326 secpolicy_contract_identity(const cred_t *cr)
2328 return (PRIV_POLICY(cr, PRIV_CONTRACT_IDENTITY, B_FALSE, EPERM, NULL));
2332 * secpolicy_contract_observer
2334 * Determine if the subject may observe a specific contract's events.
2337 secpolicy_contract_observer(const cred_t *cr, struct contract *ct)
2339 if (contract_owned(ct, cr, B_FALSE))
2340 return (0);
2341 return (PRIV_POLICY(cr, PRIV_CONTRACT_OBSERVER, B_FALSE, EPERM, NULL));
2345 * secpolicy_contract_observer_choice
2347 * Determine if the subject may observe any contract's events. Just
2348 * tests privilege and audits on success.
2350 boolean_t
2351 secpolicy_contract_observer_choice(const cred_t *cr)
2353 return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_OBSERVER, B_FALSE));
2357 * secpolicy_contract_event
2359 * Determine if the subject may request critical contract events or
2360 * reliable contract event delivery.
2363 secpolicy_contract_event(const cred_t *cr)
2365 return (PRIV_POLICY(cr, PRIV_CONTRACT_EVENT, B_FALSE, EPERM, NULL));
2369 * secpolicy_contract_event_choice
2371 * Determine if the subject may retain contract events in its critical
2372 * set when a change in other terms would normally require a change in
2373 * the critical set. Just tests privilege and audits on success.
2375 boolean_t
2376 secpolicy_contract_event_choice(const cred_t *cr)
2378 return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_EVENT, B_FALSE));
2382 * secpolicy_gart_access
2384 * Determine if the subject has sufficient priveleges to make ioctls to agpgart
2385 * device.
2388 secpolicy_gart_access(const cred_t *cr)
2390 return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, NULL));
2394 * secpolicy_gart_map
2396 * Determine if the subject has sufficient priveleges to map aperture range
2397 * through agpgart driver.
2400 secpolicy_gart_map(const cred_t *cr)
2402 if (PRIV_POLICY_ONLY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE)) {
2403 return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM,
2404 NULL));
2405 } else {
2406 return (PRIV_POLICY(cr, PRIV_GRAPHICS_MAP, B_FALSE, EPERM,
2407 NULL));
2412 * secpolicy_xhci
2414 * Determine if the subject can observe and manipulate the xhci driver with a
2415 * dangerous blunt hammer. Requires all privileges.
2418 secpolicy_xhci(const cred_t *cr)
2420 return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE));
2424 * secpolicy_zinject
2426 * Determine if the subject can inject faults in the ZFS fault injection
2427 * framework. Requires all privileges.
2430 secpolicy_zinject(const cred_t *cr)
2432 return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE));
2436 * secpolicy_zfs
2438 * Determine if the subject has permission to manipulate ZFS datasets
2439 * (not pools). Equivalent to the SYS_MOUNT privilege.
2442 secpolicy_zfs(const cred_t *cr)
2444 return (PRIV_POLICY(cr, PRIV_SYS_MOUNT, B_FALSE, EPERM, NULL));
2448 * secpolicy_idmap
2450 * Determine if the calling process has permissions to register an SID
2451 * mapping daemon and allocate ephemeral IDs.
2454 secpolicy_idmap(const cred_t *cr)
2456 return (PRIV_POLICY(cr, PRIV_FILE_SETID, B_TRUE, EPERM, NULL));
2460 * secpolicy_ucode_update
2462 * Determine if the subject has sufficient privilege to update microcode.
2465 secpolicy_ucode_update(const cred_t *scr)
2467 return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL));
2471 * secpolicy_sadopen
2473 * Determine if the subject has sufficient privilege to access /dev/sad/admin.
2474 * /dev/sad/admin appear in global zone and exclusive-IP zones only.
2475 * In global zone, sys_config is required.
2476 * In exclusive-IP zones, sys_ip_config is required.
2477 * Note that sys_config is prohibited in non-global zones.
2480 secpolicy_sadopen(const cred_t *credp)
2482 priv_set_t pset;
2484 priv_emptyset(&pset);
2486 if (crgetzoneid(credp) == GLOBAL_ZONEID)
2487 priv_addset(&pset, PRIV_SYS_CONFIG);
2488 else
2489 priv_addset(&pset, PRIV_SYS_IP_CONFIG);
2491 return (secpolicy_require_set(credp, &pset, "devpolicy", KLPDARG_NONE));
2496 * Add privileges to a particular privilege set; this is called when the
2497 * current sets of privileges are not sufficient. I.e., we should always
2498 * call the policy override functions from here.
2499 * What we are allowed to have is in the Observed Permitted set; so
2500 * we compute the difference between that and the newset.
2503 secpolicy_require_privs(const cred_t *cr, const priv_set_t *nset)
2505 priv_set_t rqd;
2507 rqd = CR_OPPRIV(cr);
2509 priv_inverse(&rqd);
2510 priv_intersect(nset, &rqd);
2512 return (secpolicy_require_set(cr, &rqd, NULL, KLPDARG_NONE));
2516 * secpolicy_smb
2518 * Determine if the cred_t has PRIV_SYS_SMB privilege, indicating
2519 * that it has permission to access the smbsrv kernel driver.
2520 * PRIV_POLICY checks the privilege and audits the check.
2522 * Returns:
2523 * 0 Driver access is allowed.
2524 * EPERM Driver access is NOT permitted.
2527 secpolicy_smb(const cred_t *cr)
2529 return (PRIV_POLICY(cr, PRIV_SYS_SMB, B_FALSE, EPERM, NULL));
2533 * secpolicy_vscan
2535 * Determine if cred_t has the necessary privileges to access a file
2536 * for virus scanning and update its extended system attributes.
2537 * PRIV_FILE_DAC_SEARCH, PRIV_FILE_DAC_READ - file access
2538 * PRIV_FILE_FLAG_SET - set extended system attributes
2540 * PRIV_POLICY checks the privilege and audits the check.
2542 * Returns:
2543 * 0 file access for virus scanning allowed.
2544 * EPERM file access for virus scanning is NOT permitted.
2547 secpolicy_vscan(const cred_t *cr)
2549 if ((PRIV_POLICY(cr, PRIV_FILE_DAC_SEARCH, B_FALSE, EPERM, NULL)) ||
2550 (PRIV_POLICY(cr, PRIV_FILE_DAC_READ, B_FALSE, EPERM, NULL)) ||
2551 (PRIV_POLICY(cr, PRIV_FILE_FLAG_SET, B_FALSE, EPERM, NULL))) {
2552 return (EPERM);
2555 return (0);
2559 * secpolicy_smbfs_login
2561 * Determines if the caller can add and delete the smbfs login
2562 * password in the the nsmb kernel module for the CIFS client.
2564 * Returns:
2565 * 0 access is allowed.
2566 * EPERM access is NOT allowed.
2569 secpolicy_smbfs_login(const cred_t *cr, uid_t uid)
2571 uid_t cruid = crgetruid(cr);
2573 if (cruid == uid)
2574 return (0);
2575 return (PRIV_POLICY(cr, PRIV_PROC_OWNER, B_FALSE,
2576 EPERM, NULL));
2580 * secpolicy_xvm_control
2582 * Determines if a caller can control the xVM hypervisor and/or running
2583 * domains (x86 specific).
2585 * Returns:
2586 * 0 access is allowed.
2587 * EPERM access is NOT allowed.
2590 secpolicy_xvm_control(const cred_t *cr)
2592 if (PRIV_POLICY(cr, PRIV_XVM_CONTROL, B_FALSE, EPERM, NULL))
2593 return (EPERM);
2594 return (0);
2598 * secpolicy_ppp_config
2600 * Determine if the subject has sufficient privileges to configure PPP and
2601 * PPP-related devices.
2604 secpolicy_ppp_config(const cred_t *cr)
2606 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
2607 return (secpolicy_net_config(cr, B_FALSE));
2608 return (PRIV_POLICY(cr, PRIV_SYS_PPP_CONFIG, B_FALSE, EPERM, NULL));