10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51544Seschrock * Common Development and Distribution License (the "License"). 61544Seschrock * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 223446Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/sysmacros.h> 300Sstevel@tonic-gate #include <sys/param.h> 310Sstevel@tonic-gate #include <sys/systm.h> 320Sstevel@tonic-gate #include <sys/cred_impl.h> 330Sstevel@tonic-gate #include <sys/vnode.h> 340Sstevel@tonic-gate #include <sys/vfs.h> 350Sstevel@tonic-gate #include <sys/stat.h> 360Sstevel@tonic-gate #include <sys/errno.h> 370Sstevel@tonic-gate #include <sys/kmem.h> 380Sstevel@tonic-gate #include <sys/user.h> 390Sstevel@tonic-gate #include <sys/proc.h> 400Sstevel@tonic-gate #include <sys/acct.h> 410Sstevel@tonic-gate #include <sys/ipc_impl.h> 420Sstevel@tonic-gate #include <sys/cmn_err.h> 430Sstevel@tonic-gate #include <sys/debug.h> 440Sstevel@tonic-gate #include <sys/policy.h> 450Sstevel@tonic-gate #include <sys/kobj.h> 460Sstevel@tonic-gate #include <sys/msg.h> 470Sstevel@tonic-gate #include <sys/devpolicy.h> 480Sstevel@tonic-gate #include <c2/audit.h> 490Sstevel@tonic-gate #include <sys/varargs.h> 500Sstevel@tonic-gate #include <sys/modctl.h> 510Sstevel@tonic-gate #include <sys/disp.h> 520Sstevel@tonic-gate #include <sys/zone.h> 530Sstevel@tonic-gate #include <inet/optcom.h> 540Sstevel@tonic-gate #include <sys/sdt.h> 550Sstevel@tonic-gate #include <sys/vfs.h> 560Sstevel@tonic-gate #include <sys/mntent.h> 570Sstevel@tonic-gate #include <sys/contract_impl.h> 580Sstevel@tonic-gate 590Sstevel@tonic-gate /* 600Sstevel@tonic-gate * There are two possible layers of privilege routines and two possible 610Sstevel@tonic-gate * levels of secpolicy. Plus one other we may not be interested in, so 620Sstevel@tonic-gate * we may need as many as 6 but no more. 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate #define MAXPRIVSTACK 6 650Sstevel@tonic-gate 660Sstevel@tonic-gate int priv_debug = 0; 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * This file contains the majority of the policy routines. 700Sstevel@tonic-gate * Since the policy routines are defined by function and not 710Sstevel@tonic-gate * by privilege, there is quite a bit of duplication of 720Sstevel@tonic-gate * functions. 730Sstevel@tonic-gate * 745331Samw * The secpolicy functions must not make assumptions about 750Sstevel@tonic-gate * locks held or not held as any lock can be held while they're 760Sstevel@tonic-gate * being called. 770Sstevel@tonic-gate * 780Sstevel@tonic-gate * Credentials are read-only so no special precautions need to 790Sstevel@tonic-gate * be taken while locking them. 800Sstevel@tonic-gate * 810Sstevel@tonic-gate * When a new policy check needs to be added to the system the 820Sstevel@tonic-gate * following procedure should be followed: 830Sstevel@tonic-gate * 840Sstevel@tonic-gate * Pick an appropriate secpolicy_*() function 850Sstevel@tonic-gate * -> done if one exists. 860Sstevel@tonic-gate * Create a new secpolicy function, preferably with 870Sstevel@tonic-gate * a descriptive name using the standard template. 880Sstevel@tonic-gate * Pick an appropriate privilege for the policy. 890Sstevel@tonic-gate * If no appropraite privilege exists, define new one 900Sstevel@tonic-gate * (this should be done with extreme care; in most cases 910Sstevel@tonic-gate * little is gained by adding another privilege) 920Sstevel@tonic-gate * 930Sstevel@tonic-gate * WHY ROOT IS STILL SPECIAL. 940Sstevel@tonic-gate * 950Sstevel@tonic-gate * In a number of the policy functions, there are still explicit 960Sstevel@tonic-gate * checks for uid 0. The rationale behind these is that many root 970Sstevel@tonic-gate * owned files/objects hold configuration information which can give full 980Sstevel@tonic-gate * privileges to the user once written to. To prevent escalation 990Sstevel@tonic-gate * of privilege by allowing just a single privilege to modify root owned 1000Sstevel@tonic-gate * objects, we've added these root specific checks where we considered 1010Sstevel@tonic-gate * them necessary: modifying root owned files, changing uids to 0, etc. 1020Sstevel@tonic-gate * 1030Sstevel@tonic-gate * PRIVILEGE ESCALATION AND ZONES. 1040Sstevel@tonic-gate * 1050Sstevel@tonic-gate * A number of operations potentially allow the caller to achieve 1060Sstevel@tonic-gate * privileges beyond the ones normally required to perform the operation. 1070Sstevel@tonic-gate * For example, if allowed to create a setuid 0 executable, a process can 1080Sstevel@tonic-gate * gain privileges beyond PRIV_FILE_SETID. Zones, however, place 1090Sstevel@tonic-gate * restrictions on the ability to gain privileges beyond those available 1100Sstevel@tonic-gate * within the zone through file and process manipulation. Hence, such 1110Sstevel@tonic-gate * operations require that the caller have an effective set that includes 1120Sstevel@tonic-gate * all privileges available within the current zone, or all privileges 1130Sstevel@tonic-gate * if executing in the global zone. 1140Sstevel@tonic-gate * 1150Sstevel@tonic-gate * This is indicated in the priv_policy* policy checking functions 1160Sstevel@tonic-gate * through a combination of parameters. The "priv" parameter indicates 1170Sstevel@tonic-gate * the privilege that is required, and the "allzone" parameter indicates 1180Sstevel@tonic-gate * whether or not all privileges in the zone are required. In addition, 1190Sstevel@tonic-gate * priv can be set to PRIV_ALL to indicate that all privileges are 1200Sstevel@tonic-gate * required (regardless of zone). There are three scenarios of interest: 1210Sstevel@tonic-gate * (1) operation requires a specific privilege 1220Sstevel@tonic-gate * (2) operation requires a specific privilege, and requires all 1230Sstevel@tonic-gate * privileges available within the zone (or all privileges if in 1240Sstevel@tonic-gate * the global zone) 1250Sstevel@tonic-gate * (3) operation requires all privileges, regardless of zone 1260Sstevel@tonic-gate * 1270Sstevel@tonic-gate * For (1), priv should be set to the specific privilege, and allzone 1280Sstevel@tonic-gate * should be set to B_FALSE. 1290Sstevel@tonic-gate * For (2), priv should be set to the specific privilege, and allzone 1300Sstevel@tonic-gate * should be set to B_TRUE. 1310Sstevel@tonic-gate * For (3), priv should be set to PRIV_ALL, and allzone should be set 1320Sstevel@tonic-gate * to B_FALSE. 1330Sstevel@tonic-gate * 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* 1370Sstevel@tonic-gate * The privileges are checked against the Effective set for 1380Sstevel@tonic-gate * ordinary processes and checked against the Limit set 1390Sstevel@tonic-gate * for euid 0 processes that haven't manipulated their privilege 1400Sstevel@tonic-gate * sets. 1410Sstevel@tonic-gate */ 1420Sstevel@tonic-gate #define HAS_ALLPRIVS(cr) priv_isfullset(&CR_OEPRIV(cr)) 1430Sstevel@tonic-gate #define ZONEPRIVS(cr) ((cr)->cr_zone->zone_privset) 1440Sstevel@tonic-gate #define HAS_ALLZONEPRIVS(cr) priv_issubset(ZONEPRIVS(cr), &CR_OEPRIV(cr)) 1450Sstevel@tonic-gate #define HAS_PRIVILEGE(cr, pr) ((pr) == PRIV_ALL ? \ 1460Sstevel@tonic-gate HAS_ALLPRIVS(cr) : \ 1470Sstevel@tonic-gate PRIV_ISASSERT(&CR_OEPRIV(cr), pr)) 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate /* 1500Sstevel@tonic-gate * Policy checking functions 1510Sstevel@tonic-gate * 1520Sstevel@tonic-gate * In future, these will migrate to several files when policy 1530Sstevel@tonic-gate * becomes more or less pluggable. 1540Sstevel@tonic-gate * 1550Sstevel@tonic-gate * For now, there's only one policy and this is it. 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate /* 1590Sstevel@tonic-gate * Generic policy calls 1600Sstevel@tonic-gate * 1610Sstevel@tonic-gate * The "bottom" functions of policy control 1620Sstevel@tonic-gate */ 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate static char * 1650Sstevel@tonic-gate mprintf(const char *fmt, ...) 1660Sstevel@tonic-gate { 1670Sstevel@tonic-gate va_list args; 1680Sstevel@tonic-gate char *buf; 1690Sstevel@tonic-gate size_t len; 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate va_start(args, fmt); 1720Sstevel@tonic-gate len = vsnprintf(NULL, 0, fmt, args) + 1; 1730Sstevel@tonic-gate va_end(args); 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate buf = kmem_alloc(len, KM_NOSLEEP); 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate if (buf == NULL) 1780Sstevel@tonic-gate return (NULL); 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate va_start(args, fmt); 1810Sstevel@tonic-gate (void) vsnprintf(buf, len, fmt, args); 1820Sstevel@tonic-gate va_end(args); 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate return (buf); 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* 1880Sstevel@tonic-gate * priv_policy_errmsg() 1890Sstevel@tonic-gate * 1900Sstevel@tonic-gate * Generate an error message if privilege debugging is enabled system wide 1910Sstevel@tonic-gate * or for this particular process. 1920Sstevel@tonic-gate */ 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate #define FMTHDR "%s[%d]: missing privilege \"%s\" (euid = %d, syscall = %d)" 1950Sstevel@tonic-gate #define FMTMSG " for \"%s\"" 1960Sstevel@tonic-gate #define FMTFUN " needed at %s+0x%lx" 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate /* The maximum size privilege format: the concatenation of the above */ 1990Sstevel@tonic-gate #define FMTMAX FMTHDR FMTMSG FMTFUN "\n" 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate static void 2020Sstevel@tonic-gate priv_policy_errmsg(const cred_t *cr, int priv, const char *msg) 2030Sstevel@tonic-gate { 2040Sstevel@tonic-gate struct proc *me; 2050Sstevel@tonic-gate pc_t stack[MAXPRIVSTACK]; 2060Sstevel@tonic-gate int depth; 2070Sstevel@tonic-gate int i; 2080Sstevel@tonic-gate char *sym; 2090Sstevel@tonic-gate ulong_t off; 2100Sstevel@tonic-gate const char *pname; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate char *cmd; 2130Sstevel@tonic-gate char fmt[sizeof (FMTMAX)]; 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate if ((me = curproc) == &p0) 2160Sstevel@tonic-gate return; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate /* Privileges must be defined */ 2190Sstevel@tonic-gate ASSERT(priv == PRIV_ALL || priv == PRIV_MULTIPLE || 2200Sstevel@tonic-gate priv == PRIV_ALLZONE || priv == PRIV_GLOBAL || 2210Sstevel@tonic-gate priv_getbynum(priv) != NULL); 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate if (priv == PRIV_ALLZONE && INGLOBALZONE(me)) 2240Sstevel@tonic-gate priv = PRIV_ALL; 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate if (curthread->t_pre_sys) 2270Sstevel@tonic-gate ttolwp(curthread)->lwp_badpriv = (short)priv; 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate if (priv_debug == 0 && (CR_FLAGS(cr) & PRIV_DEBUG) == 0) 2300Sstevel@tonic-gate return; 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate (void) strcpy(fmt, FMTHDR); 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate if (me->p_user.u_comm[0]) 2350Sstevel@tonic-gate cmd = &me->p_user.u_comm[0]; 2360Sstevel@tonic-gate else 2370Sstevel@tonic-gate cmd = "priv_policy"; 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate if (msg != NULL && *msg != '\0') { 2400Sstevel@tonic-gate (void) strcat(fmt, FMTMSG); 2410Sstevel@tonic-gate } else { 2420Sstevel@tonic-gate (void) strcat(fmt, "%s"); 2430Sstevel@tonic-gate msg = ""; 2440Sstevel@tonic-gate } 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate sym = NULL; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate depth = getpcstack(stack, MAXPRIVSTACK); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* 2510Sstevel@tonic-gate * Try to find the first interesting function on the stack. 2520Sstevel@tonic-gate * priv_policy* that's us, so completely uninteresting. 2530Sstevel@tonic-gate * suser(), drv_priv(), secpolicy_* are also called from 2540Sstevel@tonic-gate * too many locations to convey useful information. 2550Sstevel@tonic-gate */ 2560Sstevel@tonic-gate for (i = 0; i < depth; i++) { 2570Sstevel@tonic-gate sym = kobj_getsymname((uintptr_t)stack[i], &off); 2580Sstevel@tonic-gate if (sym != NULL && 2590Sstevel@tonic-gate strstr(sym, "hasprocperm") == 0 && 2600Sstevel@tonic-gate strcmp("suser", sym) != 0 && 2610Sstevel@tonic-gate strcmp("ipcaccess", sym) != 0 && 2620Sstevel@tonic-gate strcmp("drv_priv", sym) != 0 && 2630Sstevel@tonic-gate strncmp("secpolicy_", sym, 10) != 0 && 2640Sstevel@tonic-gate strncmp("priv_policy", sym, 11) != 0) 2650Sstevel@tonic-gate break; 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate if (sym != NULL) 2690Sstevel@tonic-gate (void) strcat(fmt, FMTFUN); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate (void) strcat(fmt, "\n"); 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate switch (priv) { 2740Sstevel@tonic-gate case PRIV_ALL: 2750Sstevel@tonic-gate pname = "ALL"; 2760Sstevel@tonic-gate break; 2770Sstevel@tonic-gate case PRIV_MULTIPLE: 2780Sstevel@tonic-gate pname = "MULTIPLE"; 2790Sstevel@tonic-gate break; 2800Sstevel@tonic-gate case PRIV_ALLZONE: 2810Sstevel@tonic-gate pname = "ZONE"; 2820Sstevel@tonic-gate break; 2830Sstevel@tonic-gate case PRIV_GLOBAL: 2840Sstevel@tonic-gate pname = "GLOBAL"; 2850Sstevel@tonic-gate break; 2860Sstevel@tonic-gate default: 2870Sstevel@tonic-gate pname = priv_getbynum(priv); 2880Sstevel@tonic-gate break; 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate if (CR_FLAGS(cr) & PRIV_DEBUG) { 2920Sstevel@tonic-gate /* Remember last message, just like lwp_badpriv. */ 2930Sstevel@tonic-gate if (curthread->t_pdmsg != NULL) { 2940Sstevel@tonic-gate kmem_free(curthread->t_pdmsg, 2950Sstevel@tonic-gate strlen(curthread->t_pdmsg) + 1); 2960Sstevel@tonic-gate } 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate curthread->t_pdmsg = mprintf(fmt, cmd, me->p_pid, pname, 2994543Smarks cr->cr_uid, curthread->t_sysnum, msg, sym, off); 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate curthread->t_post_sys = 1; 3020Sstevel@tonic-gate } else { 3030Sstevel@tonic-gate cmn_err(CE_NOTE, fmt, cmd, me->p_pid, pname, cr->cr_uid, 3040Sstevel@tonic-gate curthread->t_sysnum, msg, sym, off); 3050Sstevel@tonic-gate } 3060Sstevel@tonic-gate } 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate /* 3090Sstevel@tonic-gate * Audit failure, log error message. 3100Sstevel@tonic-gate */ 3110Sstevel@tonic-gate static void 3120Sstevel@tonic-gate priv_policy_err(const cred_t *cr, int priv, boolean_t allzone, const char *msg) 3130Sstevel@tonic-gate { 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate #ifdef C2_AUDIT 3160Sstevel@tonic-gate if (audit_active) 3170Sstevel@tonic-gate audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 0); 3180Sstevel@tonic-gate #endif 3190Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || 3220Sstevel@tonic-gate curthread->t_pre_sys) { 3230Sstevel@tonic-gate if (allzone && !HAS_ALLZONEPRIVS(cr)) { 3240Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_ALLZONE, msg); 3250Sstevel@tonic-gate } else { 3260Sstevel@tonic-gate ASSERT(!HAS_PRIVILEGE(cr, priv)); 3270Sstevel@tonic-gate priv_policy_errmsg(cr, priv, msg); 3280Sstevel@tonic-gate } 3290Sstevel@tonic-gate } 3300Sstevel@tonic-gate } 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate /* 3330Sstevel@tonic-gate * priv_policy() 3340Sstevel@tonic-gate * return 0 or error. 3350Sstevel@tonic-gate * See block comment above for a description of "priv" and "allzone" usage. 3360Sstevel@tonic-gate */ 3370Sstevel@tonic-gate int 3380Sstevel@tonic-gate priv_policy(const cred_t *cr, int priv, boolean_t allzone, int err, 3390Sstevel@tonic-gate const char *msg) 3400Sstevel@tonic-gate { 3410Sstevel@tonic-gate if (HAS_PRIVILEGE(cr, priv) && (!allzone || HAS_ALLZONEPRIVS(cr))) { 3420Sstevel@tonic-gate if ((allzone || priv == PRIV_ALL || 3430Sstevel@tonic-gate !PRIV_ISASSERT(priv_basic, priv)) && 3440Sstevel@tonic-gate !servicing_interrupt()) { 3453446Smrj PTOU(curproc)->u_acflag |= ASU; /* Needed for SVVS */ 3460Sstevel@tonic-gate #ifdef C2_AUDIT 3470Sstevel@tonic-gate if (audit_active) 3480Sstevel@tonic-gate audit_priv(priv, 3490Sstevel@tonic-gate allzone ? ZONEPRIVS(cr) : NULL, 1); 3500Sstevel@tonic-gate #endif 3510Sstevel@tonic-gate } 3520Sstevel@tonic-gate err = 0; 3530Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 3540Sstevel@tonic-gate } else if (!servicing_interrupt()) { 3550Sstevel@tonic-gate /* Failure audited in this procedure */ 3560Sstevel@tonic-gate priv_policy_err(cr, priv, allzone, msg); 3570Sstevel@tonic-gate } 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate return (err); 3600Sstevel@tonic-gate } 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate /* 3630Sstevel@tonic-gate * Return B_TRUE for sufficient privileges, B_FALSE for insufficient privileges. 3640Sstevel@tonic-gate */ 3650Sstevel@tonic-gate boolean_t 3660Sstevel@tonic-gate priv_policy_choice(const cred_t *cr, int priv, boolean_t allzone) 3670Sstevel@tonic-gate { 3680Sstevel@tonic-gate boolean_t res = HAS_PRIVILEGE(cr, priv) && 3690Sstevel@tonic-gate (!allzone || HAS_ALLZONEPRIVS(cr)); 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate #ifdef C2_AUDIT 3720Sstevel@tonic-gate /* Audit success only */ 3730Sstevel@tonic-gate if (res && audit_active && 3740Sstevel@tonic-gate (allzone || priv == PRIV_ALL || !PRIV_ISASSERT(priv_basic, priv)) && 3750Sstevel@tonic-gate !servicing_interrupt()) { 3760Sstevel@tonic-gate audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 1); 3770Sstevel@tonic-gate } 3780Sstevel@tonic-gate #endif 3790Sstevel@tonic-gate if (res) { 3800Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 3810Sstevel@tonic-gate } else { 3820Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 3830Sstevel@tonic-gate } 3840Sstevel@tonic-gate return (res); 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate /* 3880Sstevel@tonic-gate * Non-auditing variant of priv_policy_choice(). 3890Sstevel@tonic-gate */ 3900Sstevel@tonic-gate boolean_t 3910Sstevel@tonic-gate priv_policy_only(const cred_t *cr, int priv, boolean_t allzone) 3920Sstevel@tonic-gate { 3930Sstevel@tonic-gate boolean_t res = HAS_PRIVILEGE(cr, priv) && 3940Sstevel@tonic-gate (!allzone || HAS_ALLZONEPRIVS(cr)); 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate if (res) { 3970Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 3980Sstevel@tonic-gate } else { 3990Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 4000Sstevel@tonic-gate } 4010Sstevel@tonic-gate return (res); 4020Sstevel@tonic-gate } 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate /* 4050Sstevel@tonic-gate * Check whether all privileges in the required set are present. 4060Sstevel@tonic-gate */ 4070Sstevel@tonic-gate static int 4080Sstevel@tonic-gate secpolicy_require_set(const cred_t *cr, const priv_set_t *req, const char *msg) 4090Sstevel@tonic-gate { 4100Sstevel@tonic-gate int priv; 4110Sstevel@tonic-gate int pfound = -1; 4120Sstevel@tonic-gate priv_set_t pset; 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate if (req == PRIV_FULLSET ? HAS_ALLPRIVS(cr) : priv_issubset(req, 4154543Smarks &CR_OEPRIV(cr))) { 4160Sstevel@tonic-gate return (0); 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate if (req == PRIV_FULLSET || priv_isfullset(req)) { 4200Sstevel@tonic-gate priv_policy_err(cr, PRIV_ALL, B_FALSE, msg); 4210Sstevel@tonic-gate return (EACCES); 4220Sstevel@tonic-gate } 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate pset = CR_OEPRIV(cr); /* present privileges */ 4250Sstevel@tonic-gate priv_inverse(&pset); /* all non present privileges */ 4260Sstevel@tonic-gate priv_intersect(req, &pset); /* the actual missing privs */ 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate #ifdef C2_AUDIT 4290Sstevel@tonic-gate if (audit_active) 4300Sstevel@tonic-gate audit_priv(PRIV_NONE, &pset, 0); 4310Sstevel@tonic-gate #endif 4320Sstevel@tonic-gate /* 4330Sstevel@tonic-gate * Privilege debugging; special case "one privilege in set". 4340Sstevel@tonic-gate */ 4350Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || curthread->t_pre_sys) { 4360Sstevel@tonic-gate for (priv = 0; priv < nprivs; priv++) { 4370Sstevel@tonic-gate if (priv_ismember(&pset, priv)) { 4380Sstevel@tonic-gate if (pfound != -1) { 4390Sstevel@tonic-gate /* Multiple missing privs */ 4400Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_MULTIPLE, 4414543Smarks msg); 4420Sstevel@tonic-gate return (EACCES); 4430Sstevel@tonic-gate } 4440Sstevel@tonic-gate pfound = priv; 4450Sstevel@tonic-gate } 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate ASSERT(pfound != -1); 4480Sstevel@tonic-gate /* Just the one missing privilege */ 4490Sstevel@tonic-gate priv_policy_errmsg(cr, pfound, msg); 4500Sstevel@tonic-gate } 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate return (EACCES); 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate /* 4560Sstevel@tonic-gate * Called when an operation requires that the caller be in the 4570Sstevel@tonic-gate * global zone, regardless of privilege. 4580Sstevel@tonic-gate */ 4590Sstevel@tonic-gate static int 4600Sstevel@tonic-gate priv_policy_global(const cred_t *cr) 4610Sstevel@tonic-gate { 4620Sstevel@tonic-gate if (crgetzoneid(cr) == GLOBAL_ZONEID) 4630Sstevel@tonic-gate return (0); /* success */ 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || 4660Sstevel@tonic-gate curthread->t_pre_sys) { 4670Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_GLOBAL, NULL); 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate return (EPERM); 4700Sstevel@tonic-gate } 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate /* 4730Sstevel@tonic-gate * Changing process priority 4740Sstevel@tonic-gate */ 4750Sstevel@tonic-gate int 4760Sstevel@tonic-gate secpolicy_setpriority(const cred_t *cr) 4770Sstevel@tonic-gate { 4780Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_PRIOCNTL, B_FALSE, EPERM, NULL)); 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate /* 4820Sstevel@tonic-gate * Binding to a privileged port, port must be specified in host byte 4830Sstevel@tonic-gate * order. 4840Sstevel@tonic-gate */ 4850Sstevel@tonic-gate int 4860Sstevel@tonic-gate secpolicy_net_privaddr(const cred_t *cr, in_port_t port) 4870Sstevel@tonic-gate { 4885331Samw char *reason; 4895331Samw int priv; 4905331Samw 4915331Samw switch (port) { 4925331Samw case 137: 4935331Samw case 138: 4945331Samw case 139: 4955331Samw case 445: 4965331Samw /* 4975331Samw * NBT and SMB ports, these are extra privileged ports, 4985331Samw * allow bind only if the SYS_SMB privilege is present. 4995331Samw */ 5005331Samw priv = PRIV_SYS_SMB; 5015331Samw reason = "NBT or SMB port"; 5025331Samw break; 5035331Samw 5045331Samw case 2049: 5055331Samw case 4045: 5065331Samw /* 5075331Samw * NFS ports, these are extra privileged ports, allow bind 5085331Samw * only if the SYS_NFS privilege is present. 5095331Samw */ 5105331Samw priv = PRIV_SYS_NFS; 5115331Samw reason = "NFS port"; 5125331Samw break; 5135331Samw 5145331Samw default: 5155331Samw priv = PRIV_NET_PRIVADDR; 5165331Samw reason = NULL; 5175331Samw break; 5185331Samw 5195331Samw } 5205331Samw 5215331Samw return (PRIV_POLICY(cr, priv, B_FALSE, EACCES, reason)); 5220Sstevel@tonic-gate } 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate /* 5251676Sjpk * Binding to a multilevel port on a trusted (labeled) system. 5261676Sjpk */ 5271676Sjpk int 5281676Sjpk secpolicy_net_bindmlp(const cred_t *cr) 5291676Sjpk { 5301676Sjpk return (PRIV_POLICY(cr, PRIV_NET_BINDMLP, B_FALSE, EACCES, 5311676Sjpk NULL)); 5321676Sjpk } 5331676Sjpk 5341676Sjpk /* 5351676Sjpk * Allow a communication between a zone and an unlabeled host when their 5361676Sjpk * labels don't match. 5371676Sjpk */ 5381676Sjpk int 5391676Sjpk secpolicy_net_mac_aware(const cred_t *cr) 5401676Sjpk { 5411676Sjpk return (PRIV_POLICY(cr, PRIV_NET_MAC_AWARE, B_FALSE, EACCES, 5421676Sjpk NULL)); 5431676Sjpk } 5441676Sjpk 5451676Sjpk /* 5460Sstevel@tonic-gate * Common routine which determines whether a given credential can 5470Sstevel@tonic-gate * act on a given mount. 5480Sstevel@tonic-gate * When called through mount, the parameter needoptcheck is a pointer 5490Sstevel@tonic-gate * to a boolean variable which will be set to either true or false, 5500Sstevel@tonic-gate * depending on whether the mount policy should change the mount options. 5510Sstevel@tonic-gate * In all other cases, needoptcheck should be a NULL pointer. 5520Sstevel@tonic-gate */ 5530Sstevel@tonic-gate static int 5540Sstevel@tonic-gate secpolicy_fs_common(cred_t *cr, vnode_t *mvp, const vfs_t *vfsp, 5550Sstevel@tonic-gate boolean_t *needoptcheck) 5560Sstevel@tonic-gate { 5570Sstevel@tonic-gate boolean_t allzone = B_FALSE; 5580Sstevel@tonic-gate boolean_t mounting = needoptcheck != NULL; 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate /* 5610Sstevel@tonic-gate * Short circuit the following cases: 5620Sstevel@tonic-gate * vfsp == NULL or mvp == NULL (pure privilege check) 5630Sstevel@tonic-gate * have all privileges - no further checks required 5640Sstevel@tonic-gate * and no mount options need to be set. 5650Sstevel@tonic-gate */ 5660Sstevel@tonic-gate if (vfsp == NULL || mvp == NULL || HAS_ALLPRIVS(cr)) { 5670Sstevel@tonic-gate if (mounting) 5680Sstevel@tonic-gate *needoptcheck = B_FALSE; 5690Sstevel@tonic-gate 5700Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_MOUNT, allzone, EPERM, NULL)); 5710Sstevel@tonic-gate } 5720Sstevel@tonic-gate 5730Sstevel@tonic-gate /* 5740Sstevel@tonic-gate * When operating on an existing mount (either we're not mounting 5750Sstevel@tonic-gate * or we're doing a remount and VFS_REMOUNT will be set), zones 5760Sstevel@tonic-gate * can operate only on mounts established by the zone itself. 5770Sstevel@tonic-gate */ 5780Sstevel@tonic-gate if (!mounting || (vfsp->vfs_flag & VFS_REMOUNT) != 0) { 5790Sstevel@tonic-gate zoneid_t zoneid = crgetzoneid(cr); 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate if (zoneid != GLOBAL_ZONEID && 5820Sstevel@tonic-gate vfsp->vfs_zone->zone_id != zoneid) { 5830Sstevel@tonic-gate return (EPERM); 5840Sstevel@tonic-gate } 5850Sstevel@tonic-gate } 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate if (mounting) 5880Sstevel@tonic-gate *needoptcheck = B_TRUE; 5890Sstevel@tonic-gate 5900Sstevel@tonic-gate /* 5910Sstevel@tonic-gate * Overlay mounts may hide important stuff; if you can't write to a 5920Sstevel@tonic-gate * mount point but would be able to mount on top of it, you can 5930Sstevel@tonic-gate * escalate your privileges. 5940Sstevel@tonic-gate * So we go about asking the same questions namefs does when it 5950Sstevel@tonic-gate * decides whether you can mount over a file or not but with the 5960Sstevel@tonic-gate * added restriction that you can only mount on top of a regular 5970Sstevel@tonic-gate * file or directory. 5980Sstevel@tonic-gate * If we have all the zone's privileges, we skip all other checks, 5990Sstevel@tonic-gate * or else we may actually get in trouble inside the automounter. 6000Sstevel@tonic-gate */ 6010Sstevel@tonic-gate if ((mvp->v_flag & VROOT) != 0 || 6020Sstevel@tonic-gate (mvp->v_type != VDIR && mvp->v_type != VREG) || 6030Sstevel@tonic-gate HAS_ALLZONEPRIVS(cr)) { 6040Sstevel@tonic-gate allzone = B_TRUE; 6050Sstevel@tonic-gate } else { 6060Sstevel@tonic-gate vattr_t va; 6070Sstevel@tonic-gate int err; 6080Sstevel@tonic-gate 6090Sstevel@tonic-gate va.va_mask = AT_UID|AT_MODE; 6105331Samw err = VOP_GETATTR(mvp, &va, 0, cr, NULL); 6110Sstevel@tonic-gate if (err != 0) 6120Sstevel@tonic-gate return (err); 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate if ((err = secpolicy_vnode_owner(cr, va.va_uid)) != 0) 6150Sstevel@tonic-gate return (err); 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate if ((va.va_mode & VWRITE) == 0 && 6180Sstevel@tonic-gate secpolicy_vnode_access(cr, mvp, va.va_uid, VWRITE) != 0) { 6190Sstevel@tonic-gate return (EACCES); 6200Sstevel@tonic-gate } 6210Sstevel@tonic-gate } 6220Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_MOUNT, allzone, EPERM, NULL)); 6230Sstevel@tonic-gate } 6240Sstevel@tonic-gate 6254543Smarks void 6264543Smarks secpolicy_fs_mount_clearopts(cred_t *cr, struct vfs *vfsp) 6274543Smarks { 6284543Smarks boolean_t amsuper = HAS_ALLZONEPRIVS(cr); 6294543Smarks 6304543Smarks /* 6314543Smarks * check; if we don't have either "nosuid" or 6324543Smarks * both "nosetuid" and "nodevices", then we add 6334543Smarks * "nosuid"; this depends on how the current 6344543Smarks * implementation works (it first checks nosuid). In a 6354543Smarks * zone, a user with all zone privileges can mount with 6364543Smarks * "setuid" but never with "devices". 6374543Smarks */ 6384543Smarks if (!vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL) && 6394543Smarks (!vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL) || 6404543Smarks !vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL))) { 6414543Smarks if (crgetzoneid(cr) == GLOBAL_ZONEID || !amsuper) 6424543Smarks vfs_setmntopt(vfsp, MNTOPT_NOSUID, NULL, 0); 6434543Smarks else 6444543Smarks vfs_setmntopt(vfsp, MNTOPT_NODEVICES, NULL, 0); 6454543Smarks } 6464543Smarks /* 6474543Smarks * If we're not the local super user, we set the "restrict" 6484543Smarks * option to indicate to automountd that this mount should 6494543Smarks * be handled with care. 6504543Smarks */ 6514543Smarks if (!amsuper) 6524543Smarks vfs_setmntopt(vfsp, MNTOPT_RESTRICT, NULL, 0); 6534543Smarks 6544543Smarks } 6554543Smarks 656148Scasper extern vnode_t *rootvp; 657148Scasper extern vfs_t *rootvfs; 658148Scasper 6590Sstevel@tonic-gate int 6600Sstevel@tonic-gate secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct vfs *vfsp) 6610Sstevel@tonic-gate { 6620Sstevel@tonic-gate boolean_t needoptchk; 6630Sstevel@tonic-gate int error; 6640Sstevel@tonic-gate 665148Scasper /* 666148Scasper * If it's a remount, get the underlying mount point, 667148Scasper * except for the root where we use the rootvp. 668148Scasper */ 669148Scasper if ((vfsp->vfs_flag & VFS_REMOUNT) != 0) { 670148Scasper if (vfsp == rootvfs) 671148Scasper mvp = rootvp; 672148Scasper else 673148Scasper mvp = vfsp->vfs_vnodecovered; 674148Scasper } 675148Scasper 6760Sstevel@tonic-gate error = secpolicy_fs_common(cr, mvp, vfsp, &needoptchk); 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate if (error == 0 && needoptchk) { 6794543Smarks secpolicy_fs_mount_clearopts(cr, vfsp); 6804543Smarks } 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate return (error); 6830Sstevel@tonic-gate } 6840Sstevel@tonic-gate 6850Sstevel@tonic-gate /* 6860Sstevel@tonic-gate * Does the policy computations for "ownership" of a mount; 6870Sstevel@tonic-gate * here ownership is defined as the ability to "mount" 6880Sstevel@tonic-gate * the filesystem originally. The rootvfs doesn't cover any 6890Sstevel@tonic-gate * vnodes; we attribute its ownership to the rootvp. 6900Sstevel@tonic-gate */ 6910Sstevel@tonic-gate static int 6920Sstevel@tonic-gate secpolicy_fs_owner(cred_t *cr, const struct vfs *vfsp) 6930Sstevel@tonic-gate { 6940Sstevel@tonic-gate vnode_t *mvp; 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate if (vfsp == NULL) 6970Sstevel@tonic-gate mvp = NULL; 6980Sstevel@tonic-gate else if (vfsp == rootvfs) 6990Sstevel@tonic-gate mvp = rootvp; 7000Sstevel@tonic-gate else 7010Sstevel@tonic-gate mvp = vfsp->vfs_vnodecovered; 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate return (secpolicy_fs_common(cr, mvp, vfsp, NULL)); 7040Sstevel@tonic-gate } 7050Sstevel@tonic-gate 7060Sstevel@tonic-gate int 7070Sstevel@tonic-gate secpolicy_fs_unmount(cred_t *cr, struct vfs *vfsp) 7080Sstevel@tonic-gate { 7090Sstevel@tonic-gate return (secpolicy_fs_owner(cr, vfsp)); 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate /* 7130Sstevel@tonic-gate * Quotas are a resource, but if one has the ability to mount a filesystem, he 7140Sstevel@tonic-gate * should be able to modify quotas on it. 7150Sstevel@tonic-gate */ 7160Sstevel@tonic-gate int 7170Sstevel@tonic-gate secpolicy_fs_quota(const cred_t *cr, const vfs_t *vfsp) 7180Sstevel@tonic-gate { 7190Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 7200Sstevel@tonic-gate } 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate /* 7230Sstevel@tonic-gate * Exceeding minfree: also a per-mount resource constraint. 7240Sstevel@tonic-gate */ 7250Sstevel@tonic-gate int 7260Sstevel@tonic-gate secpolicy_fs_minfree(const cred_t *cr, const vfs_t *vfsp) 7270Sstevel@tonic-gate { 7280Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 7290Sstevel@tonic-gate } 7300Sstevel@tonic-gate 7310Sstevel@tonic-gate int 7320Sstevel@tonic-gate secpolicy_fs_config(const cred_t *cr, const vfs_t *vfsp) 7330Sstevel@tonic-gate { 7340Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 7350Sstevel@tonic-gate } 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate /* ARGSUSED */ 7380Sstevel@tonic-gate int 7390Sstevel@tonic-gate secpolicy_fs_linkdir(const cred_t *cr, const vfs_t *vfsp) 7400Sstevel@tonic-gate { 7410Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_LINKDIR, B_FALSE, EPERM, NULL)); 7420Sstevel@tonic-gate } 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate /* 7450Sstevel@tonic-gate * Name: secpolicy_vnode_access() 7460Sstevel@tonic-gate * 7470Sstevel@tonic-gate * Parameters: Process credential 7480Sstevel@tonic-gate * vnode 7490Sstevel@tonic-gate * uid of owner of vnode 7500Sstevel@tonic-gate * permission bits not granted to the caller when examining 7510Sstevel@tonic-gate * file mode bits (i.e., when a process wants to open a 7520Sstevel@tonic-gate * mode 444 file for VREAD|VWRITE, this function should be 7530Sstevel@tonic-gate * called only with a VWRITE argument). 7540Sstevel@tonic-gate * 7550Sstevel@tonic-gate * Normal: Verifies that cred has the appropriate privileges to 7560Sstevel@tonic-gate * override the mode bits that were denied. 7570Sstevel@tonic-gate * 7580Sstevel@tonic-gate * Override: file_dac_execute - if VEXEC bit was denied and vnode is 7590Sstevel@tonic-gate * not a directory. 7600Sstevel@tonic-gate * file_dac_read - if VREAD bit was denied. 7610Sstevel@tonic-gate * file_dac_search - if VEXEC bit was denied and vnode is 7620Sstevel@tonic-gate * a directory. 7630Sstevel@tonic-gate * file_dac_write - if VWRITE bit was denied. 7640Sstevel@tonic-gate * 7650Sstevel@tonic-gate * Root owned files are special cased to protect system 7660Sstevel@tonic-gate * configuration files and such. 7670Sstevel@tonic-gate * 7680Sstevel@tonic-gate * Output: EACCES - if privilege check fails. 7690Sstevel@tonic-gate */ 7700Sstevel@tonic-gate 7710Sstevel@tonic-gate /* ARGSUSED */ 7720Sstevel@tonic-gate int 7730Sstevel@tonic-gate secpolicy_vnode_access(const cred_t *cr, vnode_t *vp, uid_t owner, mode_t mode) 7740Sstevel@tonic-gate { 7750Sstevel@tonic-gate if ((mode & VREAD) && 7760Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_FILE_DAC_READ, B_FALSE, EACCES, NULL) != 0) 7770Sstevel@tonic-gate return (EACCES); 7780Sstevel@tonic-gate 7790Sstevel@tonic-gate if (mode & VWRITE) { 7800Sstevel@tonic-gate boolean_t allzone; 7810Sstevel@tonic-gate 7820Sstevel@tonic-gate if (owner == 0 && cr->cr_uid != 0) 7830Sstevel@tonic-gate allzone = B_TRUE; 7840Sstevel@tonic-gate else 7850Sstevel@tonic-gate allzone = B_FALSE; 7860Sstevel@tonic-gate if (PRIV_POLICY(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES, NULL) 7870Sstevel@tonic-gate != 0) 7880Sstevel@tonic-gate return (EACCES); 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate if (mode & VEXEC) { 7920Sstevel@tonic-gate /* 7930Sstevel@tonic-gate * Directories use file_dac_search to override the execute bit. 7940Sstevel@tonic-gate */ 7950Sstevel@tonic-gate vtype_t vtype = vp->v_type; 7960Sstevel@tonic-gate 7970Sstevel@tonic-gate if (vtype == VDIR) 7980Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_DAC_SEARCH, B_FALSE, 7990Sstevel@tonic-gate EACCES, NULL)); 8000Sstevel@tonic-gate else 8010Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_DAC_EXECUTE, B_FALSE, 8020Sstevel@tonic-gate EACCES, NULL)); 8030Sstevel@tonic-gate } 8040Sstevel@tonic-gate return (0); 8050Sstevel@tonic-gate } 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate /* 8080Sstevel@tonic-gate * Name: secpolicy_vnode_setid_modify() 8090Sstevel@tonic-gate * 8100Sstevel@tonic-gate * Normal: verify that subject can set the file setid flags. 8110Sstevel@tonic-gate * 8120Sstevel@tonic-gate * Output: EPERM - if not privileged. 8130Sstevel@tonic-gate */ 8140Sstevel@tonic-gate 8150Sstevel@tonic-gate static int 8160Sstevel@tonic-gate secpolicy_vnode_setid_modify(const cred_t *cr, uid_t owner) 8170Sstevel@tonic-gate { 8180Sstevel@tonic-gate /* If changing to suid root, must have all zone privs */ 8190Sstevel@tonic-gate boolean_t allzone = B_TRUE; 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate if (owner != 0) { 8220Sstevel@tonic-gate if (owner == cr->cr_uid) 8230Sstevel@tonic-gate return (0); 8240Sstevel@tonic-gate allzone = B_FALSE; 8250Sstevel@tonic-gate } 8260Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_SETID, allzone, EPERM, NULL)); 8270Sstevel@tonic-gate } 8280Sstevel@tonic-gate 8290Sstevel@tonic-gate /* 8300Sstevel@tonic-gate * Are we allowed to retain the set-uid/set-gid bits when 8310Sstevel@tonic-gate * changing ownership or when writing to a file? 8320Sstevel@tonic-gate * "issuid" should be true when set-uid; only in that case 8330Sstevel@tonic-gate * root ownership is checked (setgid is assumed). 8340Sstevel@tonic-gate */ 8350Sstevel@tonic-gate int 8360Sstevel@tonic-gate secpolicy_vnode_setid_retain(const cred_t *cred, boolean_t issuidroot) 8370Sstevel@tonic-gate { 8380Sstevel@tonic-gate if (issuidroot && !HAS_ALLZONEPRIVS(cred)) 8390Sstevel@tonic-gate return (EPERM); 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate return (!PRIV_POLICY_CHOICE(cred, PRIV_FILE_SETID, B_FALSE)); 8420Sstevel@tonic-gate } 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate /* 8450Sstevel@tonic-gate * Name: secpolicy_vnode_setids_setgids() 8460Sstevel@tonic-gate * 8470Sstevel@tonic-gate * Normal: verify that subject can set the file setgid flag. 8480Sstevel@tonic-gate * 8490Sstevel@tonic-gate * Output: EPERM - if not privileged 8500Sstevel@tonic-gate */ 8510Sstevel@tonic-gate 8520Sstevel@tonic-gate int 8530Sstevel@tonic-gate secpolicy_vnode_setids_setgids(const cred_t *cred, gid_t gid) 8540Sstevel@tonic-gate { 8550Sstevel@tonic-gate if (!groupmember(gid, cred)) 8560Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_SETID, B_FALSE, EPERM, 8570Sstevel@tonic-gate NULL)); 8580Sstevel@tonic-gate return (0); 8590Sstevel@tonic-gate } 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate /* 8620Sstevel@tonic-gate * Create a file with a group different than any of the groups allowed: 8630Sstevel@tonic-gate * the group of the directory the file is created in, the effective 8640Sstevel@tonic-gate * group or any of the supplementary groups. 8650Sstevel@tonic-gate */ 8660Sstevel@tonic-gate int 8670Sstevel@tonic-gate secpolicy_vnode_create_gid(const cred_t *cred) 8680Sstevel@tonic-gate { 8690Sstevel@tonic-gate if (HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN)) 8700Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_CHOWN, B_FALSE, EPERM, 8710Sstevel@tonic-gate NULL)); 8720Sstevel@tonic-gate else 8730Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_CHOWN_SELF, B_FALSE, EPERM, 8740Sstevel@tonic-gate NULL)); 8750Sstevel@tonic-gate } 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate /* 8780Sstevel@tonic-gate * Name: secpolicy_vnode_utime_modify() 8790Sstevel@tonic-gate * 8800Sstevel@tonic-gate * Normal: verify that subject can modify the utime on a file. 8810Sstevel@tonic-gate * 8820Sstevel@tonic-gate * Output: EPERM - if access denied. 8830Sstevel@tonic-gate */ 8840Sstevel@tonic-gate 8850Sstevel@tonic-gate static int 8860Sstevel@tonic-gate secpolicy_vnode_utime_modify(const cred_t *cred) 8870Sstevel@tonic-gate { 8880Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_OWNER, B_FALSE, EPERM, 8890Sstevel@tonic-gate "modify file times")); 8900Sstevel@tonic-gate } 8910Sstevel@tonic-gate 8920Sstevel@tonic-gate 8930Sstevel@tonic-gate /* 8940Sstevel@tonic-gate * Name: secpolicy_vnode_setdac() 8950Sstevel@tonic-gate * 8960Sstevel@tonic-gate * Normal: verify that subject can modify the mode of a file. 8970Sstevel@tonic-gate * allzone privilege needed when modifying root owned object. 8980Sstevel@tonic-gate * 8990Sstevel@tonic-gate * Output: EPERM - if access denied. 9000Sstevel@tonic-gate */ 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate int 9030Sstevel@tonic-gate secpolicy_vnode_setdac(const cred_t *cred, uid_t owner) 9040Sstevel@tonic-gate { 9050Sstevel@tonic-gate if (owner == cred->cr_uid) 9060Sstevel@tonic-gate return (0); 9070Sstevel@tonic-gate 9080Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_OWNER, owner == 0, EPERM, NULL)); 9090Sstevel@tonic-gate } 9100Sstevel@tonic-gate /* 9110Sstevel@tonic-gate * Name: secpolicy_vnode_stky_modify() 9120Sstevel@tonic-gate * 9130Sstevel@tonic-gate * Normal: verify that subject can make a file a "sticky". 9140Sstevel@tonic-gate * 9150Sstevel@tonic-gate * Output: EPERM - if access denied. 9160Sstevel@tonic-gate */ 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate int 9190Sstevel@tonic-gate secpolicy_vnode_stky_modify(const cred_t *cred) 9200Sstevel@tonic-gate { 9210Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_SYS_CONFIG, B_FALSE, EPERM, 9220Sstevel@tonic-gate "set file sticky")); 9230Sstevel@tonic-gate } 9240Sstevel@tonic-gate 9250Sstevel@tonic-gate /* 9260Sstevel@tonic-gate * Policy determines whether we can remove an entry from a directory, 9270Sstevel@tonic-gate * regardless of permission bits. 9280Sstevel@tonic-gate */ 9290Sstevel@tonic-gate int 9300Sstevel@tonic-gate secpolicy_vnode_remove(const cred_t *cr) 9310Sstevel@tonic-gate { 9320Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_OWNER, B_FALSE, EACCES, 9330Sstevel@tonic-gate "sticky directory")); 9340Sstevel@tonic-gate } 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate int 9370Sstevel@tonic-gate secpolicy_vnode_owner(const cred_t *cr, uid_t owner) 9380Sstevel@tonic-gate { 9390Sstevel@tonic-gate boolean_t allzone = (owner == 0); 9400Sstevel@tonic-gate 9410Sstevel@tonic-gate if (owner == cr->cr_uid) 9420Sstevel@tonic-gate return (0); 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_OWNER, allzone, EPERM, NULL)); 9450Sstevel@tonic-gate } 9460Sstevel@tonic-gate 9471115Smarks void 9481115Smarks secpolicy_setid_clear(vattr_t *vap, cred_t *cr) 9491115Smarks { 9501115Smarks if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0 && 9511115Smarks secpolicy_vnode_setid_retain(cr, 9521115Smarks (vap->va_mode & S_ISUID) != 0 && 9531115Smarks (vap->va_mask & AT_UID) != 0 && vap->va_uid == 0) != 0) { 9541115Smarks vap->va_mask |= AT_MODE; 9551115Smarks vap->va_mode &= ~(S_ISUID|S_ISGID); 9561115Smarks } 9571115Smarks } 9581115Smarks 9592796Smarks int 9602796Smarks secpolicy_setid_setsticky_clear(vnode_t *vp, vattr_t *vap, const vattr_t *ovap, 9612796Smarks cred_t *cr) 9622796Smarks { 9632796Smarks int error; 9642796Smarks 9652796Smarks if ((vap->va_mode & S_ISUID) != 0 && 9662796Smarks (error = secpolicy_vnode_setid_modify(cr, 9672796Smarks ovap->va_uid)) != 0) { 9682796Smarks return (error); 9692796Smarks } 9702796Smarks 9712796Smarks /* 9722796Smarks * Check privilege if attempting to set the 9732796Smarks * sticky bit on a non-directory. 9742796Smarks */ 9752796Smarks if (vp->v_type != VDIR && (vap->va_mode & S_ISVTX) != 0 && 9762796Smarks secpolicy_vnode_stky_modify(cr) != 0) { 9774543Smarks vap->va_mode &= ~S_ISVTX; 9782796Smarks } 9792796Smarks 9802796Smarks /* 9812796Smarks * Check for privilege if attempting to set the 9822796Smarks * group-id bit. 9832796Smarks */ 9842796Smarks if ((vap->va_mode & S_ISGID) != 0 && 9852796Smarks secpolicy_vnode_setids_setgids(cr, ovap->va_gid) != 0) { 9864543Smarks vap->va_mode &= ~S_ISGID; 9872796Smarks } 9882796Smarks 9892796Smarks return (0); 9902796Smarks } 9912796Smarks 9925331Samw #define ATTR_FLAG_PRIV(attr, value, cr) \ 9935331Samw PRIV_POLICY(cr, value ? PRIV_FILE_FLAG_SET : PRIV_ALL, \ 9945331Samw B_FALSE, EPERM, NULL) 9955331Samw 9965331Samw /* 9975331Samw * Check privileges for setting xvattr attributes 9985331Samw */ 9995331Samw int 10005331Samw secpolicy_xvattr(xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype) 10015331Samw { 10025331Samw xoptattr_t *xoap; 10035331Samw int error = 0; 10045331Samw 10055331Samw if ((xoap = xva_getxoptattr(xvap)) == NULL) 10065331Samw return (EINVAL); 10075331Samw 10085331Samw /* 10095331Samw * First process the DOS bits 10105331Samw */ 10115331Samw if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE) || 10125331Samw XVA_ISSET_REQ(xvap, XAT_HIDDEN) || 10135331Samw XVA_ISSET_REQ(xvap, XAT_READONLY) || 10145331Samw XVA_ISSET_REQ(xvap, XAT_SYSTEM) || 10155331Samw XVA_ISSET_REQ(xvap, XAT_CREATETIME)) { 10165331Samw if ((error = secpolicy_vnode_owner(cr, owner)) != 0) 10175331Samw return (error); 10185331Samw } 10195331Samw 10205331Samw /* 10215331Samw * Now handle special attributes 10225331Samw */ 10235331Samw 10245331Samw if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) 10255331Samw error = ATTR_FLAG_PRIV(XAT_IMMUTABLE, 10265331Samw xoap->xoa_immutable, cr); 10275331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) 10285331Samw error = ATTR_FLAG_PRIV(XAT_NOUNLINK, 10295331Samw xoap->xoa_nounlink, cr); 10305331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) 10315331Samw error = ATTR_FLAG_PRIV(XAT_APPENDONLY, 10325331Samw xoap->xoa_appendonly, cr); 10335331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NODUMP)) 10345331Samw error = ATTR_FLAG_PRIV(XAT_NODUMP, 10355331Samw xoap->xoa_nodump, cr); 10365331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_OPAQUE)) 10375331Samw error = EPERM; 10385331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) { 10395331Samw error = ATTR_FLAG_PRIV(XAT_AV_QUARANTINED, 10405331Samw xoap->xoa_av_quarantined, cr); 10415331Samw if (error == 0 && vtype != VREG) 10425331Samw error = EINVAL; 10435331Samw } 10445331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) 10455331Samw error = ATTR_FLAG_PRIV(XAT_AV_MODIFIED, 10465331Samw xoap->xoa_av_modified, cr); 10475331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) { 10485331Samw error = ATTR_FLAG_PRIV(XAT_AV_SCANSTAMP, 10495331Samw xoap->xoa_av_scanstamp, cr); 10505331Samw if (error == 0 && vtype != VREG) 10515331Samw error = EINVAL; 10525331Samw } 10535331Samw return (error); 10545331Samw } 10555331Samw 10560Sstevel@tonic-gate /* 10570Sstevel@tonic-gate * This function checks the policy decisions surrounding the 10580Sstevel@tonic-gate * vop setattr call. 10590Sstevel@tonic-gate * 10600Sstevel@tonic-gate * It should be called after sufficient locks have been established 10610Sstevel@tonic-gate * on the underlying data structures. No concurrent modifications 10620Sstevel@tonic-gate * should be allowed. 10630Sstevel@tonic-gate * 10640Sstevel@tonic-gate * The caller must pass in unlocked version of its vaccess function 10650Sstevel@tonic-gate * this is required because vop_access function should lock the 10660Sstevel@tonic-gate * node for reading. A three argument function should be defined 10670Sstevel@tonic-gate * which accepts the following argument: 10680Sstevel@tonic-gate * A pointer to the internal "node" type (inode *) 10690Sstevel@tonic-gate * vnode access bits (VREAD|VWRITE|VEXEC) 10700Sstevel@tonic-gate * a pointer to the credential 10710Sstevel@tonic-gate * 10720Sstevel@tonic-gate * This function makes the following policy decisions: 10730Sstevel@tonic-gate * 10740Sstevel@tonic-gate * - change permissions 10750Sstevel@tonic-gate * - permission to change file mode if not owner 10760Sstevel@tonic-gate * - permission to add sticky bit to non-directory 10770Sstevel@tonic-gate * - permission to add set-gid bit 10780Sstevel@tonic-gate * 10790Sstevel@tonic-gate * The ovap argument should include AT_MODE|AT_UID|AT_GID. 10800Sstevel@tonic-gate * 10810Sstevel@tonic-gate * If the vap argument does not include AT_MODE, the mode will be copied from 10820Sstevel@tonic-gate * ovap. In certain situations set-uid/set-gid bits need to be removed; 10830Sstevel@tonic-gate * this is done by marking vap->va_mask to include AT_MODE and va_mode 10840Sstevel@tonic-gate * is updated to the newly computed mode. 10850Sstevel@tonic-gate */ 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate int 10880Sstevel@tonic-gate secpolicy_vnode_setattr(cred_t *cr, struct vnode *vp, struct vattr *vap, 10890Sstevel@tonic-gate const struct vattr *ovap, int flags, 10900Sstevel@tonic-gate int unlocked_access(void *, int, cred_t *), 10910Sstevel@tonic-gate void *node) 10920Sstevel@tonic-gate { 10930Sstevel@tonic-gate int mask = vap->va_mask; 10940Sstevel@tonic-gate int error = 0; 10955331Samw boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE; 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate if (mask & AT_SIZE) { 10980Sstevel@tonic-gate if (vp->v_type == VDIR) { 10990Sstevel@tonic-gate error = EISDIR; 11000Sstevel@tonic-gate goto out; 11010Sstevel@tonic-gate } 11025331Samw 11035331Samw /* 11045331Samw * If ATTR_NOACLCHECK is set in the flags, then we don't 11055331Samw * perform the secondary unlocked_access() call since the 11065331Samw * ACL (if any) is being checked there. 11075331Samw */ 11085331Samw if (skipaclchk == B_FALSE) { 11095331Samw error = unlocked_access(node, VWRITE, cr); 11105331Samw if (error) 11115331Samw goto out; 11125331Samw } 11130Sstevel@tonic-gate } 11140Sstevel@tonic-gate if (mask & AT_MODE) { 11150Sstevel@tonic-gate /* 11160Sstevel@tonic-gate * If not the owner of the file then check privilege 11170Sstevel@tonic-gate * for two things: the privilege to set the mode at all 11180Sstevel@tonic-gate * and, if we're setting setuid, we also need permissions 11190Sstevel@tonic-gate * to add the set-uid bit, if we're not the owner. 11200Sstevel@tonic-gate * In the specific case of creating a set-uid root 11210Sstevel@tonic-gate * file, we need even more permissions. 11220Sstevel@tonic-gate */ 11230Sstevel@tonic-gate if ((error = secpolicy_vnode_setdac(cr, ovap->va_uid)) != 0) 11240Sstevel@tonic-gate goto out; 11250Sstevel@tonic-gate 11262796Smarks if ((error = secpolicy_setid_setsticky_clear(vp, vap, 11272796Smarks ovap, cr)) != 0) 11280Sstevel@tonic-gate goto out; 11290Sstevel@tonic-gate } else 11300Sstevel@tonic-gate vap->va_mode = ovap->va_mode; 11310Sstevel@tonic-gate 11320Sstevel@tonic-gate if (mask & (AT_UID|AT_GID)) { 11330Sstevel@tonic-gate boolean_t checkpriv = B_FALSE; 11340Sstevel@tonic-gate int priv; 11350Sstevel@tonic-gate boolean_t allzone = B_FALSE; 11360Sstevel@tonic-gate 11370Sstevel@tonic-gate /* 11380Sstevel@tonic-gate * Chowning files. 11390Sstevel@tonic-gate * 11400Sstevel@tonic-gate * If you are the file owner: 11410Sstevel@tonic-gate * chown to other uid FILE_CHOWN_SELF 11420Sstevel@tonic-gate * chown to gid (non-member) FILE_CHOWN_SELF 11430Sstevel@tonic-gate * chown to gid (member) <none> 11440Sstevel@tonic-gate * 11450Sstevel@tonic-gate * Instead of PRIV_FILE_CHOWN_SELF, FILE_CHOWN is also 11460Sstevel@tonic-gate * acceptable but the first one is reported when debugging. 11470Sstevel@tonic-gate * 11480Sstevel@tonic-gate * If you are not the file owner: 11490Sstevel@tonic-gate * chown from root PRIV_FILE_CHOWN + zone 11500Sstevel@tonic-gate * chown from other to any PRIV_FILE_CHOWN 11510Sstevel@tonic-gate * 11520Sstevel@tonic-gate */ 11530Sstevel@tonic-gate if (cr->cr_uid != ovap->va_uid) { 11540Sstevel@tonic-gate checkpriv = B_TRUE; 11550Sstevel@tonic-gate allzone = (ovap->va_uid == 0); 11560Sstevel@tonic-gate priv = PRIV_FILE_CHOWN; 11570Sstevel@tonic-gate } else { 11580Sstevel@tonic-gate if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) || 11590Sstevel@tonic-gate ((mask & AT_GID) && vap->va_gid != ovap->va_gid && 11600Sstevel@tonic-gate !groupmember(vap->va_gid, cr))) { 11610Sstevel@tonic-gate checkpriv = B_TRUE; 11620Sstevel@tonic-gate priv = HAS_PRIVILEGE(cr, PRIV_FILE_CHOWN) ? 11630Sstevel@tonic-gate PRIV_FILE_CHOWN : PRIV_FILE_CHOWN_SELF; 11640Sstevel@tonic-gate } 11650Sstevel@tonic-gate } 11660Sstevel@tonic-gate /* 11670Sstevel@tonic-gate * If necessary, check privilege to see if update can be done. 11680Sstevel@tonic-gate */ 11690Sstevel@tonic-gate if (checkpriv && 11700Sstevel@tonic-gate (error = PRIV_POLICY(cr, priv, allzone, EPERM, NULL)) 11710Sstevel@tonic-gate != 0) { 11720Sstevel@tonic-gate goto out; 11730Sstevel@tonic-gate } 11740Sstevel@tonic-gate 11750Sstevel@tonic-gate /* 11760Sstevel@tonic-gate * If the file has either the set UID or set GID bits 11770Sstevel@tonic-gate * set and the caller can set the bits, then leave them. 11780Sstevel@tonic-gate */ 11791115Smarks secpolicy_setid_clear(vap, cr); 11800Sstevel@tonic-gate } 11810Sstevel@tonic-gate if (mask & (AT_ATIME|AT_MTIME)) { 11820Sstevel@tonic-gate /* 11830Sstevel@tonic-gate * If not the file owner and not otherwise privileged, 11840Sstevel@tonic-gate * always return an error when setting the 11850Sstevel@tonic-gate * time other than the current (ATTR_UTIME flag set). 11860Sstevel@tonic-gate * If setting the current time (ATTR_UTIME not set) then 11870Sstevel@tonic-gate * unlocked_access will check permissions according to policy. 11880Sstevel@tonic-gate */ 11890Sstevel@tonic-gate if (cr->cr_uid != ovap->va_uid) { 11900Sstevel@tonic-gate if (flags & ATTR_UTIME) 11910Sstevel@tonic-gate error = secpolicy_vnode_utime_modify(cr); 11925331Samw else if (skipaclchk == B_FALSE) { 11930Sstevel@tonic-gate error = unlocked_access(node, VWRITE, cr); 11940Sstevel@tonic-gate if (error == EACCES && 11950Sstevel@tonic-gate secpolicy_vnode_utime_modify(cr) == 0) 11960Sstevel@tonic-gate error = 0; 11970Sstevel@tonic-gate } 11980Sstevel@tonic-gate if (error) 11990Sstevel@tonic-gate goto out; 12000Sstevel@tonic-gate } 12010Sstevel@tonic-gate } 12025331Samw 12035331Samw /* 12045331Samw * Check for optional attributes here by checking the following: 12055331Samw */ 12065331Samw if (mask & AT_XVATTR) 12075331Samw error = secpolicy_xvattr((xvattr_t *)vap, ovap->va_uid, cr, 12085331Samw vp->v_type); 12090Sstevel@tonic-gate out: 12100Sstevel@tonic-gate return (error); 12110Sstevel@tonic-gate } 12120Sstevel@tonic-gate 12130Sstevel@tonic-gate /* 12140Sstevel@tonic-gate * Name: secpolicy_pcfs_modify_bootpartition() 12150Sstevel@tonic-gate * 12160Sstevel@tonic-gate * Normal: verify that subject can modify a pcfs boot partition. 12170Sstevel@tonic-gate * 12180Sstevel@tonic-gate * Output: EACCES - if privilege check failed. 12190Sstevel@tonic-gate */ 12200Sstevel@tonic-gate /*ARGSUSED*/ 12210Sstevel@tonic-gate int 12220Sstevel@tonic-gate secpolicy_pcfs_modify_bootpartition(const cred_t *cred) 12230Sstevel@tonic-gate { 12240Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_ALL, B_FALSE, EACCES, 12250Sstevel@tonic-gate "modify pcfs boot partition")); 12260Sstevel@tonic-gate } 12270Sstevel@tonic-gate 12280Sstevel@tonic-gate /* 12290Sstevel@tonic-gate * System V IPC routines 12300Sstevel@tonic-gate */ 12310Sstevel@tonic-gate int 12320Sstevel@tonic-gate secpolicy_ipc_owner(const cred_t *cr, const struct kipc_perm *ip) 12330Sstevel@tonic-gate { 12340Sstevel@tonic-gate if (crgetzoneid(cr) != ip->ipc_zoneid || 12350Sstevel@tonic-gate (cr->cr_uid != ip->ipc_uid && cr->cr_uid != ip->ipc_cuid)) { 12360Sstevel@tonic-gate boolean_t allzone = B_FALSE; 12370Sstevel@tonic-gate if (ip->ipc_uid == 0 || ip->ipc_cuid == 0) 12380Sstevel@tonic-gate allzone = B_TRUE; 12390Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_OWNER, allzone, EPERM, NULL)); 12400Sstevel@tonic-gate } 12410Sstevel@tonic-gate return (0); 12420Sstevel@tonic-gate } 12430Sstevel@tonic-gate 12440Sstevel@tonic-gate int 12450Sstevel@tonic-gate secpolicy_ipc_config(const cred_t *cr) 12460Sstevel@tonic-gate { 12470Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_IPC_CONFIG, B_FALSE, EPERM, NULL)); 12480Sstevel@tonic-gate } 12490Sstevel@tonic-gate 12500Sstevel@tonic-gate int 12510Sstevel@tonic-gate secpolicy_ipc_access(const cred_t *cr, const struct kipc_perm *ip, mode_t mode) 12520Sstevel@tonic-gate { 12530Sstevel@tonic-gate 12540Sstevel@tonic-gate boolean_t allzone = B_FALSE; 12550Sstevel@tonic-gate 12560Sstevel@tonic-gate ASSERT((mode & (MSG_R|MSG_W)) != 0); 12570Sstevel@tonic-gate 12580Sstevel@tonic-gate if ((mode & MSG_R) && 12590Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0) 12600Sstevel@tonic-gate return (EACCES); 12610Sstevel@tonic-gate 12620Sstevel@tonic-gate if (mode & MSG_W) { 12630Sstevel@tonic-gate if (cr->cr_uid != 0 && (ip->ipc_uid == 0 || ip->ipc_cuid == 0)) 12640Sstevel@tonic-gate allzone = B_TRUE; 12650Sstevel@tonic-gate 12660Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES, 12670Sstevel@tonic-gate NULL)); 12680Sstevel@tonic-gate } 12690Sstevel@tonic-gate return (0); 12700Sstevel@tonic-gate } 12710Sstevel@tonic-gate 12720Sstevel@tonic-gate int 12730Sstevel@tonic-gate secpolicy_rsm_access(const cred_t *cr, uid_t owner, mode_t mode) 12740Sstevel@tonic-gate { 12750Sstevel@tonic-gate boolean_t allzone = B_FALSE; 12760Sstevel@tonic-gate 12770Sstevel@tonic-gate ASSERT((mode & (MSG_R|MSG_W)) != 0); 12780Sstevel@tonic-gate 12790Sstevel@tonic-gate if ((mode & MSG_R) && 12800Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0) 12810Sstevel@tonic-gate return (EACCES); 12820Sstevel@tonic-gate 12830Sstevel@tonic-gate if (mode & MSG_W) { 12840Sstevel@tonic-gate if (cr->cr_uid != 0 && owner == 0) 12850Sstevel@tonic-gate allzone = B_TRUE; 12860Sstevel@tonic-gate 12870Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES, 12880Sstevel@tonic-gate NULL)); 12890Sstevel@tonic-gate } 12900Sstevel@tonic-gate return (0); 12910Sstevel@tonic-gate } 12920Sstevel@tonic-gate 12930Sstevel@tonic-gate /* 12940Sstevel@tonic-gate * Audit configuration. 12950Sstevel@tonic-gate */ 12960Sstevel@tonic-gate int 12970Sstevel@tonic-gate secpolicy_audit_config(const cred_t *cr) 12980Sstevel@tonic-gate { 12990Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL)); 13000Sstevel@tonic-gate } 13010Sstevel@tonic-gate 13020Sstevel@tonic-gate /* 13030Sstevel@tonic-gate * Audit record generation. 13040Sstevel@tonic-gate */ 13050Sstevel@tonic-gate int 13060Sstevel@tonic-gate secpolicy_audit_modify(const cred_t *cr) 13070Sstevel@tonic-gate { 13080Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, NULL)); 13090Sstevel@tonic-gate } 13100Sstevel@tonic-gate 13110Sstevel@tonic-gate /* 13120Sstevel@tonic-gate * Get audit attributes. 13130Sstevel@tonic-gate * Either PRIV_SYS_AUDIT or PRIV_PROC_AUDIT required; report the 13140Sstevel@tonic-gate * "Least" of the two privileges on error. 13150Sstevel@tonic-gate */ 13160Sstevel@tonic-gate int 13170Sstevel@tonic-gate secpolicy_audit_getattr(const cred_t *cr) 13180Sstevel@tonic-gate { 13190Sstevel@tonic-gate if (!PRIV_POLICY_ONLY(cr, PRIV_SYS_AUDIT, B_FALSE)) { 13200Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, 13210Sstevel@tonic-gate NULL)); 13220Sstevel@tonic-gate } else { 13230Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL)); 13240Sstevel@tonic-gate } 13250Sstevel@tonic-gate } 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate 13280Sstevel@tonic-gate /* 13290Sstevel@tonic-gate * Locking physical memory 13300Sstevel@tonic-gate */ 13310Sstevel@tonic-gate int 13320Sstevel@tonic-gate secpolicy_lock_memory(const cred_t *cr) 13330Sstevel@tonic-gate { 13340Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_LOCK_MEMORY, B_FALSE, EPERM, NULL)); 13350Sstevel@tonic-gate } 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate /* 13380Sstevel@tonic-gate * Accounting (both acct(2) and exacct). 13390Sstevel@tonic-gate */ 13400Sstevel@tonic-gate int 13410Sstevel@tonic-gate secpolicy_acct(const cred_t *cr) 13420Sstevel@tonic-gate { 13430Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ACCT, B_FALSE, EPERM, NULL)); 13440Sstevel@tonic-gate } 13450Sstevel@tonic-gate 13460Sstevel@tonic-gate /* 13470Sstevel@tonic-gate * Is this process privileged to change its uids at will? 13480Sstevel@tonic-gate * Uid 0 is still considered "special" and having the SETID 13490Sstevel@tonic-gate * privilege is not sufficient to get uid 0. 13500Sstevel@tonic-gate * Files are owned by root, so the privilege would give 13510Sstevel@tonic-gate * full access and euid 0 is still effective. 13520Sstevel@tonic-gate * 13530Sstevel@tonic-gate * If you have the privilege and euid 0 only then do you 13540Sstevel@tonic-gate * get the powers of root wrt uid 0. 13550Sstevel@tonic-gate * 13560Sstevel@tonic-gate * For gid manipulations, this is should be called with an 13570Sstevel@tonic-gate * uid of -1. 13580Sstevel@tonic-gate * 13590Sstevel@tonic-gate */ 13600Sstevel@tonic-gate int 13610Sstevel@tonic-gate secpolicy_allow_setid(const cred_t *cr, uid_t newuid, boolean_t checkonly) 13620Sstevel@tonic-gate { 13630Sstevel@tonic-gate boolean_t allzone = B_FALSE; 13640Sstevel@tonic-gate 13650Sstevel@tonic-gate if (newuid == 0 && cr->cr_uid != 0 && cr->cr_suid != 0 && 13660Sstevel@tonic-gate cr->cr_ruid != 0) { 13670Sstevel@tonic-gate allzone = B_TRUE; 13680Sstevel@tonic-gate } 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate return (checkonly ? !PRIV_POLICY_ONLY(cr, PRIV_PROC_SETID, allzone) : 13710Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_PROC_SETID, allzone, EPERM, NULL)); 13720Sstevel@tonic-gate } 13730Sstevel@tonic-gate 13740Sstevel@tonic-gate 13750Sstevel@tonic-gate /* 13760Sstevel@tonic-gate * Acting on a different process: if the mode is for writing, 13770Sstevel@tonic-gate * the restrictions are more severe. This is called after 13780Sstevel@tonic-gate * we've verified that the uids do not match. 13790Sstevel@tonic-gate */ 13800Sstevel@tonic-gate int 13810Sstevel@tonic-gate secpolicy_proc_owner(const cred_t *scr, const cred_t *tcr, int mode) 13820Sstevel@tonic-gate { 13830Sstevel@tonic-gate boolean_t allzone = B_FALSE; 13840Sstevel@tonic-gate 13850Sstevel@tonic-gate if ((mode & VWRITE) && scr->cr_uid != 0 && 13860Sstevel@tonic-gate (tcr->cr_uid == 0 || tcr->cr_ruid == 0 || tcr->cr_suid == 0)) 13870Sstevel@tonic-gate allzone = B_TRUE; 13880Sstevel@tonic-gate 13890Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, allzone, EPERM, NULL)); 13900Sstevel@tonic-gate } 13910Sstevel@tonic-gate 13920Sstevel@tonic-gate int 13930Sstevel@tonic-gate secpolicy_proc_access(const cred_t *scr) 13940Sstevel@tonic-gate { 13950Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EACCES, NULL)); 13960Sstevel@tonic-gate } 13970Sstevel@tonic-gate 13980Sstevel@tonic-gate int 13990Sstevel@tonic-gate secpolicy_proc_excl_open(const cred_t *scr) 14000Sstevel@tonic-gate { 14010Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EBUSY, NULL)); 14020Sstevel@tonic-gate } 14030Sstevel@tonic-gate 14040Sstevel@tonic-gate int 14050Sstevel@tonic-gate secpolicy_proc_zone(const cred_t *scr) 14060Sstevel@tonic-gate { 14070Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_ZONE, B_FALSE, EPERM, NULL)); 14080Sstevel@tonic-gate } 14090Sstevel@tonic-gate 14100Sstevel@tonic-gate /* 14110Sstevel@tonic-gate * Destroying the system 14120Sstevel@tonic-gate */ 14130Sstevel@tonic-gate 14140Sstevel@tonic-gate int 14150Sstevel@tonic-gate secpolicy_kmdb(const cred_t *scr) 14160Sstevel@tonic-gate { 14170Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 14180Sstevel@tonic-gate } 14190Sstevel@tonic-gate 14201414Scindi int 14211414Scindi secpolicy_error_inject(const cred_t *scr) 14221414Scindi { 14231414Scindi return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 14241414Scindi } 14251414Scindi 14260Sstevel@tonic-gate /* 14270Sstevel@tonic-gate * Processor sets, cpu configuration, resource pools. 14280Sstevel@tonic-gate */ 14290Sstevel@tonic-gate int 14300Sstevel@tonic-gate secpolicy_pset(const cred_t *cr) 14310Sstevel@tonic-gate { 14320Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 14330Sstevel@tonic-gate } 14340Sstevel@tonic-gate 14350Sstevel@tonic-gate int 14360Sstevel@tonic-gate secpolicy_ponline(const cred_t *cr) 14370Sstevel@tonic-gate { 14380Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 14390Sstevel@tonic-gate } 14400Sstevel@tonic-gate 14410Sstevel@tonic-gate int 14420Sstevel@tonic-gate secpolicy_pool(const cred_t *cr) 14430Sstevel@tonic-gate { 14440Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 14450Sstevel@tonic-gate } 14460Sstevel@tonic-gate 14470Sstevel@tonic-gate int 14480Sstevel@tonic-gate secpolicy_blacklist(const cred_t *cr) 14490Sstevel@tonic-gate { 14500Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 14510Sstevel@tonic-gate } 14520Sstevel@tonic-gate 14530Sstevel@tonic-gate /* 14540Sstevel@tonic-gate * Catch all system configuration. 14550Sstevel@tonic-gate */ 14560Sstevel@tonic-gate int 14570Sstevel@tonic-gate secpolicy_sys_config(const cred_t *cr, boolean_t checkonly) 14580Sstevel@tonic-gate { 14590Sstevel@tonic-gate if (checkonly) { 14600Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_CONFIG, B_FALSE) ? 0 : 14610Sstevel@tonic-gate EPERM); 14620Sstevel@tonic-gate } else { 14630Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 14640Sstevel@tonic-gate } 14650Sstevel@tonic-gate } 14660Sstevel@tonic-gate 14670Sstevel@tonic-gate /* 14680Sstevel@tonic-gate * Zone administration (halt, reboot, etc.) from within zone. 14690Sstevel@tonic-gate */ 14700Sstevel@tonic-gate int 14710Sstevel@tonic-gate secpolicy_zone_admin(const cred_t *cr, boolean_t checkonly) 14720Sstevel@tonic-gate { 14730Sstevel@tonic-gate if (checkonly) { 14740Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_ADMIN, B_FALSE) ? 0 : 14750Sstevel@tonic-gate EPERM); 14760Sstevel@tonic-gate } else { 14770Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, 14780Sstevel@tonic-gate NULL)); 14790Sstevel@tonic-gate } 14800Sstevel@tonic-gate } 14810Sstevel@tonic-gate 14820Sstevel@tonic-gate /* 14830Sstevel@tonic-gate * Zone configuration (create, halt, enter). 14840Sstevel@tonic-gate */ 14850Sstevel@tonic-gate int 14860Sstevel@tonic-gate secpolicy_zone_config(const cred_t *cr) 14870Sstevel@tonic-gate { 14880Sstevel@tonic-gate /* 14890Sstevel@tonic-gate * Require all privileges to avoid possibility of privilege 14900Sstevel@tonic-gate * escalation. 14910Sstevel@tonic-gate */ 14920Sstevel@tonic-gate return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 14930Sstevel@tonic-gate } 14940Sstevel@tonic-gate 14950Sstevel@tonic-gate /* 14960Sstevel@tonic-gate * Various other system configuration calls 14970Sstevel@tonic-gate */ 14980Sstevel@tonic-gate int 14990Sstevel@tonic-gate secpolicy_coreadm(const cred_t *cr) 15000Sstevel@tonic-gate { 15010Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL)); 15020Sstevel@tonic-gate } 15030Sstevel@tonic-gate 15040Sstevel@tonic-gate int 15050Sstevel@tonic-gate secpolicy_systeminfo(const cred_t *cr) 15060Sstevel@tonic-gate { 15070Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL)); 15080Sstevel@tonic-gate } 15090Sstevel@tonic-gate 15100Sstevel@tonic-gate int 15110Sstevel@tonic-gate secpolicy_dispadm(const cred_t *cr) 15120Sstevel@tonic-gate { 15130Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 15140Sstevel@tonic-gate } 15150Sstevel@tonic-gate 15160Sstevel@tonic-gate int 15170Sstevel@tonic-gate secpolicy_settime(const cred_t *cr) 15180Sstevel@tonic-gate { 15190Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_TIME, B_FALSE, EPERM, NULL)); 15200Sstevel@tonic-gate } 15210Sstevel@tonic-gate 15220Sstevel@tonic-gate /* 15230Sstevel@tonic-gate * For realtime users: high resolution clock. 15240Sstevel@tonic-gate */ 15250Sstevel@tonic-gate int 15260Sstevel@tonic-gate secpolicy_clock_highres(const cred_t *cr) 15270Sstevel@tonic-gate { 15280Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_CLOCK_HIGHRES, B_FALSE, EPERM, 15290Sstevel@tonic-gate NULL)); 15300Sstevel@tonic-gate } 15310Sstevel@tonic-gate 15320Sstevel@tonic-gate /* 15330Sstevel@tonic-gate * drv_priv() is documented as callable from interrupt context, not that 15340Sstevel@tonic-gate * anyone ever does, but still. No debugging or auditing can be done when 15350Sstevel@tonic-gate * it is called from interrupt context. 15360Sstevel@tonic-gate * returns 0 on succes, EPERM on failure. 15370Sstevel@tonic-gate */ 15380Sstevel@tonic-gate int 15390Sstevel@tonic-gate drv_priv(cred_t *cr) 15400Sstevel@tonic-gate { 15410Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 15420Sstevel@tonic-gate } 15430Sstevel@tonic-gate 15440Sstevel@tonic-gate int 15450Sstevel@tonic-gate secpolicy_sys_devices(const cred_t *cr) 15460Sstevel@tonic-gate { 15470Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 15480Sstevel@tonic-gate } 15490Sstevel@tonic-gate 15500Sstevel@tonic-gate int 15510Sstevel@tonic-gate secpolicy_excl_open(const cred_t *cr) 15520Sstevel@tonic-gate { 15530Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EBUSY, NULL)); 15540Sstevel@tonic-gate } 15550Sstevel@tonic-gate 15560Sstevel@tonic-gate int 15570Sstevel@tonic-gate secpolicy_rctlsys(const cred_t *cr, boolean_t is_zone_rctl) 15580Sstevel@tonic-gate { 15590Sstevel@tonic-gate /* zone.* rctls can only be set from the global zone */ 15600Sstevel@tonic-gate if (is_zone_rctl && priv_policy_global(cr) != 0) 15610Sstevel@tonic-gate return (EPERM); 15620Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 15630Sstevel@tonic-gate } 15640Sstevel@tonic-gate 15650Sstevel@tonic-gate int 15660Sstevel@tonic-gate secpolicy_resource(const cred_t *cr) 15670Sstevel@tonic-gate { 15680Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 15690Sstevel@tonic-gate } 15700Sstevel@tonic-gate 15710Sstevel@tonic-gate /* 15720Sstevel@tonic-gate * Processes with a real uid of 0 escape any form of accounting, much 15730Sstevel@tonic-gate * like before. 15740Sstevel@tonic-gate */ 15750Sstevel@tonic-gate int 15760Sstevel@tonic-gate secpolicy_newproc(const cred_t *cr) 15770Sstevel@tonic-gate { 15780Sstevel@tonic-gate if (cr->cr_ruid == 0) 15790Sstevel@tonic-gate return (0); 15800Sstevel@tonic-gate 15810Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 15820Sstevel@tonic-gate } 15830Sstevel@tonic-gate 15840Sstevel@tonic-gate /* 15850Sstevel@tonic-gate * Networking 15860Sstevel@tonic-gate */ 15870Sstevel@tonic-gate int 15880Sstevel@tonic-gate secpolicy_net_rawaccess(const cred_t *cr) 15890Sstevel@tonic-gate { 15900Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_NET_RAWACCESS, B_FALSE, EACCES, NULL)); 15910Sstevel@tonic-gate } 15920Sstevel@tonic-gate 15930Sstevel@tonic-gate /* 15940Sstevel@tonic-gate * Need this privilege for accessing the ICMP device 15950Sstevel@tonic-gate */ 15960Sstevel@tonic-gate int 15970Sstevel@tonic-gate secpolicy_net_icmpaccess(const cred_t *cr) 15980Sstevel@tonic-gate { 15990Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_NET_ICMPACCESS, B_FALSE, EACCES, NULL)); 16000Sstevel@tonic-gate } 16010Sstevel@tonic-gate 16020Sstevel@tonic-gate /* 16030Sstevel@tonic-gate * There are a few rare cases where the kernel generates ioctls() from 16040Sstevel@tonic-gate * interrupt context with a credential of kcred rather than NULL. 16050Sstevel@tonic-gate * In those cases, we take the safe and cheap test. 16060Sstevel@tonic-gate */ 16070Sstevel@tonic-gate int 16080Sstevel@tonic-gate secpolicy_net_config(const cred_t *cr, boolean_t checkonly) 16090Sstevel@tonic-gate { 16100Sstevel@tonic-gate if (checkonly) { 16110Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE) ? 16120Sstevel@tonic-gate 0 : EPERM); 16130Sstevel@tonic-gate } else { 16140Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_NET_CONFIG, B_FALSE, EPERM, 16150Sstevel@tonic-gate NULL)); 16160Sstevel@tonic-gate } 16170Sstevel@tonic-gate } 16180Sstevel@tonic-gate 16190Sstevel@tonic-gate 16200Sstevel@tonic-gate /* 16214962Sdh155122 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG. 16223448Sdh155122 * 16233448Sdh155122 * There are a few rare cases where the kernel generates ioctls() from 16243448Sdh155122 * interrupt context with a credential of kcred rather than NULL. 16253448Sdh155122 * In those cases, we take the safe and cheap test. 16263448Sdh155122 */ 16273448Sdh155122 int 16283448Sdh155122 secpolicy_ip_config(const cred_t *cr, boolean_t checkonly) 16293448Sdh155122 { 16303448Sdh155122 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 16313448Sdh155122 return (secpolicy_net_config(cr, checkonly)); 16323448Sdh155122 16333448Sdh155122 if (checkonly) { 16343448Sdh155122 return (PRIV_POLICY_ONLY(cr, PRIV_SYS_IP_CONFIG, B_FALSE) ? 16353448Sdh155122 0 : EPERM); 16363448Sdh155122 } else { 16373448Sdh155122 return (PRIV_POLICY(cr, PRIV_SYS_IP_CONFIG, B_FALSE, EPERM, 16383448Sdh155122 NULL)); 16393448Sdh155122 } 16403448Sdh155122 } 16413448Sdh155122 16423448Sdh155122 16433448Sdh155122 /* 16443448Sdh155122 * Map IP pseudo privileges to actual privileges. 16453448Sdh155122 * So we don't need to recompile IP when we change the privileges. 16463448Sdh155122 */ 16473448Sdh155122 int 16483448Sdh155122 secpolicy_ip(const cred_t *cr, int netpriv, boolean_t checkonly) 16493448Sdh155122 { 16503448Sdh155122 int priv = PRIV_ALL; 16513448Sdh155122 16523448Sdh155122 switch (netpriv) { 16533448Sdh155122 case OP_CONFIG: 16543448Sdh155122 priv = PRIV_SYS_IP_CONFIG; 16553448Sdh155122 break; 16563448Sdh155122 case OP_RAW: 16573448Sdh155122 priv = PRIV_NET_RAWACCESS; 16583448Sdh155122 break; 16593448Sdh155122 case OP_PRIVPORT: 16603448Sdh155122 priv = PRIV_NET_PRIVADDR; 16613448Sdh155122 break; 16623448Sdh155122 } 16633448Sdh155122 ASSERT(priv != PRIV_ALL); 16643448Sdh155122 if (checkonly) 16653448Sdh155122 return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM); 16663448Sdh155122 else 16673448Sdh155122 return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL)); 16683448Sdh155122 } 16693448Sdh155122 16703448Sdh155122 /* 16710Sstevel@tonic-gate * Map network pseudo privileges to actual privileges. 16720Sstevel@tonic-gate * So we don't need to recompile IP when we change the privileges. 16730Sstevel@tonic-gate */ 16740Sstevel@tonic-gate int 16750Sstevel@tonic-gate secpolicy_net(const cred_t *cr, int netpriv, boolean_t checkonly) 16760Sstevel@tonic-gate { 16770Sstevel@tonic-gate int priv = PRIV_ALL; 16780Sstevel@tonic-gate 16790Sstevel@tonic-gate switch (netpriv) { 16800Sstevel@tonic-gate case OP_CONFIG: 16810Sstevel@tonic-gate priv = PRIV_SYS_NET_CONFIG; 16820Sstevel@tonic-gate break; 16830Sstevel@tonic-gate case OP_RAW: 16840Sstevel@tonic-gate priv = PRIV_NET_RAWACCESS; 16850Sstevel@tonic-gate break; 16860Sstevel@tonic-gate case OP_PRIVPORT: 16870Sstevel@tonic-gate priv = PRIV_NET_PRIVADDR; 16880Sstevel@tonic-gate break; 16890Sstevel@tonic-gate } 16900Sstevel@tonic-gate ASSERT(priv != PRIV_ALL); 16910Sstevel@tonic-gate if (checkonly) 16920Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM); 16930Sstevel@tonic-gate else 16940Sstevel@tonic-gate return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL)); 16950Sstevel@tonic-gate } 16960Sstevel@tonic-gate 16970Sstevel@tonic-gate /* 16980Sstevel@tonic-gate * Checks for operations that are either client-only or are used by 16990Sstevel@tonic-gate * both clients and servers. 17000Sstevel@tonic-gate */ 17010Sstevel@tonic-gate int 17020Sstevel@tonic-gate secpolicy_nfs(const cred_t *cr) 17030Sstevel@tonic-gate { 17040Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_NFS, B_FALSE, EPERM, NULL)); 17050Sstevel@tonic-gate } 17060Sstevel@tonic-gate 17070Sstevel@tonic-gate /* 17080Sstevel@tonic-gate * Special case for opening rpcmod: have NFS privileges or network 17090Sstevel@tonic-gate * config privileges. 17100Sstevel@tonic-gate */ 17110Sstevel@tonic-gate int 17120Sstevel@tonic-gate secpolicy_rpcmod_open(const cred_t *cr) 17130Sstevel@tonic-gate { 17140Sstevel@tonic-gate if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NFS, B_FALSE)) 17150Sstevel@tonic-gate return (secpolicy_nfs(cr)); 17160Sstevel@tonic-gate else 17170Sstevel@tonic-gate return (secpolicy_net_config(cr, NULL)); 17180Sstevel@tonic-gate } 17190Sstevel@tonic-gate 17200Sstevel@tonic-gate int 17210Sstevel@tonic-gate secpolicy_chroot(const cred_t *cr) 17220Sstevel@tonic-gate { 17230Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_CHROOT, B_FALSE, EPERM, NULL)); 17240Sstevel@tonic-gate } 17250Sstevel@tonic-gate 17260Sstevel@tonic-gate int 17270Sstevel@tonic-gate secpolicy_tasksys(const cred_t *cr) 17280Sstevel@tonic-gate { 17290Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_TASKID, B_FALSE, EPERM, NULL)); 17300Sstevel@tonic-gate } 17310Sstevel@tonic-gate 17320Sstevel@tonic-gate /* 17330Sstevel@tonic-gate * Basic privilege checks. 17340Sstevel@tonic-gate */ 17350Sstevel@tonic-gate int 17360Sstevel@tonic-gate secpolicy_basic_exec(const cred_t *cr) 17370Sstevel@tonic-gate { 17380Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_EXEC, B_FALSE, EPERM, NULL)); 17390Sstevel@tonic-gate } 17400Sstevel@tonic-gate 17410Sstevel@tonic-gate int 17420Sstevel@tonic-gate secpolicy_basic_fork(const cred_t *cr) 17430Sstevel@tonic-gate { 17440Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_FORK, B_FALSE, EPERM, NULL)); 17450Sstevel@tonic-gate } 17460Sstevel@tonic-gate 17470Sstevel@tonic-gate int 17480Sstevel@tonic-gate secpolicy_basic_proc(const cred_t *cr) 17490Sstevel@tonic-gate { 17500Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_SESSION, B_FALSE, EPERM, NULL)); 17510Sstevel@tonic-gate } 17520Sstevel@tonic-gate 17530Sstevel@tonic-gate /* 17540Sstevel@tonic-gate * Slightly complicated because we don't want to trigger the policy too 17550Sstevel@tonic-gate * often. First we shortcircuit access to "self" (tp == sp) or if 17560Sstevel@tonic-gate * we don't have the privilege but if we have permission 17570Sstevel@tonic-gate * just return (0) and we don't flag the privilege as needed. 17580Sstevel@tonic-gate * Else, we test for the privilege because we either have it or need it. 17590Sstevel@tonic-gate */ 17600Sstevel@tonic-gate int 17610Sstevel@tonic-gate secpolicy_basic_procinfo(const cred_t *cr, proc_t *tp, proc_t *sp) 17620Sstevel@tonic-gate { 17630Sstevel@tonic-gate if (tp == sp || 17640Sstevel@tonic-gate !HAS_PRIVILEGE(cr, PRIV_PROC_INFO) && prochasprocperm(tp, sp, cr)) { 17650Sstevel@tonic-gate return (0); 17660Sstevel@tonic-gate } else { 17670Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_INFO, B_FALSE, EPERM, NULL)); 17680Sstevel@tonic-gate } 17690Sstevel@tonic-gate } 17700Sstevel@tonic-gate 17710Sstevel@tonic-gate int 17720Sstevel@tonic-gate secpolicy_basic_link(const cred_t *cr) 17730Sstevel@tonic-gate { 17740Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_LINK_ANY, B_FALSE, EPERM, NULL)); 17750Sstevel@tonic-gate } 17760Sstevel@tonic-gate 17770Sstevel@tonic-gate /* 17780Sstevel@tonic-gate * Additional device protection. 17790Sstevel@tonic-gate * 17800Sstevel@tonic-gate * Traditionally, a device has specific permissions on the node in 17810Sstevel@tonic-gate * the filesystem which govern which devices can be opened by what 17820Sstevel@tonic-gate * processes. In certain cases, it is desirable to add extra 17830Sstevel@tonic-gate * restrictions, as writing to certain devices is identical to 17840Sstevel@tonic-gate * having a complete run of the system. 17850Sstevel@tonic-gate * 17860Sstevel@tonic-gate * This mechanism is called the device policy. 17870Sstevel@tonic-gate * 17880Sstevel@tonic-gate * When a device is opened, its policy entry is looked up in the 17890Sstevel@tonic-gate * policy cache and checked. 17900Sstevel@tonic-gate */ 17910Sstevel@tonic-gate int 17920Sstevel@tonic-gate secpolicy_spec_open(const cred_t *cr, struct vnode *vp, int oflag) 17930Sstevel@tonic-gate { 17940Sstevel@tonic-gate devplcy_t *plcy; 17950Sstevel@tonic-gate int err; 17960Sstevel@tonic-gate struct snode *csp = VTOS(common_specvp(vp)); 17974962Sdh155122 priv_set_t pset; 17980Sstevel@tonic-gate 17990Sstevel@tonic-gate mutex_enter(&csp->s_lock); 18000Sstevel@tonic-gate 18010Sstevel@tonic-gate if (csp->s_plcy == NULL || csp->s_plcy->dp_gen != devplcy_gen) { 18020Sstevel@tonic-gate plcy = devpolicy_find(vp); 18030Sstevel@tonic-gate if (csp->s_plcy) 18040Sstevel@tonic-gate dpfree(csp->s_plcy); 18050Sstevel@tonic-gate csp->s_plcy = plcy; 18060Sstevel@tonic-gate ASSERT(plcy != NULL); 18070Sstevel@tonic-gate } else 18080Sstevel@tonic-gate plcy = csp->s_plcy; 18090Sstevel@tonic-gate 18100Sstevel@tonic-gate if (plcy == nullpolicy) { 18110Sstevel@tonic-gate mutex_exit(&csp->s_lock); 18120Sstevel@tonic-gate return (0); 18130Sstevel@tonic-gate } 18140Sstevel@tonic-gate 18150Sstevel@tonic-gate dphold(plcy); 18160Sstevel@tonic-gate 18170Sstevel@tonic-gate mutex_exit(&csp->s_lock); 18180Sstevel@tonic-gate 18194962Sdh155122 if (oflag & FWRITE) 18204962Sdh155122 pset = plcy->dp_wrp; 18214962Sdh155122 else 18224962Sdh155122 pset = plcy->dp_rdp; 18234962Sdh155122 /* 18244962Sdh155122 * Special case: 18254962Sdh155122 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG. 18264962Sdh155122 * If PRIV_SYS_NET_CONFIG is present and PRIV_SYS_IP_CONFIG is 18274962Sdh155122 * required, replace PRIV_SYS_IP_CONFIG with PRIV_SYS_NET_CONFIG 18284962Sdh155122 * in the required privilege set before doing the check. 18294962Sdh155122 */ 18304962Sdh155122 if (priv_ismember(&pset, PRIV_SYS_IP_CONFIG) && 18314962Sdh155122 priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_NET_CONFIG) && 18324962Sdh155122 !priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_IP_CONFIG)) { 18334962Sdh155122 priv_delset(&pset, PRIV_SYS_IP_CONFIG); 18344962Sdh155122 priv_addset(&pset, PRIV_SYS_NET_CONFIG); 18354962Sdh155122 } 18364962Sdh155122 18374962Sdh155122 err = secpolicy_require_set(cr, &pset, "devpolicy"); 18380Sstevel@tonic-gate dpfree(plcy); 18390Sstevel@tonic-gate 18400Sstevel@tonic-gate return (err); 18410Sstevel@tonic-gate } 18420Sstevel@tonic-gate 18430Sstevel@tonic-gate int 18440Sstevel@tonic-gate secpolicy_modctl(const cred_t *cr, int cmd) 18450Sstevel@tonic-gate { 18460Sstevel@tonic-gate switch (cmd) { 18470Sstevel@tonic-gate case MODINFO: 18482723Scth case MODGETMAJBIND: 18490Sstevel@tonic-gate case MODGETPATH: 18500Sstevel@tonic-gate case MODGETPATHLEN: 18512723Scth case MODGETNAME: 18520Sstevel@tonic-gate case MODGETFBNAME: 18530Sstevel@tonic-gate case MODGETDEVPOLICY: 18540Sstevel@tonic-gate case MODGETDEVPOLICYBYNAME: 18552723Scth case MODDEVT2INSTANCE: 18562723Scth case MODSIZEOF_DEVID: 18572723Scth case MODGETDEVID: 18582723Scth case MODSIZEOF_MINORNAME: 18592723Scth case MODGETMINORNAME: 18602723Scth case MODGETDEVFSPATH_LEN: 18612723Scth case MODGETDEVFSPATH: 18622723Scth case MODGETDEVFSPATH_MI_LEN: 18632723Scth case MODGETDEVFSPATH_MI: 18640Sstevel@tonic-gate /* Unprivileged */ 18650Sstevel@tonic-gate return (0); 18660Sstevel@tonic-gate case MODLOAD: 18670Sstevel@tonic-gate case MODSETDEVPOLICY: 18680Sstevel@tonic-gate return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 18690Sstevel@tonic-gate default: 18700Sstevel@tonic-gate return (secpolicy_sys_config(cr, B_FALSE)); 18710Sstevel@tonic-gate } 18720Sstevel@tonic-gate } 18730Sstevel@tonic-gate 18740Sstevel@tonic-gate int 18750Sstevel@tonic-gate secpolicy_console(const cred_t *cr) 18760Sstevel@tonic-gate { 18770Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 18780Sstevel@tonic-gate } 18790Sstevel@tonic-gate 18800Sstevel@tonic-gate int 18810Sstevel@tonic-gate secpolicy_power_mgmt(const cred_t *cr) 18820Sstevel@tonic-gate { 18830Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 18840Sstevel@tonic-gate } 18850Sstevel@tonic-gate 18860Sstevel@tonic-gate /* 18870Sstevel@tonic-gate * Simulate terminal input; another escalation of privileges avenue. 18880Sstevel@tonic-gate */ 18890Sstevel@tonic-gate 18900Sstevel@tonic-gate int 18910Sstevel@tonic-gate secpolicy_sti(const cred_t *cr) 18920Sstevel@tonic-gate { 18930Sstevel@tonic-gate return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 18940Sstevel@tonic-gate } 18950Sstevel@tonic-gate 18961676Sjpk boolean_t 18971676Sjpk secpolicy_net_reply_equal(const cred_t *cr) 18981676Sjpk { 18991676Sjpk return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 19001676Sjpk } 19011676Sjpk 19020Sstevel@tonic-gate int 19030Sstevel@tonic-gate secpolicy_swapctl(const cred_t *cr) 19040Sstevel@tonic-gate { 19050Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 19060Sstevel@tonic-gate } 19070Sstevel@tonic-gate 19080Sstevel@tonic-gate int 19090Sstevel@tonic-gate secpolicy_cpc_cpu(const cred_t *cr) 19100Sstevel@tonic-gate { 19110Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CPC_CPU, B_FALSE, EACCES, NULL)); 19120Sstevel@tonic-gate } 19130Sstevel@tonic-gate 19140Sstevel@tonic-gate /* 19150Sstevel@tonic-gate * secpolicy_contract_observer 19160Sstevel@tonic-gate * 19170Sstevel@tonic-gate * Determine if the subject may observe a specific contract's events. 19180Sstevel@tonic-gate */ 19190Sstevel@tonic-gate int 19200Sstevel@tonic-gate secpolicy_contract_observer(const cred_t *cr, struct contract *ct) 19210Sstevel@tonic-gate { 19220Sstevel@tonic-gate if (contract_owned(ct, cr, B_FALSE)) 19230Sstevel@tonic-gate return (0); 19240Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CONTRACT_OBSERVER, B_FALSE, EPERM, NULL)); 19250Sstevel@tonic-gate } 19260Sstevel@tonic-gate 19270Sstevel@tonic-gate /* 19280Sstevel@tonic-gate * secpolicy_contract_observer_choice 19290Sstevel@tonic-gate * 19300Sstevel@tonic-gate * Determine if the subject may observe any contract's events. Just 19310Sstevel@tonic-gate * tests privilege and audits on success. 19320Sstevel@tonic-gate */ 19330Sstevel@tonic-gate boolean_t 19340Sstevel@tonic-gate secpolicy_contract_observer_choice(const cred_t *cr) 19350Sstevel@tonic-gate { 19360Sstevel@tonic-gate return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_OBSERVER, B_FALSE)); 19370Sstevel@tonic-gate } 19380Sstevel@tonic-gate 19390Sstevel@tonic-gate /* 19400Sstevel@tonic-gate * secpolicy_contract_event 19410Sstevel@tonic-gate * 19420Sstevel@tonic-gate * Determine if the subject may request critical contract events or 19430Sstevel@tonic-gate * reliable contract event delivery. 19440Sstevel@tonic-gate */ 19450Sstevel@tonic-gate int 19460Sstevel@tonic-gate secpolicy_contract_event(const cred_t *cr) 19470Sstevel@tonic-gate { 19480Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CONTRACT_EVENT, B_FALSE, EPERM, NULL)); 19490Sstevel@tonic-gate } 19500Sstevel@tonic-gate 19510Sstevel@tonic-gate /* 19520Sstevel@tonic-gate * secpolicy_contract_event_choice 19530Sstevel@tonic-gate * 19540Sstevel@tonic-gate * Determine if the subject may retain contract events in its critical 19550Sstevel@tonic-gate * set when a change in other terms would normally require a change in 19560Sstevel@tonic-gate * the critical set. Just tests privilege and audits on success. 19570Sstevel@tonic-gate */ 19580Sstevel@tonic-gate boolean_t 19590Sstevel@tonic-gate secpolicy_contract_event_choice(const cred_t *cr) 19600Sstevel@tonic-gate { 19610Sstevel@tonic-gate return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_EVENT, B_FALSE)); 19620Sstevel@tonic-gate } 19630Sstevel@tonic-gate 19640Sstevel@tonic-gate /* 19651544Seschrock * secpolicy_gart_access 19660Sstevel@tonic-gate * 19671544Seschrock * Determine if the subject has sufficient priveleges to make ioctls to agpgart 19681544Seschrock * device. 19690Sstevel@tonic-gate */ 19700Sstevel@tonic-gate int 19710Sstevel@tonic-gate secpolicy_gart_access(const cred_t *cr) 19720Sstevel@tonic-gate { 19731862Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, NULL)); 19740Sstevel@tonic-gate } 19750Sstevel@tonic-gate 19760Sstevel@tonic-gate /* 19771544Seschrock * secpolicy_gart_map 19780Sstevel@tonic-gate * 19791544Seschrock * Determine if the subject has sufficient priveleges to map aperture range 19801544Seschrock * through agpgart driver. 19810Sstevel@tonic-gate */ 19820Sstevel@tonic-gate int 19830Sstevel@tonic-gate secpolicy_gart_map(const cred_t *cr) 19840Sstevel@tonic-gate { 19851862Scasper if (PRIV_POLICY_ONLY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE)) { 19861862Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, 19871862Scasper NULL)); 19881862Scasper } else { 19891862Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_MAP, B_FALSE, EPERM, 19901862Scasper NULL)); 19910Sstevel@tonic-gate } 19920Sstevel@tonic-gate } 1993789Sahrens 1994789Sahrens /* 19951544Seschrock * secpolicy_zinject 19961544Seschrock * 19971544Seschrock * Determine if the subject can inject faults in the ZFS fault injection 19981544Seschrock * framework. Requires all privileges. 19991544Seschrock */ 20001544Seschrock int 20011544Seschrock secpolicy_zinject(const cred_t *cr) 20021544Seschrock { 20031544Seschrock return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 20041544Seschrock } 20051544Seschrock 20061544Seschrock /* 2007789Sahrens * secpolicy_zfs 2008789Sahrens * 20091544Seschrock * Determine if the subject has permission to manipulate ZFS datasets 20101544Seschrock * (not pools). Equivalent to the SYS_MOUNT privilege. 2011789Sahrens */ 2012789Sahrens int 2013789Sahrens secpolicy_zfs(const cred_t *cr) 2014789Sahrens { 2015789Sahrens return (PRIV_POLICY(cr, PRIV_SYS_MOUNT, B_FALSE, EPERM, NULL)); 2016789Sahrens } 20174321Scasper 20184321Scasper /* 20194321Scasper * secpolicy_idmap 20204321Scasper * 20214321Scasper * Determine if the calling process has permissions to register an SID 20224321Scasper * mapping daemon and allocate ephemeral IDs. 20234321Scasper */ 20244321Scasper int 20254321Scasper secpolicy_idmap(const cred_t *cr) 20264321Scasper { 20274321Scasper return (PRIV_POLICY(cr, PRIV_ALL, B_FALSE, EPERM, NULL)); 20284321Scasper } 20294581Ssherrym 20304581Ssherrym /* 20314581Ssherrym * secpolicy_ucode_update 20324581Ssherrym * 20334581Ssherrym * Determine if the subject has sufficient privilege to update microcode. 20344581Ssherrym */ 20354581Ssherrym int 20364581Ssherrym secpolicy_ucode_update(const cred_t *scr) 20374581Ssherrym { 20384581Ssherrym return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 20394581Ssherrym } 20404962Sdh155122 20414962Sdh155122 /* 20424962Sdh155122 * secpolicy_sadopen 20434962Sdh155122 * 20444962Sdh155122 * Determine if the subject has sufficient privilege to access /dev/sad/admin. 20454962Sdh155122 * /dev/sad/admin appear in global zone and exclusive-IP zones only. 20464962Sdh155122 * In global zone, sys_config is required. 20474962Sdh155122 * In exclusive-IP zones, sys_ip_config is required. 20484962Sdh155122 * Note that sys_config is prohibited in non-global zones. 20494962Sdh155122 */ 20504962Sdh155122 int 20514962Sdh155122 secpolicy_sadopen(const cred_t *credp) 20524962Sdh155122 { 20534962Sdh155122 priv_set_t pset; 20544962Sdh155122 20554962Sdh155122 priv_emptyset(&pset); 20564962Sdh155122 20574962Sdh155122 if (crgetzoneid(credp) == GLOBAL_ZONEID) 20584962Sdh155122 priv_addset(&pset, PRIV_SYS_CONFIG); 20594962Sdh155122 else 20604962Sdh155122 priv_addset(&pset, PRIV_SYS_IP_CONFIG); 20614962Sdh155122 20624962Sdh155122 return (secpolicy_require_set(credp, &pset, "devpolicy")); 20634962Sdh155122 } 20645331Samw 20655331Samw /* 20665331Samw * secpolicy_smb 20675331Samw * 20685331Samw * Determine if the cred_t has PRIV_SYS_SMB privilege, indicating 20695331Samw * that it has permission to access the smbsrv kernel driver. 20705331Samw * PRIV_POLICY checks the privilege and audits the check. 20715331Samw * 20725331Samw * Returns: 20735331Samw * 0 Driver access is allowed. 20745331Samw * EPERM Driver access is NOT permitted. 20755331Samw */ 20765331Samw int 20775331Samw secpolicy_smb(const cred_t *cr) 20785331Samw { 20795331Samw return (PRIV_POLICY(cr, PRIV_SYS_SMB, B_FALSE, EPERM, NULL)); 20805331Samw } 2081*5440Sjm199354 2082*5440Sjm199354 /* 2083*5440Sjm199354 * secpolicy_vscan 2084*5440Sjm199354 * 2085*5440Sjm199354 * Determine if cred_t has the necessary privileges to access a file 2086*5440Sjm199354 * for virus scanning and update its extended system attributes. 2087*5440Sjm199354 * PRIV_FILE_DAC_SEARCH, PRIV_FILE_DAC_READ - file access 2088*5440Sjm199354 * PRIV_FILE_FLAG_SET - set extended system attributes 2089*5440Sjm199354 * 2090*5440Sjm199354 * PRIV_POLICY checks the privilege and audits the check. 2091*5440Sjm199354 * 2092*5440Sjm199354 * Returns: 2093*5440Sjm199354 * 0 file access for virus scanning allowed. 2094*5440Sjm199354 * EPERM file access for virus scanning is NOT permitted. 2095*5440Sjm199354 */ 2096*5440Sjm199354 int 2097*5440Sjm199354 secpolicy_vscan(const cred_t *cr) 2098*5440Sjm199354 { 2099*5440Sjm199354 if ((PRIV_POLICY(cr, PRIV_FILE_DAC_SEARCH, B_FALSE, EPERM, NULL)) || 2100*5440Sjm199354 (PRIV_POLICY(cr, PRIV_FILE_DAC_READ, B_FALSE, EPERM, NULL)) || 2101*5440Sjm199354 (PRIV_POLICY(cr, PRIV_FILE_FLAG_SET, B_FALSE, EPERM, NULL))) { 2102*5440Sjm199354 return (EPERM); 2103*5440Sjm199354 } 2104*5440Sjm199354 2105*5440Sjm199354 return (0); 2106*5440Sjm199354 } 2107