xref: /titanic_52/usr/src/uts/common/os/policy.c (revision 634e26ec75c89095090605284938356a3145f2b8)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*634e26ecSCasper H.S. Dik  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/systm.h>
307c478bd9Sstevel@tonic-gate #include <sys/cred_impl.h>
317c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
327c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
337c478bd9Sstevel@tonic-gate #include <sys/stat.h>
347c478bd9Sstevel@tonic-gate #include <sys/errno.h>
357c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
367c478bd9Sstevel@tonic-gate #include <sys/user.h>
377c478bd9Sstevel@tonic-gate #include <sys/proc.h>
387c478bd9Sstevel@tonic-gate #include <sys/acct.h>
397c478bd9Sstevel@tonic-gate #include <sys/ipc_impl.h>
407c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
417c478bd9Sstevel@tonic-gate #include <sys/debug.h>
427c478bd9Sstevel@tonic-gate #include <sys/policy.h>
437c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
447c478bd9Sstevel@tonic-gate #include <sys/msg.h>
457c478bd9Sstevel@tonic-gate #include <sys/devpolicy.h>
467c478bd9Sstevel@tonic-gate #include <c2/audit.h>
477c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
48ddf7fe95Scasper #include <sys/klpd.h>
497c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
507c478bd9Sstevel@tonic-gate #include <sys/disp.h>
517c478bd9Sstevel@tonic-gate #include <sys/zone.h>
527c478bd9Sstevel@tonic-gate #include <inet/optcom.h>
537c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
547c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
557c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
567c478bd9Sstevel@tonic-gate #include <sys/contract_impl.h>
57da14cebeSEric Cheng #include <sys/dld_ioc.h>
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * There are two possible layers of privilege routines and two possible
617c478bd9Sstevel@tonic-gate  * levels of secpolicy.  Plus one other we may not be interested in, so
627c478bd9Sstevel@tonic-gate  * we may need as many as 6 but no more.
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate #define	MAXPRIVSTACK		6
657c478bd9Sstevel@tonic-gate 
66*634e26ecSCasper H.S. Dik #ifdef DEBUG
67*634e26ecSCasper H.S. Dik int priv_debug = 1;
68*634e26ecSCasper H.S. Dik #else
697c478bd9Sstevel@tonic-gate int priv_debug = 0;
70*634e26ecSCasper H.S. Dik #endif
71*634e26ecSCasper H.S. Dik int priv_basic_test = -1;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * This file contains the majority of the policy routines.
757c478bd9Sstevel@tonic-gate  * Since the policy routines are defined by function and not
767c478bd9Sstevel@tonic-gate  * by privilege, there is quite a bit of duplication of
777c478bd9Sstevel@tonic-gate  * functions.
787c478bd9Sstevel@tonic-gate  *
79da6c28aaSamw  * The secpolicy functions must not make assumptions about
807c478bd9Sstevel@tonic-gate  * locks held or not held as any lock can be held while they're
817c478bd9Sstevel@tonic-gate  * being called.
827c478bd9Sstevel@tonic-gate  *
837c478bd9Sstevel@tonic-gate  * Credentials are read-only so no special precautions need to
847c478bd9Sstevel@tonic-gate  * be taken while locking them.
857c478bd9Sstevel@tonic-gate  *
867c478bd9Sstevel@tonic-gate  * When a new policy check needs to be added to the system the
877c478bd9Sstevel@tonic-gate  * following procedure should be followed:
887c478bd9Sstevel@tonic-gate  *
897c478bd9Sstevel@tonic-gate  *		Pick an appropriate secpolicy_*() function
907c478bd9Sstevel@tonic-gate  *			-> done if one exists.
917c478bd9Sstevel@tonic-gate  *		Create a new secpolicy function, preferably with
927c478bd9Sstevel@tonic-gate  *		a descriptive name using the standard template.
937c478bd9Sstevel@tonic-gate  *		Pick an appropriate privilege for the policy.
947c478bd9Sstevel@tonic-gate  *		If no appropraite privilege exists, define new one
957c478bd9Sstevel@tonic-gate  *		(this should be done with extreme care; in most cases
967c478bd9Sstevel@tonic-gate  *		little is gained by adding another privilege)
977c478bd9Sstevel@tonic-gate  *
987c478bd9Sstevel@tonic-gate  * WHY ROOT IS STILL SPECIAL.
997c478bd9Sstevel@tonic-gate  *
1007c478bd9Sstevel@tonic-gate  * In a number of the policy functions, there are still explicit
1017c478bd9Sstevel@tonic-gate  * checks for uid 0.  The rationale behind these is that many root
1027c478bd9Sstevel@tonic-gate  * owned files/objects hold configuration information which can give full
1037c478bd9Sstevel@tonic-gate  * privileges to the user once written to.  To prevent escalation
1047c478bd9Sstevel@tonic-gate  * of privilege by allowing just a single privilege to modify root owned
1057c478bd9Sstevel@tonic-gate  * objects, we've added these root specific checks where we considered
1067c478bd9Sstevel@tonic-gate  * them necessary: modifying root owned files, changing uids to 0, etc.
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  * PRIVILEGE ESCALATION AND ZONES.
1097c478bd9Sstevel@tonic-gate  *
1107c478bd9Sstevel@tonic-gate  * A number of operations potentially allow the caller to achieve
1117c478bd9Sstevel@tonic-gate  * privileges beyond the ones normally required to perform the operation.
1127c478bd9Sstevel@tonic-gate  * For example, if allowed to create a setuid 0 executable, a process can
1137c478bd9Sstevel@tonic-gate  * gain privileges beyond PRIV_FILE_SETID.  Zones, however, place
1147c478bd9Sstevel@tonic-gate  * restrictions on the ability to gain privileges beyond those available
1157c478bd9Sstevel@tonic-gate  * within the zone through file and process manipulation.  Hence, such
1167c478bd9Sstevel@tonic-gate  * operations require that the caller have an effective set that includes
1177c478bd9Sstevel@tonic-gate  * all privileges available within the current zone, or all privileges
1187c478bd9Sstevel@tonic-gate  * if executing in the global zone.
1197c478bd9Sstevel@tonic-gate  *
1207c478bd9Sstevel@tonic-gate  * This is indicated in the priv_policy* policy checking functions
1217c478bd9Sstevel@tonic-gate  * through a combination of parameters.  The "priv" parameter indicates
1227c478bd9Sstevel@tonic-gate  * the privilege that is required, and the "allzone" parameter indicates
1237c478bd9Sstevel@tonic-gate  * whether or not all privileges in the zone are required.  In addition,
1247c478bd9Sstevel@tonic-gate  * priv can be set to PRIV_ALL to indicate that all privileges are
1257c478bd9Sstevel@tonic-gate  * required (regardless of zone).  There are three scenarios of interest:
1267c478bd9Sstevel@tonic-gate  * (1) operation requires a specific privilege
1277c478bd9Sstevel@tonic-gate  * (2) operation requires a specific privilege, and requires all
1287c478bd9Sstevel@tonic-gate  *     privileges available within the zone (or all privileges if in
1297c478bd9Sstevel@tonic-gate  *     the global zone)
1307c478bd9Sstevel@tonic-gate  * (3) operation requires all privileges, regardless of zone
1317c478bd9Sstevel@tonic-gate  *
1327c478bd9Sstevel@tonic-gate  * For (1), priv should be set to the specific privilege, and allzone
1337c478bd9Sstevel@tonic-gate  * should be set to B_FALSE.
1347c478bd9Sstevel@tonic-gate  * For (2), priv should be set to the specific privilege, and allzone
1357c478bd9Sstevel@tonic-gate  * should be set to B_TRUE.
1367c478bd9Sstevel@tonic-gate  * For (3), priv should be set to PRIV_ALL, and allzone should be set
1377c478bd9Sstevel@tonic-gate  * to B_FALSE.
1387c478bd9Sstevel@tonic-gate  *
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * The privileges are checked against the Effective set for
1437c478bd9Sstevel@tonic-gate  * ordinary processes and checked against the Limit set
1447c478bd9Sstevel@tonic-gate  * for euid 0 processes that haven't manipulated their privilege
1457c478bd9Sstevel@tonic-gate  * sets.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate #define	HAS_ALLPRIVS(cr)	priv_isfullset(&CR_OEPRIV(cr))
1487c478bd9Sstevel@tonic-gate #define	ZONEPRIVS(cr)		((cr)->cr_zone->zone_privset)
1497c478bd9Sstevel@tonic-gate #define	HAS_ALLZONEPRIVS(cr)	priv_issubset(ZONEPRIVS(cr), &CR_OEPRIV(cr))
1507c478bd9Sstevel@tonic-gate #define	HAS_PRIVILEGE(cr, pr)	((pr) == PRIV_ALL ? \
1517c478bd9Sstevel@tonic-gate 					HAS_ALLPRIVS(cr) : \
1527c478bd9Sstevel@tonic-gate 					PRIV_ISASSERT(&CR_OEPRIV(cr), pr))
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
155ddf7fe95Scasper  * Policy checking functions.
1567c478bd9Sstevel@tonic-gate  *
157ddf7fe95Scasper  * All of the system's policy should be implemented here.
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate /*
161ddf7fe95Scasper  * Private functions which take an additional va_list argument to
162ddf7fe95Scasper  * implement an object specific policy override.
163ddf7fe95Scasper  */
164ddf7fe95Scasper static int priv_policy_ap(const cred_t *, int, boolean_t, int,
165ddf7fe95Scasper     const char *, va_list);
166ddf7fe95Scasper static int priv_policy_va(const cred_t *, int, boolean_t, int,
167ddf7fe95Scasper     const char *, ...);
168ddf7fe95Scasper 
169ddf7fe95Scasper /*
1707c478bd9Sstevel@tonic-gate  * Generic policy calls
1717c478bd9Sstevel@tonic-gate  *
1727c478bd9Sstevel@tonic-gate  * The "bottom" functions of policy control
1737c478bd9Sstevel@tonic-gate  */
1747c478bd9Sstevel@tonic-gate static char *
1757c478bd9Sstevel@tonic-gate mprintf(const char *fmt, ...)
1767c478bd9Sstevel@tonic-gate {
1777c478bd9Sstevel@tonic-gate 	va_list args;
1787c478bd9Sstevel@tonic-gate 	char *buf;
1797c478bd9Sstevel@tonic-gate 	size_t len;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
1827c478bd9Sstevel@tonic-gate 	len = vsnprintf(NULL, 0, fmt, args) + 1;
1837c478bd9Sstevel@tonic-gate 	va_end(args);
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	buf = kmem_alloc(len, KM_NOSLEEP);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	if (buf == NULL)
1887c478bd9Sstevel@tonic-gate 		return (NULL);
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
1917c478bd9Sstevel@tonic-gate 	(void) vsnprintf(buf, len, fmt, args);
1927c478bd9Sstevel@tonic-gate 	va_end(args);
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	return (buf);
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * priv_policy_errmsg()
1997c478bd9Sstevel@tonic-gate  *
2007c478bd9Sstevel@tonic-gate  * Generate an error message if privilege debugging is enabled system wide
2017c478bd9Sstevel@tonic-gate  * or for this particular process.
2027c478bd9Sstevel@tonic-gate  */
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate #define	FMTHDR	"%s[%d]: missing privilege \"%s\" (euid = %d, syscall = %d)"
2057c478bd9Sstevel@tonic-gate #define	FMTMSG	" for \"%s\""
2067c478bd9Sstevel@tonic-gate #define	FMTFUN	" needed at %s+0x%lx"
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /* The maximum size privilege format: the concatenation of the above */
2097c478bd9Sstevel@tonic-gate #define	FMTMAX	FMTHDR FMTMSG FMTFUN "\n"
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate static void
2127c478bd9Sstevel@tonic-gate priv_policy_errmsg(const cred_t *cr, int priv, const char *msg)
2137c478bd9Sstevel@tonic-gate {
2147c478bd9Sstevel@tonic-gate 	struct proc *me;
2157c478bd9Sstevel@tonic-gate 	pc_t stack[MAXPRIVSTACK];
2167c478bd9Sstevel@tonic-gate 	int depth;
2177c478bd9Sstevel@tonic-gate 	int i;
2187c478bd9Sstevel@tonic-gate 	char *sym;
2197c478bd9Sstevel@tonic-gate 	ulong_t off;
2207c478bd9Sstevel@tonic-gate 	const char *pname;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	char *cmd;
2237c478bd9Sstevel@tonic-gate 	char fmt[sizeof (FMTMAX)];
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	if ((me = curproc) == &p0)
2267c478bd9Sstevel@tonic-gate 		return;
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	/* Privileges must be defined  */
2297c478bd9Sstevel@tonic-gate 	ASSERT(priv == PRIV_ALL || priv == PRIV_MULTIPLE ||
2307c478bd9Sstevel@tonic-gate 	    priv == PRIV_ALLZONE || priv == PRIV_GLOBAL ||
2317c478bd9Sstevel@tonic-gate 	    priv_getbynum(priv) != NULL);
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	if (priv == PRIV_ALLZONE && INGLOBALZONE(me))
2347c478bd9Sstevel@tonic-gate 		priv = PRIV_ALL;
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	if (curthread->t_pre_sys)
2377c478bd9Sstevel@tonic-gate 		ttolwp(curthread)->lwp_badpriv = (short)priv;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	if (priv_debug == 0 && (CR_FLAGS(cr) & PRIV_DEBUG) == 0)
2407c478bd9Sstevel@tonic-gate 		return;
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	(void) strcpy(fmt, FMTHDR);
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	if (me->p_user.u_comm[0])
2457c478bd9Sstevel@tonic-gate 		cmd = &me->p_user.u_comm[0];
2467c478bd9Sstevel@tonic-gate 	else
2477c478bd9Sstevel@tonic-gate 		cmd = "priv_policy";
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	if (msg != NULL && *msg != '\0') {
2507c478bd9Sstevel@tonic-gate 		(void) strcat(fmt, FMTMSG);
2517c478bd9Sstevel@tonic-gate 	} else {
2527c478bd9Sstevel@tonic-gate 		(void) strcat(fmt, "%s");
2537c478bd9Sstevel@tonic-gate 		msg = "";
2547c478bd9Sstevel@tonic-gate 	}
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	sym = NULL;
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	depth = getpcstack(stack, MAXPRIVSTACK);
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 	/*
2617c478bd9Sstevel@tonic-gate 	 * Try to find the first interesting function on the stack.
2627c478bd9Sstevel@tonic-gate 	 * priv_policy* that's us, so completely uninteresting.
2637c478bd9Sstevel@tonic-gate 	 * suser(), drv_priv(), secpolicy_* are also called from
2647c478bd9Sstevel@tonic-gate 	 * too many locations to convey useful information.
2657c478bd9Sstevel@tonic-gate 	 */
2667c478bd9Sstevel@tonic-gate 	for (i = 0; i < depth; i++) {
2677c478bd9Sstevel@tonic-gate 		sym = kobj_getsymname((uintptr_t)stack[i], &off);
2687c478bd9Sstevel@tonic-gate 		if (sym != NULL &&
2697c478bd9Sstevel@tonic-gate 		    strstr(sym, "hasprocperm") == 0 &&
2707c478bd9Sstevel@tonic-gate 		    strcmp("suser", sym) != 0 &&
2717c478bd9Sstevel@tonic-gate 		    strcmp("ipcaccess", sym) != 0 &&
2727c478bd9Sstevel@tonic-gate 		    strcmp("drv_priv", sym) != 0 &&
2737c478bd9Sstevel@tonic-gate 		    strncmp("secpolicy_", sym, 10) != 0 &&
2747c478bd9Sstevel@tonic-gate 		    strncmp("priv_policy", sym, 11) != 0)
2757c478bd9Sstevel@tonic-gate 			break;
2767c478bd9Sstevel@tonic-gate 	}
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	if (sym != NULL)
2797c478bd9Sstevel@tonic-gate 		(void) strcat(fmt, FMTFUN);
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	(void) strcat(fmt, "\n");
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	switch (priv) {
2847c478bd9Sstevel@tonic-gate 	case PRIV_ALL:
2857c478bd9Sstevel@tonic-gate 		pname = "ALL";
2867c478bd9Sstevel@tonic-gate 		break;
2877c478bd9Sstevel@tonic-gate 	case PRIV_MULTIPLE:
2887c478bd9Sstevel@tonic-gate 		pname = "MULTIPLE";
2897c478bd9Sstevel@tonic-gate 		break;
2907c478bd9Sstevel@tonic-gate 	case PRIV_ALLZONE:
2917c478bd9Sstevel@tonic-gate 		pname = "ZONE";
2927c478bd9Sstevel@tonic-gate 		break;
2937c478bd9Sstevel@tonic-gate 	case PRIV_GLOBAL:
2947c478bd9Sstevel@tonic-gate 		pname = "GLOBAL";
2957c478bd9Sstevel@tonic-gate 		break;
2967c478bd9Sstevel@tonic-gate 	default:
2977c478bd9Sstevel@tonic-gate 		pname = priv_getbynum(priv);
2987c478bd9Sstevel@tonic-gate 		break;
2997c478bd9Sstevel@tonic-gate 	}
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	if (CR_FLAGS(cr) & PRIV_DEBUG) {
3027c478bd9Sstevel@tonic-gate 		/* Remember last message, just like lwp_badpriv. */
3037c478bd9Sstevel@tonic-gate 		if (curthread->t_pdmsg != NULL) {
3047c478bd9Sstevel@tonic-gate 			kmem_free(curthread->t_pdmsg,
3057c478bd9Sstevel@tonic-gate 			    strlen(curthread->t_pdmsg) + 1);
3067c478bd9Sstevel@tonic-gate 		}
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 		curthread->t_pdmsg = mprintf(fmt, cmd, me->p_pid, pname,
3097c478bd9Sstevel@tonic-gate 		    cr->cr_uid, curthread->t_sysnum, msg, sym, off);
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 		curthread->t_post_sys = 1;
312ddf7fe95Scasper 	}
313ddf7fe95Scasper 	if (priv_debug) {
3147c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, fmt, cmd, me->p_pid, pname, cr->cr_uid,
3157c478bd9Sstevel@tonic-gate 		    curthread->t_sysnum, msg, sym, off);
3167c478bd9Sstevel@tonic-gate 	}
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate /*
320ddf7fe95Scasper  * Override the policy, if appropriate.  Return 0 if the external
321ddf7fe95Scasper  * policy engine approves.
322ddf7fe95Scasper  */
323ddf7fe95Scasper static int
324ddf7fe95Scasper priv_policy_override(const cred_t *cr, int priv, boolean_t allzone, va_list ap)
325ddf7fe95Scasper {
326ddf7fe95Scasper 	priv_set_t set;
327ddf7fe95Scasper 	int ret;
328ddf7fe95Scasper 
329ddf7fe95Scasper 	if (!(CR_FLAGS(cr) & PRIV_XPOLICY))
330ddf7fe95Scasper 		return (-1);
331ddf7fe95Scasper 
332ddf7fe95Scasper 	if (priv == PRIV_ALL) {
333ddf7fe95Scasper 		priv_fillset(&set);
334ddf7fe95Scasper 	} else if (allzone) {
335ddf7fe95Scasper 		set = *ZONEPRIVS(cr);
336ddf7fe95Scasper 	} else {
337ddf7fe95Scasper 		priv_emptyset(&set);
338ddf7fe95Scasper 		priv_addset(&set, priv);
339ddf7fe95Scasper 	}
340ddf7fe95Scasper 	ret = klpd_call(cr, &set, ap);
341ddf7fe95Scasper 	return (ret);
342ddf7fe95Scasper }
343ddf7fe95Scasper 
344ddf7fe95Scasper static int
345ddf7fe95Scasper priv_policy_override_set(const cred_t *cr, const priv_set_t *req, ...)
346ddf7fe95Scasper {
347ddf7fe95Scasper 	va_list ap;
348ddf7fe95Scasper 
349ddf7fe95Scasper 	if (CR_FLAGS(cr) & PRIV_XPOLICY) {
350ddf7fe95Scasper 		va_start(ap, req);
351ddf7fe95Scasper 		return (klpd_call(cr, req, ap));
352ddf7fe95Scasper 	}
353ddf7fe95Scasper 	return (-1);
354ddf7fe95Scasper }
355ddf7fe95Scasper 
356ddf7fe95Scasper /*
3577c478bd9Sstevel@tonic-gate  * Audit failure, log error message.
3587c478bd9Sstevel@tonic-gate  */
3597c478bd9Sstevel@tonic-gate static void
3607c478bd9Sstevel@tonic-gate priv_policy_err(const cred_t *cr, int priv, boolean_t allzone, const char *msg)
3617c478bd9Sstevel@tonic-gate {
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	if (audit_active)
3647c478bd9Sstevel@tonic-gate 		audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 0);
3657c478bd9Sstevel@tonic-gate 	DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone);
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) ||
3687c478bd9Sstevel@tonic-gate 	    curthread->t_pre_sys) {
3697c478bd9Sstevel@tonic-gate 		if (allzone && !HAS_ALLZONEPRIVS(cr)) {
3707c478bd9Sstevel@tonic-gate 			priv_policy_errmsg(cr, PRIV_ALLZONE, msg);
3717c478bd9Sstevel@tonic-gate 		} else {
3727c478bd9Sstevel@tonic-gate 			ASSERT(!HAS_PRIVILEGE(cr, priv));
3737c478bd9Sstevel@tonic-gate 			priv_policy_errmsg(cr, priv, msg);
3747c478bd9Sstevel@tonic-gate 		}
3757c478bd9Sstevel@tonic-gate 	}
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate /*
379ddf7fe95Scasper  * priv_policy_ap()
3807c478bd9Sstevel@tonic-gate  * return 0 or error.
3817c478bd9Sstevel@tonic-gate  * See block comment above for a description of "priv" and "allzone" usage.
3827c478bd9Sstevel@tonic-gate  */
383ddf7fe95Scasper static int
384ddf7fe95Scasper priv_policy_ap(const cred_t *cr, int priv, boolean_t allzone, int err,
385ddf7fe95Scasper     const char *msg, va_list ap)
3867c478bd9Sstevel@tonic-gate {
387ddf7fe95Scasper 	if ((HAS_PRIVILEGE(cr, priv) && (!allzone || HAS_ALLZONEPRIVS(cr))) ||
388ddf7fe95Scasper 	    (!servicing_interrupt() &&
389ddf7fe95Scasper 	    priv_policy_override(cr, priv, allzone, ap) == 0)) {
3907c478bd9Sstevel@tonic-gate 		if ((allzone || priv == PRIV_ALL ||
3917c478bd9Sstevel@tonic-gate 		    !PRIV_ISASSERT(priv_basic, priv)) &&
3927c478bd9Sstevel@tonic-gate 		    !servicing_interrupt()) {
393ae115bc7Smrj 			PTOU(curproc)->u_acflag |= ASU; /* Needed for SVVS */
3947c478bd9Sstevel@tonic-gate 			if (audit_active)
3957c478bd9Sstevel@tonic-gate 				audit_priv(priv,
3967c478bd9Sstevel@tonic-gate 				    allzone ? ZONEPRIVS(cr) : NULL, 1);
3977c478bd9Sstevel@tonic-gate 		}
3987c478bd9Sstevel@tonic-gate 		err = 0;
3997c478bd9Sstevel@tonic-gate 		DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone);
4007c478bd9Sstevel@tonic-gate 	} else if (!servicing_interrupt()) {
4017c478bd9Sstevel@tonic-gate 		/* Failure audited in this procedure */
4027c478bd9Sstevel@tonic-gate 		priv_policy_err(cr, priv, allzone, msg);
4037c478bd9Sstevel@tonic-gate 	}
4047c478bd9Sstevel@tonic-gate 	return (err);
4057c478bd9Sstevel@tonic-gate }
4067c478bd9Sstevel@tonic-gate 
407ddf7fe95Scasper int
408ddf7fe95Scasper priv_policy_va(const cred_t *cr, int priv, boolean_t allzone, int err,
409ddf7fe95Scasper     const char *msg, ...)
410ddf7fe95Scasper {
411ddf7fe95Scasper 	int ret;
412ddf7fe95Scasper 	va_list ap;
413ddf7fe95Scasper 
414ddf7fe95Scasper 	va_start(ap, msg);
415ddf7fe95Scasper 	ret = priv_policy_ap(cr, priv, allzone, err, msg, ap);
416ddf7fe95Scasper 	va_end(ap);
417ddf7fe95Scasper 
418ddf7fe95Scasper 	return (ret);
419ddf7fe95Scasper }
420ddf7fe95Scasper 
421ddf7fe95Scasper int
422ddf7fe95Scasper priv_policy(const cred_t *cr, int priv, boolean_t allzone, int err,
423ddf7fe95Scasper     const char *msg)
424ddf7fe95Scasper {
425ddf7fe95Scasper 	return (priv_policy_va(cr, priv, allzone, err, msg, KLPDARG_NOMORE));
426ddf7fe95Scasper }
427ddf7fe95Scasper 
4287c478bd9Sstevel@tonic-gate /*
4297c478bd9Sstevel@tonic-gate  * Return B_TRUE for sufficient privileges, B_FALSE for insufficient privileges.
4307c478bd9Sstevel@tonic-gate  */
4317c478bd9Sstevel@tonic-gate boolean_t
4327c478bd9Sstevel@tonic-gate priv_policy_choice(const cred_t *cr, int priv, boolean_t allzone)
4337c478bd9Sstevel@tonic-gate {
4347c478bd9Sstevel@tonic-gate 	boolean_t res = HAS_PRIVILEGE(cr, priv) &&
4357c478bd9Sstevel@tonic-gate 	    (!allzone || HAS_ALLZONEPRIVS(cr));
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 	/* Audit success only */
4387c478bd9Sstevel@tonic-gate 	if (res && audit_active &&
4397c478bd9Sstevel@tonic-gate 	    (allzone || priv == PRIV_ALL || !PRIV_ISASSERT(priv_basic, priv)) &&
4407c478bd9Sstevel@tonic-gate 	    !servicing_interrupt()) {
4417c478bd9Sstevel@tonic-gate 		audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 1);
4427c478bd9Sstevel@tonic-gate 	}
4437c478bd9Sstevel@tonic-gate 	if (res) {
4447c478bd9Sstevel@tonic-gate 		DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone);
4457c478bd9Sstevel@tonic-gate 	} else {
4467c478bd9Sstevel@tonic-gate 		DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone);
4477c478bd9Sstevel@tonic-gate 	}
4487c478bd9Sstevel@tonic-gate 	return (res);
4497c478bd9Sstevel@tonic-gate }
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate /*
4527c478bd9Sstevel@tonic-gate  * Non-auditing variant of priv_policy_choice().
4537c478bd9Sstevel@tonic-gate  */
4547c478bd9Sstevel@tonic-gate boolean_t
4557c478bd9Sstevel@tonic-gate priv_policy_only(const cred_t *cr, int priv, boolean_t allzone)
4567c478bd9Sstevel@tonic-gate {
4577c478bd9Sstevel@tonic-gate 	boolean_t res = HAS_PRIVILEGE(cr, priv) &&
4587c478bd9Sstevel@tonic-gate 	    (!allzone || HAS_ALLZONEPRIVS(cr));
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 	if (res) {
4617c478bd9Sstevel@tonic-gate 		DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone);
4627c478bd9Sstevel@tonic-gate 	} else {
4637c478bd9Sstevel@tonic-gate 		DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone);
4647c478bd9Sstevel@tonic-gate 	}
4657c478bd9Sstevel@tonic-gate 	return (res);
4667c478bd9Sstevel@tonic-gate }
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate /*
4697c478bd9Sstevel@tonic-gate  * Check whether all privileges in the required set are present.
4707c478bd9Sstevel@tonic-gate  */
4717c478bd9Sstevel@tonic-gate static int
4727c478bd9Sstevel@tonic-gate secpolicy_require_set(const cred_t *cr, const priv_set_t *req, const char *msg)
4737c478bd9Sstevel@tonic-gate {
4747c478bd9Sstevel@tonic-gate 	int priv;
4757c478bd9Sstevel@tonic-gate 	int pfound = -1;
4767c478bd9Sstevel@tonic-gate 	priv_set_t pset;
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate 	if (req == PRIV_FULLSET ? HAS_ALLPRIVS(cr) : priv_issubset(req,
4797c478bd9Sstevel@tonic-gate 	    &CR_OEPRIV(cr))) {
4807c478bd9Sstevel@tonic-gate 		return (0);
4817c478bd9Sstevel@tonic-gate 	}
4827c478bd9Sstevel@tonic-gate 
483ddf7fe95Scasper 	if (priv_policy_override_set(cr, req, KLPDARG_NOMORE) == 0)
484ddf7fe95Scasper 		return (0);
485ddf7fe95Scasper 
4867c478bd9Sstevel@tonic-gate 	if (req == PRIV_FULLSET || priv_isfullset(req)) {
4877c478bd9Sstevel@tonic-gate 		priv_policy_err(cr, PRIV_ALL, B_FALSE, msg);
4887c478bd9Sstevel@tonic-gate 		return (EACCES);
4897c478bd9Sstevel@tonic-gate 	}
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	pset = CR_OEPRIV(cr);		/* present privileges */
4927c478bd9Sstevel@tonic-gate 	priv_inverse(&pset);		/* all non present privileges */
4937c478bd9Sstevel@tonic-gate 	priv_intersect(req, &pset);	/* the actual missing privs */
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate 	if (audit_active)
4967c478bd9Sstevel@tonic-gate 		audit_priv(PRIV_NONE, &pset, 0);
4977c478bd9Sstevel@tonic-gate 	/*
4987c478bd9Sstevel@tonic-gate 	 * Privilege debugging; special case "one privilege in set".
4997c478bd9Sstevel@tonic-gate 	 */
5007c478bd9Sstevel@tonic-gate 	if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || curthread->t_pre_sys) {
5017c478bd9Sstevel@tonic-gate 		for (priv = 0; priv < nprivs; priv++) {
5027c478bd9Sstevel@tonic-gate 			if (priv_ismember(&pset, priv)) {
5037c478bd9Sstevel@tonic-gate 				if (pfound != -1) {
5047c478bd9Sstevel@tonic-gate 					/* Multiple missing privs */
5057c478bd9Sstevel@tonic-gate 					priv_policy_errmsg(cr, PRIV_MULTIPLE,
5067c478bd9Sstevel@tonic-gate 					    msg);
5077c478bd9Sstevel@tonic-gate 					return (EACCES);
5087c478bd9Sstevel@tonic-gate 				}
5097c478bd9Sstevel@tonic-gate 				pfound = priv;
5107c478bd9Sstevel@tonic-gate 			}
5117c478bd9Sstevel@tonic-gate 		}
5127c478bd9Sstevel@tonic-gate 		ASSERT(pfound != -1);
5137c478bd9Sstevel@tonic-gate 		/* Just the one missing privilege */
5147c478bd9Sstevel@tonic-gate 		priv_policy_errmsg(cr, pfound, msg);
5157c478bd9Sstevel@tonic-gate 	}
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	return (EACCES);
5187c478bd9Sstevel@tonic-gate }
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate /*
5217c478bd9Sstevel@tonic-gate  * Called when an operation requires that the caller be in the
5227c478bd9Sstevel@tonic-gate  * global zone, regardless of privilege.
5237c478bd9Sstevel@tonic-gate  */
5247c478bd9Sstevel@tonic-gate static int
5257c478bd9Sstevel@tonic-gate priv_policy_global(const cred_t *cr)
5267c478bd9Sstevel@tonic-gate {
5277c478bd9Sstevel@tonic-gate 	if (crgetzoneid(cr) == GLOBAL_ZONEID)
5287c478bd9Sstevel@tonic-gate 		return (0);	/* success */
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate 	if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) ||
5317c478bd9Sstevel@tonic-gate 	    curthread->t_pre_sys) {
5327c478bd9Sstevel@tonic-gate 		priv_policy_errmsg(cr, PRIV_GLOBAL, NULL);
5337c478bd9Sstevel@tonic-gate 	}
5347c478bd9Sstevel@tonic-gate 	return (EPERM);
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate /*
5387c478bd9Sstevel@tonic-gate  * Changing process priority
5397c478bd9Sstevel@tonic-gate  */
5407c478bd9Sstevel@tonic-gate int
5417c478bd9Sstevel@tonic-gate secpolicy_setpriority(const cred_t *cr)
5427c478bd9Sstevel@tonic-gate {
5437c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_PROC_PRIOCNTL, B_FALSE, EPERM, NULL));
5447c478bd9Sstevel@tonic-gate }
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate /*
5477c478bd9Sstevel@tonic-gate  * Binding to a privileged port, port must be specified in host byte
5487c478bd9Sstevel@tonic-gate  * order.
5497c478bd9Sstevel@tonic-gate  */
5507c478bd9Sstevel@tonic-gate int
551ddf7fe95Scasper secpolicy_net_privaddr(const cred_t *cr, in_port_t port, int proto)
5527c478bd9Sstevel@tonic-gate {
553da6c28aaSamw 	char *reason;
554da6c28aaSamw 	int priv;
555da6c28aaSamw 
556da6c28aaSamw 	switch (port) {
557da6c28aaSamw 	case 137:
558da6c28aaSamw 	case 138:
559da6c28aaSamw 	case 139:
560da6c28aaSamw 	case 445:
561da6c28aaSamw 		/*
562da6c28aaSamw 		 * NBT and SMB ports, these are extra privileged ports,
563da6c28aaSamw 		 * allow bind only if the SYS_SMB privilege is present.
564da6c28aaSamw 		 */
565da6c28aaSamw 		priv = PRIV_SYS_SMB;
566da6c28aaSamw 		reason = "NBT or SMB port";
567da6c28aaSamw 		break;
568da6c28aaSamw 
569da6c28aaSamw 	case 2049:
570da6c28aaSamw 	case 4045:
5717c478bd9Sstevel@tonic-gate 		/*
5727c478bd9Sstevel@tonic-gate 		 * NFS ports, these are extra privileged ports, allow bind
5737c478bd9Sstevel@tonic-gate 		 * only if the SYS_NFS privilege is present.
5747c478bd9Sstevel@tonic-gate 		 */
575da6c28aaSamw 		priv = PRIV_SYS_NFS;
576da6c28aaSamw 		reason = "NFS port";
577da6c28aaSamw 		break;
578da6c28aaSamw 
579da6c28aaSamw 	default:
580da6c28aaSamw 		priv = PRIV_NET_PRIVADDR;
581da6c28aaSamw 		reason = NULL;
582da6c28aaSamw 		break;
583da6c28aaSamw 
584da6c28aaSamw 	}
585da6c28aaSamw 
586ddf7fe95Scasper 	return (priv_policy_va(cr, priv, B_FALSE, EACCES, reason,
587ddf7fe95Scasper 	    KLPDARG_PORT, (int)proto, (int)port, KLPDARG_NOMORE));
5887c478bd9Sstevel@tonic-gate }
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate /*
59145916cd2Sjpk  * Binding to a multilevel port on a trusted (labeled) system.
59245916cd2Sjpk  */
59345916cd2Sjpk int
59445916cd2Sjpk secpolicy_net_bindmlp(const cred_t *cr)
59545916cd2Sjpk {
596ddf7fe95Scasper 	return (PRIV_POLICY(cr, PRIV_NET_BINDMLP, B_FALSE, EACCES, NULL));
59745916cd2Sjpk }
59845916cd2Sjpk 
59945916cd2Sjpk /*
60045916cd2Sjpk  * Allow a communication between a zone and an unlabeled host when their
60145916cd2Sjpk  * labels don't match.
60245916cd2Sjpk  */
60345916cd2Sjpk int
60445916cd2Sjpk secpolicy_net_mac_aware(const cred_t *cr)
60545916cd2Sjpk {
606ddf7fe95Scasper 	return (PRIV_POLICY(cr, PRIV_NET_MAC_AWARE, B_FALSE, EACCES, NULL));
60745916cd2Sjpk }
60845916cd2Sjpk 
60945916cd2Sjpk /*
6105d3b8cb7SBill Sommerfeld  * Allow a privileged process to transmit traffic without explicit labels
6115d3b8cb7SBill Sommerfeld  */
6125d3b8cb7SBill Sommerfeld int
6135d3b8cb7SBill Sommerfeld secpolicy_net_mac_implicit(const cred_t *cr)
6145d3b8cb7SBill Sommerfeld {
6155d3b8cb7SBill Sommerfeld 	return (PRIV_POLICY(cr, PRIV_NET_MAC_IMPLICIT, B_FALSE, EACCES, NULL));
6165d3b8cb7SBill Sommerfeld }
6175d3b8cb7SBill Sommerfeld 
6185d3b8cb7SBill Sommerfeld /*
6197c478bd9Sstevel@tonic-gate  * Common routine which determines whether a given credential can
6207c478bd9Sstevel@tonic-gate  * act on a given mount.
6217c478bd9Sstevel@tonic-gate  * When called through mount, the parameter needoptcheck is a pointer
6227c478bd9Sstevel@tonic-gate  * to a boolean variable which will be set to either true or false,
6237c478bd9Sstevel@tonic-gate  * depending on whether the mount policy should change the mount options.
6247c478bd9Sstevel@tonic-gate  * In all other cases, needoptcheck should be a NULL pointer.
6257c478bd9Sstevel@tonic-gate  */
6267c478bd9Sstevel@tonic-gate static int
6277c478bd9Sstevel@tonic-gate secpolicy_fs_common(cred_t *cr, vnode_t *mvp, const vfs_t *vfsp,
6287c478bd9Sstevel@tonic-gate     boolean_t *needoptcheck)
6297c478bd9Sstevel@tonic-gate {
6307c478bd9Sstevel@tonic-gate 	boolean_t allzone = B_FALSE;
6317c478bd9Sstevel@tonic-gate 	boolean_t mounting = needoptcheck != NULL;
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate 	/*
6347c478bd9Sstevel@tonic-gate 	 * Short circuit the following cases:
6357c478bd9Sstevel@tonic-gate 	 *	vfsp == NULL or mvp == NULL (pure privilege check)
6367c478bd9Sstevel@tonic-gate 	 *	have all privileges - no further checks required
6377c478bd9Sstevel@tonic-gate 	 *	and no mount options need to be set.
6387c478bd9Sstevel@tonic-gate 	 */
6397c478bd9Sstevel@tonic-gate 	if (vfsp == NULL || mvp == NULL || HAS_ALLPRIVS(cr)) {
6407c478bd9Sstevel@tonic-gate 		if (mounting)
6417c478bd9Sstevel@tonic-gate 			*needoptcheck = B_FALSE;
6427c478bd9Sstevel@tonic-gate 
643ddf7fe95Scasper 		return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM,
644ddf7fe95Scasper 		    NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE));
6457c478bd9Sstevel@tonic-gate 	}
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate 	/*
6487c478bd9Sstevel@tonic-gate 	 * When operating on an existing mount (either we're not mounting
6497c478bd9Sstevel@tonic-gate 	 * or we're doing a remount and VFS_REMOUNT will be set), zones
6507c478bd9Sstevel@tonic-gate 	 * can operate only on mounts established by the zone itself.
6517c478bd9Sstevel@tonic-gate 	 */
6527c478bd9Sstevel@tonic-gate 	if (!mounting || (vfsp->vfs_flag & VFS_REMOUNT) != 0) {
6537c478bd9Sstevel@tonic-gate 		zoneid_t zoneid = crgetzoneid(cr);
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 		if (zoneid != GLOBAL_ZONEID &&
6567c478bd9Sstevel@tonic-gate 		    vfsp->vfs_zone->zone_id != zoneid) {
6577c478bd9Sstevel@tonic-gate 			return (EPERM);
6587c478bd9Sstevel@tonic-gate 		}
6597c478bd9Sstevel@tonic-gate 	}
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate 	if (mounting)
6627c478bd9Sstevel@tonic-gate 		*needoptcheck = B_TRUE;
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate 	/*
6657c478bd9Sstevel@tonic-gate 	 * Overlay mounts may hide important stuff; if you can't write to a
6667c478bd9Sstevel@tonic-gate 	 * mount point but would be able to mount on top of it, you can
6677c478bd9Sstevel@tonic-gate 	 * escalate your privileges.
6687c478bd9Sstevel@tonic-gate 	 * So we go about asking the same questions namefs does when it
6697c478bd9Sstevel@tonic-gate 	 * decides whether you can mount over a file or not but with the
6707c478bd9Sstevel@tonic-gate 	 * added restriction that you can only mount on top of a regular
6717c478bd9Sstevel@tonic-gate 	 * file or directory.
6727c478bd9Sstevel@tonic-gate 	 * If we have all the zone's privileges, we skip all other checks,
6737c478bd9Sstevel@tonic-gate 	 * or else we may actually get in trouble inside the automounter.
6747c478bd9Sstevel@tonic-gate 	 */
6757c478bd9Sstevel@tonic-gate 	if ((mvp->v_flag & VROOT) != 0 ||
6767c478bd9Sstevel@tonic-gate 	    (mvp->v_type != VDIR && mvp->v_type != VREG) ||
6777c478bd9Sstevel@tonic-gate 	    HAS_ALLZONEPRIVS(cr)) {
6787c478bd9Sstevel@tonic-gate 		allzone = B_TRUE;
6797c478bd9Sstevel@tonic-gate 	} else {
6807c478bd9Sstevel@tonic-gate 		vattr_t va;
6817c478bd9Sstevel@tonic-gate 		int err;
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 		va.va_mask = AT_UID|AT_MODE;
684da6c28aaSamw 		err = VOP_GETATTR(mvp, &va, 0, cr, NULL);
6857c478bd9Sstevel@tonic-gate 		if (err != 0)
6867c478bd9Sstevel@tonic-gate 			return (err);
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate 		if ((err = secpolicy_vnode_owner(cr, va.va_uid)) != 0)
6897c478bd9Sstevel@tonic-gate 			return (err);
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 		if ((va.va_mode & VWRITE) == 0 &&
6927c478bd9Sstevel@tonic-gate 		    secpolicy_vnode_access(cr, mvp, va.va_uid, VWRITE) != 0) {
6937c478bd9Sstevel@tonic-gate 			return (EACCES);
6947c478bd9Sstevel@tonic-gate 		}
6957c478bd9Sstevel@tonic-gate 	}
696ddf7fe95Scasper 	return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM,
697ddf7fe95Scasper 	    NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE));
6987c478bd9Sstevel@tonic-gate }
6997c478bd9Sstevel@tonic-gate 
700ecd6cf80Smarks void
701ecd6cf80Smarks secpolicy_fs_mount_clearopts(cred_t *cr, struct vfs *vfsp)
7027c478bd9Sstevel@tonic-gate {
7037c478bd9Sstevel@tonic-gate 	boolean_t amsuper = HAS_ALLZONEPRIVS(cr);
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	/*
706ecd6cf80Smarks 	 * check; if we don't have either "nosuid" or
7077c478bd9Sstevel@tonic-gate 	 * both "nosetuid" and "nodevices", then we add
7087c478bd9Sstevel@tonic-gate 	 * "nosuid"; this depends on how the current
7097c478bd9Sstevel@tonic-gate 	 * implementation works (it first checks nosuid).  In a
7107c478bd9Sstevel@tonic-gate 	 * zone, a user with all zone privileges can mount with
7117c478bd9Sstevel@tonic-gate 	 * "setuid" but never with "devices".
7127c478bd9Sstevel@tonic-gate 	 */
7137c478bd9Sstevel@tonic-gate 	if (!vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL) &&
7147c478bd9Sstevel@tonic-gate 	    (!vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL) ||
7157c478bd9Sstevel@tonic-gate 	    !vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL))) {
7167c478bd9Sstevel@tonic-gate 		if (crgetzoneid(cr) == GLOBAL_ZONEID || !amsuper)
7177c478bd9Sstevel@tonic-gate 			vfs_setmntopt(vfsp, MNTOPT_NOSUID, NULL, 0);
7187c478bd9Sstevel@tonic-gate 		else
7197c478bd9Sstevel@tonic-gate 			vfs_setmntopt(vfsp, MNTOPT_NODEVICES, NULL, 0);
7207c478bd9Sstevel@tonic-gate 	}
7217c478bd9Sstevel@tonic-gate 	/*
7227c478bd9Sstevel@tonic-gate 	 * If we're not the local super user, we set the "restrict"
7237c478bd9Sstevel@tonic-gate 	 * option to indicate to automountd that this mount should
7247c478bd9Sstevel@tonic-gate 	 * be handled with care.
7257c478bd9Sstevel@tonic-gate 	 */
7267c478bd9Sstevel@tonic-gate 	if (!amsuper)
7277c478bd9Sstevel@tonic-gate 		vfs_setmntopt(vfsp, MNTOPT_RESTRICT, NULL, 0);
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate }
730ecd6cf80Smarks 
731ecd6cf80Smarks extern vnode_t *rootvp;
732ecd6cf80Smarks extern vfs_t *rootvfs;
733ecd6cf80Smarks 
734ecd6cf80Smarks int
735ecd6cf80Smarks secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct vfs *vfsp)
736ecd6cf80Smarks {
737ecd6cf80Smarks 	boolean_t needoptchk;
738ecd6cf80Smarks 	int error;
739ecd6cf80Smarks 
740ecd6cf80Smarks 	/*
741ecd6cf80Smarks 	 * If it's a remount, get the underlying mount point,
742ecd6cf80Smarks 	 * except for the root where we use the rootvp.
743ecd6cf80Smarks 	 */
744ecd6cf80Smarks 	if ((vfsp->vfs_flag & VFS_REMOUNT) != 0) {
745ecd6cf80Smarks 		if (vfsp == rootvfs)
746ecd6cf80Smarks 			mvp = rootvp;
747ecd6cf80Smarks 		else
748ecd6cf80Smarks 			mvp = vfsp->vfs_vnodecovered;
749ecd6cf80Smarks 	}
750ecd6cf80Smarks 
751ecd6cf80Smarks 	error = secpolicy_fs_common(cr, mvp, vfsp, &needoptchk);
752ecd6cf80Smarks 
753ecd6cf80Smarks 	if (error == 0 && needoptchk) {
754ecd6cf80Smarks 		secpolicy_fs_mount_clearopts(cr, vfsp);
755ecd6cf80Smarks 	}
756ecd6cf80Smarks 
7577c478bd9Sstevel@tonic-gate 	return (error);
7587c478bd9Sstevel@tonic-gate }
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate /*
7617c478bd9Sstevel@tonic-gate  * Does the policy computations for "ownership" of a mount;
7627c478bd9Sstevel@tonic-gate  * here ownership is defined as the ability to "mount"
7637c478bd9Sstevel@tonic-gate  * the filesystem originally.  The rootvfs doesn't cover any
7647c478bd9Sstevel@tonic-gate  * vnodes; we attribute its ownership to the rootvp.
7657c478bd9Sstevel@tonic-gate  */
7667c478bd9Sstevel@tonic-gate static int
7677c478bd9Sstevel@tonic-gate secpolicy_fs_owner(cred_t *cr, const struct vfs *vfsp)
7687c478bd9Sstevel@tonic-gate {
7697c478bd9Sstevel@tonic-gate 	vnode_t *mvp;
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 	if (vfsp == NULL)
7727c478bd9Sstevel@tonic-gate 		mvp = NULL;
7737c478bd9Sstevel@tonic-gate 	else if (vfsp == rootvfs)
7747c478bd9Sstevel@tonic-gate 		mvp = rootvp;
7757c478bd9Sstevel@tonic-gate 	else
7767c478bd9Sstevel@tonic-gate 		mvp = vfsp->vfs_vnodecovered;
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate 	return (secpolicy_fs_common(cr, mvp, vfsp, NULL));
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate int
7827c478bd9Sstevel@tonic-gate secpolicy_fs_unmount(cred_t *cr, struct vfs *vfsp)
7837c478bd9Sstevel@tonic-gate {
7847c478bd9Sstevel@tonic-gate 	return (secpolicy_fs_owner(cr, vfsp));
7857c478bd9Sstevel@tonic-gate }
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate /*
7887c478bd9Sstevel@tonic-gate  * Quotas are a resource, but if one has the ability to mount a filesystem, he
7897c478bd9Sstevel@tonic-gate  * should be able to modify quotas on it.
7907c478bd9Sstevel@tonic-gate  */
7917c478bd9Sstevel@tonic-gate int
7927c478bd9Sstevel@tonic-gate secpolicy_fs_quota(const cred_t *cr, const vfs_t *vfsp)
7937c478bd9Sstevel@tonic-gate {
7947c478bd9Sstevel@tonic-gate 	return (secpolicy_fs_owner((cred_t *)cr, vfsp));
7957c478bd9Sstevel@tonic-gate }
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate /*
7987c478bd9Sstevel@tonic-gate  * Exceeding minfree: also a per-mount resource constraint.
7997c478bd9Sstevel@tonic-gate  */
8007c478bd9Sstevel@tonic-gate int
8017c478bd9Sstevel@tonic-gate secpolicy_fs_minfree(const cred_t *cr, const vfs_t *vfsp)
8027c478bd9Sstevel@tonic-gate {
8037c478bd9Sstevel@tonic-gate 	return (secpolicy_fs_owner((cred_t *)cr, vfsp));
8047c478bd9Sstevel@tonic-gate }
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate int
8077c478bd9Sstevel@tonic-gate secpolicy_fs_config(const cred_t *cr, const vfs_t *vfsp)
8087c478bd9Sstevel@tonic-gate {
8097c478bd9Sstevel@tonic-gate 	return (secpolicy_fs_owner((cred_t *)cr, vfsp));
8107c478bd9Sstevel@tonic-gate }
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate /* ARGSUSED */
8137c478bd9Sstevel@tonic-gate int
8147c478bd9Sstevel@tonic-gate secpolicy_fs_linkdir(const cred_t *cr, const vfs_t *vfsp)
8157c478bd9Sstevel@tonic-gate {
8167c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_LINKDIR, B_FALSE, EPERM, NULL));
8177c478bd9Sstevel@tonic-gate }
8187c478bd9Sstevel@tonic-gate 
8197c478bd9Sstevel@tonic-gate /*
8207c478bd9Sstevel@tonic-gate  * Name:        secpolicy_vnode_access()
8217c478bd9Sstevel@tonic-gate  *
8227c478bd9Sstevel@tonic-gate  * Parameters:  Process credential
8237c478bd9Sstevel@tonic-gate  *		vnode
8247c478bd9Sstevel@tonic-gate  *		uid of owner of vnode
8257c478bd9Sstevel@tonic-gate  *		permission bits not granted to the caller when examining
8267c478bd9Sstevel@tonic-gate  *		file mode bits (i.e., when a process wants to open a
8277c478bd9Sstevel@tonic-gate  *		mode 444 file for VREAD|VWRITE, this function should be
8287c478bd9Sstevel@tonic-gate  *		called only with a VWRITE argument).
8297c478bd9Sstevel@tonic-gate  *
8307c478bd9Sstevel@tonic-gate  * Normal:      Verifies that cred has the appropriate privileges to
8317c478bd9Sstevel@tonic-gate  *              override the mode bits that were denied.
8327c478bd9Sstevel@tonic-gate  *
8337c478bd9Sstevel@tonic-gate  * Override:    file_dac_execute - if VEXEC bit was denied and vnode is
8347c478bd9Sstevel@tonic-gate  *                      not a directory.
8357c478bd9Sstevel@tonic-gate  *              file_dac_read - if VREAD bit was denied.
8367c478bd9Sstevel@tonic-gate  *              file_dac_search - if VEXEC bit was denied and vnode is
8377c478bd9Sstevel@tonic-gate  *                      a directory.
8387c478bd9Sstevel@tonic-gate  *              file_dac_write - if VWRITE bit was denied.
8397c478bd9Sstevel@tonic-gate  *
8407c478bd9Sstevel@tonic-gate  *		Root owned files are special cased to protect system
8417c478bd9Sstevel@tonic-gate  *		configuration files and such.
8427c478bd9Sstevel@tonic-gate  *
8437c478bd9Sstevel@tonic-gate  * Output:      EACCES - if privilege check fails.
8447c478bd9Sstevel@tonic-gate  */
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate /* ARGSUSED */
8477c478bd9Sstevel@tonic-gate int
8487c478bd9Sstevel@tonic-gate secpolicy_vnode_access(const cred_t *cr, vnode_t *vp, uid_t owner, mode_t mode)
8497c478bd9Sstevel@tonic-gate {
850ddf7fe95Scasper 	if ((mode & VREAD) && priv_policy_va(cr, PRIV_FILE_DAC_READ, B_FALSE,
851ddf7fe95Scasper 	    EACCES, NULL, KLPDARG_VNODE, vp, (char *)NULL,
852ddf7fe95Scasper 	    KLPDARG_NOMORE) != 0) {
8537c478bd9Sstevel@tonic-gate 		return (EACCES);
854ddf7fe95Scasper 	}
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate 	if (mode & VWRITE) {
8577c478bd9Sstevel@tonic-gate 		boolean_t allzone;
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 		if (owner == 0 && cr->cr_uid != 0)
8607c478bd9Sstevel@tonic-gate 			allzone = B_TRUE;
8617c478bd9Sstevel@tonic-gate 		else
8627c478bd9Sstevel@tonic-gate 			allzone = B_FALSE;
863ddf7fe95Scasper 		if (priv_policy_va(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES,
864ddf7fe95Scasper 		    NULL, KLPDARG_VNODE, vp, (char *)NULL,
865ddf7fe95Scasper 		    KLPDARG_NOMORE) != 0) {
8667c478bd9Sstevel@tonic-gate 			return (EACCES);
8677c478bd9Sstevel@tonic-gate 		}
868ddf7fe95Scasper 	}
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 	if (mode & VEXEC) {
8717c478bd9Sstevel@tonic-gate 		/*
8727c478bd9Sstevel@tonic-gate 		 * Directories use file_dac_search to override the execute bit.
8737c478bd9Sstevel@tonic-gate 		 */
874ddf7fe95Scasper 		int p = vp->v_type == VDIR ? PRIV_FILE_DAC_SEARCH :
875ddf7fe95Scasper 		    PRIV_FILE_DAC_EXECUTE;
8767c478bd9Sstevel@tonic-gate 
877ddf7fe95Scasper 		return (priv_policy_va(cr, p, B_FALSE, EACCES, NULL,
878ddf7fe95Scasper 		    KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE));
8797c478bd9Sstevel@tonic-gate 	}
8807c478bd9Sstevel@tonic-gate 	return (0);
8817c478bd9Sstevel@tonic-gate }
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate /*
8847c478bd9Sstevel@tonic-gate  * Name:	secpolicy_vnode_setid_modify()
8857c478bd9Sstevel@tonic-gate  *
8867c478bd9Sstevel@tonic-gate  * Normal:	verify that subject can set the file setid flags.
8877c478bd9Sstevel@tonic-gate  *
8887c478bd9Sstevel@tonic-gate  * Output:	EPERM - if not privileged.
8897c478bd9Sstevel@tonic-gate  */
8907c478bd9Sstevel@tonic-gate 
8917c478bd9Sstevel@tonic-gate static int
8927c478bd9Sstevel@tonic-gate secpolicy_vnode_setid_modify(const cred_t *cr, uid_t owner)
8937c478bd9Sstevel@tonic-gate {
8947c478bd9Sstevel@tonic-gate 	/* If changing to suid root, must have all zone privs */
8957c478bd9Sstevel@tonic-gate 	boolean_t allzone = B_TRUE;
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate 	if (owner != 0) {
8987c478bd9Sstevel@tonic-gate 		if (owner == cr->cr_uid)
8997c478bd9Sstevel@tonic-gate 			return (0);
9007c478bd9Sstevel@tonic-gate 		allzone = B_FALSE;
9017c478bd9Sstevel@tonic-gate 	}
9027c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_FILE_SETID, allzone, EPERM, NULL));
9037c478bd9Sstevel@tonic-gate }
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate /*
9067c478bd9Sstevel@tonic-gate  * Are we allowed to retain the set-uid/set-gid bits when
9077c478bd9Sstevel@tonic-gate  * changing ownership or when writing to a file?
9087c478bd9Sstevel@tonic-gate  * "issuid" should be true when set-uid; only in that case
9097c478bd9Sstevel@tonic-gate  * root ownership is checked (setgid is assumed).
9107c478bd9Sstevel@tonic-gate  */
9117c478bd9Sstevel@tonic-gate int
9127c478bd9Sstevel@tonic-gate secpolicy_vnode_setid_retain(const cred_t *cred, boolean_t issuidroot)
9137c478bd9Sstevel@tonic-gate {
9147c478bd9Sstevel@tonic-gate 	if (issuidroot && !HAS_ALLZONEPRIVS(cred))
9157c478bd9Sstevel@tonic-gate 		return (EPERM);
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate 	return (!PRIV_POLICY_CHOICE(cred, PRIV_FILE_SETID, B_FALSE));
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate 
9207c478bd9Sstevel@tonic-gate /*
9217c478bd9Sstevel@tonic-gate  * Name:	secpolicy_vnode_setids_setgids()
9227c478bd9Sstevel@tonic-gate  *
9237c478bd9Sstevel@tonic-gate  * Normal:	verify that subject can set the file setgid flag.
9247c478bd9Sstevel@tonic-gate  *
9257c478bd9Sstevel@tonic-gate  * Output:	EPERM - if not privileged
9267c478bd9Sstevel@tonic-gate  */
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate int
9297c478bd9Sstevel@tonic-gate secpolicy_vnode_setids_setgids(const cred_t *cred, gid_t gid)
9307c478bd9Sstevel@tonic-gate {
9317c478bd9Sstevel@tonic-gate 	if (!groupmember(gid, cred))
9327c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cred, PRIV_FILE_SETID, B_FALSE, EPERM,
9337c478bd9Sstevel@tonic-gate 		    NULL));
9347c478bd9Sstevel@tonic-gate 	return (0);
9357c478bd9Sstevel@tonic-gate }
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate /*
93847def0dcSMark Shellenbaum  * Name:	secpolicy_vnode_chown
93947def0dcSMark Shellenbaum  *
94047def0dcSMark Shellenbaum  * Normal:	Determine if subject can chown owner of a file.
94147def0dcSMark Shellenbaum  *
94247def0dcSMark Shellenbaum  * Output:	EPERM - if access denied
9437c478bd9Sstevel@tonic-gate  */
94447def0dcSMark Shellenbaum 
9457c478bd9Sstevel@tonic-gate int
946e02bc683SMark Shellenbaum secpolicy_vnode_chown(const cred_t *cred, uid_t owner)
9477c478bd9Sstevel@tonic-gate {
948e02bc683SMark Shellenbaum 	boolean_t is_owner = (owner == crgetuid(cred));
949e02bc683SMark Shellenbaum 	boolean_t allzone = B_FALSE;
950e02bc683SMark Shellenbaum 	int priv;
951e02bc683SMark Shellenbaum 
952e02bc683SMark Shellenbaum 	if (!is_owner) {
953e02bc683SMark Shellenbaum 		allzone = (owner == 0);
954e02bc683SMark Shellenbaum 		priv = PRIV_FILE_CHOWN;
955e02bc683SMark Shellenbaum 	} else {
956e02bc683SMark Shellenbaum 		priv = HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN) ?
957e02bc683SMark Shellenbaum 		    PRIV_FILE_CHOWN : PRIV_FILE_CHOWN_SELF;
958e02bc683SMark Shellenbaum 	}
959e02bc683SMark Shellenbaum 
960e02bc683SMark Shellenbaum 	return (PRIV_POLICY(cred, priv, allzone, EPERM, NULL));
96147def0dcSMark Shellenbaum }
96247def0dcSMark Shellenbaum 
96347def0dcSMark Shellenbaum /*
96447def0dcSMark Shellenbaum  * Name:	secpolicy_vnode_create_gid
96547def0dcSMark Shellenbaum  *
96647def0dcSMark Shellenbaum  * Normal:	Determine if subject can change group ownership of a file.
96747def0dcSMark Shellenbaum  *
96847def0dcSMark Shellenbaum  * Output:	EPERM - if access denied
96947def0dcSMark Shellenbaum  */
97047def0dcSMark Shellenbaum int
97147def0dcSMark Shellenbaum secpolicy_vnode_create_gid(const cred_t *cred)
97247def0dcSMark Shellenbaum {
973e02bc683SMark Shellenbaum 	if (HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN))
974e02bc683SMark Shellenbaum 		return (PRIV_POLICY(cred, PRIV_FILE_CHOWN, B_FALSE, EPERM,
975e02bc683SMark Shellenbaum 		    NULL));
976e02bc683SMark Shellenbaum 	else
977e02bc683SMark Shellenbaum 		return (PRIV_POLICY(cred, PRIV_FILE_CHOWN_SELF, B_FALSE, EPERM,
978e02bc683SMark Shellenbaum 		    NULL));
9797c478bd9Sstevel@tonic-gate }
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate /*
9827c478bd9Sstevel@tonic-gate  * Name:	secpolicy_vnode_utime_modify()
9837c478bd9Sstevel@tonic-gate  *
9847c478bd9Sstevel@tonic-gate  * Normal:	verify that subject can modify the utime on a file.
9857c478bd9Sstevel@tonic-gate  *
9867c478bd9Sstevel@tonic-gate  * Output:	EPERM - if access denied.
9877c478bd9Sstevel@tonic-gate  */
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate static int
9907c478bd9Sstevel@tonic-gate secpolicy_vnode_utime_modify(const cred_t *cred)
9917c478bd9Sstevel@tonic-gate {
9927c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cred, PRIV_FILE_OWNER, B_FALSE, EPERM,
9937c478bd9Sstevel@tonic-gate 	    "modify file times"));
9947c478bd9Sstevel@tonic-gate }
9957c478bd9Sstevel@tonic-gate 
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate /*
9987c478bd9Sstevel@tonic-gate  * Name:	secpolicy_vnode_setdac()
9997c478bd9Sstevel@tonic-gate  *
10007c478bd9Sstevel@tonic-gate  * Normal:	verify that subject can modify the mode of a file.
10017c478bd9Sstevel@tonic-gate  *		allzone privilege needed when modifying root owned object.
10027c478bd9Sstevel@tonic-gate  *
10037c478bd9Sstevel@tonic-gate  * Output:	EPERM - if access denied.
10047c478bd9Sstevel@tonic-gate  */
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate int
10077c478bd9Sstevel@tonic-gate secpolicy_vnode_setdac(const cred_t *cred, uid_t owner)
10087c478bd9Sstevel@tonic-gate {
10097c478bd9Sstevel@tonic-gate 	if (owner == cred->cr_uid)
10107c478bd9Sstevel@tonic-gate 		return (0);
10117c478bd9Sstevel@tonic-gate 
10127c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cred, PRIV_FILE_OWNER, owner == 0, EPERM, NULL));
10137c478bd9Sstevel@tonic-gate }
10147c478bd9Sstevel@tonic-gate /*
10157c478bd9Sstevel@tonic-gate  * Name:	secpolicy_vnode_stky_modify()
10167c478bd9Sstevel@tonic-gate  *
10177c478bd9Sstevel@tonic-gate  * Normal:	verify that subject can make a file a "sticky".
10187c478bd9Sstevel@tonic-gate  *
10197c478bd9Sstevel@tonic-gate  * Output:	EPERM - if access denied.
10207c478bd9Sstevel@tonic-gate  */
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate int
10237c478bd9Sstevel@tonic-gate secpolicy_vnode_stky_modify(const cred_t *cred)
10247c478bd9Sstevel@tonic-gate {
10257c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cred, PRIV_SYS_CONFIG, B_FALSE, EPERM,
10267c478bd9Sstevel@tonic-gate 	    "set file sticky"));
10277c478bd9Sstevel@tonic-gate }
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate /*
10307c478bd9Sstevel@tonic-gate  * Policy determines whether we can remove an entry from a directory,
10317c478bd9Sstevel@tonic-gate  * regardless of permission bits.
10327c478bd9Sstevel@tonic-gate  */
10337c478bd9Sstevel@tonic-gate int
10347c478bd9Sstevel@tonic-gate secpolicy_vnode_remove(const cred_t *cr)
10357c478bd9Sstevel@tonic-gate {
10367c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_FILE_OWNER, B_FALSE, EACCES,
10377c478bd9Sstevel@tonic-gate 	    "sticky directory"));
10387c478bd9Sstevel@tonic-gate }
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate int
10417c478bd9Sstevel@tonic-gate secpolicy_vnode_owner(const cred_t *cr, uid_t owner)
10427c478bd9Sstevel@tonic-gate {
10437c478bd9Sstevel@tonic-gate 	boolean_t allzone = (owner == 0);
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate 	if (owner == cr->cr_uid)
10467c478bd9Sstevel@tonic-gate 		return (0);
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_FILE_OWNER, allzone, EPERM, NULL));
10497c478bd9Sstevel@tonic-gate }
10507c478bd9Sstevel@tonic-gate 
105113f9f30eSmarks void
105213f9f30eSmarks secpolicy_setid_clear(vattr_t *vap, cred_t *cr)
105313f9f30eSmarks {
105413f9f30eSmarks 	if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0 &&
105513f9f30eSmarks 	    secpolicy_vnode_setid_retain(cr,
105613f9f30eSmarks 	    (vap->va_mode & S_ISUID) != 0 &&
105713f9f30eSmarks 	    (vap->va_mask & AT_UID) != 0 && vap->va_uid == 0) != 0) {
105813f9f30eSmarks 		vap->va_mask |= AT_MODE;
105913f9f30eSmarks 		vap->va_mode &= ~(S_ISUID|S_ISGID);
106013f9f30eSmarks 	}
106113f9f30eSmarks }
106213f9f30eSmarks 
1063f92daba9Smarks int
1064f92daba9Smarks secpolicy_setid_setsticky_clear(vnode_t *vp, vattr_t *vap, const vattr_t *ovap,
1065f92daba9Smarks     cred_t *cr)
1066f92daba9Smarks {
1067f92daba9Smarks 	int error;
1068f92daba9Smarks 
1069f92daba9Smarks 	if ((vap->va_mode & S_ISUID) != 0 &&
1070f92daba9Smarks 	    (error = secpolicy_vnode_setid_modify(cr,
1071f92daba9Smarks 	    ovap->va_uid)) != 0) {
1072f92daba9Smarks 		return (error);
1073f92daba9Smarks 	}
1074f92daba9Smarks 
1075f92daba9Smarks 	/*
1076f92daba9Smarks 	 * Check privilege if attempting to set the
1077f92daba9Smarks 	 * sticky bit on a non-directory.
1078f92daba9Smarks 	 */
1079f92daba9Smarks 	if (vp->v_type != VDIR && (vap->va_mode & S_ISVTX) != 0 &&
1080f92daba9Smarks 	    secpolicy_vnode_stky_modify(cr) != 0) {
1081f92daba9Smarks 		vap->va_mode &= ~S_ISVTX;
1082f92daba9Smarks 	}
1083f92daba9Smarks 
1084f92daba9Smarks 	/*
1085f92daba9Smarks 	 * Check for privilege if attempting to set the
1086f92daba9Smarks 	 * group-id bit.
1087f92daba9Smarks 	 */
1088f92daba9Smarks 	if ((vap->va_mode & S_ISGID) != 0 &&
1089f92daba9Smarks 	    secpolicy_vnode_setids_setgids(cr, ovap->va_gid) != 0) {
1090f92daba9Smarks 		vap->va_mode &= ~S_ISGID;
1091f92daba9Smarks 	}
1092f92daba9Smarks 
1093f92daba9Smarks 	return (0);
1094f92daba9Smarks }
1095f92daba9Smarks 
1096da6c28aaSamw #define	ATTR_FLAG_PRIV(attr, value, cr)	\
1097da6c28aaSamw 	PRIV_POLICY(cr, value ? PRIV_FILE_FLAG_SET : PRIV_ALL, \
1098da6c28aaSamw 	B_FALSE, EPERM, NULL)
1099da6c28aaSamw 
1100da6c28aaSamw /*
1101da6c28aaSamw  * Check privileges for setting xvattr attributes
1102da6c28aaSamw  */
1103da6c28aaSamw int
1104da6c28aaSamw secpolicy_xvattr(xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype)
1105da6c28aaSamw {
1106da6c28aaSamw 	xoptattr_t *xoap;
1107da6c28aaSamw 	int error = 0;
1108da6c28aaSamw 
1109da6c28aaSamw 	if ((xoap = xva_getxoptattr(xvap)) == NULL)
1110da6c28aaSamw 		return (EINVAL);
1111da6c28aaSamw 
1112da6c28aaSamw 	/*
1113da6c28aaSamw 	 * First process the DOS bits
1114da6c28aaSamw 	 */
1115da6c28aaSamw 	if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE) ||
1116da6c28aaSamw 	    XVA_ISSET_REQ(xvap, XAT_HIDDEN) ||
1117da6c28aaSamw 	    XVA_ISSET_REQ(xvap, XAT_READONLY) ||
1118da6c28aaSamw 	    XVA_ISSET_REQ(xvap, XAT_SYSTEM) ||
1119da6c28aaSamw 	    XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
1120da6c28aaSamw 		if ((error = secpolicy_vnode_owner(cr, owner)) != 0)
1121da6c28aaSamw 			return (error);
1122da6c28aaSamw 	}
1123da6c28aaSamw 
1124da6c28aaSamw 	/*
1125da6c28aaSamw 	 * Now handle special attributes
1126da6c28aaSamw 	 */
1127da6c28aaSamw 
1128da6c28aaSamw 	if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
1129da6c28aaSamw 		error = ATTR_FLAG_PRIV(XAT_IMMUTABLE,
1130da6c28aaSamw 		    xoap->xoa_immutable, cr);
1131da6c28aaSamw 	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
1132da6c28aaSamw 		error = ATTR_FLAG_PRIV(XAT_NOUNLINK,
1133da6c28aaSamw 		    xoap->xoa_nounlink, cr);
1134da6c28aaSamw 	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
1135da6c28aaSamw 		error = ATTR_FLAG_PRIV(XAT_APPENDONLY,
1136da6c28aaSamw 		    xoap->xoa_appendonly, cr);
1137da6c28aaSamw 	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NODUMP))
1138da6c28aaSamw 		error = ATTR_FLAG_PRIV(XAT_NODUMP,
1139da6c28aaSamw 		    xoap->xoa_nodump, cr);
1140da6c28aaSamw 	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_OPAQUE))
1141da6c28aaSamw 		error = EPERM;
1142da6c28aaSamw 	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
1143da6c28aaSamw 		error = ATTR_FLAG_PRIV(XAT_AV_QUARANTINED,
1144da6c28aaSamw 		    xoap->xoa_av_quarantined, cr);
1145e8f97327Smarks 		if (error == 0 && vtype != VREG && xoap->xoa_av_quarantined)
1146da6c28aaSamw 			error = EINVAL;
1147da6c28aaSamw 	}
1148da6c28aaSamw 	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
1149da6c28aaSamw 		error = ATTR_FLAG_PRIV(XAT_AV_MODIFIED,
1150da6c28aaSamw 		    xoap->xoa_av_modified, cr);
1151da6c28aaSamw 	if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
1152da6c28aaSamw 		error = ATTR_FLAG_PRIV(XAT_AV_SCANSTAMP,
1153da6c28aaSamw 		    xoap->xoa_av_scanstamp, cr);
1154da6c28aaSamw 		if (error == 0 && vtype != VREG)
1155da6c28aaSamw 			error = EINVAL;
1156da6c28aaSamw 	}
1157da6c28aaSamw 	return (error);
1158da6c28aaSamw }
1159da6c28aaSamw 
11607c478bd9Sstevel@tonic-gate /*
11617c478bd9Sstevel@tonic-gate  * This function checks the policy decisions surrounding the
11627c478bd9Sstevel@tonic-gate  * vop setattr call.
11637c478bd9Sstevel@tonic-gate  *
11647c478bd9Sstevel@tonic-gate  * It should be called after sufficient locks have been established
11657c478bd9Sstevel@tonic-gate  * on the underlying data structures.  No concurrent modifications
11667c478bd9Sstevel@tonic-gate  * should be allowed.
11677c478bd9Sstevel@tonic-gate  *
11687c478bd9Sstevel@tonic-gate  * The caller must pass in unlocked version of its vaccess function
11697c478bd9Sstevel@tonic-gate  * this is required because vop_access function should lock the
11707c478bd9Sstevel@tonic-gate  * node for reading.  A three argument function should be defined
11717c478bd9Sstevel@tonic-gate  * which accepts the following argument:
11727c478bd9Sstevel@tonic-gate  * 	A pointer to the internal "node" type (inode *)
11737c478bd9Sstevel@tonic-gate  *	vnode access bits (VREAD|VWRITE|VEXEC)
11747c478bd9Sstevel@tonic-gate  *	a pointer to the credential
11757c478bd9Sstevel@tonic-gate  *
11767c478bd9Sstevel@tonic-gate  * This function makes the following policy decisions:
11777c478bd9Sstevel@tonic-gate  *
11787c478bd9Sstevel@tonic-gate  *		- change permissions
11797c478bd9Sstevel@tonic-gate  *			- permission to change file mode if not owner
11807c478bd9Sstevel@tonic-gate  *			- permission to add sticky bit to non-directory
11817c478bd9Sstevel@tonic-gate  *			- permission to add set-gid bit
11827c478bd9Sstevel@tonic-gate  *
11837c478bd9Sstevel@tonic-gate  * The ovap argument should include AT_MODE|AT_UID|AT_GID.
11847c478bd9Sstevel@tonic-gate  *
11857c478bd9Sstevel@tonic-gate  * If the vap argument does not include AT_MODE, the mode will be copied from
11867c478bd9Sstevel@tonic-gate  * ovap.  In certain situations set-uid/set-gid bits need to be removed;
11877c478bd9Sstevel@tonic-gate  * this is done by marking vap->va_mask to include AT_MODE and va_mode
11887c478bd9Sstevel@tonic-gate  * is updated to the newly computed mode.
11897c478bd9Sstevel@tonic-gate  */
11907c478bd9Sstevel@tonic-gate 
11917c478bd9Sstevel@tonic-gate int
11927c478bd9Sstevel@tonic-gate secpolicy_vnode_setattr(cred_t *cr, struct vnode *vp, struct vattr *vap,
11937c478bd9Sstevel@tonic-gate 	const struct vattr *ovap, int flags,
11947c478bd9Sstevel@tonic-gate 	int unlocked_access(void *, int, cred_t *),
11957c478bd9Sstevel@tonic-gate 	void *node)
11967c478bd9Sstevel@tonic-gate {
11977c478bd9Sstevel@tonic-gate 	int mask = vap->va_mask;
11987c478bd9Sstevel@tonic-gate 	int error = 0;
1199da6c28aaSamw 	boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
12007c478bd9Sstevel@tonic-gate 
12017c478bd9Sstevel@tonic-gate 	if (mask & AT_SIZE) {
12027c478bd9Sstevel@tonic-gate 		if (vp->v_type == VDIR) {
12037c478bd9Sstevel@tonic-gate 			error = EISDIR;
12047c478bd9Sstevel@tonic-gate 			goto out;
12057c478bd9Sstevel@tonic-gate 		}
1206da6c28aaSamw 
1207da6c28aaSamw 		/*
1208da6c28aaSamw 		 * If ATTR_NOACLCHECK is set in the flags, then we don't
1209da6c28aaSamw 		 * perform the secondary unlocked_access() call since the
1210da6c28aaSamw 		 * ACL (if any) is being checked there.
1211da6c28aaSamw 		 */
1212da6c28aaSamw 		if (skipaclchk == B_FALSE) {
12137c478bd9Sstevel@tonic-gate 			error = unlocked_access(node, VWRITE, cr);
12147c478bd9Sstevel@tonic-gate 			if (error)
12157c478bd9Sstevel@tonic-gate 				goto out;
12167c478bd9Sstevel@tonic-gate 		}
1217da6c28aaSamw 	}
12187c478bd9Sstevel@tonic-gate 	if (mask & AT_MODE) {
12197c478bd9Sstevel@tonic-gate 		/*
12207c478bd9Sstevel@tonic-gate 		 * If not the owner of the file then check privilege
12217c478bd9Sstevel@tonic-gate 		 * for two things: the privilege to set the mode at all
12227c478bd9Sstevel@tonic-gate 		 * and, if we're setting setuid, we also need permissions
12237c478bd9Sstevel@tonic-gate 		 * to add the set-uid bit, if we're not the owner.
12247c478bd9Sstevel@tonic-gate 		 * In the specific case of creating a set-uid root
12257c478bd9Sstevel@tonic-gate 		 * file, we need even more permissions.
12267c478bd9Sstevel@tonic-gate 		 */
12277c478bd9Sstevel@tonic-gate 		if ((error = secpolicy_vnode_setdac(cr, ovap->va_uid)) != 0)
12287c478bd9Sstevel@tonic-gate 			goto out;
12297c478bd9Sstevel@tonic-gate 
1230f92daba9Smarks 		if ((error = secpolicy_setid_setsticky_clear(vp, vap,
1231f92daba9Smarks 		    ovap, cr)) != 0)
12327c478bd9Sstevel@tonic-gate 			goto out;
12337c478bd9Sstevel@tonic-gate 	} else
12347c478bd9Sstevel@tonic-gate 		vap->va_mode = ovap->va_mode;
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate 	if (mask & (AT_UID|AT_GID)) {
12377c478bd9Sstevel@tonic-gate 		boolean_t checkpriv = B_FALSE;
12387c478bd9Sstevel@tonic-gate 
12397c478bd9Sstevel@tonic-gate 		/*
12407c478bd9Sstevel@tonic-gate 		 * Chowning files.
12417c478bd9Sstevel@tonic-gate 		 *
12427c478bd9Sstevel@tonic-gate 		 * If you are the file owner:
12437c478bd9Sstevel@tonic-gate 		 *	chown to other uid		FILE_CHOWN_SELF
12447c478bd9Sstevel@tonic-gate 		 *	chown to gid (non-member) 	FILE_CHOWN_SELF
12457c478bd9Sstevel@tonic-gate 		 *	chown to gid (member) 		<none>
12467c478bd9Sstevel@tonic-gate 		 *
12477c478bd9Sstevel@tonic-gate 		 * Instead of PRIV_FILE_CHOWN_SELF, FILE_CHOWN is also
12487c478bd9Sstevel@tonic-gate 		 * acceptable but the first one is reported when debugging.
12497c478bd9Sstevel@tonic-gate 		 *
12507c478bd9Sstevel@tonic-gate 		 * If you are not the file owner:
12517c478bd9Sstevel@tonic-gate 		 *	chown from root			PRIV_FILE_CHOWN + zone
12527c478bd9Sstevel@tonic-gate 		 *	chown from other to any		PRIV_FILE_CHOWN
12537c478bd9Sstevel@tonic-gate 		 *
12547c478bd9Sstevel@tonic-gate 		 */
12557c478bd9Sstevel@tonic-gate 		if (cr->cr_uid != ovap->va_uid) {
12567c478bd9Sstevel@tonic-gate 			checkpriv = B_TRUE;
12577c478bd9Sstevel@tonic-gate 		} else {
12587c478bd9Sstevel@tonic-gate 			if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) ||
12597c478bd9Sstevel@tonic-gate 			    ((mask & AT_GID) && vap->va_gid != ovap->va_gid &&
12607c478bd9Sstevel@tonic-gate 			    !groupmember(vap->va_gid, cr))) {
12617c478bd9Sstevel@tonic-gate 				checkpriv = B_TRUE;
12627c478bd9Sstevel@tonic-gate 			}
12637c478bd9Sstevel@tonic-gate 		}
12647c478bd9Sstevel@tonic-gate 		/*
12657c478bd9Sstevel@tonic-gate 		 * If necessary, check privilege to see if update can be done.
12667c478bd9Sstevel@tonic-gate 		 */
12677c478bd9Sstevel@tonic-gate 		if (checkpriv &&
1268e02bc683SMark Shellenbaum 		    (error = secpolicy_vnode_chown(cr, ovap->va_uid)) != 0) {
12697c478bd9Sstevel@tonic-gate 			goto out;
12707c478bd9Sstevel@tonic-gate 		}
12717c478bd9Sstevel@tonic-gate 
12727c478bd9Sstevel@tonic-gate 		/*
12737c478bd9Sstevel@tonic-gate 		 * If the file has either the set UID or set GID bits
12747c478bd9Sstevel@tonic-gate 		 * set and the caller can set the bits, then leave them.
12757c478bd9Sstevel@tonic-gate 		 */
127613f9f30eSmarks 		secpolicy_setid_clear(vap, cr);
12777c478bd9Sstevel@tonic-gate 	}
12787c478bd9Sstevel@tonic-gate 	if (mask & (AT_ATIME|AT_MTIME)) {
12797c478bd9Sstevel@tonic-gate 		/*
12807c478bd9Sstevel@tonic-gate 		 * If not the file owner and not otherwise privileged,
12817c478bd9Sstevel@tonic-gate 		 * always return an error when setting the
12827c478bd9Sstevel@tonic-gate 		 * time other than the current (ATTR_UTIME flag set).
12837c478bd9Sstevel@tonic-gate 		 * If setting the current time (ATTR_UTIME not set) then
12847c478bd9Sstevel@tonic-gate 		 * unlocked_access will check permissions according to policy.
12857c478bd9Sstevel@tonic-gate 		 */
12867c478bd9Sstevel@tonic-gate 		if (cr->cr_uid != ovap->va_uid) {
12877c478bd9Sstevel@tonic-gate 			if (flags & ATTR_UTIME)
12887c478bd9Sstevel@tonic-gate 				error = secpolicy_vnode_utime_modify(cr);
1289da6c28aaSamw 			else if (skipaclchk == B_FALSE) {
12907c478bd9Sstevel@tonic-gate 				error = unlocked_access(node, VWRITE, cr);
12917c478bd9Sstevel@tonic-gate 				if (error == EACCES &&
12927c478bd9Sstevel@tonic-gate 				    secpolicy_vnode_utime_modify(cr) == 0)
12937c478bd9Sstevel@tonic-gate 					error = 0;
12947c478bd9Sstevel@tonic-gate 			}
12957c478bd9Sstevel@tonic-gate 			if (error)
12967c478bd9Sstevel@tonic-gate 				goto out;
12977c478bd9Sstevel@tonic-gate 		}
12987c478bd9Sstevel@tonic-gate 	}
1299da6c28aaSamw 
1300da6c28aaSamw 	/*
1301da6c28aaSamw 	 * Check for optional attributes here by checking the following:
1302da6c28aaSamw 	 */
1303da6c28aaSamw 	if (mask & AT_XVATTR)
1304da6c28aaSamw 		error = secpolicy_xvattr((xvattr_t *)vap, ovap->va_uid, cr,
1305da6c28aaSamw 		    vp->v_type);
13067c478bd9Sstevel@tonic-gate out:
13077c478bd9Sstevel@tonic-gate 	return (error);
13087c478bd9Sstevel@tonic-gate }
13097c478bd9Sstevel@tonic-gate 
13107c478bd9Sstevel@tonic-gate /*
13117c478bd9Sstevel@tonic-gate  * Name:	secpolicy_pcfs_modify_bootpartition()
13127c478bd9Sstevel@tonic-gate  *
13137c478bd9Sstevel@tonic-gate  * Normal:	verify that subject can modify a pcfs boot partition.
13147c478bd9Sstevel@tonic-gate  *
13157c478bd9Sstevel@tonic-gate  * Output:	EACCES - if privilege check failed.
13167c478bd9Sstevel@tonic-gate  */
13177c478bd9Sstevel@tonic-gate /*ARGSUSED*/
13187c478bd9Sstevel@tonic-gate int
13197c478bd9Sstevel@tonic-gate secpolicy_pcfs_modify_bootpartition(const cred_t *cred)
13207c478bd9Sstevel@tonic-gate {
13217c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cred, PRIV_ALL, B_FALSE, EACCES,
13227c478bd9Sstevel@tonic-gate 	    "modify pcfs boot partition"));
13237c478bd9Sstevel@tonic-gate }
13247c478bd9Sstevel@tonic-gate 
13257c478bd9Sstevel@tonic-gate /*
13267c478bd9Sstevel@tonic-gate  * System V IPC routines
13277c478bd9Sstevel@tonic-gate  */
13287c478bd9Sstevel@tonic-gate int
13297c478bd9Sstevel@tonic-gate secpolicy_ipc_owner(const cred_t *cr, const struct kipc_perm *ip)
13307c478bd9Sstevel@tonic-gate {
13317c478bd9Sstevel@tonic-gate 	if (crgetzoneid(cr) != ip->ipc_zoneid ||
13327c478bd9Sstevel@tonic-gate 	    (cr->cr_uid != ip->ipc_uid && cr->cr_uid != ip->ipc_cuid)) {
13337c478bd9Sstevel@tonic-gate 		boolean_t allzone = B_FALSE;
13347c478bd9Sstevel@tonic-gate 		if (ip->ipc_uid == 0 || ip->ipc_cuid == 0)
13357c478bd9Sstevel@tonic-gate 			allzone = B_TRUE;
13367c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, PRIV_IPC_OWNER, allzone, EPERM, NULL));
13377c478bd9Sstevel@tonic-gate 	}
13387c478bd9Sstevel@tonic-gate 	return (0);
13397c478bd9Sstevel@tonic-gate }
13407c478bd9Sstevel@tonic-gate 
13417c478bd9Sstevel@tonic-gate int
13427c478bd9Sstevel@tonic-gate secpolicy_ipc_config(const cred_t *cr)
13437c478bd9Sstevel@tonic-gate {
13447c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_IPC_CONFIG, B_FALSE, EPERM, NULL));
13457c478bd9Sstevel@tonic-gate }
13467c478bd9Sstevel@tonic-gate 
13477c478bd9Sstevel@tonic-gate int
13487c478bd9Sstevel@tonic-gate secpolicy_ipc_access(const cred_t *cr, const struct kipc_perm *ip, mode_t mode)
13497c478bd9Sstevel@tonic-gate {
13507c478bd9Sstevel@tonic-gate 
13517c478bd9Sstevel@tonic-gate 	boolean_t allzone = B_FALSE;
13527c478bd9Sstevel@tonic-gate 
13537c478bd9Sstevel@tonic-gate 	ASSERT((mode & (MSG_R|MSG_W)) != 0);
13547c478bd9Sstevel@tonic-gate 
13557c478bd9Sstevel@tonic-gate 	if ((mode & MSG_R) &&
13567c478bd9Sstevel@tonic-gate 	    PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0)
13577c478bd9Sstevel@tonic-gate 		return (EACCES);
13587c478bd9Sstevel@tonic-gate 
13597c478bd9Sstevel@tonic-gate 	if (mode & MSG_W) {
13607c478bd9Sstevel@tonic-gate 		if (cr->cr_uid != 0 && (ip->ipc_uid == 0 || ip->ipc_cuid == 0))
13617c478bd9Sstevel@tonic-gate 			allzone = B_TRUE;
13627c478bd9Sstevel@tonic-gate 
13637c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES,
13647c478bd9Sstevel@tonic-gate 		    NULL));
13657c478bd9Sstevel@tonic-gate 	}
13667c478bd9Sstevel@tonic-gate 	return (0);
13677c478bd9Sstevel@tonic-gate }
13687c478bd9Sstevel@tonic-gate 
13697c478bd9Sstevel@tonic-gate int
13707c478bd9Sstevel@tonic-gate secpolicy_rsm_access(const cred_t *cr, uid_t owner, mode_t mode)
13717c478bd9Sstevel@tonic-gate {
13727c478bd9Sstevel@tonic-gate 	boolean_t allzone = B_FALSE;
13737c478bd9Sstevel@tonic-gate 
13747c478bd9Sstevel@tonic-gate 	ASSERT((mode & (MSG_R|MSG_W)) != 0);
13757c478bd9Sstevel@tonic-gate 
13767c478bd9Sstevel@tonic-gate 	if ((mode & MSG_R) &&
13777c478bd9Sstevel@tonic-gate 	    PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0)
13787c478bd9Sstevel@tonic-gate 		return (EACCES);
13797c478bd9Sstevel@tonic-gate 
13807c478bd9Sstevel@tonic-gate 	if (mode & MSG_W) {
13817c478bd9Sstevel@tonic-gate 		if (cr->cr_uid != 0 && owner == 0)
13827c478bd9Sstevel@tonic-gate 			allzone = B_TRUE;
13837c478bd9Sstevel@tonic-gate 
13847c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES,
13857c478bd9Sstevel@tonic-gate 		    NULL));
13867c478bd9Sstevel@tonic-gate 	}
13877c478bd9Sstevel@tonic-gate 	return (0);
13887c478bd9Sstevel@tonic-gate }
13897c478bd9Sstevel@tonic-gate 
13907c478bd9Sstevel@tonic-gate /*
13917c478bd9Sstevel@tonic-gate  * Audit configuration.
13927c478bd9Sstevel@tonic-gate  */
13937c478bd9Sstevel@tonic-gate int
13947c478bd9Sstevel@tonic-gate secpolicy_audit_config(const cred_t *cr)
13957c478bd9Sstevel@tonic-gate {
13967c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL));
13977c478bd9Sstevel@tonic-gate }
13987c478bd9Sstevel@tonic-gate 
13997c478bd9Sstevel@tonic-gate /*
14007c478bd9Sstevel@tonic-gate  * Audit record generation.
14017c478bd9Sstevel@tonic-gate  */
14027c478bd9Sstevel@tonic-gate int
14037c478bd9Sstevel@tonic-gate secpolicy_audit_modify(const cred_t *cr)
14047c478bd9Sstevel@tonic-gate {
14057c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, NULL));
14067c478bd9Sstevel@tonic-gate }
14077c478bd9Sstevel@tonic-gate 
14087c478bd9Sstevel@tonic-gate /*
14097c478bd9Sstevel@tonic-gate  * Get audit attributes.
14107c478bd9Sstevel@tonic-gate  * Either PRIV_SYS_AUDIT or PRIV_PROC_AUDIT required; report the
14117c478bd9Sstevel@tonic-gate  * "Least" of the two privileges on error.
14127c478bd9Sstevel@tonic-gate  */
14137c478bd9Sstevel@tonic-gate int
14147c478bd9Sstevel@tonic-gate secpolicy_audit_getattr(const cred_t *cr)
14157c478bd9Sstevel@tonic-gate {
14167c478bd9Sstevel@tonic-gate 	if (!PRIV_POLICY_ONLY(cr, PRIV_SYS_AUDIT, B_FALSE)) {
14177c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM,
14187c478bd9Sstevel@tonic-gate 		    NULL));
14197c478bd9Sstevel@tonic-gate 	} else {
14207c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL));
14217c478bd9Sstevel@tonic-gate 	}
14227c478bd9Sstevel@tonic-gate }
14237c478bd9Sstevel@tonic-gate 
14247c478bd9Sstevel@tonic-gate 
14257c478bd9Sstevel@tonic-gate /*
14267c478bd9Sstevel@tonic-gate  * Locking physical memory
14277c478bd9Sstevel@tonic-gate  */
14287c478bd9Sstevel@tonic-gate int
14297c478bd9Sstevel@tonic-gate secpolicy_lock_memory(const cred_t *cr)
14307c478bd9Sstevel@tonic-gate {
14317c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_PROC_LOCK_MEMORY, B_FALSE, EPERM, NULL));
14327c478bd9Sstevel@tonic-gate }
14337c478bd9Sstevel@tonic-gate 
14347c478bd9Sstevel@tonic-gate /*
14357c478bd9Sstevel@tonic-gate  * Accounting (both acct(2) and exacct).
14367c478bd9Sstevel@tonic-gate  */
14377c478bd9Sstevel@tonic-gate int
14387c478bd9Sstevel@tonic-gate secpolicy_acct(const cred_t *cr)
14397c478bd9Sstevel@tonic-gate {
14407c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_ACCT, B_FALSE, EPERM, NULL));
14417c478bd9Sstevel@tonic-gate }
14427c478bd9Sstevel@tonic-gate 
14437c478bd9Sstevel@tonic-gate /*
14447c478bd9Sstevel@tonic-gate  * Is this process privileged to change its uids at will?
14457c478bd9Sstevel@tonic-gate  * Uid 0 is still considered "special" and having the SETID
14467c478bd9Sstevel@tonic-gate  * privilege is not sufficient to get uid 0.
14477c478bd9Sstevel@tonic-gate  * Files are owned by root, so the privilege would give
14487c478bd9Sstevel@tonic-gate  * full access and euid 0 is still effective.
14497c478bd9Sstevel@tonic-gate  *
14507c478bd9Sstevel@tonic-gate  * If you have the privilege and euid 0 only then do you
14517c478bd9Sstevel@tonic-gate  * get the powers of root wrt uid 0.
14527c478bd9Sstevel@tonic-gate  *
14537c478bd9Sstevel@tonic-gate  * For gid manipulations, this is should be called with an
14547c478bd9Sstevel@tonic-gate  * uid of -1.
14557c478bd9Sstevel@tonic-gate  *
14567c478bd9Sstevel@tonic-gate  */
14577c478bd9Sstevel@tonic-gate int
14587c478bd9Sstevel@tonic-gate secpolicy_allow_setid(const cred_t *cr, uid_t newuid, boolean_t checkonly)
14597c478bd9Sstevel@tonic-gate {
14607c478bd9Sstevel@tonic-gate 	boolean_t allzone = B_FALSE;
14617c478bd9Sstevel@tonic-gate 
14627c478bd9Sstevel@tonic-gate 	if (newuid == 0 && cr->cr_uid != 0 && cr->cr_suid != 0 &&
14637c478bd9Sstevel@tonic-gate 	    cr->cr_ruid != 0) {
14647c478bd9Sstevel@tonic-gate 		allzone = B_TRUE;
14657c478bd9Sstevel@tonic-gate 	}
14667c478bd9Sstevel@tonic-gate 
14677c478bd9Sstevel@tonic-gate 	return (checkonly ? !PRIV_POLICY_ONLY(cr, PRIV_PROC_SETID, allzone) :
14687c478bd9Sstevel@tonic-gate 	    PRIV_POLICY(cr, PRIV_PROC_SETID, allzone, EPERM, NULL));
14697c478bd9Sstevel@tonic-gate }
14707c478bd9Sstevel@tonic-gate 
14717c478bd9Sstevel@tonic-gate 
14727c478bd9Sstevel@tonic-gate /*
14737c478bd9Sstevel@tonic-gate  * Acting on a different process: if the mode is for writing,
14747c478bd9Sstevel@tonic-gate  * the restrictions are more severe.  This is called after
14757c478bd9Sstevel@tonic-gate  * we've verified that the uids do not match.
14767c478bd9Sstevel@tonic-gate  */
14777c478bd9Sstevel@tonic-gate int
14787c478bd9Sstevel@tonic-gate secpolicy_proc_owner(const cred_t *scr, const cred_t *tcr, int mode)
14797c478bd9Sstevel@tonic-gate {
14807c478bd9Sstevel@tonic-gate 	boolean_t allzone = B_FALSE;
14817c478bd9Sstevel@tonic-gate 
14827c478bd9Sstevel@tonic-gate 	if ((mode & VWRITE) && scr->cr_uid != 0 &&
14837c478bd9Sstevel@tonic-gate 	    (tcr->cr_uid == 0 || tcr->cr_ruid == 0 || tcr->cr_suid == 0))
14847c478bd9Sstevel@tonic-gate 		allzone = B_TRUE;
14857c478bd9Sstevel@tonic-gate 
14867c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(scr, PRIV_PROC_OWNER, allzone, EPERM, NULL));
14877c478bd9Sstevel@tonic-gate }
14887c478bd9Sstevel@tonic-gate 
14897c478bd9Sstevel@tonic-gate int
14907c478bd9Sstevel@tonic-gate secpolicy_proc_access(const cred_t *scr)
14917c478bd9Sstevel@tonic-gate {
14927c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EACCES, NULL));
14937c478bd9Sstevel@tonic-gate }
14947c478bd9Sstevel@tonic-gate 
14957c478bd9Sstevel@tonic-gate int
14967c478bd9Sstevel@tonic-gate secpolicy_proc_excl_open(const cred_t *scr)
14977c478bd9Sstevel@tonic-gate {
14987c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EBUSY, NULL));
14997c478bd9Sstevel@tonic-gate }
15007c478bd9Sstevel@tonic-gate 
15017c478bd9Sstevel@tonic-gate int
15027c478bd9Sstevel@tonic-gate secpolicy_proc_zone(const cred_t *scr)
15037c478bd9Sstevel@tonic-gate {
15047c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(scr, PRIV_PROC_ZONE, B_FALSE, EPERM, NULL));
15057c478bd9Sstevel@tonic-gate }
15067c478bd9Sstevel@tonic-gate 
15077c478bd9Sstevel@tonic-gate /*
15087c478bd9Sstevel@tonic-gate  * Destroying the system
15097c478bd9Sstevel@tonic-gate  */
15107c478bd9Sstevel@tonic-gate 
15117c478bd9Sstevel@tonic-gate int
15127c478bd9Sstevel@tonic-gate secpolicy_kmdb(const cred_t *scr)
15137c478bd9Sstevel@tonic-gate {
15147c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL));
15157c478bd9Sstevel@tonic-gate }
15167c478bd9Sstevel@tonic-gate 
15177aec1d6eScindi int
15187aec1d6eScindi secpolicy_error_inject(const cred_t *scr)
15197aec1d6eScindi {
15207aec1d6eScindi 	return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL));
15217aec1d6eScindi }
15227aec1d6eScindi 
15237c478bd9Sstevel@tonic-gate /*
15247c478bd9Sstevel@tonic-gate  * Processor sets, cpu configuration, resource pools.
15257c478bd9Sstevel@tonic-gate  */
15267c478bd9Sstevel@tonic-gate int
15277c478bd9Sstevel@tonic-gate secpolicy_pset(const cred_t *cr)
15287c478bd9Sstevel@tonic-gate {
15297c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
15307c478bd9Sstevel@tonic-gate }
15317c478bd9Sstevel@tonic-gate 
15327c478bd9Sstevel@tonic-gate int
15337c478bd9Sstevel@tonic-gate secpolicy_ponline(const cred_t *cr)
15347c478bd9Sstevel@tonic-gate {
15357c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
15367c478bd9Sstevel@tonic-gate }
15377c478bd9Sstevel@tonic-gate 
15387c478bd9Sstevel@tonic-gate int
15397c478bd9Sstevel@tonic-gate secpolicy_pool(const cred_t *cr)
15407c478bd9Sstevel@tonic-gate {
15417c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
15427c478bd9Sstevel@tonic-gate }
15437c478bd9Sstevel@tonic-gate 
15447c478bd9Sstevel@tonic-gate int
15457c478bd9Sstevel@tonic-gate secpolicy_blacklist(const cred_t *cr)
15467c478bd9Sstevel@tonic-gate {
15477c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL));
15487c478bd9Sstevel@tonic-gate }
15497c478bd9Sstevel@tonic-gate 
15507c478bd9Sstevel@tonic-gate /*
15517c478bd9Sstevel@tonic-gate  * Catch all system configuration.
15527c478bd9Sstevel@tonic-gate  */
15537c478bd9Sstevel@tonic-gate int
15547c478bd9Sstevel@tonic-gate secpolicy_sys_config(const cred_t *cr, boolean_t checkonly)
15557c478bd9Sstevel@tonic-gate {
15567c478bd9Sstevel@tonic-gate 	if (checkonly) {
15577c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY_ONLY(cr, PRIV_SYS_CONFIG, B_FALSE) ? 0 :
15587c478bd9Sstevel@tonic-gate 		    EPERM);
15597c478bd9Sstevel@tonic-gate 	} else {
15607c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
15617c478bd9Sstevel@tonic-gate 	}
15627c478bd9Sstevel@tonic-gate }
15637c478bd9Sstevel@tonic-gate 
15647c478bd9Sstevel@tonic-gate /*
15657c478bd9Sstevel@tonic-gate  * Zone administration (halt, reboot, etc.) from within zone.
15667c478bd9Sstevel@tonic-gate  */
15677c478bd9Sstevel@tonic-gate int
15687c478bd9Sstevel@tonic-gate secpolicy_zone_admin(const cred_t *cr, boolean_t checkonly)
15697c478bd9Sstevel@tonic-gate {
15707c478bd9Sstevel@tonic-gate 	if (checkonly) {
15717c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY_ONLY(cr, PRIV_SYS_ADMIN, B_FALSE) ? 0 :
15727c478bd9Sstevel@tonic-gate 		    EPERM);
15737c478bd9Sstevel@tonic-gate 	} else {
15747c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM,
15757c478bd9Sstevel@tonic-gate 		    NULL));
15767c478bd9Sstevel@tonic-gate 	}
15777c478bd9Sstevel@tonic-gate }
15787c478bd9Sstevel@tonic-gate 
15797c478bd9Sstevel@tonic-gate /*
15807c478bd9Sstevel@tonic-gate  * Zone configuration (create, halt, enter).
15817c478bd9Sstevel@tonic-gate  */
15827c478bd9Sstevel@tonic-gate int
15837c478bd9Sstevel@tonic-gate secpolicy_zone_config(const cred_t *cr)
15847c478bd9Sstevel@tonic-gate {
15857c478bd9Sstevel@tonic-gate 	/*
15867c478bd9Sstevel@tonic-gate 	 * Require all privileges to avoid possibility of privilege
15877c478bd9Sstevel@tonic-gate 	 * escalation.
15887c478bd9Sstevel@tonic-gate 	 */
15897c478bd9Sstevel@tonic-gate 	return (secpolicy_require_set(cr, PRIV_FULLSET, NULL));
15907c478bd9Sstevel@tonic-gate }
15917c478bd9Sstevel@tonic-gate 
15927c478bd9Sstevel@tonic-gate /*
15937c478bd9Sstevel@tonic-gate  * Various other system configuration calls
15947c478bd9Sstevel@tonic-gate  */
15957c478bd9Sstevel@tonic-gate int
15967c478bd9Sstevel@tonic-gate secpolicy_coreadm(const cred_t *cr)
15977c478bd9Sstevel@tonic-gate {
15987c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL));
15997c478bd9Sstevel@tonic-gate }
16007c478bd9Sstevel@tonic-gate 
16017c478bd9Sstevel@tonic-gate int
16027c478bd9Sstevel@tonic-gate secpolicy_systeminfo(const cred_t *cr)
16037c478bd9Sstevel@tonic-gate {
16047c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL));
16057c478bd9Sstevel@tonic-gate }
16067c478bd9Sstevel@tonic-gate 
16077c478bd9Sstevel@tonic-gate int
16087c478bd9Sstevel@tonic-gate secpolicy_dispadm(const cred_t *cr)
16097c478bd9Sstevel@tonic-gate {
16107c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
16117c478bd9Sstevel@tonic-gate }
16127c478bd9Sstevel@tonic-gate 
16137c478bd9Sstevel@tonic-gate int
16147c478bd9Sstevel@tonic-gate secpolicy_settime(const cred_t *cr)
16157c478bd9Sstevel@tonic-gate {
16167c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_TIME, B_FALSE, EPERM, NULL));
16177c478bd9Sstevel@tonic-gate }
16187c478bd9Sstevel@tonic-gate 
16197c478bd9Sstevel@tonic-gate /*
16207c478bd9Sstevel@tonic-gate  * For realtime users: high resolution clock.
16217c478bd9Sstevel@tonic-gate  */
16227c478bd9Sstevel@tonic-gate int
16237c478bd9Sstevel@tonic-gate secpolicy_clock_highres(const cred_t *cr)
16247c478bd9Sstevel@tonic-gate {
16257c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_PROC_CLOCK_HIGHRES, B_FALSE, EPERM,
16267c478bd9Sstevel@tonic-gate 	    NULL));
16277c478bd9Sstevel@tonic-gate }
16287c478bd9Sstevel@tonic-gate 
16297c478bd9Sstevel@tonic-gate /*
16307c478bd9Sstevel@tonic-gate  * drv_priv() is documented as callable from interrupt context, not that
16317c478bd9Sstevel@tonic-gate  * anyone ever does, but still.  No debugging or auditing can be done when
16327c478bd9Sstevel@tonic-gate  * it is called from interrupt context.
16337c478bd9Sstevel@tonic-gate  * returns 0 on succes, EPERM on failure.
16347c478bd9Sstevel@tonic-gate  */
16357c478bd9Sstevel@tonic-gate int
16367c478bd9Sstevel@tonic-gate drv_priv(cred_t *cr)
16377c478bd9Sstevel@tonic-gate {
16387c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
16397c478bd9Sstevel@tonic-gate }
16407c478bd9Sstevel@tonic-gate 
16417c478bd9Sstevel@tonic-gate int
16427c478bd9Sstevel@tonic-gate secpolicy_sys_devices(const cred_t *cr)
16437c478bd9Sstevel@tonic-gate {
16447c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
16457c478bd9Sstevel@tonic-gate }
16467c478bd9Sstevel@tonic-gate 
16477c478bd9Sstevel@tonic-gate int
16487c478bd9Sstevel@tonic-gate secpolicy_excl_open(const cred_t *cr)
16497c478bd9Sstevel@tonic-gate {
16507c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EBUSY, NULL));
16517c478bd9Sstevel@tonic-gate }
16527c478bd9Sstevel@tonic-gate 
16537c478bd9Sstevel@tonic-gate int
16547c478bd9Sstevel@tonic-gate secpolicy_rctlsys(const cred_t *cr, boolean_t is_zone_rctl)
16557c478bd9Sstevel@tonic-gate {
16567c478bd9Sstevel@tonic-gate 	/* zone.* rctls can only be set from the global zone */
16577c478bd9Sstevel@tonic-gate 	if (is_zone_rctl && priv_policy_global(cr) != 0)
16587c478bd9Sstevel@tonic-gate 		return (EPERM);
16597c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL));
16607c478bd9Sstevel@tonic-gate }
16617c478bd9Sstevel@tonic-gate 
16627c478bd9Sstevel@tonic-gate int
16637c478bd9Sstevel@tonic-gate secpolicy_resource(const cred_t *cr)
16647c478bd9Sstevel@tonic-gate {
16657c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL));
16667c478bd9Sstevel@tonic-gate }
16677c478bd9Sstevel@tonic-gate 
16681c7cef2bSStan Studzinski int
16691c7cef2bSStan Studzinski secpolicy_resource_anon_mem(const cred_t *cr)
16701c7cef2bSStan Studzinski {
16711c7cef2bSStan Studzinski 	return (PRIV_POLICY_ONLY(cr, PRIV_SYS_RESOURCE, B_FALSE));
16721c7cef2bSStan Studzinski }
16731c7cef2bSStan Studzinski 
16747c478bd9Sstevel@tonic-gate /*
16757c478bd9Sstevel@tonic-gate  * Processes with a real uid of 0 escape any form of accounting, much
16767c478bd9Sstevel@tonic-gate  * like before.
16777c478bd9Sstevel@tonic-gate  */
16787c478bd9Sstevel@tonic-gate int
16797c478bd9Sstevel@tonic-gate secpolicy_newproc(const cred_t *cr)
16807c478bd9Sstevel@tonic-gate {
16817c478bd9Sstevel@tonic-gate 	if (cr->cr_ruid == 0)
16827c478bd9Sstevel@tonic-gate 		return (0);
16837c478bd9Sstevel@tonic-gate 
16847c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL));
16857c478bd9Sstevel@tonic-gate }
16867c478bd9Sstevel@tonic-gate 
16877c478bd9Sstevel@tonic-gate /*
16887c478bd9Sstevel@tonic-gate  * Networking
16897c478bd9Sstevel@tonic-gate  */
16907c478bd9Sstevel@tonic-gate int
16917c478bd9Sstevel@tonic-gate secpolicy_net_rawaccess(const cred_t *cr)
16927c478bd9Sstevel@tonic-gate {
16937c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_NET_RAWACCESS, B_FALSE, EACCES, NULL));
16947c478bd9Sstevel@tonic-gate }
16957c478bd9Sstevel@tonic-gate 
16960a0e9771SDarren Reed int
16970a0e9771SDarren Reed secpolicy_net_observability(const cred_t *cr)
16980a0e9771SDarren Reed {
16990a0e9771SDarren Reed 	return (PRIV_POLICY(cr, PRIV_NET_OBSERVABILITY, B_FALSE, EACCES, NULL));
17000a0e9771SDarren Reed }
17010a0e9771SDarren Reed 
17027c478bd9Sstevel@tonic-gate /*
17037c478bd9Sstevel@tonic-gate  * Need this privilege for accessing the ICMP device
17047c478bd9Sstevel@tonic-gate  */
17057c478bd9Sstevel@tonic-gate int
17067c478bd9Sstevel@tonic-gate secpolicy_net_icmpaccess(const cred_t *cr)
17077c478bd9Sstevel@tonic-gate {
17087c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_NET_ICMPACCESS, B_FALSE, EACCES, NULL));
17097c478bd9Sstevel@tonic-gate }
17107c478bd9Sstevel@tonic-gate 
17117c478bd9Sstevel@tonic-gate /*
17127c478bd9Sstevel@tonic-gate  * There are a few rare cases where the kernel generates ioctls() from
17137c478bd9Sstevel@tonic-gate  * interrupt context with a credential of kcred rather than NULL.
17147c478bd9Sstevel@tonic-gate  * In those cases, we take the safe and cheap test.
17157c478bd9Sstevel@tonic-gate  */
17167c478bd9Sstevel@tonic-gate int
17177c478bd9Sstevel@tonic-gate secpolicy_net_config(const cred_t *cr, boolean_t checkonly)
17187c478bd9Sstevel@tonic-gate {
17197c478bd9Sstevel@tonic-gate 	if (checkonly) {
17207c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE) ?
17217c478bd9Sstevel@tonic-gate 		    0 : EPERM);
17227c478bd9Sstevel@tonic-gate 	} else {
17237c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, PRIV_SYS_NET_CONFIG, B_FALSE, EPERM,
17247c478bd9Sstevel@tonic-gate 		    NULL));
17257c478bd9Sstevel@tonic-gate 	}
17267c478bd9Sstevel@tonic-gate }
17277c478bd9Sstevel@tonic-gate 
17287c478bd9Sstevel@tonic-gate 
17297c478bd9Sstevel@tonic-gate /*
1730e6bdcbd5Sdh155122  * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG.
1731f4b3ec61Sdh155122  *
1732f4b3ec61Sdh155122  * There are a few rare cases where the kernel generates ioctls() from
1733f4b3ec61Sdh155122  * interrupt context with a credential of kcred rather than NULL.
1734f4b3ec61Sdh155122  * In those cases, we take the safe and cheap test.
1735f4b3ec61Sdh155122  */
1736f4b3ec61Sdh155122 int
1737f4b3ec61Sdh155122 secpolicy_ip_config(const cred_t *cr, boolean_t checkonly)
1738f4b3ec61Sdh155122 {
1739f4b3ec61Sdh155122 	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
1740f4b3ec61Sdh155122 		return (secpolicy_net_config(cr, checkonly));
1741f4b3ec61Sdh155122 
1742f4b3ec61Sdh155122 	if (checkonly) {
1743f4b3ec61Sdh155122 		return (PRIV_POLICY_ONLY(cr, PRIV_SYS_IP_CONFIG, B_FALSE) ?
1744f4b3ec61Sdh155122 		    0 : EPERM);
1745f4b3ec61Sdh155122 	} else {
1746f4b3ec61Sdh155122 		return (PRIV_POLICY(cr, PRIV_SYS_IP_CONFIG, B_FALSE, EPERM,
1747f4b3ec61Sdh155122 		    NULL));
1748f4b3ec61Sdh155122 	}
1749f4b3ec61Sdh155122 }
1750f4b3ec61Sdh155122 
1751eae72b5bSSebastien Roy /*
1752eae72b5bSSebastien Roy  * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_DL_CONFIG.
1753eae72b5bSSebastien Roy  */
1754eae72b5bSSebastien Roy int
1755eae72b5bSSebastien Roy secpolicy_dl_config(const cred_t *cr)
1756eae72b5bSSebastien Roy {
1757eae72b5bSSebastien Roy 	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
1758eae72b5bSSebastien Roy 		return (secpolicy_net_config(cr, B_FALSE));
17592b24ab6bSSebastien Roy 	return (PRIV_POLICY(cr, PRIV_SYS_DL_CONFIG, B_FALSE, EPERM, NULL));
1760eae72b5bSSebastien Roy }
1761eae72b5bSSebastien Roy 
17622b24ab6bSSebastien Roy /*
17632b24ab6bSSebastien Roy  * PRIV_SYS_DL_CONFIG is a superset of PRIV_SYS_IPTUN_CONFIG.
17642b24ab6bSSebastien Roy  */
17652b24ab6bSSebastien Roy int
17662b24ab6bSSebastien Roy secpolicy_iptun_config(const cred_t *cr)
17672b24ab6bSSebastien Roy {
17682b24ab6bSSebastien Roy 	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
17692b24ab6bSSebastien Roy 		return (secpolicy_net_config(cr, B_FALSE));
17702b24ab6bSSebastien Roy 	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_DL_CONFIG, B_FALSE))
17712b24ab6bSSebastien Roy 		return (secpolicy_dl_config(cr));
17722b24ab6bSSebastien Roy 	return (PRIV_POLICY(cr, PRIV_SYS_IPTUN_CONFIG, B_FALSE, EPERM, NULL));
17732b24ab6bSSebastien Roy }
1774f4b3ec61Sdh155122 
1775f4b3ec61Sdh155122 /*
1776f4b3ec61Sdh155122  * Map IP pseudo privileges to actual privileges.
1777f4b3ec61Sdh155122  * So we don't need to recompile IP when we change the privileges.
1778f4b3ec61Sdh155122  */
1779f4b3ec61Sdh155122 int
1780f4b3ec61Sdh155122 secpolicy_ip(const cred_t *cr, int netpriv, boolean_t checkonly)
1781f4b3ec61Sdh155122 {
1782f4b3ec61Sdh155122 	int priv = PRIV_ALL;
1783f4b3ec61Sdh155122 
1784f4b3ec61Sdh155122 	switch (netpriv) {
1785f4b3ec61Sdh155122 	case OP_CONFIG:
1786f4b3ec61Sdh155122 		priv = PRIV_SYS_IP_CONFIG;
1787f4b3ec61Sdh155122 		break;
1788f4b3ec61Sdh155122 	case OP_RAW:
1789f4b3ec61Sdh155122 		priv = PRIV_NET_RAWACCESS;
1790f4b3ec61Sdh155122 		break;
1791f4b3ec61Sdh155122 	case OP_PRIVPORT:
1792f4b3ec61Sdh155122 		priv = PRIV_NET_PRIVADDR;
1793f4b3ec61Sdh155122 		break;
1794f4b3ec61Sdh155122 	}
1795f4b3ec61Sdh155122 	ASSERT(priv != PRIV_ALL);
1796f4b3ec61Sdh155122 	if (checkonly)
1797f4b3ec61Sdh155122 		return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM);
1798f4b3ec61Sdh155122 	else
1799f4b3ec61Sdh155122 		return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL));
1800f4b3ec61Sdh155122 }
1801f4b3ec61Sdh155122 
1802f4b3ec61Sdh155122 /*
18037c478bd9Sstevel@tonic-gate  * Map network pseudo privileges to actual privileges.
18047c478bd9Sstevel@tonic-gate  * So we don't need to recompile IP when we change the privileges.
18057c478bd9Sstevel@tonic-gate  */
18067c478bd9Sstevel@tonic-gate int
18077c478bd9Sstevel@tonic-gate secpolicy_net(const cred_t *cr, int netpriv, boolean_t checkonly)
18087c478bd9Sstevel@tonic-gate {
18097c478bd9Sstevel@tonic-gate 	int priv = PRIV_ALL;
18107c478bd9Sstevel@tonic-gate 
18117c478bd9Sstevel@tonic-gate 	switch (netpriv) {
18127c478bd9Sstevel@tonic-gate 	case OP_CONFIG:
18137c478bd9Sstevel@tonic-gate 		priv = PRIV_SYS_NET_CONFIG;
18147c478bd9Sstevel@tonic-gate 		break;
18157c478bd9Sstevel@tonic-gate 	case OP_RAW:
18167c478bd9Sstevel@tonic-gate 		priv = PRIV_NET_RAWACCESS;
18177c478bd9Sstevel@tonic-gate 		break;
18187c478bd9Sstevel@tonic-gate 	case OP_PRIVPORT:
18197c478bd9Sstevel@tonic-gate 		priv = PRIV_NET_PRIVADDR;
18207c478bd9Sstevel@tonic-gate 		break;
18217c478bd9Sstevel@tonic-gate 	}
18227c478bd9Sstevel@tonic-gate 	ASSERT(priv != PRIV_ALL);
18237c478bd9Sstevel@tonic-gate 	if (checkonly)
18247c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM);
18257c478bd9Sstevel@tonic-gate 	else
18267c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL));
18277c478bd9Sstevel@tonic-gate }
18287c478bd9Sstevel@tonic-gate 
18297c478bd9Sstevel@tonic-gate /*
18307c478bd9Sstevel@tonic-gate  * Checks for operations that are either client-only or are used by
18317c478bd9Sstevel@tonic-gate  * both clients and servers.
18327c478bd9Sstevel@tonic-gate  */
18337c478bd9Sstevel@tonic-gate int
18347c478bd9Sstevel@tonic-gate secpolicy_nfs(const cred_t *cr)
18357c478bd9Sstevel@tonic-gate {
18367c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_NFS, B_FALSE, EPERM, NULL));
18377c478bd9Sstevel@tonic-gate }
18387c478bd9Sstevel@tonic-gate 
18397c478bd9Sstevel@tonic-gate /*
18407c478bd9Sstevel@tonic-gate  * Special case for opening rpcmod: have NFS privileges or network
18417c478bd9Sstevel@tonic-gate  * config privileges.
18427c478bd9Sstevel@tonic-gate  */
18437c478bd9Sstevel@tonic-gate int
18447c478bd9Sstevel@tonic-gate secpolicy_rpcmod_open(const cred_t *cr)
18457c478bd9Sstevel@tonic-gate {
18467c478bd9Sstevel@tonic-gate 	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NFS, B_FALSE))
18477c478bd9Sstevel@tonic-gate 		return (secpolicy_nfs(cr));
18487c478bd9Sstevel@tonic-gate 	else
18497c478bd9Sstevel@tonic-gate 		return (secpolicy_net_config(cr, NULL));
18507c478bd9Sstevel@tonic-gate }
18517c478bd9Sstevel@tonic-gate 
18527c478bd9Sstevel@tonic-gate int
18537c478bd9Sstevel@tonic-gate secpolicy_chroot(const cred_t *cr)
18547c478bd9Sstevel@tonic-gate {
18557c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_PROC_CHROOT, B_FALSE, EPERM, NULL));
18567c478bd9Sstevel@tonic-gate }
18577c478bd9Sstevel@tonic-gate 
18587c478bd9Sstevel@tonic-gate int
18597c478bd9Sstevel@tonic-gate secpolicy_tasksys(const cred_t *cr)
18607c478bd9Sstevel@tonic-gate {
18617c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_PROC_TASKID, B_FALSE, EPERM, NULL));
18627c478bd9Sstevel@tonic-gate }
18637c478bd9Sstevel@tonic-gate 
18647c478bd9Sstevel@tonic-gate /*
18657c478bd9Sstevel@tonic-gate  * Basic privilege checks.
18667c478bd9Sstevel@tonic-gate  */
18677c478bd9Sstevel@tonic-gate int
1868ddf7fe95Scasper secpolicy_basic_exec(const cred_t *cr, vnode_t *vp)
18697c478bd9Sstevel@tonic-gate {
1870ddf7fe95Scasper 	return (priv_policy_va(cr, PRIV_PROC_EXEC, B_FALSE, EPERM, NULL,
1871ddf7fe95Scasper 	    KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE));
18727c478bd9Sstevel@tonic-gate }
18737c478bd9Sstevel@tonic-gate 
18747c478bd9Sstevel@tonic-gate int
18757c478bd9Sstevel@tonic-gate secpolicy_basic_fork(const cred_t *cr)
18767c478bd9Sstevel@tonic-gate {
18777c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_PROC_FORK, B_FALSE, EPERM, NULL));
18787c478bd9Sstevel@tonic-gate }
18797c478bd9Sstevel@tonic-gate 
18807c478bd9Sstevel@tonic-gate int
18817c478bd9Sstevel@tonic-gate secpolicy_basic_proc(const cred_t *cr)
18827c478bd9Sstevel@tonic-gate {
18837c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_PROC_SESSION, B_FALSE, EPERM, NULL));
18847c478bd9Sstevel@tonic-gate }
18857c478bd9Sstevel@tonic-gate 
18867c478bd9Sstevel@tonic-gate /*
18877c478bd9Sstevel@tonic-gate  * Slightly complicated because we don't want to trigger the policy too
18887c478bd9Sstevel@tonic-gate  * often.  First we shortcircuit access to "self" (tp == sp) or if
18897c478bd9Sstevel@tonic-gate  * we don't have the privilege but if we have permission
18907c478bd9Sstevel@tonic-gate  * just return (0) and we don't flag the privilege as needed.
18917c478bd9Sstevel@tonic-gate  * Else, we test for the privilege because we either have it or need it.
18927c478bd9Sstevel@tonic-gate  */
18937c478bd9Sstevel@tonic-gate int
18947c478bd9Sstevel@tonic-gate secpolicy_basic_procinfo(const cred_t *cr, proc_t *tp, proc_t *sp)
18957c478bd9Sstevel@tonic-gate {
18967c478bd9Sstevel@tonic-gate 	if (tp == sp ||
18977c478bd9Sstevel@tonic-gate 	    !HAS_PRIVILEGE(cr, PRIV_PROC_INFO) && prochasprocperm(tp, sp, cr)) {
18987c478bd9Sstevel@tonic-gate 		return (0);
18997c478bd9Sstevel@tonic-gate 	} else {
19007c478bd9Sstevel@tonic-gate 		return (PRIV_POLICY(cr, PRIV_PROC_INFO, B_FALSE, EPERM, NULL));
19017c478bd9Sstevel@tonic-gate 	}
19027c478bd9Sstevel@tonic-gate }
19037c478bd9Sstevel@tonic-gate 
19047c478bd9Sstevel@tonic-gate int
19057c478bd9Sstevel@tonic-gate secpolicy_basic_link(const cred_t *cr)
19067c478bd9Sstevel@tonic-gate {
19077c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_FILE_LINK_ANY, B_FALSE, EPERM, NULL));
19087c478bd9Sstevel@tonic-gate }
19097c478bd9Sstevel@tonic-gate 
1910*634e26ecSCasper H.S. Dik int
1911*634e26ecSCasper H.S. Dik secpolicy_basic_net_access(const cred_t *cr)
1912*634e26ecSCasper H.S. Dik {
1913*634e26ecSCasper H.S. Dik 	return (PRIV_POLICY(cr, PRIV_NET_ACCESS, B_FALSE, EACCES, NULL));
1914*634e26ecSCasper H.S. Dik }
1915*634e26ecSCasper H.S. Dik 
19167c478bd9Sstevel@tonic-gate /*
19177c478bd9Sstevel@tonic-gate  * Additional device protection.
19187c478bd9Sstevel@tonic-gate  *
19197c478bd9Sstevel@tonic-gate  * Traditionally, a device has specific permissions on the node in
19207c478bd9Sstevel@tonic-gate  * the filesystem which govern which devices can be opened by what
19217c478bd9Sstevel@tonic-gate  * processes.  In certain cases, it is desirable to add extra
19227c478bd9Sstevel@tonic-gate  * restrictions, as writing to certain devices is identical to
19237c478bd9Sstevel@tonic-gate  * having a complete run of the system.
19247c478bd9Sstevel@tonic-gate  *
19257c478bd9Sstevel@tonic-gate  * This mechanism is called the device policy.
19267c478bd9Sstevel@tonic-gate  *
19277c478bd9Sstevel@tonic-gate  * When a device is opened, its policy entry is looked up in the
19287c478bd9Sstevel@tonic-gate  * policy cache and checked.
19297c478bd9Sstevel@tonic-gate  */
19307c478bd9Sstevel@tonic-gate int
19317c478bd9Sstevel@tonic-gate secpolicy_spec_open(const cred_t *cr, struct vnode *vp, int oflag)
19327c478bd9Sstevel@tonic-gate {
19337c478bd9Sstevel@tonic-gate 	devplcy_t *plcy;
19347c478bd9Sstevel@tonic-gate 	int err;
19357c478bd9Sstevel@tonic-gate 	struct snode *csp = VTOS(common_specvp(vp));
1936e6bdcbd5Sdh155122 	priv_set_t pset;
19377c478bd9Sstevel@tonic-gate 
19387c478bd9Sstevel@tonic-gate 	mutex_enter(&csp->s_lock);
19397c478bd9Sstevel@tonic-gate 
19407c478bd9Sstevel@tonic-gate 	if (csp->s_plcy == NULL || csp->s_plcy->dp_gen != devplcy_gen) {
19417c478bd9Sstevel@tonic-gate 		plcy = devpolicy_find(vp);
19427c478bd9Sstevel@tonic-gate 		if (csp->s_plcy)
19437c478bd9Sstevel@tonic-gate 			dpfree(csp->s_plcy);
19447c478bd9Sstevel@tonic-gate 		csp->s_plcy = plcy;
19457c478bd9Sstevel@tonic-gate 		ASSERT(plcy != NULL);
19467c478bd9Sstevel@tonic-gate 	} else
19477c478bd9Sstevel@tonic-gate 		plcy = csp->s_plcy;
19487c478bd9Sstevel@tonic-gate 
19497c478bd9Sstevel@tonic-gate 	if (plcy == nullpolicy) {
19507c478bd9Sstevel@tonic-gate 		mutex_exit(&csp->s_lock);
19517c478bd9Sstevel@tonic-gate 		return (0);
19527c478bd9Sstevel@tonic-gate 	}
19537c478bd9Sstevel@tonic-gate 
19547c478bd9Sstevel@tonic-gate 	dphold(plcy);
19557c478bd9Sstevel@tonic-gate 
19567c478bd9Sstevel@tonic-gate 	mutex_exit(&csp->s_lock);
19577c478bd9Sstevel@tonic-gate 
1958e6bdcbd5Sdh155122 	if (oflag & FWRITE)
1959e6bdcbd5Sdh155122 		pset = plcy->dp_wrp;
1960e6bdcbd5Sdh155122 	else
1961e6bdcbd5Sdh155122 		pset = plcy->dp_rdp;
1962e6bdcbd5Sdh155122 	/*
1963e6bdcbd5Sdh155122 	 * Special case:
1964e6bdcbd5Sdh155122 	 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG.
1965e6bdcbd5Sdh155122 	 * If PRIV_SYS_NET_CONFIG is present and PRIV_SYS_IP_CONFIG is
1966e6bdcbd5Sdh155122 	 * required, replace PRIV_SYS_IP_CONFIG with PRIV_SYS_NET_CONFIG
1967e6bdcbd5Sdh155122 	 * in the required privilege set before doing the check.
1968e6bdcbd5Sdh155122 	 */
1969e6bdcbd5Sdh155122 	if (priv_ismember(&pset, PRIV_SYS_IP_CONFIG) &&
1970e6bdcbd5Sdh155122 	    priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_NET_CONFIG) &&
1971e6bdcbd5Sdh155122 	    !priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_IP_CONFIG)) {
1972e6bdcbd5Sdh155122 		priv_delset(&pset, PRIV_SYS_IP_CONFIG);
1973e6bdcbd5Sdh155122 		priv_addset(&pset, PRIV_SYS_NET_CONFIG);
1974e6bdcbd5Sdh155122 	}
1975e6bdcbd5Sdh155122 
1976e6bdcbd5Sdh155122 	err = secpolicy_require_set(cr, &pset, "devpolicy");
19777c478bd9Sstevel@tonic-gate 	dpfree(plcy);
19787c478bd9Sstevel@tonic-gate 
19797c478bd9Sstevel@tonic-gate 	return (err);
19807c478bd9Sstevel@tonic-gate }
19817c478bd9Sstevel@tonic-gate 
19827c478bd9Sstevel@tonic-gate int
19837c478bd9Sstevel@tonic-gate secpolicy_modctl(const cred_t *cr, int cmd)
19847c478bd9Sstevel@tonic-gate {
19857c478bd9Sstevel@tonic-gate 	switch (cmd) {
19867c478bd9Sstevel@tonic-gate 	case MODINFO:
1987a08731ecScth 	case MODGETMAJBIND:
19887c478bd9Sstevel@tonic-gate 	case MODGETPATH:
19897c478bd9Sstevel@tonic-gate 	case MODGETPATHLEN:
19907c478bd9Sstevel@tonic-gate 	case MODGETNAME:
1991a08731ecScth 	case MODGETFBNAME:
19927c478bd9Sstevel@tonic-gate 	case MODGETDEVPOLICY:
19937c478bd9Sstevel@tonic-gate 	case MODGETDEVPOLICYBYNAME:
1994a08731ecScth 	case MODDEVT2INSTANCE:
1995a08731ecScth 	case MODSIZEOF_DEVID:
1996a08731ecScth 	case MODGETDEVID:
1997a08731ecScth 	case MODSIZEOF_MINORNAME:
1998a08731ecScth 	case MODGETMINORNAME:
1999a08731ecScth 	case MODGETDEVFSPATH_LEN:
2000a08731ecScth 	case MODGETDEVFSPATH:
2001a08731ecScth 	case MODGETDEVFSPATH_MI_LEN:
2002a08731ecScth 	case MODGETDEVFSPATH_MI:
20037c478bd9Sstevel@tonic-gate 		/* Unprivileged */
20047c478bd9Sstevel@tonic-gate 		return (0);
20057c478bd9Sstevel@tonic-gate 	case MODLOAD:
20067c478bd9Sstevel@tonic-gate 	case MODSETDEVPOLICY:
20077c478bd9Sstevel@tonic-gate 		return (secpolicy_require_set(cr, PRIV_FULLSET, NULL));
20087c478bd9Sstevel@tonic-gate 	default:
20097c478bd9Sstevel@tonic-gate 		return (secpolicy_sys_config(cr, B_FALSE));
20107c478bd9Sstevel@tonic-gate 	}
20117c478bd9Sstevel@tonic-gate }
20127c478bd9Sstevel@tonic-gate 
20137c478bd9Sstevel@tonic-gate int
20147c478bd9Sstevel@tonic-gate secpolicy_console(const cred_t *cr)
20157c478bd9Sstevel@tonic-gate {
20167c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
20177c478bd9Sstevel@tonic-gate }
20187c478bd9Sstevel@tonic-gate 
20197c478bd9Sstevel@tonic-gate int
20207c478bd9Sstevel@tonic-gate secpolicy_power_mgmt(const cred_t *cr)
20217c478bd9Sstevel@tonic-gate {
20227c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL));
20237c478bd9Sstevel@tonic-gate }
20247c478bd9Sstevel@tonic-gate 
20257c478bd9Sstevel@tonic-gate /*
20267c478bd9Sstevel@tonic-gate  * Simulate terminal input; another escalation of privileges avenue.
20277c478bd9Sstevel@tonic-gate  */
20287c478bd9Sstevel@tonic-gate 
20297c478bd9Sstevel@tonic-gate int
20307c478bd9Sstevel@tonic-gate secpolicy_sti(const cred_t *cr)
20317c478bd9Sstevel@tonic-gate {
20327c478bd9Sstevel@tonic-gate 	return (secpolicy_require_set(cr, PRIV_FULLSET, NULL));
20337c478bd9Sstevel@tonic-gate }
20347c478bd9Sstevel@tonic-gate 
203545916cd2Sjpk boolean_t
203645916cd2Sjpk secpolicy_net_reply_equal(const cred_t *cr)
203745916cd2Sjpk {
203845916cd2Sjpk 	return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
203945916cd2Sjpk }
204045916cd2Sjpk 
20417c478bd9Sstevel@tonic-gate int
20427c478bd9Sstevel@tonic-gate secpolicy_swapctl(const cred_t *cr)
20437c478bd9Sstevel@tonic-gate {
20447c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL));
20457c478bd9Sstevel@tonic-gate }
20467c478bd9Sstevel@tonic-gate 
20477c478bd9Sstevel@tonic-gate int
20487c478bd9Sstevel@tonic-gate secpolicy_cpc_cpu(const cred_t *cr)
20497c478bd9Sstevel@tonic-gate {
20507c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_CPC_CPU, B_FALSE, EACCES, NULL));
20517c478bd9Sstevel@tonic-gate }
20527c478bd9Sstevel@tonic-gate 
20537c478bd9Sstevel@tonic-gate /*
20547b209c2cSacruz  * secpolicy_contract_identity
20557b209c2cSacruz  *
20567b209c2cSacruz  * Determine if the subject may set the process contract FMRI value
20577b209c2cSacruz  */
20587b209c2cSacruz int
20597b209c2cSacruz secpolicy_contract_identity(const cred_t *cr)
20607b209c2cSacruz {
20617b209c2cSacruz 	return (PRIV_POLICY(cr, PRIV_CONTRACT_IDENTITY, B_FALSE, EPERM, NULL));
20627b209c2cSacruz }
20637b209c2cSacruz 
20647b209c2cSacruz /*
20657c478bd9Sstevel@tonic-gate  * secpolicy_contract_observer
20667c478bd9Sstevel@tonic-gate  *
20677c478bd9Sstevel@tonic-gate  * Determine if the subject may observe a specific contract's events.
20687c478bd9Sstevel@tonic-gate  */
20697c478bd9Sstevel@tonic-gate int
20707c478bd9Sstevel@tonic-gate secpolicy_contract_observer(const cred_t *cr, struct contract *ct)
20717c478bd9Sstevel@tonic-gate {
20727c478bd9Sstevel@tonic-gate 	if (contract_owned(ct, cr, B_FALSE))
20737c478bd9Sstevel@tonic-gate 		return (0);
20747c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_CONTRACT_OBSERVER, B_FALSE, EPERM, NULL));
20757c478bd9Sstevel@tonic-gate }
20767c478bd9Sstevel@tonic-gate 
20777c478bd9Sstevel@tonic-gate /*
20787c478bd9Sstevel@tonic-gate  * secpolicy_contract_observer_choice
20797c478bd9Sstevel@tonic-gate  *
20807c478bd9Sstevel@tonic-gate  * Determine if the subject may observe any contract's events.  Just
20817c478bd9Sstevel@tonic-gate  * tests privilege and audits on success.
20827c478bd9Sstevel@tonic-gate  */
20837c478bd9Sstevel@tonic-gate boolean_t
20847c478bd9Sstevel@tonic-gate secpolicy_contract_observer_choice(const cred_t *cr)
20857c478bd9Sstevel@tonic-gate {
20867c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_OBSERVER, B_FALSE));
20877c478bd9Sstevel@tonic-gate }
20887c478bd9Sstevel@tonic-gate 
20897c478bd9Sstevel@tonic-gate /*
20907c478bd9Sstevel@tonic-gate  * secpolicy_contract_event
20917c478bd9Sstevel@tonic-gate  *
20927c478bd9Sstevel@tonic-gate  * Determine if the subject may request critical contract events or
20937c478bd9Sstevel@tonic-gate  * reliable contract event delivery.
20947c478bd9Sstevel@tonic-gate  */
20957c478bd9Sstevel@tonic-gate int
20967c478bd9Sstevel@tonic-gate secpolicy_contract_event(const cred_t *cr)
20977c478bd9Sstevel@tonic-gate {
20987c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY(cr, PRIV_CONTRACT_EVENT, B_FALSE, EPERM, NULL));
20997c478bd9Sstevel@tonic-gate }
21007c478bd9Sstevel@tonic-gate 
21017c478bd9Sstevel@tonic-gate /*
21027c478bd9Sstevel@tonic-gate  * secpolicy_contract_event_choice
21037c478bd9Sstevel@tonic-gate  *
21047c478bd9Sstevel@tonic-gate  * Determine if the subject may retain contract events in its critical
21057c478bd9Sstevel@tonic-gate  * set when a change in other terms would normally require a change in
21067c478bd9Sstevel@tonic-gate  * the critical set.  Just tests privilege and audits on success.
21077c478bd9Sstevel@tonic-gate  */
21087c478bd9Sstevel@tonic-gate boolean_t
21097c478bd9Sstevel@tonic-gate secpolicy_contract_event_choice(const cred_t *cr)
21107c478bd9Sstevel@tonic-gate {
21117c478bd9Sstevel@tonic-gate 	return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_EVENT, B_FALSE));
21127c478bd9Sstevel@tonic-gate }
21137c478bd9Sstevel@tonic-gate 
21147c478bd9Sstevel@tonic-gate /*
2115ea8dc4b6Seschrock  * secpolicy_gart_access
21167c478bd9Sstevel@tonic-gate  *
2117ea8dc4b6Seschrock  * Determine if the subject has sufficient priveleges to make ioctls to agpgart
2118ea8dc4b6Seschrock  * device.
21197c478bd9Sstevel@tonic-gate  */
21207c478bd9Sstevel@tonic-gate int
21217c478bd9Sstevel@tonic-gate secpolicy_gart_access(const cred_t *cr)
21227c478bd9Sstevel@tonic-gate {
212326f24838Scasper 	return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, NULL));
21247c478bd9Sstevel@tonic-gate }
21257c478bd9Sstevel@tonic-gate 
21267c478bd9Sstevel@tonic-gate /*
2127ea8dc4b6Seschrock  * secpolicy_gart_map
21287c478bd9Sstevel@tonic-gate  *
2129ea8dc4b6Seschrock  * Determine if the subject has sufficient priveleges to map aperture range
2130ea8dc4b6Seschrock  * through agpgart driver.
21317c478bd9Sstevel@tonic-gate  */
21327c478bd9Sstevel@tonic-gate int
21337c478bd9Sstevel@tonic-gate secpolicy_gart_map(const cred_t *cr)
21347c478bd9Sstevel@tonic-gate {
213526f24838Scasper 	if (PRIV_POLICY_ONLY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE)) {
213626f24838Scasper 		return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM,
213726f24838Scasper 		    NULL));
213826f24838Scasper 	} else {
213926f24838Scasper 		return (PRIV_POLICY(cr, PRIV_GRAPHICS_MAP, B_FALSE, EPERM,
214026f24838Scasper 		    NULL));
21417c478bd9Sstevel@tonic-gate 	}
21427c478bd9Sstevel@tonic-gate }
2143fa9e4066Sahrens 
2144fa9e4066Sahrens /*
2145ea8dc4b6Seschrock  * secpolicy_zinject
2146ea8dc4b6Seschrock  *
2147ea8dc4b6Seschrock  * Determine if the subject can inject faults in the ZFS fault injection
2148ea8dc4b6Seschrock  * framework.  Requires all privileges.
2149ea8dc4b6Seschrock  */
2150ea8dc4b6Seschrock int
2151ea8dc4b6Seschrock secpolicy_zinject(const cred_t *cr)
2152ea8dc4b6Seschrock {
2153ea8dc4b6Seschrock 	return (secpolicy_require_set(cr, PRIV_FULLSET, NULL));
2154ea8dc4b6Seschrock }
2155ea8dc4b6Seschrock 
2156ea8dc4b6Seschrock /*
2157fa9e4066Sahrens  * secpolicy_zfs
2158fa9e4066Sahrens  *
2159ea8dc4b6Seschrock  * Determine if the subject has permission to manipulate ZFS datasets
2160ea8dc4b6Seschrock  * (not pools).  Equivalent to the SYS_MOUNT privilege.
2161fa9e4066Sahrens  */
2162fa9e4066Sahrens int
2163fa9e4066Sahrens secpolicy_zfs(const cred_t *cr)
2164fa9e4066Sahrens {
2165fa9e4066Sahrens 	return (PRIV_POLICY(cr, PRIV_SYS_MOUNT, B_FALSE, EPERM, NULL));
2166fa9e4066Sahrens }
2167f48205beScasper 
2168f48205beScasper /*
2169f48205beScasper  * secpolicy_idmap
2170f48205beScasper  *
2171f48205beScasper  * Determine if the calling process has permissions to register an SID
2172f48205beScasper  * mapping daemon and allocate ephemeral IDs.
2173f48205beScasper  */
2174f48205beScasper int
2175f48205beScasper secpolicy_idmap(const cred_t *cr)
2176f48205beScasper {
2177bda89588Sjp151216 	return (PRIV_POLICY(cr, PRIV_FILE_SETID, B_TRUE, EPERM, NULL));
2178f48205beScasper }
21792449e17fSsherrym 
21802449e17fSsherrym /*
21812449e17fSsherrym  * secpolicy_ucode_update
21822449e17fSsherrym  *
21832449e17fSsherrym  * Determine if the subject has sufficient privilege to update microcode.
21842449e17fSsherrym  */
21852449e17fSsherrym int
21862449e17fSsherrym secpolicy_ucode_update(const cred_t *scr)
21872449e17fSsherrym {
21882449e17fSsherrym 	return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL));
21892449e17fSsherrym }
2190e6bdcbd5Sdh155122 
2191e6bdcbd5Sdh155122 /*
2192e6bdcbd5Sdh155122  * secpolicy_sadopen
2193e6bdcbd5Sdh155122  *
2194e6bdcbd5Sdh155122  * Determine if the subject has sufficient privilege to access /dev/sad/admin.
2195e6bdcbd5Sdh155122  * /dev/sad/admin appear in global zone and exclusive-IP zones only.
2196e6bdcbd5Sdh155122  * In global zone, sys_config is required.
2197e6bdcbd5Sdh155122  * In exclusive-IP zones, sys_ip_config is required.
2198e6bdcbd5Sdh155122  * Note that sys_config is prohibited in non-global zones.
2199e6bdcbd5Sdh155122  */
2200e6bdcbd5Sdh155122 int
2201e6bdcbd5Sdh155122 secpolicy_sadopen(const cred_t *credp)
2202e6bdcbd5Sdh155122 {
2203e6bdcbd5Sdh155122 	priv_set_t pset;
2204e6bdcbd5Sdh155122 
2205e6bdcbd5Sdh155122 	priv_emptyset(&pset);
2206e6bdcbd5Sdh155122 
2207e6bdcbd5Sdh155122 	if (crgetzoneid(credp) == GLOBAL_ZONEID)
2208e6bdcbd5Sdh155122 		priv_addset(&pset, PRIV_SYS_CONFIG);
2209e6bdcbd5Sdh155122 	else
2210e6bdcbd5Sdh155122 		priv_addset(&pset, PRIV_SYS_IP_CONFIG);
2211e6bdcbd5Sdh155122 
2212e6bdcbd5Sdh155122 	return (secpolicy_require_set(credp, &pset, "devpolicy"));
2213e6bdcbd5Sdh155122 }
2214da6c28aaSamw 
2215ddf7fe95Scasper 
2216ddf7fe95Scasper /*
2217ddf7fe95Scasper  * Add privileges to a particular privilege set; this is called when the
2218ddf7fe95Scasper  * current sets of privileges are not sufficient.  I.e., we should always
2219ddf7fe95Scasper  * call the policy override functions from here.
2220ddf7fe95Scasper  * What we are allowed to have is in the Observed Permitted set; so
2221ddf7fe95Scasper  * we compute the difference between that and the newset.
2222ddf7fe95Scasper  */
2223ddf7fe95Scasper int
2224ddf7fe95Scasper secpolicy_require_privs(const cred_t *cr, const priv_set_t *nset)
2225ddf7fe95Scasper {
2226ddf7fe95Scasper 	priv_set_t rqd;
2227ddf7fe95Scasper 
2228ddf7fe95Scasper 	rqd = CR_OPPRIV(cr);
2229ddf7fe95Scasper 
2230ddf7fe95Scasper 	priv_inverse(&rqd);
2231ddf7fe95Scasper 	priv_intersect(nset, &rqd);
2232ddf7fe95Scasper 
2233ddf7fe95Scasper 	return (secpolicy_require_set(cr, &rqd, NULL));
2234ddf7fe95Scasper }
2235ddf7fe95Scasper 
2236da6c28aaSamw /*
2237da6c28aaSamw  * secpolicy_smb
2238da6c28aaSamw  *
2239da6c28aaSamw  * Determine if the cred_t has PRIV_SYS_SMB privilege, indicating
2240da6c28aaSamw  * that it has permission to access the smbsrv kernel driver.
2241da6c28aaSamw  * PRIV_POLICY checks the privilege and audits the check.
2242da6c28aaSamw  *
2243da6c28aaSamw  * Returns:
2244da6c28aaSamw  * 0       Driver access is allowed.
2245da6c28aaSamw  * EPERM   Driver access is NOT permitted.
2246da6c28aaSamw  */
2247da6c28aaSamw int
2248da6c28aaSamw secpolicy_smb(const cred_t *cr)
2249da6c28aaSamw {
2250da6c28aaSamw 	return (PRIV_POLICY(cr, PRIV_SYS_SMB, B_FALSE, EPERM, NULL));
2251da6c28aaSamw }
2252911106dfSjm199354 
2253911106dfSjm199354 /*
2254911106dfSjm199354  * secpolicy_vscan
2255911106dfSjm199354  *
2256911106dfSjm199354  * Determine if cred_t has the necessary privileges to access a file
2257911106dfSjm199354  * for virus scanning and update its extended system attributes.
2258911106dfSjm199354  * PRIV_FILE_DAC_SEARCH, PRIV_FILE_DAC_READ - file access
2259911106dfSjm199354  * PRIV_FILE_FLAG_SET - set extended system attributes
2260911106dfSjm199354  *
2261911106dfSjm199354  * PRIV_POLICY checks the privilege and audits the check.
2262911106dfSjm199354  *
2263911106dfSjm199354  * Returns:
2264911106dfSjm199354  * 0      file access for virus scanning allowed.
2265911106dfSjm199354  * EPERM  file access for virus scanning is NOT permitted.
2266911106dfSjm199354  */
2267911106dfSjm199354 int
2268911106dfSjm199354 secpolicy_vscan(const cred_t *cr)
2269911106dfSjm199354 {
2270911106dfSjm199354 	if ((PRIV_POLICY(cr, PRIV_FILE_DAC_SEARCH, B_FALSE, EPERM, NULL)) ||
2271911106dfSjm199354 	    (PRIV_POLICY(cr, PRIV_FILE_DAC_READ, B_FALSE, EPERM, NULL)) ||
2272911106dfSjm199354 	    (PRIV_POLICY(cr, PRIV_FILE_FLAG_SET, B_FALSE, EPERM, NULL))) {
2273911106dfSjm199354 		return (EPERM);
2274911106dfSjm199354 	}
2275911106dfSjm199354 
2276911106dfSjm199354 	return (0);
2277911106dfSjm199354 }
22784bff34e3Sthurlow 
22794bff34e3Sthurlow /*
22804bff34e3Sthurlow  * secpolicy_smbfs_login
22814bff34e3Sthurlow  *
22824bff34e3Sthurlow  * Determines if the caller can add and delete the smbfs login
22834bff34e3Sthurlow  * password in the the nsmb kernel module for the CIFS client.
22844bff34e3Sthurlow  *
22854bff34e3Sthurlow  * Returns:
22864bff34e3Sthurlow  * 0       access is allowed.
22874bff34e3Sthurlow  * EPERM   access is NOT allowed.
22884bff34e3Sthurlow  */
22894bff34e3Sthurlow int
22904bff34e3Sthurlow secpolicy_smbfs_login(const cred_t *cr, uid_t uid)
22914bff34e3Sthurlow {
22924bff34e3Sthurlow 	uid_t cruid = crgetruid(cr);
22934bff34e3Sthurlow 
22944bff34e3Sthurlow 	if (cruid == uid)
22954bff34e3Sthurlow 		return (0);
22964bff34e3Sthurlow 	return (PRIV_POLICY(cr, PRIV_PROC_OWNER, B_FALSE,
22974bff34e3Sthurlow 	    EPERM, NULL));
22984bff34e3Sthurlow }
2299b26a64aeSjohnlev 
2300b26a64aeSjohnlev /*
2301b26a64aeSjohnlev  * secpolicy_xvm_control
2302b26a64aeSjohnlev  *
2303b26a64aeSjohnlev  * Determines if a caller can control the xVM hypervisor and/or running
2304b26a64aeSjohnlev  * domains (x86 specific).
2305b26a64aeSjohnlev  *
2306b26a64aeSjohnlev  * Returns:
2307b26a64aeSjohnlev  * 0       access is allowed.
2308b26a64aeSjohnlev  * EPERM   access is NOT allowed.
2309b26a64aeSjohnlev  */
2310b26a64aeSjohnlev int
2311b26a64aeSjohnlev secpolicy_xvm_control(const cred_t *cr)
2312b26a64aeSjohnlev {
2313b26a64aeSjohnlev 	if (PRIV_POLICY(cr, PRIV_XVM_CONTROL, B_FALSE, EPERM, NULL))
2314b26a64aeSjohnlev 		return (EPERM);
2315b26a64aeSjohnlev 	return (0);
2316b26a64aeSjohnlev }
2317da14cebeSEric Cheng 
2318da14cebeSEric Cheng /*
2319f53eecf5SJames Carlson  * secpolicy_ppp_config
2320f53eecf5SJames Carlson  *
2321f53eecf5SJames Carlson  * Determine if the subject has sufficient privileges to configure PPP and
2322f53eecf5SJames Carlson  * PPP-related devices.
2323f53eecf5SJames Carlson  */
2324f53eecf5SJames Carlson int
2325f53eecf5SJames Carlson secpolicy_ppp_config(const cred_t *cr)
2326f53eecf5SJames Carlson {
2327f53eecf5SJames Carlson 	if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE))
2328f53eecf5SJames Carlson 		return (secpolicy_net_config(cr, B_FALSE));
2329f53eecf5SJames Carlson 	return (PRIV_POLICY(cr, PRIV_SYS_PPP_CONFIG, B_FALSE, EPERM, NULL));
2330f53eecf5SJames Carlson }
2331