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 /* 225771Sjp151216 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #include <sys/types.h> 270Sstevel@tonic-gate #include <sys/sysmacros.h> 280Sstevel@tonic-gate #include <sys/param.h> 290Sstevel@tonic-gate #include <sys/systm.h> 300Sstevel@tonic-gate #include <sys/cred_impl.h> 310Sstevel@tonic-gate #include <sys/vnode.h> 320Sstevel@tonic-gate #include <sys/vfs.h> 330Sstevel@tonic-gate #include <sys/stat.h> 340Sstevel@tonic-gate #include <sys/errno.h> 350Sstevel@tonic-gate #include <sys/kmem.h> 360Sstevel@tonic-gate #include <sys/user.h> 370Sstevel@tonic-gate #include <sys/proc.h> 380Sstevel@tonic-gate #include <sys/acct.h> 390Sstevel@tonic-gate #include <sys/ipc_impl.h> 400Sstevel@tonic-gate #include <sys/cmn_err.h> 410Sstevel@tonic-gate #include <sys/debug.h> 420Sstevel@tonic-gate #include <sys/policy.h> 430Sstevel@tonic-gate #include <sys/kobj.h> 440Sstevel@tonic-gate #include <sys/msg.h> 450Sstevel@tonic-gate #include <sys/devpolicy.h> 460Sstevel@tonic-gate #include <c2/audit.h> 470Sstevel@tonic-gate #include <sys/varargs.h> 486134Scasper #include <sys/klpd.h> 490Sstevel@tonic-gate #include <sys/modctl.h> 500Sstevel@tonic-gate #include <sys/disp.h> 510Sstevel@tonic-gate #include <sys/zone.h> 520Sstevel@tonic-gate #include <inet/optcom.h> 530Sstevel@tonic-gate #include <sys/sdt.h> 540Sstevel@tonic-gate #include <sys/vfs.h> 550Sstevel@tonic-gate #include <sys/mntent.h> 560Sstevel@tonic-gate #include <sys/contract_impl.h> 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * There are two possible layers of privilege routines and two possible 600Sstevel@tonic-gate * levels of secpolicy. Plus one other we may not be interested in, so 610Sstevel@tonic-gate * we may need as many as 6 but no more. 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate #define MAXPRIVSTACK 6 640Sstevel@tonic-gate 650Sstevel@tonic-gate int priv_debug = 0; 660Sstevel@tonic-gate 670Sstevel@tonic-gate /* 680Sstevel@tonic-gate * This file contains the majority of the policy routines. 690Sstevel@tonic-gate * Since the policy routines are defined by function and not 700Sstevel@tonic-gate * by privilege, there is quite a bit of duplication of 710Sstevel@tonic-gate * functions. 720Sstevel@tonic-gate * 735331Samw * The secpolicy functions must not make assumptions about 740Sstevel@tonic-gate * locks held or not held as any lock can be held while they're 750Sstevel@tonic-gate * being called. 760Sstevel@tonic-gate * 770Sstevel@tonic-gate * Credentials are read-only so no special precautions need to 780Sstevel@tonic-gate * be taken while locking them. 790Sstevel@tonic-gate * 800Sstevel@tonic-gate * When a new policy check needs to be added to the system the 810Sstevel@tonic-gate * following procedure should be followed: 820Sstevel@tonic-gate * 830Sstevel@tonic-gate * Pick an appropriate secpolicy_*() function 840Sstevel@tonic-gate * -> done if one exists. 850Sstevel@tonic-gate * Create a new secpolicy function, preferably with 860Sstevel@tonic-gate * a descriptive name using the standard template. 870Sstevel@tonic-gate * Pick an appropriate privilege for the policy. 880Sstevel@tonic-gate * If no appropraite privilege exists, define new one 890Sstevel@tonic-gate * (this should be done with extreme care; in most cases 900Sstevel@tonic-gate * little is gained by adding another privilege) 910Sstevel@tonic-gate * 920Sstevel@tonic-gate * WHY ROOT IS STILL SPECIAL. 930Sstevel@tonic-gate * 940Sstevel@tonic-gate * In a number of the policy functions, there are still explicit 950Sstevel@tonic-gate * checks for uid 0. The rationale behind these is that many root 960Sstevel@tonic-gate * owned files/objects hold configuration information which can give full 970Sstevel@tonic-gate * privileges to the user once written to. To prevent escalation 980Sstevel@tonic-gate * of privilege by allowing just a single privilege to modify root owned 990Sstevel@tonic-gate * objects, we've added these root specific checks where we considered 1000Sstevel@tonic-gate * them necessary: modifying root owned files, changing uids to 0, etc. 1010Sstevel@tonic-gate * 1020Sstevel@tonic-gate * PRIVILEGE ESCALATION AND ZONES. 1030Sstevel@tonic-gate * 1040Sstevel@tonic-gate * A number of operations potentially allow the caller to achieve 1050Sstevel@tonic-gate * privileges beyond the ones normally required to perform the operation. 1060Sstevel@tonic-gate * For example, if allowed to create a setuid 0 executable, a process can 1070Sstevel@tonic-gate * gain privileges beyond PRIV_FILE_SETID. Zones, however, place 1080Sstevel@tonic-gate * restrictions on the ability to gain privileges beyond those available 1090Sstevel@tonic-gate * within the zone through file and process manipulation. Hence, such 1100Sstevel@tonic-gate * operations require that the caller have an effective set that includes 1110Sstevel@tonic-gate * all privileges available within the current zone, or all privileges 1120Sstevel@tonic-gate * if executing in the global zone. 1130Sstevel@tonic-gate * 1140Sstevel@tonic-gate * This is indicated in the priv_policy* policy checking functions 1150Sstevel@tonic-gate * through a combination of parameters. The "priv" parameter indicates 1160Sstevel@tonic-gate * the privilege that is required, and the "allzone" parameter indicates 1170Sstevel@tonic-gate * whether or not all privileges in the zone are required. In addition, 1180Sstevel@tonic-gate * priv can be set to PRIV_ALL to indicate that all privileges are 1190Sstevel@tonic-gate * required (regardless of zone). There are three scenarios of interest: 1200Sstevel@tonic-gate * (1) operation requires a specific privilege 1210Sstevel@tonic-gate * (2) operation requires a specific privilege, and requires all 1220Sstevel@tonic-gate * privileges available within the zone (or all privileges if in 1230Sstevel@tonic-gate * the global zone) 1240Sstevel@tonic-gate * (3) operation requires all privileges, regardless of zone 1250Sstevel@tonic-gate * 1260Sstevel@tonic-gate * For (1), priv should be set to the specific privilege, and allzone 1270Sstevel@tonic-gate * should be set to B_FALSE. 1280Sstevel@tonic-gate * For (2), priv should be set to the specific privilege, and allzone 1290Sstevel@tonic-gate * should be set to B_TRUE. 1300Sstevel@tonic-gate * For (3), priv should be set to PRIV_ALL, and allzone should be set 1310Sstevel@tonic-gate * to B_FALSE. 1320Sstevel@tonic-gate * 1330Sstevel@tonic-gate */ 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate /* 1360Sstevel@tonic-gate * The privileges are checked against the Effective set for 1370Sstevel@tonic-gate * ordinary processes and checked against the Limit set 1380Sstevel@tonic-gate * for euid 0 processes that haven't manipulated their privilege 1390Sstevel@tonic-gate * sets. 1400Sstevel@tonic-gate */ 1410Sstevel@tonic-gate #define HAS_ALLPRIVS(cr) priv_isfullset(&CR_OEPRIV(cr)) 1420Sstevel@tonic-gate #define ZONEPRIVS(cr) ((cr)->cr_zone->zone_privset) 1430Sstevel@tonic-gate #define HAS_ALLZONEPRIVS(cr) priv_issubset(ZONEPRIVS(cr), &CR_OEPRIV(cr)) 1440Sstevel@tonic-gate #define HAS_PRIVILEGE(cr, pr) ((pr) == PRIV_ALL ? \ 1450Sstevel@tonic-gate HAS_ALLPRIVS(cr) : \ 1460Sstevel@tonic-gate PRIV_ISASSERT(&CR_OEPRIV(cr), pr)) 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate /* 1496134Scasper * Policy checking functions. 1500Sstevel@tonic-gate * 1516134Scasper * All of the system's policy should be implemented here. 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* 1556134Scasper * Private functions which take an additional va_list argument to 1566134Scasper * implement an object specific policy override. 1576134Scasper */ 1586134Scasper static int priv_policy_ap(const cred_t *, int, boolean_t, int, 1596134Scasper const char *, va_list); 1606134Scasper static int priv_policy_va(const cred_t *, int, boolean_t, int, 1616134Scasper const char *, ...); 1626134Scasper 1636134Scasper /* 1640Sstevel@tonic-gate * Generic policy calls 1650Sstevel@tonic-gate * 1660Sstevel@tonic-gate * The "bottom" functions of policy control 1670Sstevel@tonic-gate */ 1680Sstevel@tonic-gate static char * 1690Sstevel@tonic-gate mprintf(const char *fmt, ...) 1700Sstevel@tonic-gate { 1710Sstevel@tonic-gate va_list args; 1720Sstevel@tonic-gate char *buf; 1730Sstevel@tonic-gate size_t len; 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate va_start(args, fmt); 1760Sstevel@tonic-gate len = vsnprintf(NULL, 0, fmt, args) + 1; 1770Sstevel@tonic-gate va_end(args); 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate buf = kmem_alloc(len, KM_NOSLEEP); 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate if (buf == NULL) 1820Sstevel@tonic-gate return (NULL); 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate va_start(args, fmt); 1850Sstevel@tonic-gate (void) vsnprintf(buf, len, fmt, args); 1860Sstevel@tonic-gate va_end(args); 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate return (buf); 1890Sstevel@tonic-gate } 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * priv_policy_errmsg() 1930Sstevel@tonic-gate * 1940Sstevel@tonic-gate * Generate an error message if privilege debugging is enabled system wide 1950Sstevel@tonic-gate * or for this particular process. 1960Sstevel@tonic-gate */ 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate #define FMTHDR "%s[%d]: missing privilege \"%s\" (euid = %d, syscall = %d)" 1990Sstevel@tonic-gate #define FMTMSG " for \"%s\"" 2000Sstevel@tonic-gate #define FMTFUN " needed at %s+0x%lx" 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* The maximum size privilege format: the concatenation of the above */ 2030Sstevel@tonic-gate #define FMTMAX FMTHDR FMTMSG FMTFUN "\n" 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate static void 2060Sstevel@tonic-gate priv_policy_errmsg(const cred_t *cr, int priv, const char *msg) 2070Sstevel@tonic-gate { 2080Sstevel@tonic-gate struct proc *me; 2090Sstevel@tonic-gate pc_t stack[MAXPRIVSTACK]; 2100Sstevel@tonic-gate int depth; 2110Sstevel@tonic-gate int i; 2120Sstevel@tonic-gate char *sym; 2130Sstevel@tonic-gate ulong_t off; 2140Sstevel@tonic-gate const char *pname; 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate char *cmd; 2170Sstevel@tonic-gate char fmt[sizeof (FMTMAX)]; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate if ((me = curproc) == &p0) 2200Sstevel@tonic-gate return; 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate /* Privileges must be defined */ 2230Sstevel@tonic-gate ASSERT(priv == PRIV_ALL || priv == PRIV_MULTIPLE || 2240Sstevel@tonic-gate priv == PRIV_ALLZONE || priv == PRIV_GLOBAL || 2250Sstevel@tonic-gate priv_getbynum(priv) != NULL); 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate if (priv == PRIV_ALLZONE && INGLOBALZONE(me)) 2280Sstevel@tonic-gate priv = PRIV_ALL; 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate if (curthread->t_pre_sys) 2310Sstevel@tonic-gate ttolwp(curthread)->lwp_badpriv = (short)priv; 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate if (priv_debug == 0 && (CR_FLAGS(cr) & PRIV_DEBUG) == 0) 2340Sstevel@tonic-gate return; 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate (void) strcpy(fmt, FMTHDR); 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate if (me->p_user.u_comm[0]) 2390Sstevel@tonic-gate cmd = &me->p_user.u_comm[0]; 2400Sstevel@tonic-gate else 2410Sstevel@tonic-gate cmd = "priv_policy"; 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate if (msg != NULL && *msg != '\0') { 2440Sstevel@tonic-gate (void) strcat(fmt, FMTMSG); 2450Sstevel@tonic-gate } else { 2460Sstevel@tonic-gate (void) strcat(fmt, "%s"); 2470Sstevel@tonic-gate msg = ""; 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate sym = NULL; 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate depth = getpcstack(stack, MAXPRIVSTACK); 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate /* 2550Sstevel@tonic-gate * Try to find the first interesting function on the stack. 2560Sstevel@tonic-gate * priv_policy* that's us, so completely uninteresting. 2570Sstevel@tonic-gate * suser(), drv_priv(), secpolicy_* are also called from 2580Sstevel@tonic-gate * too many locations to convey useful information. 2590Sstevel@tonic-gate */ 2600Sstevel@tonic-gate for (i = 0; i < depth; i++) { 2610Sstevel@tonic-gate sym = kobj_getsymname((uintptr_t)stack[i], &off); 2620Sstevel@tonic-gate if (sym != NULL && 2630Sstevel@tonic-gate strstr(sym, "hasprocperm") == 0 && 2640Sstevel@tonic-gate strcmp("suser", sym) != 0 && 2650Sstevel@tonic-gate strcmp("ipcaccess", sym) != 0 && 2660Sstevel@tonic-gate strcmp("drv_priv", sym) != 0 && 2670Sstevel@tonic-gate strncmp("secpolicy_", sym, 10) != 0 && 2680Sstevel@tonic-gate strncmp("priv_policy", sym, 11) != 0) 2690Sstevel@tonic-gate break; 2700Sstevel@tonic-gate } 2710Sstevel@tonic-gate 2720Sstevel@tonic-gate if (sym != NULL) 2730Sstevel@tonic-gate (void) strcat(fmt, FMTFUN); 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate (void) strcat(fmt, "\n"); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate switch (priv) { 2780Sstevel@tonic-gate case PRIV_ALL: 2790Sstevel@tonic-gate pname = "ALL"; 2800Sstevel@tonic-gate break; 2810Sstevel@tonic-gate case PRIV_MULTIPLE: 2820Sstevel@tonic-gate pname = "MULTIPLE"; 2830Sstevel@tonic-gate break; 2840Sstevel@tonic-gate case PRIV_ALLZONE: 2850Sstevel@tonic-gate pname = "ZONE"; 2860Sstevel@tonic-gate break; 2870Sstevel@tonic-gate case PRIV_GLOBAL: 2880Sstevel@tonic-gate pname = "GLOBAL"; 2890Sstevel@tonic-gate break; 2900Sstevel@tonic-gate default: 2910Sstevel@tonic-gate pname = priv_getbynum(priv); 2920Sstevel@tonic-gate break; 2930Sstevel@tonic-gate } 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate if (CR_FLAGS(cr) & PRIV_DEBUG) { 2960Sstevel@tonic-gate /* Remember last message, just like lwp_badpriv. */ 2970Sstevel@tonic-gate if (curthread->t_pdmsg != NULL) { 2980Sstevel@tonic-gate kmem_free(curthread->t_pdmsg, 2990Sstevel@tonic-gate strlen(curthread->t_pdmsg) + 1); 3000Sstevel@tonic-gate } 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate curthread->t_pdmsg = mprintf(fmt, cmd, me->p_pid, pname, 3034543Smarks cr->cr_uid, curthread->t_sysnum, msg, sym, off); 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate curthread->t_post_sys = 1; 3066134Scasper } 3076134Scasper if (priv_debug) { 3080Sstevel@tonic-gate cmn_err(CE_NOTE, fmt, cmd, me->p_pid, pname, cr->cr_uid, 3090Sstevel@tonic-gate curthread->t_sysnum, msg, sym, off); 3100Sstevel@tonic-gate } 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate /* 3146134Scasper * Override the policy, if appropriate. Return 0 if the external 3156134Scasper * policy engine approves. 3166134Scasper */ 3176134Scasper static int 3186134Scasper priv_policy_override(const cred_t *cr, int priv, boolean_t allzone, va_list ap) 3196134Scasper { 3206134Scasper priv_set_t set; 3216134Scasper int ret; 3226134Scasper 3236134Scasper if (!(CR_FLAGS(cr) & PRIV_XPOLICY)) 3246134Scasper return (-1); 3256134Scasper 3266134Scasper if (priv == PRIV_ALL) { 3276134Scasper priv_fillset(&set); 3286134Scasper } else if (allzone) { 3296134Scasper set = *ZONEPRIVS(cr); 3306134Scasper } else { 3316134Scasper priv_emptyset(&set); 3326134Scasper priv_addset(&set, priv); 3336134Scasper } 3346134Scasper ret = klpd_call(cr, &set, ap); 3356134Scasper return (ret); 3366134Scasper } 3376134Scasper 3386134Scasper static int 3396134Scasper priv_policy_override_set(const cred_t *cr, const priv_set_t *req, ...) 3406134Scasper { 3416134Scasper va_list ap; 3426134Scasper 3436134Scasper if (CR_FLAGS(cr) & PRIV_XPOLICY) { 3446134Scasper va_start(ap, req); 3456134Scasper return (klpd_call(cr, req, ap)); 3466134Scasper } 3476134Scasper return (-1); 3486134Scasper } 3496134Scasper 3506134Scasper /* 3510Sstevel@tonic-gate * Audit failure, log error message. 3520Sstevel@tonic-gate */ 3530Sstevel@tonic-gate static void 3540Sstevel@tonic-gate priv_policy_err(const cred_t *cr, int priv, boolean_t allzone, const char *msg) 3550Sstevel@tonic-gate { 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate if (audit_active) 3580Sstevel@tonic-gate audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 0); 3590Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || 3620Sstevel@tonic-gate curthread->t_pre_sys) { 3630Sstevel@tonic-gate if (allzone && !HAS_ALLZONEPRIVS(cr)) { 3640Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_ALLZONE, msg); 3650Sstevel@tonic-gate } else { 3660Sstevel@tonic-gate ASSERT(!HAS_PRIVILEGE(cr, priv)); 3670Sstevel@tonic-gate priv_policy_errmsg(cr, priv, msg); 3680Sstevel@tonic-gate } 3690Sstevel@tonic-gate } 3700Sstevel@tonic-gate } 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate /* 3736134Scasper * priv_policy_ap() 3740Sstevel@tonic-gate * return 0 or error. 3750Sstevel@tonic-gate * See block comment above for a description of "priv" and "allzone" usage. 3760Sstevel@tonic-gate */ 3776134Scasper static int 3786134Scasper priv_policy_ap(const cred_t *cr, int priv, boolean_t allzone, int err, 3796134Scasper const char *msg, va_list ap) 3800Sstevel@tonic-gate { 3816134Scasper if ((HAS_PRIVILEGE(cr, priv) && (!allzone || HAS_ALLZONEPRIVS(cr))) || 3826134Scasper (!servicing_interrupt() && 3836134Scasper priv_policy_override(cr, priv, allzone, ap) == 0)) { 3840Sstevel@tonic-gate if ((allzone || priv == PRIV_ALL || 3850Sstevel@tonic-gate !PRIV_ISASSERT(priv_basic, priv)) && 3860Sstevel@tonic-gate !servicing_interrupt()) { 3873446Smrj PTOU(curproc)->u_acflag |= ASU; /* Needed for SVVS */ 3880Sstevel@tonic-gate if (audit_active) 3890Sstevel@tonic-gate audit_priv(priv, 3900Sstevel@tonic-gate allzone ? ZONEPRIVS(cr) : NULL, 1); 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate err = 0; 3930Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 3940Sstevel@tonic-gate } else if (!servicing_interrupt()) { 3950Sstevel@tonic-gate /* Failure audited in this procedure */ 3960Sstevel@tonic-gate priv_policy_err(cr, priv, allzone, msg); 3970Sstevel@tonic-gate } 3986134Scasper return (err); 3996134Scasper } 4000Sstevel@tonic-gate 4016134Scasper int 4026134Scasper priv_policy_va(const cred_t *cr, int priv, boolean_t allzone, int err, 4036134Scasper const char *msg, ...) 4046134Scasper { 4056134Scasper int ret; 4066134Scasper va_list ap; 4076134Scasper 4086134Scasper va_start(ap, msg); 4096134Scasper ret = priv_policy_ap(cr, priv, allzone, err, msg, ap); 4106134Scasper va_end(ap); 4116134Scasper 4126134Scasper return (ret); 4136134Scasper } 4146134Scasper 4156134Scasper int 4166134Scasper priv_policy(const cred_t *cr, int priv, boolean_t allzone, int err, 4176134Scasper const char *msg) 4186134Scasper { 4196134Scasper return (priv_policy_va(cr, priv, allzone, err, msg, KLPDARG_NOMORE)); 4200Sstevel@tonic-gate } 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate /* 4230Sstevel@tonic-gate * Return B_TRUE for sufficient privileges, B_FALSE for insufficient privileges. 4240Sstevel@tonic-gate */ 4250Sstevel@tonic-gate boolean_t 4260Sstevel@tonic-gate priv_policy_choice(const cred_t *cr, int priv, boolean_t allzone) 4270Sstevel@tonic-gate { 4280Sstevel@tonic-gate boolean_t res = HAS_PRIVILEGE(cr, priv) && 4290Sstevel@tonic-gate (!allzone || HAS_ALLZONEPRIVS(cr)); 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate /* Audit success only */ 4320Sstevel@tonic-gate if (res && audit_active && 4330Sstevel@tonic-gate (allzone || priv == PRIV_ALL || !PRIV_ISASSERT(priv_basic, priv)) && 4340Sstevel@tonic-gate !servicing_interrupt()) { 4350Sstevel@tonic-gate audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 1); 4360Sstevel@tonic-gate } 4370Sstevel@tonic-gate if (res) { 4380Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 4390Sstevel@tonic-gate } else { 4400Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 4410Sstevel@tonic-gate } 4420Sstevel@tonic-gate return (res); 4430Sstevel@tonic-gate } 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate /* 4460Sstevel@tonic-gate * Non-auditing variant of priv_policy_choice(). 4470Sstevel@tonic-gate */ 4480Sstevel@tonic-gate boolean_t 4490Sstevel@tonic-gate priv_policy_only(const cred_t *cr, int priv, boolean_t allzone) 4500Sstevel@tonic-gate { 4510Sstevel@tonic-gate boolean_t res = HAS_PRIVILEGE(cr, priv) && 4520Sstevel@tonic-gate (!allzone || HAS_ALLZONEPRIVS(cr)); 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate if (res) { 4550Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 4560Sstevel@tonic-gate } else { 4570Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate return (res); 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate /* 4630Sstevel@tonic-gate * Check whether all privileges in the required set are present. 4640Sstevel@tonic-gate */ 4650Sstevel@tonic-gate static int 4660Sstevel@tonic-gate secpolicy_require_set(const cred_t *cr, const priv_set_t *req, const char *msg) 4670Sstevel@tonic-gate { 4680Sstevel@tonic-gate int priv; 4690Sstevel@tonic-gate int pfound = -1; 4700Sstevel@tonic-gate priv_set_t pset; 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate if (req == PRIV_FULLSET ? HAS_ALLPRIVS(cr) : priv_issubset(req, 4734543Smarks &CR_OEPRIV(cr))) { 4740Sstevel@tonic-gate return (0); 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate 4776134Scasper if (priv_policy_override_set(cr, req, KLPDARG_NOMORE) == 0) 4786134Scasper return (0); 4796134Scasper 4800Sstevel@tonic-gate if (req == PRIV_FULLSET || priv_isfullset(req)) { 4810Sstevel@tonic-gate priv_policy_err(cr, PRIV_ALL, B_FALSE, msg); 4820Sstevel@tonic-gate return (EACCES); 4830Sstevel@tonic-gate } 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate pset = CR_OEPRIV(cr); /* present privileges */ 4860Sstevel@tonic-gate priv_inverse(&pset); /* all non present privileges */ 4870Sstevel@tonic-gate priv_intersect(req, &pset); /* the actual missing privs */ 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate if (audit_active) 4900Sstevel@tonic-gate audit_priv(PRIV_NONE, &pset, 0); 4910Sstevel@tonic-gate /* 4920Sstevel@tonic-gate * Privilege debugging; special case "one privilege in set". 4930Sstevel@tonic-gate */ 4940Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || curthread->t_pre_sys) { 4950Sstevel@tonic-gate for (priv = 0; priv < nprivs; priv++) { 4960Sstevel@tonic-gate if (priv_ismember(&pset, priv)) { 4970Sstevel@tonic-gate if (pfound != -1) { 4980Sstevel@tonic-gate /* Multiple missing privs */ 4990Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_MULTIPLE, 5004543Smarks msg); 5010Sstevel@tonic-gate return (EACCES); 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate pfound = priv; 5040Sstevel@tonic-gate } 5050Sstevel@tonic-gate } 5060Sstevel@tonic-gate ASSERT(pfound != -1); 5070Sstevel@tonic-gate /* Just the one missing privilege */ 5080Sstevel@tonic-gate priv_policy_errmsg(cr, pfound, msg); 5090Sstevel@tonic-gate } 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate return (EACCES); 5120Sstevel@tonic-gate } 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate /* 5150Sstevel@tonic-gate * Called when an operation requires that the caller be in the 5160Sstevel@tonic-gate * global zone, regardless of privilege. 5170Sstevel@tonic-gate */ 5180Sstevel@tonic-gate static int 5190Sstevel@tonic-gate priv_policy_global(const cred_t *cr) 5200Sstevel@tonic-gate { 5210Sstevel@tonic-gate if (crgetzoneid(cr) == GLOBAL_ZONEID) 5220Sstevel@tonic-gate return (0); /* success */ 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || 5250Sstevel@tonic-gate curthread->t_pre_sys) { 5260Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_GLOBAL, NULL); 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate return (EPERM); 5290Sstevel@tonic-gate } 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate /* 5320Sstevel@tonic-gate * Changing process priority 5330Sstevel@tonic-gate */ 5340Sstevel@tonic-gate int 5350Sstevel@tonic-gate secpolicy_setpriority(const cred_t *cr) 5360Sstevel@tonic-gate { 5370Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_PRIOCNTL, B_FALSE, EPERM, NULL)); 5380Sstevel@tonic-gate } 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate /* 5410Sstevel@tonic-gate * Binding to a privileged port, port must be specified in host byte 5420Sstevel@tonic-gate * order. 5430Sstevel@tonic-gate */ 5440Sstevel@tonic-gate int 5456134Scasper secpolicy_net_privaddr(const cred_t *cr, in_port_t port, int proto) 5460Sstevel@tonic-gate { 5475331Samw char *reason; 5485331Samw int priv; 5495331Samw 5505331Samw switch (port) { 5515331Samw case 137: 5525331Samw case 138: 5535331Samw case 139: 5545331Samw case 445: 5555331Samw /* 5565331Samw * NBT and SMB ports, these are extra privileged ports, 5575331Samw * allow bind only if the SYS_SMB privilege is present. 5585331Samw */ 5595331Samw priv = PRIV_SYS_SMB; 5605331Samw reason = "NBT or SMB port"; 5615331Samw break; 5625331Samw 5635331Samw case 2049: 5645331Samw case 4045: 5655331Samw /* 5665331Samw * NFS ports, these are extra privileged ports, allow bind 5675331Samw * only if the SYS_NFS privilege is present. 5685331Samw */ 5695331Samw priv = PRIV_SYS_NFS; 5705331Samw reason = "NFS port"; 5715331Samw break; 5725331Samw 5735331Samw default: 5745331Samw priv = PRIV_NET_PRIVADDR; 5755331Samw reason = NULL; 5765331Samw break; 5775331Samw 5785331Samw } 5795331Samw 5806134Scasper return (priv_policy_va(cr, priv, B_FALSE, EACCES, reason, 5816134Scasper KLPDARG_PORT, (int)proto, (int)port, KLPDARG_NOMORE)); 5820Sstevel@tonic-gate } 5830Sstevel@tonic-gate 5840Sstevel@tonic-gate /* 5851676Sjpk * Binding to a multilevel port on a trusted (labeled) system. 5861676Sjpk */ 5871676Sjpk int 5881676Sjpk secpolicy_net_bindmlp(const cred_t *cr) 5891676Sjpk { 5906134Scasper return (PRIV_POLICY(cr, PRIV_NET_BINDMLP, B_FALSE, EACCES, NULL)); 5911676Sjpk } 5921676Sjpk 5931676Sjpk /* 5941676Sjpk * Allow a communication between a zone and an unlabeled host when their 5951676Sjpk * labels don't match. 5961676Sjpk */ 5971676Sjpk int 5981676Sjpk secpolicy_net_mac_aware(const cred_t *cr) 5991676Sjpk { 6006134Scasper return (PRIV_POLICY(cr, PRIV_NET_MAC_AWARE, B_FALSE, EACCES, NULL)); 6011676Sjpk } 6021676Sjpk 6031676Sjpk /* 6040Sstevel@tonic-gate * Common routine which determines whether a given credential can 6050Sstevel@tonic-gate * act on a given mount. 6060Sstevel@tonic-gate * When called through mount, the parameter needoptcheck is a pointer 6070Sstevel@tonic-gate * to a boolean variable which will be set to either true or false, 6080Sstevel@tonic-gate * depending on whether the mount policy should change the mount options. 6090Sstevel@tonic-gate * In all other cases, needoptcheck should be a NULL pointer. 6100Sstevel@tonic-gate */ 6110Sstevel@tonic-gate static int 6120Sstevel@tonic-gate secpolicy_fs_common(cred_t *cr, vnode_t *mvp, const vfs_t *vfsp, 6130Sstevel@tonic-gate boolean_t *needoptcheck) 6140Sstevel@tonic-gate { 6150Sstevel@tonic-gate boolean_t allzone = B_FALSE; 6160Sstevel@tonic-gate boolean_t mounting = needoptcheck != NULL; 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate /* 6190Sstevel@tonic-gate * Short circuit the following cases: 6200Sstevel@tonic-gate * vfsp == NULL or mvp == NULL (pure privilege check) 6210Sstevel@tonic-gate * have all privileges - no further checks required 6220Sstevel@tonic-gate * and no mount options need to be set. 6230Sstevel@tonic-gate */ 6240Sstevel@tonic-gate if (vfsp == NULL || mvp == NULL || HAS_ALLPRIVS(cr)) { 6250Sstevel@tonic-gate if (mounting) 6260Sstevel@tonic-gate *needoptcheck = B_FALSE; 6270Sstevel@tonic-gate 6286134Scasper return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM, 6296134Scasper NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE)); 6300Sstevel@tonic-gate } 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate /* 6330Sstevel@tonic-gate * When operating on an existing mount (either we're not mounting 6340Sstevel@tonic-gate * or we're doing a remount and VFS_REMOUNT will be set), zones 6350Sstevel@tonic-gate * can operate only on mounts established by the zone itself. 6360Sstevel@tonic-gate */ 6370Sstevel@tonic-gate if (!mounting || (vfsp->vfs_flag & VFS_REMOUNT) != 0) { 6380Sstevel@tonic-gate zoneid_t zoneid = crgetzoneid(cr); 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate if (zoneid != GLOBAL_ZONEID && 6410Sstevel@tonic-gate vfsp->vfs_zone->zone_id != zoneid) { 6420Sstevel@tonic-gate return (EPERM); 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate } 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate if (mounting) 6470Sstevel@tonic-gate *needoptcheck = B_TRUE; 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate /* 6500Sstevel@tonic-gate * Overlay mounts may hide important stuff; if you can't write to a 6510Sstevel@tonic-gate * mount point but would be able to mount on top of it, you can 6520Sstevel@tonic-gate * escalate your privileges. 6530Sstevel@tonic-gate * So we go about asking the same questions namefs does when it 6540Sstevel@tonic-gate * decides whether you can mount over a file or not but with the 6550Sstevel@tonic-gate * added restriction that you can only mount on top of a regular 6560Sstevel@tonic-gate * file or directory. 6570Sstevel@tonic-gate * If we have all the zone's privileges, we skip all other checks, 6580Sstevel@tonic-gate * or else we may actually get in trouble inside the automounter. 6590Sstevel@tonic-gate */ 6600Sstevel@tonic-gate if ((mvp->v_flag & VROOT) != 0 || 6610Sstevel@tonic-gate (mvp->v_type != VDIR && mvp->v_type != VREG) || 6620Sstevel@tonic-gate HAS_ALLZONEPRIVS(cr)) { 6630Sstevel@tonic-gate allzone = B_TRUE; 6640Sstevel@tonic-gate } else { 6650Sstevel@tonic-gate vattr_t va; 6660Sstevel@tonic-gate int err; 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate va.va_mask = AT_UID|AT_MODE; 6695331Samw err = VOP_GETATTR(mvp, &va, 0, cr, NULL); 6700Sstevel@tonic-gate if (err != 0) 6710Sstevel@tonic-gate return (err); 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate if ((err = secpolicy_vnode_owner(cr, va.va_uid)) != 0) 6740Sstevel@tonic-gate return (err); 6750Sstevel@tonic-gate 6760Sstevel@tonic-gate if ((va.va_mode & VWRITE) == 0 && 6770Sstevel@tonic-gate secpolicy_vnode_access(cr, mvp, va.va_uid, VWRITE) != 0) { 6780Sstevel@tonic-gate return (EACCES); 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate } 6816134Scasper return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM, 6826134Scasper NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE)); 6830Sstevel@tonic-gate } 6840Sstevel@tonic-gate 6854543Smarks void 6864543Smarks secpolicy_fs_mount_clearopts(cred_t *cr, struct vfs *vfsp) 6874543Smarks { 6884543Smarks boolean_t amsuper = HAS_ALLZONEPRIVS(cr); 6894543Smarks 6904543Smarks /* 6914543Smarks * check; if we don't have either "nosuid" or 6924543Smarks * both "nosetuid" and "nodevices", then we add 6934543Smarks * "nosuid"; this depends on how the current 6944543Smarks * implementation works (it first checks nosuid). In a 6954543Smarks * zone, a user with all zone privileges can mount with 6964543Smarks * "setuid" but never with "devices". 6974543Smarks */ 6984543Smarks if (!vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL) && 6994543Smarks (!vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL) || 7004543Smarks !vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL))) { 7014543Smarks if (crgetzoneid(cr) == GLOBAL_ZONEID || !amsuper) 7024543Smarks vfs_setmntopt(vfsp, MNTOPT_NOSUID, NULL, 0); 7034543Smarks else 7044543Smarks vfs_setmntopt(vfsp, MNTOPT_NODEVICES, NULL, 0); 7054543Smarks } 7064543Smarks /* 7074543Smarks * If we're not the local super user, we set the "restrict" 7084543Smarks * option to indicate to automountd that this mount should 7094543Smarks * be handled with care. 7104543Smarks */ 7114543Smarks if (!amsuper) 7124543Smarks vfs_setmntopt(vfsp, MNTOPT_RESTRICT, NULL, 0); 7134543Smarks 7144543Smarks } 7154543Smarks 716148Scasper extern vnode_t *rootvp; 717148Scasper extern vfs_t *rootvfs; 718148Scasper 7190Sstevel@tonic-gate int 7200Sstevel@tonic-gate secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct vfs *vfsp) 7210Sstevel@tonic-gate { 7220Sstevel@tonic-gate boolean_t needoptchk; 7230Sstevel@tonic-gate int error; 7240Sstevel@tonic-gate 725148Scasper /* 726148Scasper * If it's a remount, get the underlying mount point, 727148Scasper * except for the root where we use the rootvp. 728148Scasper */ 729148Scasper if ((vfsp->vfs_flag & VFS_REMOUNT) != 0) { 730148Scasper if (vfsp == rootvfs) 731148Scasper mvp = rootvp; 732148Scasper else 733148Scasper mvp = vfsp->vfs_vnodecovered; 734148Scasper } 735148Scasper 7360Sstevel@tonic-gate error = secpolicy_fs_common(cr, mvp, vfsp, &needoptchk); 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate if (error == 0 && needoptchk) { 7394543Smarks secpolicy_fs_mount_clearopts(cr, vfsp); 7404543Smarks } 7410Sstevel@tonic-gate 7420Sstevel@tonic-gate return (error); 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate /* 7460Sstevel@tonic-gate * Does the policy computations for "ownership" of a mount; 7470Sstevel@tonic-gate * here ownership is defined as the ability to "mount" 7480Sstevel@tonic-gate * the filesystem originally. The rootvfs doesn't cover any 7490Sstevel@tonic-gate * vnodes; we attribute its ownership to the rootvp. 7500Sstevel@tonic-gate */ 7510Sstevel@tonic-gate static int 7520Sstevel@tonic-gate secpolicy_fs_owner(cred_t *cr, const struct vfs *vfsp) 7530Sstevel@tonic-gate { 7540Sstevel@tonic-gate vnode_t *mvp; 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate if (vfsp == NULL) 7570Sstevel@tonic-gate mvp = NULL; 7580Sstevel@tonic-gate else if (vfsp == rootvfs) 7590Sstevel@tonic-gate mvp = rootvp; 7600Sstevel@tonic-gate else 7610Sstevel@tonic-gate mvp = vfsp->vfs_vnodecovered; 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate return (secpolicy_fs_common(cr, mvp, vfsp, NULL)); 7640Sstevel@tonic-gate } 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate int 7670Sstevel@tonic-gate secpolicy_fs_unmount(cred_t *cr, struct vfs *vfsp) 7680Sstevel@tonic-gate { 7690Sstevel@tonic-gate return (secpolicy_fs_owner(cr, vfsp)); 7700Sstevel@tonic-gate } 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate /* 7730Sstevel@tonic-gate * Quotas are a resource, but if one has the ability to mount a filesystem, he 7740Sstevel@tonic-gate * should be able to modify quotas on it. 7750Sstevel@tonic-gate */ 7760Sstevel@tonic-gate int 7770Sstevel@tonic-gate secpolicy_fs_quota(const cred_t *cr, const vfs_t *vfsp) 7780Sstevel@tonic-gate { 7790Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 7800Sstevel@tonic-gate } 7810Sstevel@tonic-gate 7820Sstevel@tonic-gate /* 7830Sstevel@tonic-gate * Exceeding minfree: also a per-mount resource constraint. 7840Sstevel@tonic-gate */ 7850Sstevel@tonic-gate int 7860Sstevel@tonic-gate secpolicy_fs_minfree(const cred_t *cr, const vfs_t *vfsp) 7870Sstevel@tonic-gate { 7880Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate int 7920Sstevel@tonic-gate secpolicy_fs_config(const cred_t *cr, const vfs_t *vfsp) 7930Sstevel@tonic-gate { 7940Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 7950Sstevel@tonic-gate } 7960Sstevel@tonic-gate 7970Sstevel@tonic-gate /* ARGSUSED */ 7980Sstevel@tonic-gate int 7990Sstevel@tonic-gate secpolicy_fs_linkdir(const cred_t *cr, const vfs_t *vfsp) 8000Sstevel@tonic-gate { 8010Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_LINKDIR, B_FALSE, EPERM, NULL)); 8020Sstevel@tonic-gate } 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate /* 8050Sstevel@tonic-gate * Name: secpolicy_vnode_access() 8060Sstevel@tonic-gate * 8070Sstevel@tonic-gate * Parameters: Process credential 8080Sstevel@tonic-gate * vnode 8090Sstevel@tonic-gate * uid of owner of vnode 8100Sstevel@tonic-gate * permission bits not granted to the caller when examining 8110Sstevel@tonic-gate * file mode bits (i.e., when a process wants to open a 8120Sstevel@tonic-gate * mode 444 file for VREAD|VWRITE, this function should be 8130Sstevel@tonic-gate * called only with a VWRITE argument). 8140Sstevel@tonic-gate * 8150Sstevel@tonic-gate * Normal: Verifies that cred has the appropriate privileges to 8160Sstevel@tonic-gate * override the mode bits that were denied. 8170Sstevel@tonic-gate * 8180Sstevel@tonic-gate * Override: file_dac_execute - if VEXEC bit was denied and vnode is 8190Sstevel@tonic-gate * not a directory. 8200Sstevel@tonic-gate * file_dac_read - if VREAD bit was denied. 8210Sstevel@tonic-gate * file_dac_search - if VEXEC bit was denied and vnode is 8220Sstevel@tonic-gate * a directory. 8230Sstevel@tonic-gate * file_dac_write - if VWRITE bit was denied. 8240Sstevel@tonic-gate * 8250Sstevel@tonic-gate * Root owned files are special cased to protect system 8260Sstevel@tonic-gate * configuration files and such. 8270Sstevel@tonic-gate * 8280Sstevel@tonic-gate * Output: EACCES - if privilege check fails. 8290Sstevel@tonic-gate */ 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate /* ARGSUSED */ 8320Sstevel@tonic-gate int 8330Sstevel@tonic-gate secpolicy_vnode_access(const cred_t *cr, vnode_t *vp, uid_t owner, mode_t mode) 8340Sstevel@tonic-gate { 8356134Scasper if ((mode & VREAD) && priv_policy_va(cr, PRIV_FILE_DAC_READ, B_FALSE, 8366134Scasper EACCES, NULL, KLPDARG_VNODE, vp, (char *)NULL, 8376134Scasper KLPDARG_NOMORE) != 0) { 8380Sstevel@tonic-gate return (EACCES); 8396134Scasper } 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate if (mode & VWRITE) { 8420Sstevel@tonic-gate boolean_t allzone; 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate if (owner == 0 && cr->cr_uid != 0) 8450Sstevel@tonic-gate allzone = B_TRUE; 8460Sstevel@tonic-gate else 8470Sstevel@tonic-gate allzone = B_FALSE; 8486134Scasper if (priv_policy_va(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES, 8496134Scasper NULL, KLPDARG_VNODE, vp, (char *)NULL, 8506134Scasper KLPDARG_NOMORE) != 0) { 8510Sstevel@tonic-gate return (EACCES); 8526134Scasper } 8530Sstevel@tonic-gate } 8540Sstevel@tonic-gate 8550Sstevel@tonic-gate if (mode & VEXEC) { 8560Sstevel@tonic-gate /* 8570Sstevel@tonic-gate * Directories use file_dac_search to override the execute bit. 8580Sstevel@tonic-gate */ 8596134Scasper int p = vp->v_type == VDIR ? PRIV_FILE_DAC_SEARCH : 8606134Scasper PRIV_FILE_DAC_EXECUTE; 8610Sstevel@tonic-gate 8626134Scasper return (priv_policy_va(cr, p, B_FALSE, EACCES, NULL, 8636134Scasper KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE)); 8640Sstevel@tonic-gate } 8650Sstevel@tonic-gate return (0); 8660Sstevel@tonic-gate } 8670Sstevel@tonic-gate 8680Sstevel@tonic-gate /* 8690Sstevel@tonic-gate * Name: secpolicy_vnode_setid_modify() 8700Sstevel@tonic-gate * 8710Sstevel@tonic-gate * Normal: verify that subject can set the file setid flags. 8720Sstevel@tonic-gate * 8730Sstevel@tonic-gate * Output: EPERM - if not privileged. 8740Sstevel@tonic-gate */ 8750Sstevel@tonic-gate 8760Sstevel@tonic-gate static int 8770Sstevel@tonic-gate secpolicy_vnode_setid_modify(const cred_t *cr, uid_t owner) 8780Sstevel@tonic-gate { 8790Sstevel@tonic-gate /* If changing to suid root, must have all zone privs */ 8800Sstevel@tonic-gate boolean_t allzone = B_TRUE; 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate if (owner != 0) { 8830Sstevel@tonic-gate if (owner == cr->cr_uid) 8840Sstevel@tonic-gate return (0); 8850Sstevel@tonic-gate allzone = B_FALSE; 8860Sstevel@tonic-gate } 8870Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_SETID, allzone, EPERM, NULL)); 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate /* 8910Sstevel@tonic-gate * Are we allowed to retain the set-uid/set-gid bits when 8920Sstevel@tonic-gate * changing ownership or when writing to a file? 8930Sstevel@tonic-gate * "issuid" should be true when set-uid; only in that case 8940Sstevel@tonic-gate * root ownership is checked (setgid is assumed). 8950Sstevel@tonic-gate */ 8960Sstevel@tonic-gate int 8970Sstevel@tonic-gate secpolicy_vnode_setid_retain(const cred_t *cred, boolean_t issuidroot) 8980Sstevel@tonic-gate { 8990Sstevel@tonic-gate if (issuidroot && !HAS_ALLZONEPRIVS(cred)) 9000Sstevel@tonic-gate return (EPERM); 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate return (!PRIV_POLICY_CHOICE(cred, PRIV_FILE_SETID, B_FALSE)); 9030Sstevel@tonic-gate } 9040Sstevel@tonic-gate 9050Sstevel@tonic-gate /* 9060Sstevel@tonic-gate * Name: secpolicy_vnode_setids_setgids() 9070Sstevel@tonic-gate * 9080Sstevel@tonic-gate * Normal: verify that subject can set the file setgid flag. 9090Sstevel@tonic-gate * 9100Sstevel@tonic-gate * Output: EPERM - if not privileged 9110Sstevel@tonic-gate */ 9120Sstevel@tonic-gate 9130Sstevel@tonic-gate int 9140Sstevel@tonic-gate secpolicy_vnode_setids_setgids(const cred_t *cred, gid_t gid) 9150Sstevel@tonic-gate { 9160Sstevel@tonic-gate if (!groupmember(gid, cred)) 9170Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_SETID, B_FALSE, EPERM, 9180Sstevel@tonic-gate NULL)); 9190Sstevel@tonic-gate return (0); 9200Sstevel@tonic-gate } 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate /* 9230Sstevel@tonic-gate * Create a file with a group different than any of the groups allowed: 9240Sstevel@tonic-gate * the group of the directory the file is created in, the effective 9250Sstevel@tonic-gate * group or any of the supplementary groups. 9260Sstevel@tonic-gate */ 9270Sstevel@tonic-gate int 9280Sstevel@tonic-gate secpolicy_vnode_create_gid(const cred_t *cred) 9290Sstevel@tonic-gate { 9300Sstevel@tonic-gate if (HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN)) 9310Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_CHOWN, B_FALSE, EPERM, 9320Sstevel@tonic-gate NULL)); 9330Sstevel@tonic-gate else 9340Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_CHOWN_SELF, B_FALSE, EPERM, 9350Sstevel@tonic-gate NULL)); 9360Sstevel@tonic-gate } 9370Sstevel@tonic-gate 9380Sstevel@tonic-gate /* 9390Sstevel@tonic-gate * Name: secpolicy_vnode_utime_modify() 9400Sstevel@tonic-gate * 9410Sstevel@tonic-gate * Normal: verify that subject can modify the utime on a file. 9420Sstevel@tonic-gate * 9430Sstevel@tonic-gate * Output: EPERM - if access denied. 9440Sstevel@tonic-gate */ 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate static int 9470Sstevel@tonic-gate secpolicy_vnode_utime_modify(const cred_t *cred) 9480Sstevel@tonic-gate { 9490Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_OWNER, B_FALSE, EPERM, 9500Sstevel@tonic-gate "modify file times")); 9510Sstevel@tonic-gate } 9520Sstevel@tonic-gate 9530Sstevel@tonic-gate 9540Sstevel@tonic-gate /* 9550Sstevel@tonic-gate * Name: secpolicy_vnode_setdac() 9560Sstevel@tonic-gate * 9570Sstevel@tonic-gate * Normal: verify that subject can modify the mode of a file. 9580Sstevel@tonic-gate * allzone privilege needed when modifying root owned object. 9590Sstevel@tonic-gate * 9600Sstevel@tonic-gate * Output: EPERM - if access denied. 9610Sstevel@tonic-gate */ 9620Sstevel@tonic-gate 9630Sstevel@tonic-gate int 9640Sstevel@tonic-gate secpolicy_vnode_setdac(const cred_t *cred, uid_t owner) 9650Sstevel@tonic-gate { 9660Sstevel@tonic-gate if (owner == cred->cr_uid) 9670Sstevel@tonic-gate return (0); 9680Sstevel@tonic-gate 9690Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_OWNER, owner == 0, EPERM, NULL)); 9700Sstevel@tonic-gate } 9710Sstevel@tonic-gate /* 9720Sstevel@tonic-gate * Name: secpolicy_vnode_stky_modify() 9730Sstevel@tonic-gate * 9740Sstevel@tonic-gate * Normal: verify that subject can make a file a "sticky". 9750Sstevel@tonic-gate * 9760Sstevel@tonic-gate * Output: EPERM - if access denied. 9770Sstevel@tonic-gate */ 9780Sstevel@tonic-gate 9790Sstevel@tonic-gate int 9800Sstevel@tonic-gate secpolicy_vnode_stky_modify(const cred_t *cred) 9810Sstevel@tonic-gate { 9820Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_SYS_CONFIG, B_FALSE, EPERM, 9830Sstevel@tonic-gate "set file sticky")); 9840Sstevel@tonic-gate } 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate /* 9870Sstevel@tonic-gate * Policy determines whether we can remove an entry from a directory, 9880Sstevel@tonic-gate * regardless of permission bits. 9890Sstevel@tonic-gate */ 9900Sstevel@tonic-gate int 9910Sstevel@tonic-gate secpolicy_vnode_remove(const cred_t *cr) 9920Sstevel@tonic-gate { 9930Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_OWNER, B_FALSE, EACCES, 9940Sstevel@tonic-gate "sticky directory")); 9950Sstevel@tonic-gate } 9960Sstevel@tonic-gate 9970Sstevel@tonic-gate int 9980Sstevel@tonic-gate secpolicy_vnode_owner(const cred_t *cr, uid_t owner) 9990Sstevel@tonic-gate { 10000Sstevel@tonic-gate boolean_t allzone = (owner == 0); 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate if (owner == cr->cr_uid) 10030Sstevel@tonic-gate return (0); 10040Sstevel@tonic-gate 10050Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_OWNER, allzone, EPERM, NULL)); 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate 10081115Smarks void 10091115Smarks secpolicy_setid_clear(vattr_t *vap, cred_t *cr) 10101115Smarks { 10111115Smarks if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0 && 10121115Smarks secpolicy_vnode_setid_retain(cr, 10131115Smarks (vap->va_mode & S_ISUID) != 0 && 10141115Smarks (vap->va_mask & AT_UID) != 0 && vap->va_uid == 0) != 0) { 10151115Smarks vap->va_mask |= AT_MODE; 10161115Smarks vap->va_mode &= ~(S_ISUID|S_ISGID); 10171115Smarks } 10181115Smarks } 10191115Smarks 10202796Smarks int 10212796Smarks secpolicy_setid_setsticky_clear(vnode_t *vp, vattr_t *vap, const vattr_t *ovap, 10222796Smarks cred_t *cr) 10232796Smarks { 10242796Smarks int error; 10252796Smarks 10262796Smarks if ((vap->va_mode & S_ISUID) != 0 && 10272796Smarks (error = secpolicy_vnode_setid_modify(cr, 10282796Smarks ovap->va_uid)) != 0) { 10292796Smarks return (error); 10302796Smarks } 10312796Smarks 10322796Smarks /* 10332796Smarks * Check privilege if attempting to set the 10342796Smarks * sticky bit on a non-directory. 10352796Smarks */ 10362796Smarks if (vp->v_type != VDIR && (vap->va_mode & S_ISVTX) != 0 && 10372796Smarks secpolicy_vnode_stky_modify(cr) != 0) { 10384543Smarks vap->va_mode &= ~S_ISVTX; 10392796Smarks } 10402796Smarks 10412796Smarks /* 10422796Smarks * Check for privilege if attempting to set the 10432796Smarks * group-id bit. 10442796Smarks */ 10452796Smarks if ((vap->va_mode & S_ISGID) != 0 && 10462796Smarks secpolicy_vnode_setids_setgids(cr, ovap->va_gid) != 0) { 10474543Smarks vap->va_mode &= ~S_ISGID; 10482796Smarks } 10492796Smarks 10502796Smarks return (0); 10512796Smarks } 10522796Smarks 10535331Samw #define ATTR_FLAG_PRIV(attr, value, cr) \ 10545331Samw PRIV_POLICY(cr, value ? PRIV_FILE_FLAG_SET : PRIV_ALL, \ 10555331Samw B_FALSE, EPERM, NULL) 10565331Samw 10575331Samw /* 10585331Samw * Check privileges for setting xvattr attributes 10595331Samw */ 10605331Samw int 10615331Samw secpolicy_xvattr(xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype) 10625331Samw { 10635331Samw xoptattr_t *xoap; 10645331Samw int error = 0; 10655331Samw 10665331Samw if ((xoap = xva_getxoptattr(xvap)) == NULL) 10675331Samw return (EINVAL); 10685331Samw 10695331Samw /* 10705331Samw * First process the DOS bits 10715331Samw */ 10725331Samw if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE) || 10735331Samw XVA_ISSET_REQ(xvap, XAT_HIDDEN) || 10745331Samw XVA_ISSET_REQ(xvap, XAT_READONLY) || 10755331Samw XVA_ISSET_REQ(xvap, XAT_SYSTEM) || 10765331Samw XVA_ISSET_REQ(xvap, XAT_CREATETIME)) { 10775331Samw if ((error = secpolicy_vnode_owner(cr, owner)) != 0) 10785331Samw return (error); 10795331Samw } 10805331Samw 10815331Samw /* 10825331Samw * Now handle special attributes 10835331Samw */ 10845331Samw 10855331Samw if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) 10865331Samw error = ATTR_FLAG_PRIV(XAT_IMMUTABLE, 10875331Samw xoap->xoa_immutable, cr); 10885331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) 10895331Samw error = ATTR_FLAG_PRIV(XAT_NOUNLINK, 10905331Samw xoap->xoa_nounlink, cr); 10915331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) 10925331Samw error = ATTR_FLAG_PRIV(XAT_APPENDONLY, 10935331Samw xoap->xoa_appendonly, cr); 10945331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NODUMP)) 10955331Samw error = ATTR_FLAG_PRIV(XAT_NODUMP, 10965331Samw xoap->xoa_nodump, cr); 10975331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_OPAQUE)) 10985331Samw error = EPERM; 10995331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) { 11005331Samw error = ATTR_FLAG_PRIV(XAT_AV_QUARANTINED, 11015331Samw xoap->xoa_av_quarantined, cr); 11025545Smarks if (error == 0 && vtype != VREG && xoap->xoa_av_quarantined) 11035331Samw error = EINVAL; 11045331Samw } 11055331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) 11065331Samw error = ATTR_FLAG_PRIV(XAT_AV_MODIFIED, 11075331Samw xoap->xoa_av_modified, cr); 11085331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) { 11095331Samw error = ATTR_FLAG_PRIV(XAT_AV_SCANSTAMP, 11105331Samw xoap->xoa_av_scanstamp, cr); 11115331Samw if (error == 0 && vtype != VREG) 11125331Samw error = EINVAL; 11135331Samw } 11145331Samw return (error); 11155331Samw } 11165331Samw 11170Sstevel@tonic-gate /* 11180Sstevel@tonic-gate * This function checks the policy decisions surrounding the 11190Sstevel@tonic-gate * vop setattr call. 11200Sstevel@tonic-gate * 11210Sstevel@tonic-gate * It should be called after sufficient locks have been established 11220Sstevel@tonic-gate * on the underlying data structures. No concurrent modifications 11230Sstevel@tonic-gate * should be allowed. 11240Sstevel@tonic-gate * 11250Sstevel@tonic-gate * The caller must pass in unlocked version of its vaccess function 11260Sstevel@tonic-gate * this is required because vop_access function should lock the 11270Sstevel@tonic-gate * node for reading. A three argument function should be defined 11280Sstevel@tonic-gate * which accepts the following argument: 11290Sstevel@tonic-gate * A pointer to the internal "node" type (inode *) 11300Sstevel@tonic-gate * vnode access bits (VREAD|VWRITE|VEXEC) 11310Sstevel@tonic-gate * a pointer to the credential 11320Sstevel@tonic-gate * 11330Sstevel@tonic-gate * This function makes the following policy decisions: 11340Sstevel@tonic-gate * 11350Sstevel@tonic-gate * - change permissions 11360Sstevel@tonic-gate * - permission to change file mode if not owner 11370Sstevel@tonic-gate * - permission to add sticky bit to non-directory 11380Sstevel@tonic-gate * - permission to add set-gid bit 11390Sstevel@tonic-gate * 11400Sstevel@tonic-gate * The ovap argument should include AT_MODE|AT_UID|AT_GID. 11410Sstevel@tonic-gate * 11420Sstevel@tonic-gate * If the vap argument does not include AT_MODE, the mode will be copied from 11430Sstevel@tonic-gate * ovap. In certain situations set-uid/set-gid bits need to be removed; 11440Sstevel@tonic-gate * this is done by marking vap->va_mask to include AT_MODE and va_mode 11450Sstevel@tonic-gate * is updated to the newly computed mode. 11460Sstevel@tonic-gate */ 11470Sstevel@tonic-gate 11480Sstevel@tonic-gate int 11490Sstevel@tonic-gate secpolicy_vnode_setattr(cred_t *cr, struct vnode *vp, struct vattr *vap, 11500Sstevel@tonic-gate const struct vattr *ovap, int flags, 11510Sstevel@tonic-gate int unlocked_access(void *, int, cred_t *), 11520Sstevel@tonic-gate void *node) 11530Sstevel@tonic-gate { 11540Sstevel@tonic-gate int mask = vap->va_mask; 11550Sstevel@tonic-gate int error = 0; 11565331Samw boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE; 11570Sstevel@tonic-gate 11580Sstevel@tonic-gate if (mask & AT_SIZE) { 11590Sstevel@tonic-gate if (vp->v_type == VDIR) { 11600Sstevel@tonic-gate error = EISDIR; 11610Sstevel@tonic-gate goto out; 11620Sstevel@tonic-gate } 11635331Samw 11645331Samw /* 11655331Samw * If ATTR_NOACLCHECK is set in the flags, then we don't 11665331Samw * perform the secondary unlocked_access() call since the 11675331Samw * ACL (if any) is being checked there. 11685331Samw */ 11695331Samw if (skipaclchk == B_FALSE) { 11705331Samw error = unlocked_access(node, VWRITE, cr); 11715331Samw if (error) 11725331Samw goto out; 11735331Samw } 11740Sstevel@tonic-gate } 11750Sstevel@tonic-gate if (mask & AT_MODE) { 11760Sstevel@tonic-gate /* 11770Sstevel@tonic-gate * If not the owner of the file then check privilege 11780Sstevel@tonic-gate * for two things: the privilege to set the mode at all 11790Sstevel@tonic-gate * and, if we're setting setuid, we also need permissions 11800Sstevel@tonic-gate * to add the set-uid bit, if we're not the owner. 11810Sstevel@tonic-gate * In the specific case of creating a set-uid root 11820Sstevel@tonic-gate * file, we need even more permissions. 11830Sstevel@tonic-gate */ 11840Sstevel@tonic-gate if ((error = secpolicy_vnode_setdac(cr, ovap->va_uid)) != 0) 11850Sstevel@tonic-gate goto out; 11860Sstevel@tonic-gate 11872796Smarks if ((error = secpolicy_setid_setsticky_clear(vp, vap, 11882796Smarks ovap, cr)) != 0) 11890Sstevel@tonic-gate goto out; 11900Sstevel@tonic-gate } else 11910Sstevel@tonic-gate vap->va_mode = ovap->va_mode; 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate if (mask & (AT_UID|AT_GID)) { 11940Sstevel@tonic-gate boolean_t checkpriv = B_FALSE; 11950Sstevel@tonic-gate int priv; 11960Sstevel@tonic-gate boolean_t allzone = B_FALSE; 11970Sstevel@tonic-gate 11980Sstevel@tonic-gate /* 11990Sstevel@tonic-gate * Chowning files. 12000Sstevel@tonic-gate * 12010Sstevel@tonic-gate * If you are the file owner: 12020Sstevel@tonic-gate * chown to other uid FILE_CHOWN_SELF 12030Sstevel@tonic-gate * chown to gid (non-member) FILE_CHOWN_SELF 12040Sstevel@tonic-gate * chown to gid (member) <none> 12050Sstevel@tonic-gate * 12060Sstevel@tonic-gate * Instead of PRIV_FILE_CHOWN_SELF, FILE_CHOWN is also 12070Sstevel@tonic-gate * acceptable but the first one is reported when debugging. 12080Sstevel@tonic-gate * 12090Sstevel@tonic-gate * If you are not the file owner: 12100Sstevel@tonic-gate * chown from root PRIV_FILE_CHOWN + zone 12110Sstevel@tonic-gate * chown from other to any PRIV_FILE_CHOWN 12120Sstevel@tonic-gate * 12130Sstevel@tonic-gate */ 12140Sstevel@tonic-gate if (cr->cr_uid != ovap->va_uid) { 12150Sstevel@tonic-gate checkpriv = B_TRUE; 12160Sstevel@tonic-gate allzone = (ovap->va_uid == 0); 12170Sstevel@tonic-gate priv = PRIV_FILE_CHOWN; 12180Sstevel@tonic-gate } else { 12190Sstevel@tonic-gate if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) || 12200Sstevel@tonic-gate ((mask & AT_GID) && vap->va_gid != ovap->va_gid && 12210Sstevel@tonic-gate !groupmember(vap->va_gid, cr))) { 12220Sstevel@tonic-gate checkpriv = B_TRUE; 12230Sstevel@tonic-gate priv = HAS_PRIVILEGE(cr, PRIV_FILE_CHOWN) ? 12240Sstevel@tonic-gate PRIV_FILE_CHOWN : PRIV_FILE_CHOWN_SELF; 12250Sstevel@tonic-gate } 12260Sstevel@tonic-gate } 12270Sstevel@tonic-gate /* 12280Sstevel@tonic-gate * If necessary, check privilege to see if update can be done. 12290Sstevel@tonic-gate */ 12300Sstevel@tonic-gate if (checkpriv && 12310Sstevel@tonic-gate (error = PRIV_POLICY(cr, priv, allzone, EPERM, NULL)) 12320Sstevel@tonic-gate != 0) { 12330Sstevel@tonic-gate goto out; 12340Sstevel@tonic-gate } 12350Sstevel@tonic-gate 12360Sstevel@tonic-gate /* 12370Sstevel@tonic-gate * If the file has either the set UID or set GID bits 12380Sstevel@tonic-gate * set and the caller can set the bits, then leave them. 12390Sstevel@tonic-gate */ 12401115Smarks secpolicy_setid_clear(vap, cr); 12410Sstevel@tonic-gate } 12420Sstevel@tonic-gate if (mask & (AT_ATIME|AT_MTIME)) { 12430Sstevel@tonic-gate /* 12440Sstevel@tonic-gate * If not the file owner and not otherwise privileged, 12450Sstevel@tonic-gate * always return an error when setting the 12460Sstevel@tonic-gate * time other than the current (ATTR_UTIME flag set). 12470Sstevel@tonic-gate * If setting the current time (ATTR_UTIME not set) then 12480Sstevel@tonic-gate * unlocked_access will check permissions according to policy. 12490Sstevel@tonic-gate */ 12500Sstevel@tonic-gate if (cr->cr_uid != ovap->va_uid) { 12510Sstevel@tonic-gate if (flags & ATTR_UTIME) 12520Sstevel@tonic-gate error = secpolicy_vnode_utime_modify(cr); 12535331Samw else if (skipaclchk == B_FALSE) { 12540Sstevel@tonic-gate error = unlocked_access(node, VWRITE, cr); 12550Sstevel@tonic-gate if (error == EACCES && 12560Sstevel@tonic-gate secpolicy_vnode_utime_modify(cr) == 0) 12570Sstevel@tonic-gate error = 0; 12580Sstevel@tonic-gate } 12590Sstevel@tonic-gate if (error) 12600Sstevel@tonic-gate goto out; 12610Sstevel@tonic-gate } 12620Sstevel@tonic-gate } 12635331Samw 12645331Samw /* 12655331Samw * Check for optional attributes here by checking the following: 12665331Samw */ 12675331Samw if (mask & AT_XVATTR) 12685331Samw error = secpolicy_xvattr((xvattr_t *)vap, ovap->va_uid, cr, 12695331Samw vp->v_type); 12700Sstevel@tonic-gate out: 12710Sstevel@tonic-gate return (error); 12720Sstevel@tonic-gate } 12730Sstevel@tonic-gate 12740Sstevel@tonic-gate /* 12750Sstevel@tonic-gate * Name: secpolicy_pcfs_modify_bootpartition() 12760Sstevel@tonic-gate * 12770Sstevel@tonic-gate * Normal: verify that subject can modify a pcfs boot partition. 12780Sstevel@tonic-gate * 12790Sstevel@tonic-gate * Output: EACCES - if privilege check failed. 12800Sstevel@tonic-gate */ 12810Sstevel@tonic-gate /*ARGSUSED*/ 12820Sstevel@tonic-gate int 12830Sstevel@tonic-gate secpolicy_pcfs_modify_bootpartition(const cred_t *cred) 12840Sstevel@tonic-gate { 12850Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_ALL, B_FALSE, EACCES, 12860Sstevel@tonic-gate "modify pcfs boot partition")); 12870Sstevel@tonic-gate } 12880Sstevel@tonic-gate 12890Sstevel@tonic-gate /* 12900Sstevel@tonic-gate * System V IPC routines 12910Sstevel@tonic-gate */ 12920Sstevel@tonic-gate int 12930Sstevel@tonic-gate secpolicy_ipc_owner(const cred_t *cr, const struct kipc_perm *ip) 12940Sstevel@tonic-gate { 12950Sstevel@tonic-gate if (crgetzoneid(cr) != ip->ipc_zoneid || 12960Sstevel@tonic-gate (cr->cr_uid != ip->ipc_uid && cr->cr_uid != ip->ipc_cuid)) { 12970Sstevel@tonic-gate boolean_t allzone = B_FALSE; 12980Sstevel@tonic-gate if (ip->ipc_uid == 0 || ip->ipc_cuid == 0) 12990Sstevel@tonic-gate allzone = B_TRUE; 13000Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_OWNER, allzone, EPERM, NULL)); 13010Sstevel@tonic-gate } 13020Sstevel@tonic-gate return (0); 13030Sstevel@tonic-gate } 13040Sstevel@tonic-gate 13050Sstevel@tonic-gate int 13060Sstevel@tonic-gate secpolicy_ipc_config(const cred_t *cr) 13070Sstevel@tonic-gate { 13080Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_IPC_CONFIG, B_FALSE, EPERM, NULL)); 13090Sstevel@tonic-gate } 13100Sstevel@tonic-gate 13110Sstevel@tonic-gate int 13120Sstevel@tonic-gate secpolicy_ipc_access(const cred_t *cr, const struct kipc_perm *ip, mode_t mode) 13130Sstevel@tonic-gate { 13140Sstevel@tonic-gate 13150Sstevel@tonic-gate boolean_t allzone = B_FALSE; 13160Sstevel@tonic-gate 13170Sstevel@tonic-gate ASSERT((mode & (MSG_R|MSG_W)) != 0); 13180Sstevel@tonic-gate 13190Sstevel@tonic-gate if ((mode & MSG_R) && 13200Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0) 13210Sstevel@tonic-gate return (EACCES); 13220Sstevel@tonic-gate 13230Sstevel@tonic-gate if (mode & MSG_W) { 13240Sstevel@tonic-gate if (cr->cr_uid != 0 && (ip->ipc_uid == 0 || ip->ipc_cuid == 0)) 13250Sstevel@tonic-gate allzone = B_TRUE; 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES, 13280Sstevel@tonic-gate NULL)); 13290Sstevel@tonic-gate } 13300Sstevel@tonic-gate return (0); 13310Sstevel@tonic-gate } 13320Sstevel@tonic-gate 13330Sstevel@tonic-gate int 13340Sstevel@tonic-gate secpolicy_rsm_access(const cred_t *cr, uid_t owner, mode_t mode) 13350Sstevel@tonic-gate { 13360Sstevel@tonic-gate boolean_t allzone = B_FALSE; 13370Sstevel@tonic-gate 13380Sstevel@tonic-gate ASSERT((mode & (MSG_R|MSG_W)) != 0); 13390Sstevel@tonic-gate 13400Sstevel@tonic-gate if ((mode & MSG_R) && 13410Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0) 13420Sstevel@tonic-gate return (EACCES); 13430Sstevel@tonic-gate 13440Sstevel@tonic-gate if (mode & MSG_W) { 13450Sstevel@tonic-gate if (cr->cr_uid != 0 && owner == 0) 13460Sstevel@tonic-gate allzone = B_TRUE; 13470Sstevel@tonic-gate 13480Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES, 13490Sstevel@tonic-gate NULL)); 13500Sstevel@tonic-gate } 13510Sstevel@tonic-gate return (0); 13520Sstevel@tonic-gate } 13530Sstevel@tonic-gate 13540Sstevel@tonic-gate /* 13550Sstevel@tonic-gate * Audit configuration. 13560Sstevel@tonic-gate */ 13570Sstevel@tonic-gate int 13580Sstevel@tonic-gate secpolicy_audit_config(const cred_t *cr) 13590Sstevel@tonic-gate { 13600Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL)); 13610Sstevel@tonic-gate } 13620Sstevel@tonic-gate 13630Sstevel@tonic-gate /* 13640Sstevel@tonic-gate * Audit record generation. 13650Sstevel@tonic-gate */ 13660Sstevel@tonic-gate int 13670Sstevel@tonic-gate secpolicy_audit_modify(const cred_t *cr) 13680Sstevel@tonic-gate { 13690Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, NULL)); 13700Sstevel@tonic-gate } 13710Sstevel@tonic-gate 13720Sstevel@tonic-gate /* 13730Sstevel@tonic-gate * Get audit attributes. 13740Sstevel@tonic-gate * Either PRIV_SYS_AUDIT or PRIV_PROC_AUDIT required; report the 13750Sstevel@tonic-gate * "Least" of the two privileges on error. 13760Sstevel@tonic-gate */ 13770Sstevel@tonic-gate int 13780Sstevel@tonic-gate secpolicy_audit_getattr(const cred_t *cr) 13790Sstevel@tonic-gate { 13800Sstevel@tonic-gate if (!PRIV_POLICY_ONLY(cr, PRIV_SYS_AUDIT, B_FALSE)) { 13810Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, 13820Sstevel@tonic-gate NULL)); 13830Sstevel@tonic-gate } else { 13840Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL)); 13850Sstevel@tonic-gate } 13860Sstevel@tonic-gate } 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate 13890Sstevel@tonic-gate /* 13900Sstevel@tonic-gate * Locking physical memory 13910Sstevel@tonic-gate */ 13920Sstevel@tonic-gate int 13930Sstevel@tonic-gate secpolicy_lock_memory(const cred_t *cr) 13940Sstevel@tonic-gate { 13950Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_LOCK_MEMORY, B_FALSE, EPERM, NULL)); 13960Sstevel@tonic-gate } 13970Sstevel@tonic-gate 13980Sstevel@tonic-gate /* 13990Sstevel@tonic-gate * Accounting (both acct(2) and exacct). 14000Sstevel@tonic-gate */ 14010Sstevel@tonic-gate int 14020Sstevel@tonic-gate secpolicy_acct(const cred_t *cr) 14030Sstevel@tonic-gate { 14040Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ACCT, B_FALSE, EPERM, NULL)); 14050Sstevel@tonic-gate } 14060Sstevel@tonic-gate 14070Sstevel@tonic-gate /* 14080Sstevel@tonic-gate * Is this process privileged to change its uids at will? 14090Sstevel@tonic-gate * Uid 0 is still considered "special" and having the SETID 14100Sstevel@tonic-gate * privilege is not sufficient to get uid 0. 14110Sstevel@tonic-gate * Files are owned by root, so the privilege would give 14120Sstevel@tonic-gate * full access and euid 0 is still effective. 14130Sstevel@tonic-gate * 14140Sstevel@tonic-gate * If you have the privilege and euid 0 only then do you 14150Sstevel@tonic-gate * get the powers of root wrt uid 0. 14160Sstevel@tonic-gate * 14170Sstevel@tonic-gate * For gid manipulations, this is should be called with an 14180Sstevel@tonic-gate * uid of -1. 14190Sstevel@tonic-gate * 14200Sstevel@tonic-gate */ 14210Sstevel@tonic-gate int 14220Sstevel@tonic-gate secpolicy_allow_setid(const cred_t *cr, uid_t newuid, boolean_t checkonly) 14230Sstevel@tonic-gate { 14240Sstevel@tonic-gate boolean_t allzone = B_FALSE; 14250Sstevel@tonic-gate 14260Sstevel@tonic-gate if (newuid == 0 && cr->cr_uid != 0 && cr->cr_suid != 0 && 14270Sstevel@tonic-gate cr->cr_ruid != 0) { 14280Sstevel@tonic-gate allzone = B_TRUE; 14290Sstevel@tonic-gate } 14300Sstevel@tonic-gate 14310Sstevel@tonic-gate return (checkonly ? !PRIV_POLICY_ONLY(cr, PRIV_PROC_SETID, allzone) : 14320Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_PROC_SETID, allzone, EPERM, NULL)); 14330Sstevel@tonic-gate } 14340Sstevel@tonic-gate 14350Sstevel@tonic-gate 14360Sstevel@tonic-gate /* 14370Sstevel@tonic-gate * Acting on a different process: if the mode is for writing, 14380Sstevel@tonic-gate * the restrictions are more severe. This is called after 14390Sstevel@tonic-gate * we've verified that the uids do not match. 14400Sstevel@tonic-gate */ 14410Sstevel@tonic-gate int 14420Sstevel@tonic-gate secpolicy_proc_owner(const cred_t *scr, const cred_t *tcr, int mode) 14430Sstevel@tonic-gate { 14440Sstevel@tonic-gate boolean_t allzone = B_FALSE; 14450Sstevel@tonic-gate 14460Sstevel@tonic-gate if ((mode & VWRITE) && scr->cr_uid != 0 && 14470Sstevel@tonic-gate (tcr->cr_uid == 0 || tcr->cr_ruid == 0 || tcr->cr_suid == 0)) 14480Sstevel@tonic-gate allzone = B_TRUE; 14490Sstevel@tonic-gate 14500Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, allzone, EPERM, NULL)); 14510Sstevel@tonic-gate } 14520Sstevel@tonic-gate 14530Sstevel@tonic-gate int 14540Sstevel@tonic-gate secpolicy_proc_access(const cred_t *scr) 14550Sstevel@tonic-gate { 14560Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EACCES, NULL)); 14570Sstevel@tonic-gate } 14580Sstevel@tonic-gate 14590Sstevel@tonic-gate int 14600Sstevel@tonic-gate secpolicy_proc_excl_open(const cred_t *scr) 14610Sstevel@tonic-gate { 14620Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EBUSY, NULL)); 14630Sstevel@tonic-gate } 14640Sstevel@tonic-gate 14650Sstevel@tonic-gate int 14660Sstevel@tonic-gate secpolicy_proc_zone(const cred_t *scr) 14670Sstevel@tonic-gate { 14680Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_ZONE, B_FALSE, EPERM, NULL)); 14690Sstevel@tonic-gate } 14700Sstevel@tonic-gate 14710Sstevel@tonic-gate /* 14720Sstevel@tonic-gate * Destroying the system 14730Sstevel@tonic-gate */ 14740Sstevel@tonic-gate 14750Sstevel@tonic-gate int 14760Sstevel@tonic-gate secpolicy_kmdb(const cred_t *scr) 14770Sstevel@tonic-gate { 14780Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 14790Sstevel@tonic-gate } 14800Sstevel@tonic-gate 14811414Scindi int 14821414Scindi secpolicy_error_inject(const cred_t *scr) 14831414Scindi { 14841414Scindi return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 14851414Scindi } 14861414Scindi 14870Sstevel@tonic-gate /* 14880Sstevel@tonic-gate * Processor sets, cpu configuration, resource pools. 14890Sstevel@tonic-gate */ 14900Sstevel@tonic-gate int 14910Sstevel@tonic-gate secpolicy_pset(const cred_t *cr) 14920Sstevel@tonic-gate { 14930Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 14940Sstevel@tonic-gate } 14950Sstevel@tonic-gate 14960Sstevel@tonic-gate int 14970Sstevel@tonic-gate secpolicy_ponline(const cred_t *cr) 14980Sstevel@tonic-gate { 14990Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 15000Sstevel@tonic-gate } 15010Sstevel@tonic-gate 15020Sstevel@tonic-gate int 15030Sstevel@tonic-gate secpolicy_pool(const cred_t *cr) 15040Sstevel@tonic-gate { 15050Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 15060Sstevel@tonic-gate } 15070Sstevel@tonic-gate 15080Sstevel@tonic-gate int 15090Sstevel@tonic-gate secpolicy_blacklist(const cred_t *cr) 15100Sstevel@tonic-gate { 15110Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 15120Sstevel@tonic-gate } 15130Sstevel@tonic-gate 15140Sstevel@tonic-gate /* 15150Sstevel@tonic-gate * Catch all system configuration. 15160Sstevel@tonic-gate */ 15170Sstevel@tonic-gate int 15180Sstevel@tonic-gate secpolicy_sys_config(const cred_t *cr, boolean_t checkonly) 15190Sstevel@tonic-gate { 15200Sstevel@tonic-gate if (checkonly) { 15210Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_CONFIG, B_FALSE) ? 0 : 15220Sstevel@tonic-gate EPERM); 15230Sstevel@tonic-gate } else { 15240Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 15250Sstevel@tonic-gate } 15260Sstevel@tonic-gate } 15270Sstevel@tonic-gate 15280Sstevel@tonic-gate /* 15290Sstevel@tonic-gate * Zone administration (halt, reboot, etc.) from within zone. 15300Sstevel@tonic-gate */ 15310Sstevel@tonic-gate int 15320Sstevel@tonic-gate secpolicy_zone_admin(const cred_t *cr, boolean_t checkonly) 15330Sstevel@tonic-gate { 15340Sstevel@tonic-gate if (checkonly) { 15350Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_ADMIN, B_FALSE) ? 0 : 15360Sstevel@tonic-gate EPERM); 15370Sstevel@tonic-gate } else { 15380Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, 15390Sstevel@tonic-gate NULL)); 15400Sstevel@tonic-gate } 15410Sstevel@tonic-gate } 15420Sstevel@tonic-gate 15430Sstevel@tonic-gate /* 15440Sstevel@tonic-gate * Zone configuration (create, halt, enter). 15450Sstevel@tonic-gate */ 15460Sstevel@tonic-gate int 15470Sstevel@tonic-gate secpolicy_zone_config(const cred_t *cr) 15480Sstevel@tonic-gate { 15490Sstevel@tonic-gate /* 15500Sstevel@tonic-gate * Require all privileges to avoid possibility of privilege 15510Sstevel@tonic-gate * escalation. 15520Sstevel@tonic-gate */ 15530Sstevel@tonic-gate return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 15540Sstevel@tonic-gate } 15550Sstevel@tonic-gate 15560Sstevel@tonic-gate /* 15570Sstevel@tonic-gate * Various other system configuration calls 15580Sstevel@tonic-gate */ 15590Sstevel@tonic-gate int 15600Sstevel@tonic-gate secpolicy_coreadm(const cred_t *cr) 15610Sstevel@tonic-gate { 15620Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL)); 15630Sstevel@tonic-gate } 15640Sstevel@tonic-gate 15650Sstevel@tonic-gate int 15660Sstevel@tonic-gate secpolicy_systeminfo(const cred_t *cr) 15670Sstevel@tonic-gate { 15680Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL)); 15690Sstevel@tonic-gate } 15700Sstevel@tonic-gate 15710Sstevel@tonic-gate int 15720Sstevel@tonic-gate secpolicy_dispadm(const cred_t *cr) 15730Sstevel@tonic-gate { 15740Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 15750Sstevel@tonic-gate } 15760Sstevel@tonic-gate 15770Sstevel@tonic-gate int 15780Sstevel@tonic-gate secpolicy_settime(const cred_t *cr) 15790Sstevel@tonic-gate { 15800Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_TIME, B_FALSE, EPERM, NULL)); 15810Sstevel@tonic-gate } 15820Sstevel@tonic-gate 15830Sstevel@tonic-gate /* 15840Sstevel@tonic-gate * For realtime users: high resolution clock. 15850Sstevel@tonic-gate */ 15860Sstevel@tonic-gate int 15870Sstevel@tonic-gate secpolicy_clock_highres(const cred_t *cr) 15880Sstevel@tonic-gate { 15890Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_CLOCK_HIGHRES, B_FALSE, EPERM, 15900Sstevel@tonic-gate NULL)); 15910Sstevel@tonic-gate } 15920Sstevel@tonic-gate 15930Sstevel@tonic-gate /* 15940Sstevel@tonic-gate * drv_priv() is documented as callable from interrupt context, not that 15950Sstevel@tonic-gate * anyone ever does, but still. No debugging or auditing can be done when 15960Sstevel@tonic-gate * it is called from interrupt context. 15970Sstevel@tonic-gate * returns 0 on succes, EPERM on failure. 15980Sstevel@tonic-gate */ 15990Sstevel@tonic-gate int 16000Sstevel@tonic-gate drv_priv(cred_t *cr) 16010Sstevel@tonic-gate { 16020Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 16030Sstevel@tonic-gate } 16040Sstevel@tonic-gate 16050Sstevel@tonic-gate int 16060Sstevel@tonic-gate secpolicy_sys_devices(const cred_t *cr) 16070Sstevel@tonic-gate { 16080Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 16090Sstevel@tonic-gate } 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate int 16120Sstevel@tonic-gate secpolicy_excl_open(const cred_t *cr) 16130Sstevel@tonic-gate { 16140Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EBUSY, NULL)); 16150Sstevel@tonic-gate } 16160Sstevel@tonic-gate 16170Sstevel@tonic-gate int 16180Sstevel@tonic-gate secpolicy_rctlsys(const cred_t *cr, boolean_t is_zone_rctl) 16190Sstevel@tonic-gate { 16200Sstevel@tonic-gate /* zone.* rctls can only be set from the global zone */ 16210Sstevel@tonic-gate if (is_zone_rctl && priv_policy_global(cr) != 0) 16220Sstevel@tonic-gate return (EPERM); 16230Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 16240Sstevel@tonic-gate } 16250Sstevel@tonic-gate 16260Sstevel@tonic-gate int 16270Sstevel@tonic-gate secpolicy_resource(const cred_t *cr) 16280Sstevel@tonic-gate { 16290Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 16300Sstevel@tonic-gate } 16310Sstevel@tonic-gate 16320Sstevel@tonic-gate /* 16330Sstevel@tonic-gate * Processes with a real uid of 0 escape any form of accounting, much 16340Sstevel@tonic-gate * like before. 16350Sstevel@tonic-gate */ 16360Sstevel@tonic-gate int 16370Sstevel@tonic-gate secpolicy_newproc(const cred_t *cr) 16380Sstevel@tonic-gate { 16390Sstevel@tonic-gate if (cr->cr_ruid == 0) 16400Sstevel@tonic-gate return (0); 16410Sstevel@tonic-gate 16420Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 16430Sstevel@tonic-gate } 16440Sstevel@tonic-gate 16450Sstevel@tonic-gate /* 16460Sstevel@tonic-gate * Networking 16470Sstevel@tonic-gate */ 16480Sstevel@tonic-gate int 16490Sstevel@tonic-gate secpolicy_net_rawaccess(const cred_t *cr) 16500Sstevel@tonic-gate { 16510Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_NET_RAWACCESS, B_FALSE, EACCES, NULL)); 16520Sstevel@tonic-gate } 16530Sstevel@tonic-gate 16540Sstevel@tonic-gate /* 16550Sstevel@tonic-gate * Need this privilege for accessing the ICMP device 16560Sstevel@tonic-gate */ 16570Sstevel@tonic-gate int 16580Sstevel@tonic-gate secpolicy_net_icmpaccess(const cred_t *cr) 16590Sstevel@tonic-gate { 16600Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_NET_ICMPACCESS, B_FALSE, EACCES, NULL)); 16610Sstevel@tonic-gate } 16620Sstevel@tonic-gate 16630Sstevel@tonic-gate /* 16640Sstevel@tonic-gate * There are a few rare cases where the kernel generates ioctls() from 16650Sstevel@tonic-gate * interrupt context with a credential of kcred rather than NULL. 16660Sstevel@tonic-gate * In those cases, we take the safe and cheap test. 16670Sstevel@tonic-gate */ 16680Sstevel@tonic-gate int 16690Sstevel@tonic-gate secpolicy_net_config(const cred_t *cr, boolean_t checkonly) 16700Sstevel@tonic-gate { 16710Sstevel@tonic-gate if (checkonly) { 16720Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE) ? 16730Sstevel@tonic-gate 0 : EPERM); 16740Sstevel@tonic-gate } else { 16750Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_NET_CONFIG, B_FALSE, EPERM, 16760Sstevel@tonic-gate NULL)); 16770Sstevel@tonic-gate } 16780Sstevel@tonic-gate } 16790Sstevel@tonic-gate 16800Sstevel@tonic-gate 16810Sstevel@tonic-gate /* 16824962Sdh155122 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG. 16833448Sdh155122 * 16843448Sdh155122 * There are a few rare cases where the kernel generates ioctls() from 16853448Sdh155122 * interrupt context with a credential of kcred rather than NULL. 16863448Sdh155122 * In those cases, we take the safe and cheap test. 16873448Sdh155122 */ 16883448Sdh155122 int 16893448Sdh155122 secpolicy_ip_config(const cred_t *cr, boolean_t checkonly) 16903448Sdh155122 { 16913448Sdh155122 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 16923448Sdh155122 return (secpolicy_net_config(cr, checkonly)); 16933448Sdh155122 16943448Sdh155122 if (checkonly) { 16953448Sdh155122 return (PRIV_POLICY_ONLY(cr, PRIV_SYS_IP_CONFIG, B_FALSE) ? 16963448Sdh155122 0 : EPERM); 16973448Sdh155122 } else { 16983448Sdh155122 return (PRIV_POLICY(cr, PRIV_SYS_IP_CONFIG, B_FALSE, EPERM, 16993448Sdh155122 NULL)); 17003448Sdh155122 } 17013448Sdh155122 } 17023448Sdh155122 1703*7408SSebastien.Roy@Sun.COM /* 1704*7408SSebastien.Roy@Sun.COM * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_DL_CONFIG. 1705*7408SSebastien.Roy@Sun.COM */ 1706*7408SSebastien.Roy@Sun.COM int 1707*7408SSebastien.Roy@Sun.COM secpolicy_dl_config(const cred_t *cr) 1708*7408SSebastien.Roy@Sun.COM { 1709*7408SSebastien.Roy@Sun.COM if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 1710*7408SSebastien.Roy@Sun.COM return (secpolicy_net_config(cr, B_FALSE)); 1711*7408SSebastien.Roy@Sun.COM return (PRIV_POLICY(cr, PRIV_SYS_DL_CONFIG, B_FALSE, EPERM, 1712*7408SSebastien.Roy@Sun.COM NULL)); 1713*7408SSebastien.Roy@Sun.COM } 1714*7408SSebastien.Roy@Sun.COM 17153448Sdh155122 17163448Sdh155122 /* 17173448Sdh155122 * Map IP pseudo privileges to actual privileges. 17183448Sdh155122 * So we don't need to recompile IP when we change the privileges. 17193448Sdh155122 */ 17203448Sdh155122 int 17213448Sdh155122 secpolicy_ip(const cred_t *cr, int netpriv, boolean_t checkonly) 17223448Sdh155122 { 17233448Sdh155122 int priv = PRIV_ALL; 17243448Sdh155122 17253448Sdh155122 switch (netpriv) { 17263448Sdh155122 case OP_CONFIG: 17273448Sdh155122 priv = PRIV_SYS_IP_CONFIG; 17283448Sdh155122 break; 17293448Sdh155122 case OP_RAW: 17303448Sdh155122 priv = PRIV_NET_RAWACCESS; 17313448Sdh155122 break; 17323448Sdh155122 case OP_PRIVPORT: 17333448Sdh155122 priv = PRIV_NET_PRIVADDR; 17343448Sdh155122 break; 17353448Sdh155122 } 17363448Sdh155122 ASSERT(priv != PRIV_ALL); 17373448Sdh155122 if (checkonly) 17383448Sdh155122 return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM); 17393448Sdh155122 else 17403448Sdh155122 return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL)); 17413448Sdh155122 } 17423448Sdh155122 17433448Sdh155122 /* 17440Sstevel@tonic-gate * Map network pseudo privileges to actual privileges. 17450Sstevel@tonic-gate * So we don't need to recompile IP when we change the privileges. 17460Sstevel@tonic-gate */ 17470Sstevel@tonic-gate int 17480Sstevel@tonic-gate secpolicy_net(const cred_t *cr, int netpriv, boolean_t checkonly) 17490Sstevel@tonic-gate { 17500Sstevel@tonic-gate int priv = PRIV_ALL; 17510Sstevel@tonic-gate 17520Sstevel@tonic-gate switch (netpriv) { 17530Sstevel@tonic-gate case OP_CONFIG: 17540Sstevel@tonic-gate priv = PRIV_SYS_NET_CONFIG; 17550Sstevel@tonic-gate break; 17560Sstevel@tonic-gate case OP_RAW: 17570Sstevel@tonic-gate priv = PRIV_NET_RAWACCESS; 17580Sstevel@tonic-gate break; 17590Sstevel@tonic-gate case OP_PRIVPORT: 17600Sstevel@tonic-gate priv = PRIV_NET_PRIVADDR; 17610Sstevel@tonic-gate break; 17620Sstevel@tonic-gate } 17630Sstevel@tonic-gate ASSERT(priv != PRIV_ALL); 17640Sstevel@tonic-gate if (checkonly) 17650Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM); 17660Sstevel@tonic-gate else 17670Sstevel@tonic-gate return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL)); 17680Sstevel@tonic-gate } 17690Sstevel@tonic-gate 17700Sstevel@tonic-gate /* 17710Sstevel@tonic-gate * Checks for operations that are either client-only or are used by 17720Sstevel@tonic-gate * both clients and servers. 17730Sstevel@tonic-gate */ 17740Sstevel@tonic-gate int 17750Sstevel@tonic-gate secpolicy_nfs(const cred_t *cr) 17760Sstevel@tonic-gate { 17770Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_NFS, B_FALSE, EPERM, NULL)); 17780Sstevel@tonic-gate } 17790Sstevel@tonic-gate 17800Sstevel@tonic-gate /* 17810Sstevel@tonic-gate * Special case for opening rpcmod: have NFS privileges or network 17820Sstevel@tonic-gate * config privileges. 17830Sstevel@tonic-gate */ 17840Sstevel@tonic-gate int 17850Sstevel@tonic-gate secpolicy_rpcmod_open(const cred_t *cr) 17860Sstevel@tonic-gate { 17870Sstevel@tonic-gate if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NFS, B_FALSE)) 17880Sstevel@tonic-gate return (secpolicy_nfs(cr)); 17890Sstevel@tonic-gate else 17900Sstevel@tonic-gate return (secpolicy_net_config(cr, NULL)); 17910Sstevel@tonic-gate } 17920Sstevel@tonic-gate 17930Sstevel@tonic-gate int 17940Sstevel@tonic-gate secpolicy_chroot(const cred_t *cr) 17950Sstevel@tonic-gate { 17960Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_CHROOT, B_FALSE, EPERM, NULL)); 17970Sstevel@tonic-gate } 17980Sstevel@tonic-gate 17990Sstevel@tonic-gate int 18000Sstevel@tonic-gate secpolicy_tasksys(const cred_t *cr) 18010Sstevel@tonic-gate { 18020Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_TASKID, B_FALSE, EPERM, NULL)); 18030Sstevel@tonic-gate } 18040Sstevel@tonic-gate 18050Sstevel@tonic-gate /* 18060Sstevel@tonic-gate * Basic privilege checks. 18070Sstevel@tonic-gate */ 18080Sstevel@tonic-gate int 18096134Scasper secpolicy_basic_exec(const cred_t *cr, vnode_t *vp) 18100Sstevel@tonic-gate { 18116134Scasper return (priv_policy_va(cr, PRIV_PROC_EXEC, B_FALSE, EPERM, NULL, 18126134Scasper KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE)); 18130Sstevel@tonic-gate } 18140Sstevel@tonic-gate 18150Sstevel@tonic-gate int 18160Sstevel@tonic-gate secpolicy_basic_fork(const cred_t *cr) 18170Sstevel@tonic-gate { 18180Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_FORK, B_FALSE, EPERM, NULL)); 18190Sstevel@tonic-gate } 18200Sstevel@tonic-gate 18210Sstevel@tonic-gate int 18220Sstevel@tonic-gate secpolicy_basic_proc(const cred_t *cr) 18230Sstevel@tonic-gate { 18240Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_SESSION, B_FALSE, EPERM, NULL)); 18250Sstevel@tonic-gate } 18260Sstevel@tonic-gate 18270Sstevel@tonic-gate /* 18280Sstevel@tonic-gate * Slightly complicated because we don't want to trigger the policy too 18290Sstevel@tonic-gate * often. First we shortcircuit access to "self" (tp == sp) or if 18300Sstevel@tonic-gate * we don't have the privilege but if we have permission 18310Sstevel@tonic-gate * just return (0) and we don't flag the privilege as needed. 18320Sstevel@tonic-gate * Else, we test for the privilege because we either have it or need it. 18330Sstevel@tonic-gate */ 18340Sstevel@tonic-gate int 18350Sstevel@tonic-gate secpolicy_basic_procinfo(const cred_t *cr, proc_t *tp, proc_t *sp) 18360Sstevel@tonic-gate { 18370Sstevel@tonic-gate if (tp == sp || 18380Sstevel@tonic-gate !HAS_PRIVILEGE(cr, PRIV_PROC_INFO) && prochasprocperm(tp, sp, cr)) { 18390Sstevel@tonic-gate return (0); 18400Sstevel@tonic-gate } else { 18410Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_INFO, B_FALSE, EPERM, NULL)); 18420Sstevel@tonic-gate } 18430Sstevel@tonic-gate } 18440Sstevel@tonic-gate 18450Sstevel@tonic-gate int 18460Sstevel@tonic-gate secpolicy_basic_link(const cred_t *cr) 18470Sstevel@tonic-gate { 18480Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_LINK_ANY, B_FALSE, EPERM, NULL)); 18490Sstevel@tonic-gate } 18500Sstevel@tonic-gate 18510Sstevel@tonic-gate /* 18520Sstevel@tonic-gate * Additional device protection. 18530Sstevel@tonic-gate * 18540Sstevel@tonic-gate * Traditionally, a device has specific permissions on the node in 18550Sstevel@tonic-gate * the filesystem which govern which devices can be opened by what 18560Sstevel@tonic-gate * processes. In certain cases, it is desirable to add extra 18570Sstevel@tonic-gate * restrictions, as writing to certain devices is identical to 18580Sstevel@tonic-gate * having a complete run of the system. 18590Sstevel@tonic-gate * 18600Sstevel@tonic-gate * This mechanism is called the device policy. 18610Sstevel@tonic-gate * 18620Sstevel@tonic-gate * When a device is opened, its policy entry is looked up in the 18630Sstevel@tonic-gate * policy cache and checked. 18640Sstevel@tonic-gate */ 18650Sstevel@tonic-gate int 18660Sstevel@tonic-gate secpolicy_spec_open(const cred_t *cr, struct vnode *vp, int oflag) 18670Sstevel@tonic-gate { 18680Sstevel@tonic-gate devplcy_t *plcy; 18690Sstevel@tonic-gate int err; 18700Sstevel@tonic-gate struct snode *csp = VTOS(common_specvp(vp)); 18714962Sdh155122 priv_set_t pset; 18720Sstevel@tonic-gate 18730Sstevel@tonic-gate mutex_enter(&csp->s_lock); 18740Sstevel@tonic-gate 18750Sstevel@tonic-gate if (csp->s_plcy == NULL || csp->s_plcy->dp_gen != devplcy_gen) { 18760Sstevel@tonic-gate plcy = devpolicy_find(vp); 18770Sstevel@tonic-gate if (csp->s_plcy) 18780Sstevel@tonic-gate dpfree(csp->s_plcy); 18790Sstevel@tonic-gate csp->s_plcy = plcy; 18800Sstevel@tonic-gate ASSERT(plcy != NULL); 18810Sstevel@tonic-gate } else 18820Sstevel@tonic-gate plcy = csp->s_plcy; 18830Sstevel@tonic-gate 18840Sstevel@tonic-gate if (plcy == nullpolicy) { 18850Sstevel@tonic-gate mutex_exit(&csp->s_lock); 18860Sstevel@tonic-gate return (0); 18870Sstevel@tonic-gate } 18880Sstevel@tonic-gate 18890Sstevel@tonic-gate dphold(plcy); 18900Sstevel@tonic-gate 18910Sstevel@tonic-gate mutex_exit(&csp->s_lock); 18920Sstevel@tonic-gate 18934962Sdh155122 if (oflag & FWRITE) 18944962Sdh155122 pset = plcy->dp_wrp; 18954962Sdh155122 else 18964962Sdh155122 pset = plcy->dp_rdp; 18974962Sdh155122 /* 18984962Sdh155122 * Special case: 18994962Sdh155122 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG. 19004962Sdh155122 * If PRIV_SYS_NET_CONFIG is present and PRIV_SYS_IP_CONFIG is 19014962Sdh155122 * required, replace PRIV_SYS_IP_CONFIG with PRIV_SYS_NET_CONFIG 19024962Sdh155122 * in the required privilege set before doing the check. 19034962Sdh155122 */ 19044962Sdh155122 if (priv_ismember(&pset, PRIV_SYS_IP_CONFIG) && 19054962Sdh155122 priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_NET_CONFIG) && 19064962Sdh155122 !priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_IP_CONFIG)) { 19074962Sdh155122 priv_delset(&pset, PRIV_SYS_IP_CONFIG); 19084962Sdh155122 priv_addset(&pset, PRIV_SYS_NET_CONFIG); 19094962Sdh155122 } 19104962Sdh155122 19114962Sdh155122 err = secpolicy_require_set(cr, &pset, "devpolicy"); 19120Sstevel@tonic-gate dpfree(plcy); 19130Sstevel@tonic-gate 19140Sstevel@tonic-gate return (err); 19150Sstevel@tonic-gate } 19160Sstevel@tonic-gate 19170Sstevel@tonic-gate int 19180Sstevel@tonic-gate secpolicy_modctl(const cred_t *cr, int cmd) 19190Sstevel@tonic-gate { 19200Sstevel@tonic-gate switch (cmd) { 19210Sstevel@tonic-gate case MODINFO: 19222723Scth case MODGETMAJBIND: 19230Sstevel@tonic-gate case MODGETPATH: 19240Sstevel@tonic-gate case MODGETPATHLEN: 19252723Scth case MODGETNAME: 19260Sstevel@tonic-gate case MODGETFBNAME: 19270Sstevel@tonic-gate case MODGETDEVPOLICY: 19280Sstevel@tonic-gate case MODGETDEVPOLICYBYNAME: 19292723Scth case MODDEVT2INSTANCE: 19302723Scth case MODSIZEOF_DEVID: 19312723Scth case MODGETDEVID: 19322723Scth case MODSIZEOF_MINORNAME: 19332723Scth case MODGETMINORNAME: 19342723Scth case MODGETDEVFSPATH_LEN: 19352723Scth case MODGETDEVFSPATH: 19362723Scth case MODGETDEVFSPATH_MI_LEN: 19372723Scth case MODGETDEVFSPATH_MI: 19380Sstevel@tonic-gate /* Unprivileged */ 19390Sstevel@tonic-gate return (0); 19400Sstevel@tonic-gate case MODLOAD: 19410Sstevel@tonic-gate case MODSETDEVPOLICY: 19420Sstevel@tonic-gate return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 19430Sstevel@tonic-gate default: 19440Sstevel@tonic-gate return (secpolicy_sys_config(cr, B_FALSE)); 19450Sstevel@tonic-gate } 19460Sstevel@tonic-gate } 19470Sstevel@tonic-gate 19480Sstevel@tonic-gate int 19490Sstevel@tonic-gate secpolicy_console(const cred_t *cr) 19500Sstevel@tonic-gate { 19510Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 19520Sstevel@tonic-gate } 19530Sstevel@tonic-gate 19540Sstevel@tonic-gate int 19550Sstevel@tonic-gate secpolicy_power_mgmt(const cred_t *cr) 19560Sstevel@tonic-gate { 19570Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 19580Sstevel@tonic-gate } 19590Sstevel@tonic-gate 19600Sstevel@tonic-gate /* 19610Sstevel@tonic-gate * Simulate terminal input; another escalation of privileges avenue. 19620Sstevel@tonic-gate */ 19630Sstevel@tonic-gate 19640Sstevel@tonic-gate int 19650Sstevel@tonic-gate secpolicy_sti(const cred_t *cr) 19660Sstevel@tonic-gate { 19670Sstevel@tonic-gate return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 19680Sstevel@tonic-gate } 19690Sstevel@tonic-gate 19701676Sjpk boolean_t 19711676Sjpk secpolicy_net_reply_equal(const cred_t *cr) 19721676Sjpk { 19731676Sjpk return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 19741676Sjpk } 19751676Sjpk 19760Sstevel@tonic-gate int 19770Sstevel@tonic-gate secpolicy_swapctl(const cred_t *cr) 19780Sstevel@tonic-gate { 19790Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 19800Sstevel@tonic-gate } 19810Sstevel@tonic-gate 19820Sstevel@tonic-gate int 19830Sstevel@tonic-gate secpolicy_cpc_cpu(const cred_t *cr) 19840Sstevel@tonic-gate { 19850Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CPC_CPU, B_FALSE, EACCES, NULL)); 19860Sstevel@tonic-gate } 19870Sstevel@tonic-gate 19880Sstevel@tonic-gate /* 19896073Sacruz * secpolicy_contract_identity 19906073Sacruz * 19916073Sacruz * Determine if the subject may set the process contract FMRI value 19926073Sacruz */ 19936073Sacruz int 19946073Sacruz secpolicy_contract_identity(const cred_t *cr) 19956073Sacruz { 19966073Sacruz return (PRIV_POLICY(cr, PRIV_CONTRACT_IDENTITY, B_FALSE, EPERM, NULL)); 19976073Sacruz } 19986073Sacruz 19996073Sacruz /* 20000Sstevel@tonic-gate * secpolicy_contract_observer 20010Sstevel@tonic-gate * 20020Sstevel@tonic-gate * Determine if the subject may observe a specific contract's events. 20030Sstevel@tonic-gate */ 20040Sstevel@tonic-gate int 20050Sstevel@tonic-gate secpolicy_contract_observer(const cred_t *cr, struct contract *ct) 20060Sstevel@tonic-gate { 20070Sstevel@tonic-gate if (contract_owned(ct, cr, B_FALSE)) 20080Sstevel@tonic-gate return (0); 20090Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CONTRACT_OBSERVER, B_FALSE, EPERM, NULL)); 20100Sstevel@tonic-gate } 20110Sstevel@tonic-gate 20120Sstevel@tonic-gate /* 20130Sstevel@tonic-gate * secpolicy_contract_observer_choice 20140Sstevel@tonic-gate * 20150Sstevel@tonic-gate * Determine if the subject may observe any contract's events. Just 20160Sstevel@tonic-gate * tests privilege and audits on success. 20170Sstevel@tonic-gate */ 20180Sstevel@tonic-gate boolean_t 20190Sstevel@tonic-gate secpolicy_contract_observer_choice(const cred_t *cr) 20200Sstevel@tonic-gate { 20210Sstevel@tonic-gate return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_OBSERVER, B_FALSE)); 20220Sstevel@tonic-gate } 20230Sstevel@tonic-gate 20240Sstevel@tonic-gate /* 20250Sstevel@tonic-gate * secpolicy_contract_event 20260Sstevel@tonic-gate * 20270Sstevel@tonic-gate * Determine if the subject may request critical contract events or 20280Sstevel@tonic-gate * reliable contract event delivery. 20290Sstevel@tonic-gate */ 20300Sstevel@tonic-gate int 20310Sstevel@tonic-gate secpolicy_contract_event(const cred_t *cr) 20320Sstevel@tonic-gate { 20330Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CONTRACT_EVENT, B_FALSE, EPERM, NULL)); 20340Sstevel@tonic-gate } 20350Sstevel@tonic-gate 20360Sstevel@tonic-gate /* 20370Sstevel@tonic-gate * secpolicy_contract_event_choice 20380Sstevel@tonic-gate * 20390Sstevel@tonic-gate * Determine if the subject may retain contract events in its critical 20400Sstevel@tonic-gate * set when a change in other terms would normally require a change in 20410Sstevel@tonic-gate * the critical set. Just tests privilege and audits on success. 20420Sstevel@tonic-gate */ 20430Sstevel@tonic-gate boolean_t 20440Sstevel@tonic-gate secpolicy_contract_event_choice(const cred_t *cr) 20450Sstevel@tonic-gate { 20460Sstevel@tonic-gate return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_EVENT, B_FALSE)); 20470Sstevel@tonic-gate } 20480Sstevel@tonic-gate 20490Sstevel@tonic-gate /* 20501544Seschrock * secpolicy_gart_access 20510Sstevel@tonic-gate * 20521544Seschrock * Determine if the subject has sufficient priveleges to make ioctls to agpgart 20531544Seschrock * device. 20540Sstevel@tonic-gate */ 20550Sstevel@tonic-gate int 20560Sstevel@tonic-gate secpolicy_gart_access(const cred_t *cr) 20570Sstevel@tonic-gate { 20581862Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, NULL)); 20590Sstevel@tonic-gate } 20600Sstevel@tonic-gate 20610Sstevel@tonic-gate /* 20621544Seschrock * secpolicy_gart_map 20630Sstevel@tonic-gate * 20641544Seschrock * Determine if the subject has sufficient priveleges to map aperture range 20651544Seschrock * through agpgart driver. 20660Sstevel@tonic-gate */ 20670Sstevel@tonic-gate int 20680Sstevel@tonic-gate secpolicy_gart_map(const cred_t *cr) 20690Sstevel@tonic-gate { 20701862Scasper if (PRIV_POLICY_ONLY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE)) { 20711862Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, 20721862Scasper NULL)); 20731862Scasper } else { 20741862Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_MAP, B_FALSE, EPERM, 20751862Scasper NULL)); 20760Sstevel@tonic-gate } 20770Sstevel@tonic-gate } 2078789Sahrens 2079789Sahrens /* 20801544Seschrock * secpolicy_zinject 20811544Seschrock * 20821544Seschrock * Determine if the subject can inject faults in the ZFS fault injection 20831544Seschrock * framework. Requires all privileges. 20841544Seschrock */ 20851544Seschrock int 20861544Seschrock secpolicy_zinject(const cred_t *cr) 20871544Seschrock { 20881544Seschrock return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 20891544Seschrock } 20901544Seschrock 20911544Seschrock /* 2092789Sahrens * secpolicy_zfs 2093789Sahrens * 20941544Seschrock * Determine if the subject has permission to manipulate ZFS datasets 20951544Seschrock * (not pools). Equivalent to the SYS_MOUNT privilege. 2096789Sahrens */ 2097789Sahrens int 2098789Sahrens secpolicy_zfs(const cred_t *cr) 2099789Sahrens { 2100789Sahrens return (PRIV_POLICY(cr, PRIV_SYS_MOUNT, B_FALSE, EPERM, NULL)); 2101789Sahrens } 21024321Scasper 21034321Scasper /* 21044321Scasper * secpolicy_idmap 21054321Scasper * 21064321Scasper * Determine if the calling process has permissions to register an SID 21074321Scasper * mapping daemon and allocate ephemeral IDs. 21084321Scasper */ 21094321Scasper int 21104321Scasper secpolicy_idmap(const cred_t *cr) 21114321Scasper { 21125771Sjp151216 return (PRIV_POLICY(cr, PRIV_FILE_SETID, B_TRUE, EPERM, NULL)); 21134321Scasper } 21144581Ssherrym 21154581Ssherrym /* 21164581Ssherrym * secpolicy_ucode_update 21174581Ssherrym * 21184581Ssherrym * Determine if the subject has sufficient privilege to update microcode. 21194581Ssherrym */ 21204581Ssherrym int 21214581Ssherrym secpolicy_ucode_update(const cred_t *scr) 21224581Ssherrym { 21234581Ssherrym return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 21244581Ssherrym } 21254962Sdh155122 21264962Sdh155122 /* 21274962Sdh155122 * secpolicy_sadopen 21284962Sdh155122 * 21294962Sdh155122 * Determine if the subject has sufficient privilege to access /dev/sad/admin. 21304962Sdh155122 * /dev/sad/admin appear in global zone and exclusive-IP zones only. 21314962Sdh155122 * In global zone, sys_config is required. 21324962Sdh155122 * In exclusive-IP zones, sys_ip_config is required. 21334962Sdh155122 * Note that sys_config is prohibited in non-global zones. 21344962Sdh155122 */ 21354962Sdh155122 int 21364962Sdh155122 secpolicy_sadopen(const cred_t *credp) 21374962Sdh155122 { 21384962Sdh155122 priv_set_t pset; 21394962Sdh155122 21404962Sdh155122 priv_emptyset(&pset); 21414962Sdh155122 21424962Sdh155122 if (crgetzoneid(credp) == GLOBAL_ZONEID) 21434962Sdh155122 priv_addset(&pset, PRIV_SYS_CONFIG); 21444962Sdh155122 else 21454962Sdh155122 priv_addset(&pset, PRIV_SYS_IP_CONFIG); 21464962Sdh155122 21474962Sdh155122 return (secpolicy_require_set(credp, &pset, "devpolicy")); 21484962Sdh155122 } 21495331Samw 21506134Scasper 21516134Scasper /* 21526134Scasper * Add privileges to a particular privilege set; this is called when the 21536134Scasper * current sets of privileges are not sufficient. I.e., we should always 21546134Scasper * call the policy override functions from here. 21556134Scasper * What we are allowed to have is in the Observed Permitted set; so 21566134Scasper * we compute the difference between that and the newset. 21576134Scasper */ 21586134Scasper int 21596134Scasper secpolicy_require_privs(const cred_t *cr, const priv_set_t *nset) 21606134Scasper { 21616134Scasper priv_set_t rqd; 21626134Scasper 21636134Scasper rqd = CR_OPPRIV(cr); 21646134Scasper 21656134Scasper priv_inverse(&rqd); 21666134Scasper priv_intersect(nset, &rqd); 21676134Scasper 21686134Scasper return (secpolicy_require_set(cr, &rqd, NULL)); 21696134Scasper } 21706134Scasper 21715331Samw /* 21725331Samw * secpolicy_smb 21735331Samw * 21745331Samw * Determine if the cred_t has PRIV_SYS_SMB privilege, indicating 21755331Samw * that it has permission to access the smbsrv kernel driver. 21765331Samw * PRIV_POLICY checks the privilege and audits the check. 21775331Samw * 21785331Samw * Returns: 21795331Samw * 0 Driver access is allowed. 21805331Samw * EPERM Driver access is NOT permitted. 21815331Samw */ 21825331Samw int 21835331Samw secpolicy_smb(const cred_t *cr) 21845331Samw { 21855331Samw return (PRIV_POLICY(cr, PRIV_SYS_SMB, B_FALSE, EPERM, NULL)); 21865331Samw } 21875440Sjm199354 21885440Sjm199354 /* 21895440Sjm199354 * secpolicy_vscan 21905440Sjm199354 * 21915440Sjm199354 * Determine if cred_t has the necessary privileges to access a file 21925440Sjm199354 * for virus scanning and update its extended system attributes. 21935440Sjm199354 * PRIV_FILE_DAC_SEARCH, PRIV_FILE_DAC_READ - file access 21945440Sjm199354 * PRIV_FILE_FLAG_SET - set extended system attributes 21955440Sjm199354 * 21965440Sjm199354 * PRIV_POLICY checks the privilege and audits the check. 21975440Sjm199354 * 21985440Sjm199354 * Returns: 21995440Sjm199354 * 0 file access for virus scanning allowed. 22005440Sjm199354 * EPERM file access for virus scanning is NOT permitted. 22015440Sjm199354 */ 22025440Sjm199354 int 22035440Sjm199354 secpolicy_vscan(const cred_t *cr) 22045440Sjm199354 { 22055440Sjm199354 if ((PRIV_POLICY(cr, PRIV_FILE_DAC_SEARCH, B_FALSE, EPERM, NULL)) || 22065440Sjm199354 (PRIV_POLICY(cr, PRIV_FILE_DAC_READ, B_FALSE, EPERM, NULL)) || 22075440Sjm199354 (PRIV_POLICY(cr, PRIV_FILE_FLAG_SET, B_FALSE, EPERM, NULL))) { 22085440Sjm199354 return (EPERM); 22095440Sjm199354 } 22105440Sjm199354 22115440Sjm199354 return (0); 22125440Sjm199354 } 22136007Sthurlow 22146007Sthurlow /* 22156007Sthurlow * secpolicy_smbfs_login 22166007Sthurlow * 22176007Sthurlow * Determines if the caller can add and delete the smbfs login 22186007Sthurlow * password in the the nsmb kernel module for the CIFS client. 22196007Sthurlow * 22206007Sthurlow * Returns: 22216007Sthurlow * 0 access is allowed. 22226007Sthurlow * EPERM access is NOT allowed. 22236007Sthurlow */ 22246007Sthurlow int 22256007Sthurlow secpolicy_smbfs_login(const cred_t *cr, uid_t uid) 22266007Sthurlow { 22276007Sthurlow uid_t cruid = crgetruid(cr); 22286007Sthurlow 22296007Sthurlow if (cruid == uid) 22306007Sthurlow return (0); 22316007Sthurlow return (PRIV_POLICY(cr, PRIV_PROC_OWNER, B_FALSE, 22326007Sthurlow EPERM, NULL)); 22336007Sthurlow } 22346784Sjohnlev 22356784Sjohnlev /* 22366784Sjohnlev * secpolicy_xvm_control 22376784Sjohnlev * 22386784Sjohnlev * Determines if a caller can control the xVM hypervisor and/or running 22396784Sjohnlev * domains (x86 specific). 22406784Sjohnlev * 22416784Sjohnlev * Returns: 22426784Sjohnlev * 0 access is allowed. 22436784Sjohnlev * EPERM access is NOT allowed. 22446784Sjohnlev */ 22456784Sjohnlev int 22466784Sjohnlev secpolicy_xvm_control(const cred_t *cr) 22476784Sjohnlev { 22486784Sjohnlev if (PRIV_POLICY(cr, PRIV_XVM_CONTROL, B_FALSE, EPERM, NULL)) 22496784Sjohnlev return (EPERM); 22506784Sjohnlev return (0); 22516784Sjohnlev } 2252