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 /* 229751Sjames.d.carlson@sun.com * Copyright 2009 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> 578275SEric Cheng #include <sys/dld_ioc.h> 580Sstevel@tonic-gate 590Sstevel@tonic-gate /* 600Sstevel@tonic-gate * There are two possible layers of privilege routines and two possible 610Sstevel@tonic-gate * levels of secpolicy. Plus one other we may not be interested in, so 620Sstevel@tonic-gate * we may need as many as 6 but no more. 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate #define MAXPRIVSTACK 6 650Sstevel@tonic-gate 660Sstevel@tonic-gate int priv_debug = 0; 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * This file contains the majority of the policy routines. 700Sstevel@tonic-gate * Since the policy routines are defined by function and not 710Sstevel@tonic-gate * by privilege, there is quite a bit of duplication of 720Sstevel@tonic-gate * functions. 730Sstevel@tonic-gate * 745331Samw * The secpolicy functions must not make assumptions about 750Sstevel@tonic-gate * locks held or not held as any lock can be held while they're 760Sstevel@tonic-gate * being called. 770Sstevel@tonic-gate * 780Sstevel@tonic-gate * Credentials are read-only so no special precautions need to 790Sstevel@tonic-gate * be taken while locking them. 800Sstevel@tonic-gate * 810Sstevel@tonic-gate * When a new policy check needs to be added to the system the 820Sstevel@tonic-gate * following procedure should be followed: 830Sstevel@tonic-gate * 840Sstevel@tonic-gate * Pick an appropriate secpolicy_*() function 850Sstevel@tonic-gate * -> done if one exists. 860Sstevel@tonic-gate * Create a new secpolicy function, preferably with 870Sstevel@tonic-gate * a descriptive name using the standard template. 880Sstevel@tonic-gate * Pick an appropriate privilege for the policy. 890Sstevel@tonic-gate * If no appropraite privilege exists, define new one 900Sstevel@tonic-gate * (this should be done with extreme care; in most cases 910Sstevel@tonic-gate * little is gained by adding another privilege) 920Sstevel@tonic-gate * 930Sstevel@tonic-gate * WHY ROOT IS STILL SPECIAL. 940Sstevel@tonic-gate * 950Sstevel@tonic-gate * In a number of the policy functions, there are still explicit 960Sstevel@tonic-gate * checks for uid 0. The rationale behind these is that many root 970Sstevel@tonic-gate * owned files/objects hold configuration information which can give full 980Sstevel@tonic-gate * privileges to the user once written to. To prevent escalation 990Sstevel@tonic-gate * of privilege by allowing just a single privilege to modify root owned 1000Sstevel@tonic-gate * objects, we've added these root specific checks where we considered 1010Sstevel@tonic-gate * them necessary: modifying root owned files, changing uids to 0, etc. 1020Sstevel@tonic-gate * 1030Sstevel@tonic-gate * PRIVILEGE ESCALATION AND ZONES. 1040Sstevel@tonic-gate * 1050Sstevel@tonic-gate * A number of operations potentially allow the caller to achieve 1060Sstevel@tonic-gate * privileges beyond the ones normally required to perform the operation. 1070Sstevel@tonic-gate * For example, if allowed to create a setuid 0 executable, a process can 1080Sstevel@tonic-gate * gain privileges beyond PRIV_FILE_SETID. Zones, however, place 1090Sstevel@tonic-gate * restrictions on the ability to gain privileges beyond those available 1100Sstevel@tonic-gate * within the zone through file and process manipulation. Hence, such 1110Sstevel@tonic-gate * operations require that the caller have an effective set that includes 1120Sstevel@tonic-gate * all privileges available within the current zone, or all privileges 1130Sstevel@tonic-gate * if executing in the global zone. 1140Sstevel@tonic-gate * 1150Sstevel@tonic-gate * This is indicated in the priv_policy* policy checking functions 1160Sstevel@tonic-gate * through a combination of parameters. The "priv" parameter indicates 1170Sstevel@tonic-gate * the privilege that is required, and the "allzone" parameter indicates 1180Sstevel@tonic-gate * whether or not all privileges in the zone are required. In addition, 1190Sstevel@tonic-gate * priv can be set to PRIV_ALL to indicate that all privileges are 1200Sstevel@tonic-gate * required (regardless of zone). There are three scenarios of interest: 1210Sstevel@tonic-gate * (1) operation requires a specific privilege 1220Sstevel@tonic-gate * (2) operation requires a specific privilege, and requires all 1230Sstevel@tonic-gate * privileges available within the zone (or all privileges if in 1240Sstevel@tonic-gate * the global zone) 1250Sstevel@tonic-gate * (3) operation requires all privileges, regardless of zone 1260Sstevel@tonic-gate * 1270Sstevel@tonic-gate * For (1), priv should be set to the specific privilege, and allzone 1280Sstevel@tonic-gate * should be set to B_FALSE. 1290Sstevel@tonic-gate * For (2), priv should be set to the specific privilege, and allzone 1300Sstevel@tonic-gate * should be set to B_TRUE. 1310Sstevel@tonic-gate * For (3), priv should be set to PRIV_ALL, and allzone should be set 1320Sstevel@tonic-gate * to B_FALSE. 1330Sstevel@tonic-gate * 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* 1370Sstevel@tonic-gate * The privileges are checked against the Effective set for 1380Sstevel@tonic-gate * ordinary processes and checked against the Limit set 1390Sstevel@tonic-gate * for euid 0 processes that haven't manipulated their privilege 1400Sstevel@tonic-gate * sets. 1410Sstevel@tonic-gate */ 1420Sstevel@tonic-gate #define HAS_ALLPRIVS(cr) priv_isfullset(&CR_OEPRIV(cr)) 1430Sstevel@tonic-gate #define ZONEPRIVS(cr) ((cr)->cr_zone->zone_privset) 1440Sstevel@tonic-gate #define HAS_ALLZONEPRIVS(cr) priv_issubset(ZONEPRIVS(cr), &CR_OEPRIV(cr)) 1450Sstevel@tonic-gate #define HAS_PRIVILEGE(cr, pr) ((pr) == PRIV_ALL ? \ 1460Sstevel@tonic-gate HAS_ALLPRIVS(cr) : \ 1470Sstevel@tonic-gate PRIV_ISASSERT(&CR_OEPRIV(cr), pr)) 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate /* 1506134Scasper * Policy checking functions. 1510Sstevel@tonic-gate * 1526134Scasper * All of the system's policy should be implemented here. 1530Sstevel@tonic-gate */ 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1566134Scasper * Private functions which take an additional va_list argument to 1576134Scasper * implement an object specific policy override. 1586134Scasper */ 1596134Scasper static int priv_policy_ap(const cred_t *, int, boolean_t, int, 1606134Scasper const char *, va_list); 1616134Scasper static int priv_policy_va(const cred_t *, int, boolean_t, int, 1626134Scasper const char *, ...); 1636134Scasper 1646134Scasper /* 1650Sstevel@tonic-gate * Generic policy calls 1660Sstevel@tonic-gate * 1670Sstevel@tonic-gate * The "bottom" functions of policy control 1680Sstevel@tonic-gate */ 1690Sstevel@tonic-gate static char * 1700Sstevel@tonic-gate mprintf(const char *fmt, ...) 1710Sstevel@tonic-gate { 1720Sstevel@tonic-gate va_list args; 1730Sstevel@tonic-gate char *buf; 1740Sstevel@tonic-gate size_t len; 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate va_start(args, fmt); 1770Sstevel@tonic-gate len = vsnprintf(NULL, 0, fmt, args) + 1; 1780Sstevel@tonic-gate va_end(args); 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate buf = kmem_alloc(len, KM_NOSLEEP); 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate if (buf == NULL) 1830Sstevel@tonic-gate return (NULL); 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate va_start(args, fmt); 1860Sstevel@tonic-gate (void) vsnprintf(buf, len, fmt, args); 1870Sstevel@tonic-gate va_end(args); 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate return (buf); 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate /* 1930Sstevel@tonic-gate * priv_policy_errmsg() 1940Sstevel@tonic-gate * 1950Sstevel@tonic-gate * Generate an error message if privilege debugging is enabled system wide 1960Sstevel@tonic-gate * or for this particular process. 1970Sstevel@tonic-gate */ 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate #define FMTHDR "%s[%d]: missing privilege \"%s\" (euid = %d, syscall = %d)" 2000Sstevel@tonic-gate #define FMTMSG " for \"%s\"" 2010Sstevel@tonic-gate #define FMTFUN " needed at %s+0x%lx" 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* The maximum size privilege format: the concatenation of the above */ 2040Sstevel@tonic-gate #define FMTMAX FMTHDR FMTMSG FMTFUN "\n" 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate static void 2070Sstevel@tonic-gate priv_policy_errmsg(const cred_t *cr, int priv, const char *msg) 2080Sstevel@tonic-gate { 2090Sstevel@tonic-gate struct proc *me; 2100Sstevel@tonic-gate pc_t stack[MAXPRIVSTACK]; 2110Sstevel@tonic-gate int depth; 2120Sstevel@tonic-gate int i; 2130Sstevel@tonic-gate char *sym; 2140Sstevel@tonic-gate ulong_t off; 2150Sstevel@tonic-gate const char *pname; 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate char *cmd; 2180Sstevel@tonic-gate char fmt[sizeof (FMTMAX)]; 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate if ((me = curproc) == &p0) 2210Sstevel@tonic-gate return; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate /* Privileges must be defined */ 2240Sstevel@tonic-gate ASSERT(priv == PRIV_ALL || priv == PRIV_MULTIPLE || 2250Sstevel@tonic-gate priv == PRIV_ALLZONE || priv == PRIV_GLOBAL || 2260Sstevel@tonic-gate priv_getbynum(priv) != NULL); 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate if (priv == PRIV_ALLZONE && INGLOBALZONE(me)) 2290Sstevel@tonic-gate priv = PRIV_ALL; 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate if (curthread->t_pre_sys) 2320Sstevel@tonic-gate ttolwp(curthread)->lwp_badpriv = (short)priv; 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate if (priv_debug == 0 && (CR_FLAGS(cr) & PRIV_DEBUG) == 0) 2350Sstevel@tonic-gate return; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate (void) strcpy(fmt, FMTHDR); 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate if (me->p_user.u_comm[0]) 2400Sstevel@tonic-gate cmd = &me->p_user.u_comm[0]; 2410Sstevel@tonic-gate else 2420Sstevel@tonic-gate cmd = "priv_policy"; 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate if (msg != NULL && *msg != '\0') { 2450Sstevel@tonic-gate (void) strcat(fmt, FMTMSG); 2460Sstevel@tonic-gate } else { 2470Sstevel@tonic-gate (void) strcat(fmt, "%s"); 2480Sstevel@tonic-gate msg = ""; 2490Sstevel@tonic-gate } 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate sym = NULL; 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate depth = getpcstack(stack, MAXPRIVSTACK); 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate /* 2560Sstevel@tonic-gate * Try to find the first interesting function on the stack. 2570Sstevel@tonic-gate * priv_policy* that's us, so completely uninteresting. 2580Sstevel@tonic-gate * suser(), drv_priv(), secpolicy_* are also called from 2590Sstevel@tonic-gate * too many locations to convey useful information. 2600Sstevel@tonic-gate */ 2610Sstevel@tonic-gate for (i = 0; i < depth; i++) { 2620Sstevel@tonic-gate sym = kobj_getsymname((uintptr_t)stack[i], &off); 2630Sstevel@tonic-gate if (sym != NULL && 2640Sstevel@tonic-gate strstr(sym, "hasprocperm") == 0 && 2650Sstevel@tonic-gate strcmp("suser", sym) != 0 && 2660Sstevel@tonic-gate strcmp("ipcaccess", sym) != 0 && 2670Sstevel@tonic-gate strcmp("drv_priv", sym) != 0 && 2680Sstevel@tonic-gate strncmp("secpolicy_", sym, 10) != 0 && 2690Sstevel@tonic-gate strncmp("priv_policy", sym, 11) != 0) 2700Sstevel@tonic-gate break; 2710Sstevel@tonic-gate } 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate if (sym != NULL) 2740Sstevel@tonic-gate (void) strcat(fmt, FMTFUN); 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate (void) strcat(fmt, "\n"); 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate switch (priv) { 2790Sstevel@tonic-gate case PRIV_ALL: 2800Sstevel@tonic-gate pname = "ALL"; 2810Sstevel@tonic-gate break; 2820Sstevel@tonic-gate case PRIV_MULTIPLE: 2830Sstevel@tonic-gate pname = "MULTIPLE"; 2840Sstevel@tonic-gate break; 2850Sstevel@tonic-gate case PRIV_ALLZONE: 2860Sstevel@tonic-gate pname = "ZONE"; 2870Sstevel@tonic-gate break; 2880Sstevel@tonic-gate case PRIV_GLOBAL: 2890Sstevel@tonic-gate pname = "GLOBAL"; 2900Sstevel@tonic-gate break; 2910Sstevel@tonic-gate default: 2920Sstevel@tonic-gate pname = priv_getbynum(priv); 2930Sstevel@tonic-gate break; 2940Sstevel@tonic-gate } 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate if (CR_FLAGS(cr) & PRIV_DEBUG) { 2970Sstevel@tonic-gate /* Remember last message, just like lwp_badpriv. */ 2980Sstevel@tonic-gate if (curthread->t_pdmsg != NULL) { 2990Sstevel@tonic-gate kmem_free(curthread->t_pdmsg, 3000Sstevel@tonic-gate strlen(curthread->t_pdmsg) + 1); 3010Sstevel@tonic-gate } 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate curthread->t_pdmsg = mprintf(fmt, cmd, me->p_pid, pname, 3044543Smarks cr->cr_uid, curthread->t_sysnum, msg, sym, off); 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate curthread->t_post_sys = 1; 3076134Scasper } 3086134Scasper if (priv_debug) { 3090Sstevel@tonic-gate cmn_err(CE_NOTE, fmt, cmd, me->p_pid, pname, cr->cr_uid, 3100Sstevel@tonic-gate curthread->t_sysnum, msg, sym, off); 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate } 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate /* 3156134Scasper * Override the policy, if appropriate. Return 0 if the external 3166134Scasper * policy engine approves. 3176134Scasper */ 3186134Scasper static int 3196134Scasper priv_policy_override(const cred_t *cr, int priv, boolean_t allzone, va_list ap) 3206134Scasper { 3216134Scasper priv_set_t set; 3226134Scasper int ret; 3236134Scasper 3246134Scasper if (!(CR_FLAGS(cr) & PRIV_XPOLICY)) 3256134Scasper return (-1); 3266134Scasper 3276134Scasper if (priv == PRIV_ALL) { 3286134Scasper priv_fillset(&set); 3296134Scasper } else if (allzone) { 3306134Scasper set = *ZONEPRIVS(cr); 3316134Scasper } else { 3326134Scasper priv_emptyset(&set); 3336134Scasper priv_addset(&set, priv); 3346134Scasper } 3356134Scasper ret = klpd_call(cr, &set, ap); 3366134Scasper return (ret); 3376134Scasper } 3386134Scasper 3396134Scasper static int 3406134Scasper priv_policy_override_set(const cred_t *cr, const priv_set_t *req, ...) 3416134Scasper { 3426134Scasper va_list ap; 3436134Scasper 3446134Scasper if (CR_FLAGS(cr) & PRIV_XPOLICY) { 3456134Scasper va_start(ap, req); 3466134Scasper return (klpd_call(cr, req, ap)); 3476134Scasper } 3486134Scasper return (-1); 3496134Scasper } 3506134Scasper 3516134Scasper /* 3520Sstevel@tonic-gate * Audit failure, log error message. 3530Sstevel@tonic-gate */ 3540Sstevel@tonic-gate static void 3550Sstevel@tonic-gate priv_policy_err(const cred_t *cr, int priv, boolean_t allzone, const char *msg) 3560Sstevel@tonic-gate { 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate if (audit_active) 3590Sstevel@tonic-gate audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 0); 3600Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || 3630Sstevel@tonic-gate curthread->t_pre_sys) { 3640Sstevel@tonic-gate if (allzone && !HAS_ALLZONEPRIVS(cr)) { 3650Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_ALLZONE, msg); 3660Sstevel@tonic-gate } else { 3670Sstevel@tonic-gate ASSERT(!HAS_PRIVILEGE(cr, priv)); 3680Sstevel@tonic-gate priv_policy_errmsg(cr, priv, msg); 3690Sstevel@tonic-gate } 3700Sstevel@tonic-gate } 3710Sstevel@tonic-gate } 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate /* 3746134Scasper * priv_policy_ap() 3750Sstevel@tonic-gate * return 0 or error. 3760Sstevel@tonic-gate * See block comment above for a description of "priv" and "allzone" usage. 3770Sstevel@tonic-gate */ 3786134Scasper static int 3796134Scasper priv_policy_ap(const cred_t *cr, int priv, boolean_t allzone, int err, 3806134Scasper const char *msg, va_list ap) 3810Sstevel@tonic-gate { 3826134Scasper if ((HAS_PRIVILEGE(cr, priv) && (!allzone || HAS_ALLZONEPRIVS(cr))) || 3836134Scasper (!servicing_interrupt() && 3846134Scasper priv_policy_override(cr, priv, allzone, ap) == 0)) { 3850Sstevel@tonic-gate if ((allzone || priv == PRIV_ALL || 3860Sstevel@tonic-gate !PRIV_ISASSERT(priv_basic, priv)) && 3870Sstevel@tonic-gate !servicing_interrupt()) { 3883446Smrj PTOU(curproc)->u_acflag |= ASU; /* Needed for SVVS */ 3890Sstevel@tonic-gate if (audit_active) 3900Sstevel@tonic-gate audit_priv(priv, 3910Sstevel@tonic-gate allzone ? ZONEPRIVS(cr) : NULL, 1); 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate err = 0; 3940Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 3950Sstevel@tonic-gate } else if (!servicing_interrupt()) { 3960Sstevel@tonic-gate /* Failure audited in this procedure */ 3970Sstevel@tonic-gate priv_policy_err(cr, priv, allzone, msg); 3980Sstevel@tonic-gate } 3996134Scasper return (err); 4006134Scasper } 4010Sstevel@tonic-gate 4026134Scasper int 4036134Scasper priv_policy_va(const cred_t *cr, int priv, boolean_t allzone, int err, 4046134Scasper const char *msg, ...) 4056134Scasper { 4066134Scasper int ret; 4076134Scasper va_list ap; 4086134Scasper 4096134Scasper va_start(ap, msg); 4106134Scasper ret = priv_policy_ap(cr, priv, allzone, err, msg, ap); 4116134Scasper va_end(ap); 4126134Scasper 4136134Scasper return (ret); 4146134Scasper } 4156134Scasper 4166134Scasper int 4176134Scasper priv_policy(const cred_t *cr, int priv, boolean_t allzone, int err, 4186134Scasper const char *msg) 4196134Scasper { 4206134Scasper return (priv_policy_va(cr, priv, allzone, err, msg, KLPDARG_NOMORE)); 4210Sstevel@tonic-gate } 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate /* 4240Sstevel@tonic-gate * Return B_TRUE for sufficient privileges, B_FALSE for insufficient privileges. 4250Sstevel@tonic-gate */ 4260Sstevel@tonic-gate boolean_t 4270Sstevel@tonic-gate priv_policy_choice(const cred_t *cr, int priv, boolean_t allzone) 4280Sstevel@tonic-gate { 4290Sstevel@tonic-gate boolean_t res = HAS_PRIVILEGE(cr, priv) && 4300Sstevel@tonic-gate (!allzone || HAS_ALLZONEPRIVS(cr)); 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate /* Audit success only */ 4330Sstevel@tonic-gate if (res && audit_active && 4340Sstevel@tonic-gate (allzone || priv == PRIV_ALL || !PRIV_ISASSERT(priv_basic, priv)) && 4350Sstevel@tonic-gate !servicing_interrupt()) { 4360Sstevel@tonic-gate audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 1); 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate if (res) { 4390Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 4400Sstevel@tonic-gate } else { 4410Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 4420Sstevel@tonic-gate } 4430Sstevel@tonic-gate return (res); 4440Sstevel@tonic-gate } 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate /* 4470Sstevel@tonic-gate * Non-auditing variant of priv_policy_choice(). 4480Sstevel@tonic-gate */ 4490Sstevel@tonic-gate boolean_t 4500Sstevel@tonic-gate priv_policy_only(const cred_t *cr, int priv, boolean_t allzone) 4510Sstevel@tonic-gate { 4520Sstevel@tonic-gate boolean_t res = HAS_PRIVILEGE(cr, priv) && 4530Sstevel@tonic-gate (!allzone || HAS_ALLZONEPRIVS(cr)); 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate if (res) { 4560Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 4570Sstevel@tonic-gate } else { 4580Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 4590Sstevel@tonic-gate } 4600Sstevel@tonic-gate return (res); 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate /* 4640Sstevel@tonic-gate * Check whether all privileges in the required set are present. 4650Sstevel@tonic-gate */ 4660Sstevel@tonic-gate static int 4670Sstevel@tonic-gate secpolicy_require_set(const cred_t *cr, const priv_set_t *req, const char *msg) 4680Sstevel@tonic-gate { 4690Sstevel@tonic-gate int priv; 4700Sstevel@tonic-gate int pfound = -1; 4710Sstevel@tonic-gate priv_set_t pset; 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate if (req == PRIV_FULLSET ? HAS_ALLPRIVS(cr) : priv_issubset(req, 4744543Smarks &CR_OEPRIV(cr))) { 4750Sstevel@tonic-gate return (0); 4760Sstevel@tonic-gate } 4770Sstevel@tonic-gate 4786134Scasper if (priv_policy_override_set(cr, req, KLPDARG_NOMORE) == 0) 4796134Scasper return (0); 4806134Scasper 4810Sstevel@tonic-gate if (req == PRIV_FULLSET || priv_isfullset(req)) { 4820Sstevel@tonic-gate priv_policy_err(cr, PRIV_ALL, B_FALSE, msg); 4830Sstevel@tonic-gate return (EACCES); 4840Sstevel@tonic-gate } 4850Sstevel@tonic-gate 4860Sstevel@tonic-gate pset = CR_OEPRIV(cr); /* present privileges */ 4870Sstevel@tonic-gate priv_inverse(&pset); /* all non present privileges */ 4880Sstevel@tonic-gate priv_intersect(req, &pset); /* the actual missing privs */ 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate if (audit_active) 4910Sstevel@tonic-gate audit_priv(PRIV_NONE, &pset, 0); 4920Sstevel@tonic-gate /* 4930Sstevel@tonic-gate * Privilege debugging; special case "one privilege in set". 4940Sstevel@tonic-gate */ 4950Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || curthread->t_pre_sys) { 4960Sstevel@tonic-gate for (priv = 0; priv < nprivs; priv++) { 4970Sstevel@tonic-gate if (priv_ismember(&pset, priv)) { 4980Sstevel@tonic-gate if (pfound != -1) { 4990Sstevel@tonic-gate /* Multiple missing privs */ 5000Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_MULTIPLE, 5014543Smarks msg); 5020Sstevel@tonic-gate return (EACCES); 5030Sstevel@tonic-gate } 5040Sstevel@tonic-gate pfound = priv; 5050Sstevel@tonic-gate } 5060Sstevel@tonic-gate } 5070Sstevel@tonic-gate ASSERT(pfound != -1); 5080Sstevel@tonic-gate /* Just the one missing privilege */ 5090Sstevel@tonic-gate priv_policy_errmsg(cr, pfound, msg); 5100Sstevel@tonic-gate } 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate return (EACCES); 5130Sstevel@tonic-gate } 5140Sstevel@tonic-gate 5150Sstevel@tonic-gate /* 5160Sstevel@tonic-gate * Called when an operation requires that the caller be in the 5170Sstevel@tonic-gate * global zone, regardless of privilege. 5180Sstevel@tonic-gate */ 5190Sstevel@tonic-gate static int 5200Sstevel@tonic-gate priv_policy_global(const cred_t *cr) 5210Sstevel@tonic-gate { 5220Sstevel@tonic-gate if (crgetzoneid(cr) == GLOBAL_ZONEID) 5230Sstevel@tonic-gate return (0); /* success */ 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || 5260Sstevel@tonic-gate curthread->t_pre_sys) { 5270Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_GLOBAL, NULL); 5280Sstevel@tonic-gate } 5290Sstevel@tonic-gate return (EPERM); 5300Sstevel@tonic-gate } 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate /* 5330Sstevel@tonic-gate * Changing process priority 5340Sstevel@tonic-gate */ 5350Sstevel@tonic-gate int 5360Sstevel@tonic-gate secpolicy_setpriority(const cred_t *cr) 5370Sstevel@tonic-gate { 5380Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_PRIOCNTL, B_FALSE, EPERM, NULL)); 5390Sstevel@tonic-gate } 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate /* 5420Sstevel@tonic-gate * Binding to a privileged port, port must be specified in host byte 5430Sstevel@tonic-gate * order. 5440Sstevel@tonic-gate */ 5450Sstevel@tonic-gate int 5466134Scasper secpolicy_net_privaddr(const cred_t *cr, in_port_t port, int proto) 5470Sstevel@tonic-gate { 5485331Samw char *reason; 5495331Samw int priv; 5505331Samw 5515331Samw switch (port) { 5525331Samw case 137: 5535331Samw case 138: 5545331Samw case 139: 5555331Samw case 445: 5565331Samw /* 5575331Samw * NBT and SMB ports, these are extra privileged ports, 5585331Samw * allow bind only if the SYS_SMB privilege is present. 5595331Samw */ 5605331Samw priv = PRIV_SYS_SMB; 5615331Samw reason = "NBT or SMB port"; 5625331Samw break; 5635331Samw 5645331Samw case 2049: 5655331Samw case 4045: 5665331Samw /* 5675331Samw * NFS ports, these are extra privileged ports, allow bind 5685331Samw * only if the SYS_NFS privilege is present. 5695331Samw */ 5705331Samw priv = PRIV_SYS_NFS; 5715331Samw reason = "NFS port"; 5725331Samw break; 5735331Samw 5745331Samw default: 5755331Samw priv = PRIV_NET_PRIVADDR; 5765331Samw reason = NULL; 5775331Samw break; 5785331Samw 5795331Samw } 5805331Samw 5816134Scasper return (priv_policy_va(cr, priv, B_FALSE, EACCES, reason, 5826134Scasper KLPDARG_PORT, (int)proto, (int)port, KLPDARG_NOMORE)); 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate /* 5861676Sjpk * Binding to a multilevel port on a trusted (labeled) system. 5871676Sjpk */ 5881676Sjpk int 5891676Sjpk secpolicy_net_bindmlp(const cred_t *cr) 5901676Sjpk { 5916134Scasper return (PRIV_POLICY(cr, PRIV_NET_BINDMLP, B_FALSE, EACCES, NULL)); 5921676Sjpk } 5931676Sjpk 5941676Sjpk /* 5951676Sjpk * Allow a communication between a zone and an unlabeled host when their 5961676Sjpk * labels don't match. 5971676Sjpk */ 5981676Sjpk int 5991676Sjpk secpolicy_net_mac_aware(const cred_t *cr) 6001676Sjpk { 6016134Scasper return (PRIV_POLICY(cr, PRIV_NET_MAC_AWARE, B_FALSE, EACCES, NULL)); 6021676Sjpk } 6031676Sjpk 6041676Sjpk /* 6050Sstevel@tonic-gate * Common routine which determines whether a given credential can 6060Sstevel@tonic-gate * act on a given mount. 6070Sstevel@tonic-gate * When called through mount, the parameter needoptcheck is a pointer 6080Sstevel@tonic-gate * to a boolean variable which will be set to either true or false, 6090Sstevel@tonic-gate * depending on whether the mount policy should change the mount options. 6100Sstevel@tonic-gate * In all other cases, needoptcheck should be a NULL pointer. 6110Sstevel@tonic-gate */ 6120Sstevel@tonic-gate static int 6130Sstevel@tonic-gate secpolicy_fs_common(cred_t *cr, vnode_t *mvp, const vfs_t *vfsp, 6140Sstevel@tonic-gate boolean_t *needoptcheck) 6150Sstevel@tonic-gate { 6160Sstevel@tonic-gate boolean_t allzone = B_FALSE; 6170Sstevel@tonic-gate boolean_t mounting = needoptcheck != NULL; 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate /* 6200Sstevel@tonic-gate * Short circuit the following cases: 6210Sstevel@tonic-gate * vfsp == NULL or mvp == NULL (pure privilege check) 6220Sstevel@tonic-gate * have all privileges - no further checks required 6230Sstevel@tonic-gate * and no mount options need to be set. 6240Sstevel@tonic-gate */ 6250Sstevel@tonic-gate if (vfsp == NULL || mvp == NULL || HAS_ALLPRIVS(cr)) { 6260Sstevel@tonic-gate if (mounting) 6270Sstevel@tonic-gate *needoptcheck = B_FALSE; 6280Sstevel@tonic-gate 6296134Scasper return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM, 6306134Scasper NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE)); 6310Sstevel@tonic-gate } 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate /* 6340Sstevel@tonic-gate * When operating on an existing mount (either we're not mounting 6350Sstevel@tonic-gate * or we're doing a remount and VFS_REMOUNT will be set), zones 6360Sstevel@tonic-gate * can operate only on mounts established by the zone itself. 6370Sstevel@tonic-gate */ 6380Sstevel@tonic-gate if (!mounting || (vfsp->vfs_flag & VFS_REMOUNT) != 0) { 6390Sstevel@tonic-gate zoneid_t zoneid = crgetzoneid(cr); 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate if (zoneid != GLOBAL_ZONEID && 6420Sstevel@tonic-gate vfsp->vfs_zone->zone_id != zoneid) { 6430Sstevel@tonic-gate return (EPERM); 6440Sstevel@tonic-gate } 6450Sstevel@tonic-gate } 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate if (mounting) 6480Sstevel@tonic-gate *needoptcheck = B_TRUE; 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate /* 6510Sstevel@tonic-gate * Overlay mounts may hide important stuff; if you can't write to a 6520Sstevel@tonic-gate * mount point but would be able to mount on top of it, you can 6530Sstevel@tonic-gate * escalate your privileges. 6540Sstevel@tonic-gate * So we go about asking the same questions namefs does when it 6550Sstevel@tonic-gate * decides whether you can mount over a file or not but with the 6560Sstevel@tonic-gate * added restriction that you can only mount on top of a regular 6570Sstevel@tonic-gate * file or directory. 6580Sstevel@tonic-gate * If we have all the zone's privileges, we skip all other checks, 6590Sstevel@tonic-gate * or else we may actually get in trouble inside the automounter. 6600Sstevel@tonic-gate */ 6610Sstevel@tonic-gate if ((mvp->v_flag & VROOT) != 0 || 6620Sstevel@tonic-gate (mvp->v_type != VDIR && mvp->v_type != VREG) || 6630Sstevel@tonic-gate HAS_ALLZONEPRIVS(cr)) { 6640Sstevel@tonic-gate allzone = B_TRUE; 6650Sstevel@tonic-gate } else { 6660Sstevel@tonic-gate vattr_t va; 6670Sstevel@tonic-gate int err; 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate va.va_mask = AT_UID|AT_MODE; 6705331Samw err = VOP_GETATTR(mvp, &va, 0, cr, NULL); 6710Sstevel@tonic-gate if (err != 0) 6720Sstevel@tonic-gate return (err); 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate if ((err = secpolicy_vnode_owner(cr, va.va_uid)) != 0) 6750Sstevel@tonic-gate return (err); 6760Sstevel@tonic-gate 6770Sstevel@tonic-gate if ((va.va_mode & VWRITE) == 0 && 6780Sstevel@tonic-gate secpolicy_vnode_access(cr, mvp, va.va_uid, VWRITE) != 0) { 6790Sstevel@tonic-gate return (EACCES); 6800Sstevel@tonic-gate } 6810Sstevel@tonic-gate } 6826134Scasper return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM, 6836134Scasper NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE)); 6840Sstevel@tonic-gate } 6850Sstevel@tonic-gate 6864543Smarks void 6874543Smarks secpolicy_fs_mount_clearopts(cred_t *cr, struct vfs *vfsp) 6884543Smarks { 6894543Smarks boolean_t amsuper = HAS_ALLZONEPRIVS(cr); 6904543Smarks 6914543Smarks /* 6924543Smarks * check; if we don't have either "nosuid" or 6934543Smarks * both "nosetuid" and "nodevices", then we add 6944543Smarks * "nosuid"; this depends on how the current 6954543Smarks * implementation works (it first checks nosuid). In a 6964543Smarks * zone, a user with all zone privileges can mount with 6974543Smarks * "setuid" but never with "devices". 6984543Smarks */ 6994543Smarks if (!vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL) && 7004543Smarks (!vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL) || 7014543Smarks !vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL))) { 7024543Smarks if (crgetzoneid(cr) == GLOBAL_ZONEID || !amsuper) 7034543Smarks vfs_setmntopt(vfsp, MNTOPT_NOSUID, NULL, 0); 7044543Smarks else 7054543Smarks vfs_setmntopt(vfsp, MNTOPT_NODEVICES, NULL, 0); 7064543Smarks } 7074543Smarks /* 7084543Smarks * If we're not the local super user, we set the "restrict" 7094543Smarks * option to indicate to automountd that this mount should 7104543Smarks * be handled with care. 7114543Smarks */ 7124543Smarks if (!amsuper) 7134543Smarks vfs_setmntopt(vfsp, MNTOPT_RESTRICT, NULL, 0); 7144543Smarks 7154543Smarks } 7164543Smarks 717148Scasper extern vnode_t *rootvp; 718148Scasper extern vfs_t *rootvfs; 719148Scasper 7200Sstevel@tonic-gate int 7210Sstevel@tonic-gate secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct vfs *vfsp) 7220Sstevel@tonic-gate { 7230Sstevel@tonic-gate boolean_t needoptchk; 7240Sstevel@tonic-gate int error; 7250Sstevel@tonic-gate 726148Scasper /* 727148Scasper * If it's a remount, get the underlying mount point, 728148Scasper * except for the root where we use the rootvp. 729148Scasper */ 730148Scasper if ((vfsp->vfs_flag & VFS_REMOUNT) != 0) { 731148Scasper if (vfsp == rootvfs) 732148Scasper mvp = rootvp; 733148Scasper else 734148Scasper mvp = vfsp->vfs_vnodecovered; 735148Scasper } 736148Scasper 7370Sstevel@tonic-gate error = secpolicy_fs_common(cr, mvp, vfsp, &needoptchk); 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate if (error == 0 && needoptchk) { 7404543Smarks secpolicy_fs_mount_clearopts(cr, vfsp); 7414543Smarks } 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate return (error); 7440Sstevel@tonic-gate } 7450Sstevel@tonic-gate 7460Sstevel@tonic-gate /* 7470Sstevel@tonic-gate * Does the policy computations for "ownership" of a mount; 7480Sstevel@tonic-gate * here ownership is defined as the ability to "mount" 7490Sstevel@tonic-gate * the filesystem originally. The rootvfs doesn't cover any 7500Sstevel@tonic-gate * vnodes; we attribute its ownership to the rootvp. 7510Sstevel@tonic-gate */ 7520Sstevel@tonic-gate static int 7530Sstevel@tonic-gate secpolicy_fs_owner(cred_t *cr, const struct vfs *vfsp) 7540Sstevel@tonic-gate { 7550Sstevel@tonic-gate vnode_t *mvp; 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate if (vfsp == NULL) 7580Sstevel@tonic-gate mvp = NULL; 7590Sstevel@tonic-gate else if (vfsp == rootvfs) 7600Sstevel@tonic-gate mvp = rootvp; 7610Sstevel@tonic-gate else 7620Sstevel@tonic-gate mvp = vfsp->vfs_vnodecovered; 7630Sstevel@tonic-gate 7640Sstevel@tonic-gate return (secpolicy_fs_common(cr, mvp, vfsp, NULL)); 7650Sstevel@tonic-gate } 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate int 7680Sstevel@tonic-gate secpolicy_fs_unmount(cred_t *cr, struct vfs *vfsp) 7690Sstevel@tonic-gate { 7700Sstevel@tonic-gate return (secpolicy_fs_owner(cr, vfsp)); 7710Sstevel@tonic-gate } 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate /* 7740Sstevel@tonic-gate * Quotas are a resource, but if one has the ability to mount a filesystem, he 7750Sstevel@tonic-gate * should be able to modify quotas on it. 7760Sstevel@tonic-gate */ 7770Sstevel@tonic-gate int 7780Sstevel@tonic-gate secpolicy_fs_quota(const cred_t *cr, const vfs_t *vfsp) 7790Sstevel@tonic-gate { 7800Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate 7830Sstevel@tonic-gate /* 7840Sstevel@tonic-gate * Exceeding minfree: also a per-mount resource constraint. 7850Sstevel@tonic-gate */ 7860Sstevel@tonic-gate int 7870Sstevel@tonic-gate secpolicy_fs_minfree(const cred_t *cr, const vfs_t *vfsp) 7880Sstevel@tonic-gate { 7890Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 7900Sstevel@tonic-gate } 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate int 7930Sstevel@tonic-gate secpolicy_fs_config(const cred_t *cr, const vfs_t *vfsp) 7940Sstevel@tonic-gate { 7950Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 7960Sstevel@tonic-gate } 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate /* ARGSUSED */ 7990Sstevel@tonic-gate int 8000Sstevel@tonic-gate secpolicy_fs_linkdir(const cred_t *cr, const vfs_t *vfsp) 8010Sstevel@tonic-gate { 8020Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_LINKDIR, B_FALSE, EPERM, NULL)); 8030Sstevel@tonic-gate } 8040Sstevel@tonic-gate 8050Sstevel@tonic-gate /* 8060Sstevel@tonic-gate * Name: secpolicy_vnode_access() 8070Sstevel@tonic-gate * 8080Sstevel@tonic-gate * Parameters: Process credential 8090Sstevel@tonic-gate * vnode 8100Sstevel@tonic-gate * uid of owner of vnode 8110Sstevel@tonic-gate * permission bits not granted to the caller when examining 8120Sstevel@tonic-gate * file mode bits (i.e., when a process wants to open a 8130Sstevel@tonic-gate * mode 444 file for VREAD|VWRITE, this function should be 8140Sstevel@tonic-gate * called only with a VWRITE argument). 8150Sstevel@tonic-gate * 8160Sstevel@tonic-gate * Normal: Verifies that cred has the appropriate privileges to 8170Sstevel@tonic-gate * override the mode bits that were denied. 8180Sstevel@tonic-gate * 8190Sstevel@tonic-gate * Override: file_dac_execute - if VEXEC bit was denied and vnode is 8200Sstevel@tonic-gate * not a directory. 8210Sstevel@tonic-gate * file_dac_read - if VREAD bit was denied. 8220Sstevel@tonic-gate * file_dac_search - if VEXEC bit was denied and vnode is 8230Sstevel@tonic-gate * a directory. 8240Sstevel@tonic-gate * file_dac_write - if VWRITE bit was denied. 8250Sstevel@tonic-gate * 8260Sstevel@tonic-gate * Root owned files are special cased to protect system 8270Sstevel@tonic-gate * configuration files and such. 8280Sstevel@tonic-gate * 8290Sstevel@tonic-gate * Output: EACCES - if privilege check fails. 8300Sstevel@tonic-gate */ 8310Sstevel@tonic-gate 8320Sstevel@tonic-gate /* ARGSUSED */ 8330Sstevel@tonic-gate int 8340Sstevel@tonic-gate secpolicy_vnode_access(const cred_t *cr, vnode_t *vp, uid_t owner, mode_t mode) 8350Sstevel@tonic-gate { 8366134Scasper if ((mode & VREAD) && priv_policy_va(cr, PRIV_FILE_DAC_READ, B_FALSE, 8376134Scasper EACCES, NULL, KLPDARG_VNODE, vp, (char *)NULL, 8386134Scasper KLPDARG_NOMORE) != 0) { 8390Sstevel@tonic-gate return (EACCES); 8406134Scasper } 8410Sstevel@tonic-gate 8420Sstevel@tonic-gate if (mode & VWRITE) { 8430Sstevel@tonic-gate boolean_t allzone; 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate if (owner == 0 && cr->cr_uid != 0) 8460Sstevel@tonic-gate allzone = B_TRUE; 8470Sstevel@tonic-gate else 8480Sstevel@tonic-gate allzone = B_FALSE; 8496134Scasper if (priv_policy_va(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES, 8506134Scasper NULL, KLPDARG_VNODE, vp, (char *)NULL, 8516134Scasper KLPDARG_NOMORE) != 0) { 8520Sstevel@tonic-gate return (EACCES); 8536134Scasper } 8540Sstevel@tonic-gate } 8550Sstevel@tonic-gate 8560Sstevel@tonic-gate if (mode & VEXEC) { 8570Sstevel@tonic-gate /* 8580Sstevel@tonic-gate * Directories use file_dac_search to override the execute bit. 8590Sstevel@tonic-gate */ 8606134Scasper int p = vp->v_type == VDIR ? PRIV_FILE_DAC_SEARCH : 8616134Scasper PRIV_FILE_DAC_EXECUTE; 8620Sstevel@tonic-gate 8636134Scasper return (priv_policy_va(cr, p, B_FALSE, EACCES, NULL, 8646134Scasper KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE)); 8650Sstevel@tonic-gate } 8660Sstevel@tonic-gate return (0); 8670Sstevel@tonic-gate } 8680Sstevel@tonic-gate 8690Sstevel@tonic-gate /* 8700Sstevel@tonic-gate * Name: secpolicy_vnode_setid_modify() 8710Sstevel@tonic-gate * 8720Sstevel@tonic-gate * Normal: verify that subject can set the file setid flags. 8730Sstevel@tonic-gate * 8740Sstevel@tonic-gate * Output: EPERM - if not privileged. 8750Sstevel@tonic-gate */ 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate static int 8780Sstevel@tonic-gate secpolicy_vnode_setid_modify(const cred_t *cr, uid_t owner) 8790Sstevel@tonic-gate { 8800Sstevel@tonic-gate /* If changing to suid root, must have all zone privs */ 8810Sstevel@tonic-gate boolean_t allzone = B_TRUE; 8820Sstevel@tonic-gate 8830Sstevel@tonic-gate if (owner != 0) { 8840Sstevel@tonic-gate if (owner == cr->cr_uid) 8850Sstevel@tonic-gate return (0); 8860Sstevel@tonic-gate allzone = B_FALSE; 8870Sstevel@tonic-gate } 8880Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_SETID, allzone, EPERM, NULL)); 8890Sstevel@tonic-gate } 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate /* 8920Sstevel@tonic-gate * Are we allowed to retain the set-uid/set-gid bits when 8930Sstevel@tonic-gate * changing ownership or when writing to a file? 8940Sstevel@tonic-gate * "issuid" should be true when set-uid; only in that case 8950Sstevel@tonic-gate * root ownership is checked (setgid is assumed). 8960Sstevel@tonic-gate */ 8970Sstevel@tonic-gate int 8980Sstevel@tonic-gate secpolicy_vnode_setid_retain(const cred_t *cred, boolean_t issuidroot) 8990Sstevel@tonic-gate { 9000Sstevel@tonic-gate if (issuidroot && !HAS_ALLZONEPRIVS(cred)) 9010Sstevel@tonic-gate return (EPERM); 9020Sstevel@tonic-gate 9030Sstevel@tonic-gate return (!PRIV_POLICY_CHOICE(cred, PRIV_FILE_SETID, B_FALSE)); 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate /* 9070Sstevel@tonic-gate * Name: secpolicy_vnode_setids_setgids() 9080Sstevel@tonic-gate * 9090Sstevel@tonic-gate * Normal: verify that subject can set the file setgid flag. 9100Sstevel@tonic-gate * 9110Sstevel@tonic-gate * Output: EPERM - if not privileged 9120Sstevel@tonic-gate */ 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate int 9150Sstevel@tonic-gate secpolicy_vnode_setids_setgids(const cred_t *cred, gid_t gid) 9160Sstevel@tonic-gate { 9170Sstevel@tonic-gate if (!groupmember(gid, cred)) 9180Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_SETID, B_FALSE, EPERM, 9190Sstevel@tonic-gate NULL)); 9200Sstevel@tonic-gate return (0); 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate /* 9247624SMark.Shellenbaum@Sun.COM * Name: secpolicy_vnode_chown 9257624SMark.Shellenbaum@Sun.COM * 9267624SMark.Shellenbaum@Sun.COM * Normal: Determine if subject can chown owner of a file. 9277624SMark.Shellenbaum@Sun.COM * 9287624SMark.Shellenbaum@Sun.COM * Output: EPERM - if access denied 9297624SMark.Shellenbaum@Sun.COM */ 9307624SMark.Shellenbaum@Sun.COM 9317624SMark.Shellenbaum@Sun.COM int 9329866SMark.Shellenbaum@Sun.COM secpolicy_vnode_chown(const cred_t *cred, uid_t owner) 9337624SMark.Shellenbaum@Sun.COM { 9349866SMark.Shellenbaum@Sun.COM boolean_t is_owner = (owner == crgetuid(cred)); 9359866SMark.Shellenbaum@Sun.COM boolean_t allzone = B_FALSE; 9369866SMark.Shellenbaum@Sun.COM int priv; 9379866SMark.Shellenbaum@Sun.COM 9389866SMark.Shellenbaum@Sun.COM if (!is_owner) { 9399866SMark.Shellenbaum@Sun.COM allzone = (owner == 0); 9409866SMark.Shellenbaum@Sun.COM priv = PRIV_FILE_CHOWN; 9419866SMark.Shellenbaum@Sun.COM } else { 9429866SMark.Shellenbaum@Sun.COM priv = HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN) ? 9439866SMark.Shellenbaum@Sun.COM PRIV_FILE_CHOWN : PRIV_FILE_CHOWN_SELF; 9449866SMark.Shellenbaum@Sun.COM } 9459866SMark.Shellenbaum@Sun.COM 9469866SMark.Shellenbaum@Sun.COM return (PRIV_POLICY(cred, priv, allzone, EPERM, NULL)); 9477624SMark.Shellenbaum@Sun.COM } 9487624SMark.Shellenbaum@Sun.COM 9497624SMark.Shellenbaum@Sun.COM /* 9507624SMark.Shellenbaum@Sun.COM * Name: secpolicy_vnode_create_gid 9517624SMark.Shellenbaum@Sun.COM * 9527624SMark.Shellenbaum@Sun.COM * Normal: Determine if subject can change group ownership of a file. 9537624SMark.Shellenbaum@Sun.COM * 9547624SMark.Shellenbaum@Sun.COM * Output: EPERM - if access denied 9550Sstevel@tonic-gate */ 9560Sstevel@tonic-gate int 9570Sstevel@tonic-gate secpolicy_vnode_create_gid(const cred_t *cred) 9580Sstevel@tonic-gate { 9599866SMark.Shellenbaum@Sun.COM if (HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN)) 9609866SMark.Shellenbaum@Sun.COM return (PRIV_POLICY(cred, PRIV_FILE_CHOWN, B_FALSE, EPERM, 9619866SMark.Shellenbaum@Sun.COM NULL)); 9629866SMark.Shellenbaum@Sun.COM else 9639866SMark.Shellenbaum@Sun.COM return (PRIV_POLICY(cred, PRIV_FILE_CHOWN_SELF, B_FALSE, EPERM, 9649866SMark.Shellenbaum@Sun.COM NULL)); 9650Sstevel@tonic-gate } 9660Sstevel@tonic-gate 9670Sstevel@tonic-gate /* 9680Sstevel@tonic-gate * Name: secpolicy_vnode_utime_modify() 9690Sstevel@tonic-gate * 9700Sstevel@tonic-gate * Normal: verify that subject can modify the utime on a file. 9710Sstevel@tonic-gate * 9720Sstevel@tonic-gate * Output: EPERM - if access denied. 9730Sstevel@tonic-gate */ 9740Sstevel@tonic-gate 9750Sstevel@tonic-gate static int 9760Sstevel@tonic-gate secpolicy_vnode_utime_modify(const cred_t *cred) 9770Sstevel@tonic-gate { 9780Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_OWNER, B_FALSE, EPERM, 9790Sstevel@tonic-gate "modify file times")); 9800Sstevel@tonic-gate } 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate /* 9840Sstevel@tonic-gate * Name: secpolicy_vnode_setdac() 9850Sstevel@tonic-gate * 9860Sstevel@tonic-gate * Normal: verify that subject can modify the mode of a file. 9870Sstevel@tonic-gate * allzone privilege needed when modifying root owned object. 9880Sstevel@tonic-gate * 9890Sstevel@tonic-gate * Output: EPERM - if access denied. 9900Sstevel@tonic-gate */ 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate int 9930Sstevel@tonic-gate secpolicy_vnode_setdac(const cred_t *cred, uid_t owner) 9940Sstevel@tonic-gate { 9950Sstevel@tonic-gate if (owner == cred->cr_uid) 9960Sstevel@tonic-gate return (0); 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_OWNER, owner == 0, EPERM, NULL)); 9990Sstevel@tonic-gate } 10000Sstevel@tonic-gate /* 10010Sstevel@tonic-gate * Name: secpolicy_vnode_stky_modify() 10020Sstevel@tonic-gate * 10030Sstevel@tonic-gate * Normal: verify that subject can make a file a "sticky". 10040Sstevel@tonic-gate * 10050Sstevel@tonic-gate * Output: EPERM - if access denied. 10060Sstevel@tonic-gate */ 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate int 10090Sstevel@tonic-gate secpolicy_vnode_stky_modify(const cred_t *cred) 10100Sstevel@tonic-gate { 10110Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_SYS_CONFIG, B_FALSE, EPERM, 10120Sstevel@tonic-gate "set file sticky")); 10130Sstevel@tonic-gate } 10140Sstevel@tonic-gate 10150Sstevel@tonic-gate /* 10160Sstevel@tonic-gate * Policy determines whether we can remove an entry from a directory, 10170Sstevel@tonic-gate * regardless of permission bits. 10180Sstevel@tonic-gate */ 10190Sstevel@tonic-gate int 10200Sstevel@tonic-gate secpolicy_vnode_remove(const cred_t *cr) 10210Sstevel@tonic-gate { 10220Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_OWNER, B_FALSE, EACCES, 10230Sstevel@tonic-gate "sticky directory")); 10240Sstevel@tonic-gate } 10250Sstevel@tonic-gate 10260Sstevel@tonic-gate int 10270Sstevel@tonic-gate secpolicy_vnode_owner(const cred_t *cr, uid_t owner) 10280Sstevel@tonic-gate { 10290Sstevel@tonic-gate boolean_t allzone = (owner == 0); 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate if (owner == cr->cr_uid) 10320Sstevel@tonic-gate return (0); 10330Sstevel@tonic-gate 10340Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_OWNER, allzone, EPERM, NULL)); 10350Sstevel@tonic-gate } 10360Sstevel@tonic-gate 10371115Smarks void 10381115Smarks secpolicy_setid_clear(vattr_t *vap, cred_t *cr) 10391115Smarks { 10401115Smarks if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0 && 10411115Smarks secpolicy_vnode_setid_retain(cr, 10421115Smarks (vap->va_mode & S_ISUID) != 0 && 10431115Smarks (vap->va_mask & AT_UID) != 0 && vap->va_uid == 0) != 0) { 10441115Smarks vap->va_mask |= AT_MODE; 10451115Smarks vap->va_mode &= ~(S_ISUID|S_ISGID); 10461115Smarks } 10471115Smarks } 10481115Smarks 10492796Smarks int 10502796Smarks secpolicy_setid_setsticky_clear(vnode_t *vp, vattr_t *vap, const vattr_t *ovap, 10512796Smarks cred_t *cr) 10522796Smarks { 10532796Smarks int error; 10542796Smarks 10552796Smarks if ((vap->va_mode & S_ISUID) != 0 && 10562796Smarks (error = secpolicy_vnode_setid_modify(cr, 10572796Smarks ovap->va_uid)) != 0) { 10582796Smarks return (error); 10592796Smarks } 10602796Smarks 10612796Smarks /* 10622796Smarks * Check privilege if attempting to set the 10632796Smarks * sticky bit on a non-directory. 10642796Smarks */ 10652796Smarks if (vp->v_type != VDIR && (vap->va_mode & S_ISVTX) != 0 && 10662796Smarks secpolicy_vnode_stky_modify(cr) != 0) { 10674543Smarks vap->va_mode &= ~S_ISVTX; 10682796Smarks } 10692796Smarks 10702796Smarks /* 10712796Smarks * Check for privilege if attempting to set the 10722796Smarks * group-id bit. 10732796Smarks */ 10742796Smarks if ((vap->va_mode & S_ISGID) != 0 && 10752796Smarks secpolicy_vnode_setids_setgids(cr, ovap->va_gid) != 0) { 10764543Smarks vap->va_mode &= ~S_ISGID; 10772796Smarks } 10782796Smarks 10792796Smarks return (0); 10802796Smarks } 10812796Smarks 10825331Samw #define ATTR_FLAG_PRIV(attr, value, cr) \ 10835331Samw PRIV_POLICY(cr, value ? PRIV_FILE_FLAG_SET : PRIV_ALL, \ 10845331Samw B_FALSE, EPERM, NULL) 10855331Samw 10865331Samw /* 10875331Samw * Check privileges for setting xvattr attributes 10885331Samw */ 10895331Samw int 10905331Samw secpolicy_xvattr(xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype) 10915331Samw { 10925331Samw xoptattr_t *xoap; 10935331Samw int error = 0; 10945331Samw 10955331Samw if ((xoap = xva_getxoptattr(xvap)) == NULL) 10965331Samw return (EINVAL); 10975331Samw 10985331Samw /* 10995331Samw * First process the DOS bits 11005331Samw */ 11015331Samw if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE) || 11025331Samw XVA_ISSET_REQ(xvap, XAT_HIDDEN) || 11035331Samw XVA_ISSET_REQ(xvap, XAT_READONLY) || 11045331Samw XVA_ISSET_REQ(xvap, XAT_SYSTEM) || 11055331Samw XVA_ISSET_REQ(xvap, XAT_CREATETIME)) { 11065331Samw if ((error = secpolicy_vnode_owner(cr, owner)) != 0) 11075331Samw return (error); 11085331Samw } 11095331Samw 11105331Samw /* 11115331Samw * Now handle special attributes 11125331Samw */ 11135331Samw 11145331Samw if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) 11155331Samw error = ATTR_FLAG_PRIV(XAT_IMMUTABLE, 11165331Samw xoap->xoa_immutable, cr); 11175331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) 11185331Samw error = ATTR_FLAG_PRIV(XAT_NOUNLINK, 11195331Samw xoap->xoa_nounlink, cr); 11205331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) 11215331Samw error = ATTR_FLAG_PRIV(XAT_APPENDONLY, 11225331Samw xoap->xoa_appendonly, cr); 11235331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NODUMP)) 11245331Samw error = ATTR_FLAG_PRIV(XAT_NODUMP, 11255331Samw xoap->xoa_nodump, cr); 11265331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_OPAQUE)) 11275331Samw error = EPERM; 11285331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) { 11295331Samw error = ATTR_FLAG_PRIV(XAT_AV_QUARANTINED, 11305331Samw xoap->xoa_av_quarantined, cr); 11315545Smarks if (error == 0 && vtype != VREG && xoap->xoa_av_quarantined) 11325331Samw error = EINVAL; 11335331Samw } 11345331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) 11355331Samw error = ATTR_FLAG_PRIV(XAT_AV_MODIFIED, 11365331Samw xoap->xoa_av_modified, cr); 11375331Samw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) { 11385331Samw error = ATTR_FLAG_PRIV(XAT_AV_SCANSTAMP, 11395331Samw xoap->xoa_av_scanstamp, cr); 11405331Samw if (error == 0 && vtype != VREG) 11415331Samw error = EINVAL; 11425331Samw } 11435331Samw return (error); 11445331Samw } 11455331Samw 11460Sstevel@tonic-gate /* 11470Sstevel@tonic-gate * This function checks the policy decisions surrounding the 11480Sstevel@tonic-gate * vop setattr call. 11490Sstevel@tonic-gate * 11500Sstevel@tonic-gate * It should be called after sufficient locks have been established 11510Sstevel@tonic-gate * on the underlying data structures. No concurrent modifications 11520Sstevel@tonic-gate * should be allowed. 11530Sstevel@tonic-gate * 11540Sstevel@tonic-gate * The caller must pass in unlocked version of its vaccess function 11550Sstevel@tonic-gate * this is required because vop_access function should lock the 11560Sstevel@tonic-gate * node for reading. A three argument function should be defined 11570Sstevel@tonic-gate * which accepts the following argument: 11580Sstevel@tonic-gate * A pointer to the internal "node" type (inode *) 11590Sstevel@tonic-gate * vnode access bits (VREAD|VWRITE|VEXEC) 11600Sstevel@tonic-gate * a pointer to the credential 11610Sstevel@tonic-gate * 11620Sstevel@tonic-gate * This function makes the following policy decisions: 11630Sstevel@tonic-gate * 11640Sstevel@tonic-gate * - change permissions 11650Sstevel@tonic-gate * - permission to change file mode if not owner 11660Sstevel@tonic-gate * - permission to add sticky bit to non-directory 11670Sstevel@tonic-gate * - permission to add set-gid bit 11680Sstevel@tonic-gate * 11690Sstevel@tonic-gate * The ovap argument should include AT_MODE|AT_UID|AT_GID. 11700Sstevel@tonic-gate * 11710Sstevel@tonic-gate * If the vap argument does not include AT_MODE, the mode will be copied from 11720Sstevel@tonic-gate * ovap. In certain situations set-uid/set-gid bits need to be removed; 11730Sstevel@tonic-gate * this is done by marking vap->va_mask to include AT_MODE and va_mode 11740Sstevel@tonic-gate * is updated to the newly computed mode. 11750Sstevel@tonic-gate */ 11760Sstevel@tonic-gate 11770Sstevel@tonic-gate int 11780Sstevel@tonic-gate secpolicy_vnode_setattr(cred_t *cr, struct vnode *vp, struct vattr *vap, 11790Sstevel@tonic-gate const struct vattr *ovap, int flags, 11800Sstevel@tonic-gate int unlocked_access(void *, int, cred_t *), 11810Sstevel@tonic-gate void *node) 11820Sstevel@tonic-gate { 11830Sstevel@tonic-gate int mask = vap->va_mask; 11840Sstevel@tonic-gate int error = 0; 11855331Samw boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE; 11860Sstevel@tonic-gate 11870Sstevel@tonic-gate if (mask & AT_SIZE) { 11880Sstevel@tonic-gate if (vp->v_type == VDIR) { 11890Sstevel@tonic-gate error = EISDIR; 11900Sstevel@tonic-gate goto out; 11910Sstevel@tonic-gate } 11925331Samw 11935331Samw /* 11945331Samw * If ATTR_NOACLCHECK is set in the flags, then we don't 11955331Samw * perform the secondary unlocked_access() call since the 11965331Samw * ACL (if any) is being checked there. 11975331Samw */ 11985331Samw if (skipaclchk == B_FALSE) { 11995331Samw error = unlocked_access(node, VWRITE, cr); 12005331Samw if (error) 12015331Samw goto out; 12025331Samw } 12030Sstevel@tonic-gate } 12040Sstevel@tonic-gate if (mask & AT_MODE) { 12050Sstevel@tonic-gate /* 12060Sstevel@tonic-gate * If not the owner of the file then check privilege 12070Sstevel@tonic-gate * for two things: the privilege to set the mode at all 12080Sstevel@tonic-gate * and, if we're setting setuid, we also need permissions 12090Sstevel@tonic-gate * to add the set-uid bit, if we're not the owner. 12100Sstevel@tonic-gate * In the specific case of creating a set-uid root 12110Sstevel@tonic-gate * file, we need even more permissions. 12120Sstevel@tonic-gate */ 12130Sstevel@tonic-gate if ((error = secpolicy_vnode_setdac(cr, ovap->va_uid)) != 0) 12140Sstevel@tonic-gate goto out; 12150Sstevel@tonic-gate 12162796Smarks if ((error = secpolicy_setid_setsticky_clear(vp, vap, 12172796Smarks ovap, cr)) != 0) 12180Sstevel@tonic-gate goto out; 12190Sstevel@tonic-gate } else 12200Sstevel@tonic-gate vap->va_mode = ovap->va_mode; 12210Sstevel@tonic-gate 12220Sstevel@tonic-gate if (mask & (AT_UID|AT_GID)) { 12230Sstevel@tonic-gate boolean_t checkpriv = B_FALSE; 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate /* 12260Sstevel@tonic-gate * Chowning files. 12270Sstevel@tonic-gate * 12280Sstevel@tonic-gate * If you are the file owner: 12290Sstevel@tonic-gate * chown to other uid FILE_CHOWN_SELF 12300Sstevel@tonic-gate * chown to gid (non-member) FILE_CHOWN_SELF 12310Sstevel@tonic-gate * chown to gid (member) <none> 12320Sstevel@tonic-gate * 12330Sstevel@tonic-gate * Instead of PRIV_FILE_CHOWN_SELF, FILE_CHOWN is also 12340Sstevel@tonic-gate * acceptable but the first one is reported when debugging. 12350Sstevel@tonic-gate * 12360Sstevel@tonic-gate * If you are not the file owner: 12370Sstevel@tonic-gate * chown from root PRIV_FILE_CHOWN + zone 12380Sstevel@tonic-gate * chown from other to any PRIV_FILE_CHOWN 12390Sstevel@tonic-gate * 12400Sstevel@tonic-gate */ 12410Sstevel@tonic-gate if (cr->cr_uid != ovap->va_uid) { 12420Sstevel@tonic-gate checkpriv = B_TRUE; 12430Sstevel@tonic-gate } else { 12440Sstevel@tonic-gate if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) || 12450Sstevel@tonic-gate ((mask & AT_GID) && vap->va_gid != ovap->va_gid && 12460Sstevel@tonic-gate !groupmember(vap->va_gid, cr))) { 12470Sstevel@tonic-gate checkpriv = B_TRUE; 12480Sstevel@tonic-gate } 12490Sstevel@tonic-gate } 12500Sstevel@tonic-gate /* 12510Sstevel@tonic-gate * If necessary, check privilege to see if update can be done. 12520Sstevel@tonic-gate */ 12530Sstevel@tonic-gate if (checkpriv && 12549866SMark.Shellenbaum@Sun.COM (error = secpolicy_vnode_chown(cr, ovap->va_uid)) != 0) { 12550Sstevel@tonic-gate goto out; 12560Sstevel@tonic-gate } 12570Sstevel@tonic-gate 12580Sstevel@tonic-gate /* 12590Sstevel@tonic-gate * If the file has either the set UID or set GID bits 12600Sstevel@tonic-gate * set and the caller can set the bits, then leave them. 12610Sstevel@tonic-gate */ 12621115Smarks secpolicy_setid_clear(vap, cr); 12630Sstevel@tonic-gate } 12640Sstevel@tonic-gate if (mask & (AT_ATIME|AT_MTIME)) { 12650Sstevel@tonic-gate /* 12660Sstevel@tonic-gate * If not the file owner and not otherwise privileged, 12670Sstevel@tonic-gate * always return an error when setting the 12680Sstevel@tonic-gate * time other than the current (ATTR_UTIME flag set). 12690Sstevel@tonic-gate * If setting the current time (ATTR_UTIME not set) then 12700Sstevel@tonic-gate * unlocked_access will check permissions according to policy. 12710Sstevel@tonic-gate */ 12720Sstevel@tonic-gate if (cr->cr_uid != ovap->va_uid) { 12730Sstevel@tonic-gate if (flags & ATTR_UTIME) 12740Sstevel@tonic-gate error = secpolicy_vnode_utime_modify(cr); 12755331Samw else if (skipaclchk == B_FALSE) { 12760Sstevel@tonic-gate error = unlocked_access(node, VWRITE, cr); 12770Sstevel@tonic-gate if (error == EACCES && 12780Sstevel@tonic-gate secpolicy_vnode_utime_modify(cr) == 0) 12790Sstevel@tonic-gate error = 0; 12800Sstevel@tonic-gate } 12810Sstevel@tonic-gate if (error) 12820Sstevel@tonic-gate goto out; 12830Sstevel@tonic-gate } 12840Sstevel@tonic-gate } 12855331Samw 12865331Samw /* 12875331Samw * Check for optional attributes here by checking the following: 12885331Samw */ 12895331Samw if (mask & AT_XVATTR) 12905331Samw error = secpolicy_xvattr((xvattr_t *)vap, ovap->va_uid, cr, 12915331Samw vp->v_type); 12920Sstevel@tonic-gate out: 12930Sstevel@tonic-gate return (error); 12940Sstevel@tonic-gate } 12950Sstevel@tonic-gate 12960Sstevel@tonic-gate /* 12970Sstevel@tonic-gate * Name: secpolicy_pcfs_modify_bootpartition() 12980Sstevel@tonic-gate * 12990Sstevel@tonic-gate * Normal: verify that subject can modify a pcfs boot partition. 13000Sstevel@tonic-gate * 13010Sstevel@tonic-gate * Output: EACCES - if privilege check failed. 13020Sstevel@tonic-gate */ 13030Sstevel@tonic-gate /*ARGSUSED*/ 13040Sstevel@tonic-gate int 13050Sstevel@tonic-gate secpolicy_pcfs_modify_bootpartition(const cred_t *cred) 13060Sstevel@tonic-gate { 13070Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_ALL, B_FALSE, EACCES, 13080Sstevel@tonic-gate "modify pcfs boot partition")); 13090Sstevel@tonic-gate } 13100Sstevel@tonic-gate 13110Sstevel@tonic-gate /* 13120Sstevel@tonic-gate * System V IPC routines 13130Sstevel@tonic-gate */ 13140Sstevel@tonic-gate int 13150Sstevel@tonic-gate secpolicy_ipc_owner(const cred_t *cr, const struct kipc_perm *ip) 13160Sstevel@tonic-gate { 13170Sstevel@tonic-gate if (crgetzoneid(cr) != ip->ipc_zoneid || 13180Sstevel@tonic-gate (cr->cr_uid != ip->ipc_uid && cr->cr_uid != ip->ipc_cuid)) { 13190Sstevel@tonic-gate boolean_t allzone = B_FALSE; 13200Sstevel@tonic-gate if (ip->ipc_uid == 0 || ip->ipc_cuid == 0) 13210Sstevel@tonic-gate allzone = B_TRUE; 13220Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_OWNER, allzone, EPERM, NULL)); 13230Sstevel@tonic-gate } 13240Sstevel@tonic-gate return (0); 13250Sstevel@tonic-gate } 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate int 13280Sstevel@tonic-gate secpolicy_ipc_config(const cred_t *cr) 13290Sstevel@tonic-gate { 13300Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_IPC_CONFIG, B_FALSE, EPERM, NULL)); 13310Sstevel@tonic-gate } 13320Sstevel@tonic-gate 13330Sstevel@tonic-gate int 13340Sstevel@tonic-gate secpolicy_ipc_access(const cred_t *cr, const struct kipc_perm *ip, mode_t mode) 13350Sstevel@tonic-gate { 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate boolean_t allzone = B_FALSE; 13380Sstevel@tonic-gate 13390Sstevel@tonic-gate ASSERT((mode & (MSG_R|MSG_W)) != 0); 13400Sstevel@tonic-gate 13410Sstevel@tonic-gate if ((mode & MSG_R) && 13420Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0) 13430Sstevel@tonic-gate return (EACCES); 13440Sstevel@tonic-gate 13450Sstevel@tonic-gate if (mode & MSG_W) { 13460Sstevel@tonic-gate if (cr->cr_uid != 0 && (ip->ipc_uid == 0 || ip->ipc_cuid == 0)) 13470Sstevel@tonic-gate allzone = B_TRUE; 13480Sstevel@tonic-gate 13490Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES, 13500Sstevel@tonic-gate NULL)); 13510Sstevel@tonic-gate } 13520Sstevel@tonic-gate return (0); 13530Sstevel@tonic-gate } 13540Sstevel@tonic-gate 13550Sstevel@tonic-gate int 13560Sstevel@tonic-gate secpolicy_rsm_access(const cred_t *cr, uid_t owner, mode_t mode) 13570Sstevel@tonic-gate { 13580Sstevel@tonic-gate boolean_t allzone = B_FALSE; 13590Sstevel@tonic-gate 13600Sstevel@tonic-gate ASSERT((mode & (MSG_R|MSG_W)) != 0); 13610Sstevel@tonic-gate 13620Sstevel@tonic-gate if ((mode & MSG_R) && 13630Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0) 13640Sstevel@tonic-gate return (EACCES); 13650Sstevel@tonic-gate 13660Sstevel@tonic-gate if (mode & MSG_W) { 13670Sstevel@tonic-gate if (cr->cr_uid != 0 && owner == 0) 13680Sstevel@tonic-gate allzone = B_TRUE; 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES, 13710Sstevel@tonic-gate NULL)); 13720Sstevel@tonic-gate } 13730Sstevel@tonic-gate return (0); 13740Sstevel@tonic-gate } 13750Sstevel@tonic-gate 13760Sstevel@tonic-gate /* 13770Sstevel@tonic-gate * Audit configuration. 13780Sstevel@tonic-gate */ 13790Sstevel@tonic-gate int 13800Sstevel@tonic-gate secpolicy_audit_config(const cred_t *cr) 13810Sstevel@tonic-gate { 13820Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL)); 13830Sstevel@tonic-gate } 13840Sstevel@tonic-gate 13850Sstevel@tonic-gate /* 13860Sstevel@tonic-gate * Audit record generation. 13870Sstevel@tonic-gate */ 13880Sstevel@tonic-gate int 13890Sstevel@tonic-gate secpolicy_audit_modify(const cred_t *cr) 13900Sstevel@tonic-gate { 13910Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, NULL)); 13920Sstevel@tonic-gate } 13930Sstevel@tonic-gate 13940Sstevel@tonic-gate /* 13950Sstevel@tonic-gate * Get audit attributes. 13960Sstevel@tonic-gate * Either PRIV_SYS_AUDIT or PRIV_PROC_AUDIT required; report the 13970Sstevel@tonic-gate * "Least" of the two privileges on error. 13980Sstevel@tonic-gate */ 13990Sstevel@tonic-gate int 14000Sstevel@tonic-gate secpolicy_audit_getattr(const cred_t *cr) 14010Sstevel@tonic-gate { 14020Sstevel@tonic-gate if (!PRIV_POLICY_ONLY(cr, PRIV_SYS_AUDIT, B_FALSE)) { 14030Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, 14040Sstevel@tonic-gate NULL)); 14050Sstevel@tonic-gate } else { 14060Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL)); 14070Sstevel@tonic-gate } 14080Sstevel@tonic-gate } 14090Sstevel@tonic-gate 14100Sstevel@tonic-gate 14110Sstevel@tonic-gate /* 14120Sstevel@tonic-gate * Locking physical memory 14130Sstevel@tonic-gate */ 14140Sstevel@tonic-gate int 14150Sstevel@tonic-gate secpolicy_lock_memory(const cred_t *cr) 14160Sstevel@tonic-gate { 14170Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_LOCK_MEMORY, B_FALSE, EPERM, NULL)); 14180Sstevel@tonic-gate } 14190Sstevel@tonic-gate 14200Sstevel@tonic-gate /* 14210Sstevel@tonic-gate * Accounting (both acct(2) and exacct). 14220Sstevel@tonic-gate */ 14230Sstevel@tonic-gate int 14240Sstevel@tonic-gate secpolicy_acct(const cred_t *cr) 14250Sstevel@tonic-gate { 14260Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ACCT, B_FALSE, EPERM, NULL)); 14270Sstevel@tonic-gate } 14280Sstevel@tonic-gate 14290Sstevel@tonic-gate /* 14300Sstevel@tonic-gate * Is this process privileged to change its uids at will? 14310Sstevel@tonic-gate * Uid 0 is still considered "special" and having the SETID 14320Sstevel@tonic-gate * privilege is not sufficient to get uid 0. 14330Sstevel@tonic-gate * Files are owned by root, so the privilege would give 14340Sstevel@tonic-gate * full access and euid 0 is still effective. 14350Sstevel@tonic-gate * 14360Sstevel@tonic-gate * If you have the privilege and euid 0 only then do you 14370Sstevel@tonic-gate * get the powers of root wrt uid 0. 14380Sstevel@tonic-gate * 14390Sstevel@tonic-gate * For gid manipulations, this is should be called with an 14400Sstevel@tonic-gate * uid of -1. 14410Sstevel@tonic-gate * 14420Sstevel@tonic-gate */ 14430Sstevel@tonic-gate int 14440Sstevel@tonic-gate secpolicy_allow_setid(const cred_t *cr, uid_t newuid, boolean_t checkonly) 14450Sstevel@tonic-gate { 14460Sstevel@tonic-gate boolean_t allzone = B_FALSE; 14470Sstevel@tonic-gate 14480Sstevel@tonic-gate if (newuid == 0 && cr->cr_uid != 0 && cr->cr_suid != 0 && 14490Sstevel@tonic-gate cr->cr_ruid != 0) { 14500Sstevel@tonic-gate allzone = B_TRUE; 14510Sstevel@tonic-gate } 14520Sstevel@tonic-gate 14530Sstevel@tonic-gate return (checkonly ? !PRIV_POLICY_ONLY(cr, PRIV_PROC_SETID, allzone) : 14540Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_PROC_SETID, allzone, EPERM, NULL)); 14550Sstevel@tonic-gate } 14560Sstevel@tonic-gate 14570Sstevel@tonic-gate 14580Sstevel@tonic-gate /* 14590Sstevel@tonic-gate * Acting on a different process: if the mode is for writing, 14600Sstevel@tonic-gate * the restrictions are more severe. This is called after 14610Sstevel@tonic-gate * we've verified that the uids do not match. 14620Sstevel@tonic-gate */ 14630Sstevel@tonic-gate int 14640Sstevel@tonic-gate secpolicy_proc_owner(const cred_t *scr, const cred_t *tcr, int mode) 14650Sstevel@tonic-gate { 14660Sstevel@tonic-gate boolean_t allzone = B_FALSE; 14670Sstevel@tonic-gate 14680Sstevel@tonic-gate if ((mode & VWRITE) && scr->cr_uid != 0 && 14690Sstevel@tonic-gate (tcr->cr_uid == 0 || tcr->cr_ruid == 0 || tcr->cr_suid == 0)) 14700Sstevel@tonic-gate allzone = B_TRUE; 14710Sstevel@tonic-gate 14720Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, allzone, EPERM, NULL)); 14730Sstevel@tonic-gate } 14740Sstevel@tonic-gate 14750Sstevel@tonic-gate int 14760Sstevel@tonic-gate secpolicy_proc_access(const cred_t *scr) 14770Sstevel@tonic-gate { 14780Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EACCES, NULL)); 14790Sstevel@tonic-gate } 14800Sstevel@tonic-gate 14810Sstevel@tonic-gate int 14820Sstevel@tonic-gate secpolicy_proc_excl_open(const cred_t *scr) 14830Sstevel@tonic-gate { 14840Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EBUSY, NULL)); 14850Sstevel@tonic-gate } 14860Sstevel@tonic-gate 14870Sstevel@tonic-gate int 14880Sstevel@tonic-gate secpolicy_proc_zone(const cred_t *scr) 14890Sstevel@tonic-gate { 14900Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_ZONE, B_FALSE, EPERM, NULL)); 14910Sstevel@tonic-gate } 14920Sstevel@tonic-gate 14930Sstevel@tonic-gate /* 14940Sstevel@tonic-gate * Destroying the system 14950Sstevel@tonic-gate */ 14960Sstevel@tonic-gate 14970Sstevel@tonic-gate int 14980Sstevel@tonic-gate secpolicy_kmdb(const cred_t *scr) 14990Sstevel@tonic-gate { 15000Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 15010Sstevel@tonic-gate } 15020Sstevel@tonic-gate 15031414Scindi int 15041414Scindi secpolicy_error_inject(const cred_t *scr) 15051414Scindi { 15061414Scindi return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 15071414Scindi } 15081414Scindi 15090Sstevel@tonic-gate /* 15100Sstevel@tonic-gate * Processor sets, cpu configuration, resource pools. 15110Sstevel@tonic-gate */ 15120Sstevel@tonic-gate int 15130Sstevel@tonic-gate secpolicy_pset(const cred_t *cr) 15140Sstevel@tonic-gate { 15150Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 15160Sstevel@tonic-gate } 15170Sstevel@tonic-gate 15180Sstevel@tonic-gate int 15190Sstevel@tonic-gate secpolicy_ponline(const cred_t *cr) 15200Sstevel@tonic-gate { 15210Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 15220Sstevel@tonic-gate } 15230Sstevel@tonic-gate 15240Sstevel@tonic-gate int 15250Sstevel@tonic-gate secpolicy_pool(const cred_t *cr) 15260Sstevel@tonic-gate { 15270Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 15280Sstevel@tonic-gate } 15290Sstevel@tonic-gate 15300Sstevel@tonic-gate int 15310Sstevel@tonic-gate secpolicy_blacklist(const cred_t *cr) 15320Sstevel@tonic-gate { 15330Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 15340Sstevel@tonic-gate } 15350Sstevel@tonic-gate 15360Sstevel@tonic-gate /* 15370Sstevel@tonic-gate * Catch all system configuration. 15380Sstevel@tonic-gate */ 15390Sstevel@tonic-gate int 15400Sstevel@tonic-gate secpolicy_sys_config(const cred_t *cr, boolean_t checkonly) 15410Sstevel@tonic-gate { 15420Sstevel@tonic-gate if (checkonly) { 15430Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_CONFIG, B_FALSE) ? 0 : 15440Sstevel@tonic-gate EPERM); 15450Sstevel@tonic-gate } else { 15460Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 15470Sstevel@tonic-gate } 15480Sstevel@tonic-gate } 15490Sstevel@tonic-gate 15500Sstevel@tonic-gate /* 15510Sstevel@tonic-gate * Zone administration (halt, reboot, etc.) from within zone. 15520Sstevel@tonic-gate */ 15530Sstevel@tonic-gate int 15540Sstevel@tonic-gate secpolicy_zone_admin(const cred_t *cr, boolean_t checkonly) 15550Sstevel@tonic-gate { 15560Sstevel@tonic-gate if (checkonly) { 15570Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_ADMIN, B_FALSE) ? 0 : 15580Sstevel@tonic-gate EPERM); 15590Sstevel@tonic-gate } else { 15600Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, 15610Sstevel@tonic-gate NULL)); 15620Sstevel@tonic-gate } 15630Sstevel@tonic-gate } 15640Sstevel@tonic-gate 15650Sstevel@tonic-gate /* 15660Sstevel@tonic-gate * Zone configuration (create, halt, enter). 15670Sstevel@tonic-gate */ 15680Sstevel@tonic-gate int 15690Sstevel@tonic-gate secpolicy_zone_config(const cred_t *cr) 15700Sstevel@tonic-gate { 15710Sstevel@tonic-gate /* 15720Sstevel@tonic-gate * Require all privileges to avoid possibility of privilege 15730Sstevel@tonic-gate * escalation. 15740Sstevel@tonic-gate */ 15750Sstevel@tonic-gate return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 15760Sstevel@tonic-gate } 15770Sstevel@tonic-gate 15780Sstevel@tonic-gate /* 15790Sstevel@tonic-gate * Various other system configuration calls 15800Sstevel@tonic-gate */ 15810Sstevel@tonic-gate int 15820Sstevel@tonic-gate secpolicy_coreadm(const cred_t *cr) 15830Sstevel@tonic-gate { 15840Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL)); 15850Sstevel@tonic-gate } 15860Sstevel@tonic-gate 15870Sstevel@tonic-gate int 15880Sstevel@tonic-gate secpolicy_systeminfo(const cred_t *cr) 15890Sstevel@tonic-gate { 15900Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL)); 15910Sstevel@tonic-gate } 15920Sstevel@tonic-gate 15930Sstevel@tonic-gate int 15940Sstevel@tonic-gate secpolicy_dispadm(const cred_t *cr) 15950Sstevel@tonic-gate { 15960Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 15970Sstevel@tonic-gate } 15980Sstevel@tonic-gate 15990Sstevel@tonic-gate int 16000Sstevel@tonic-gate secpolicy_settime(const cred_t *cr) 16010Sstevel@tonic-gate { 16020Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_TIME, B_FALSE, EPERM, NULL)); 16030Sstevel@tonic-gate } 16040Sstevel@tonic-gate 16050Sstevel@tonic-gate /* 16060Sstevel@tonic-gate * For realtime users: high resolution clock. 16070Sstevel@tonic-gate */ 16080Sstevel@tonic-gate int 16090Sstevel@tonic-gate secpolicy_clock_highres(const cred_t *cr) 16100Sstevel@tonic-gate { 16110Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_CLOCK_HIGHRES, B_FALSE, EPERM, 16120Sstevel@tonic-gate NULL)); 16130Sstevel@tonic-gate } 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate /* 16160Sstevel@tonic-gate * drv_priv() is documented as callable from interrupt context, not that 16170Sstevel@tonic-gate * anyone ever does, but still. No debugging or auditing can be done when 16180Sstevel@tonic-gate * it is called from interrupt context. 16190Sstevel@tonic-gate * returns 0 on succes, EPERM on failure. 16200Sstevel@tonic-gate */ 16210Sstevel@tonic-gate int 16220Sstevel@tonic-gate drv_priv(cred_t *cr) 16230Sstevel@tonic-gate { 16240Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 16250Sstevel@tonic-gate } 16260Sstevel@tonic-gate 16270Sstevel@tonic-gate int 16280Sstevel@tonic-gate secpolicy_sys_devices(const cred_t *cr) 16290Sstevel@tonic-gate { 16300Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 16310Sstevel@tonic-gate } 16320Sstevel@tonic-gate 16330Sstevel@tonic-gate int 16340Sstevel@tonic-gate secpolicy_excl_open(const cred_t *cr) 16350Sstevel@tonic-gate { 16360Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EBUSY, NULL)); 16370Sstevel@tonic-gate } 16380Sstevel@tonic-gate 16390Sstevel@tonic-gate int 16400Sstevel@tonic-gate secpolicy_rctlsys(const cred_t *cr, boolean_t is_zone_rctl) 16410Sstevel@tonic-gate { 16420Sstevel@tonic-gate /* zone.* rctls can only be set from the global zone */ 16430Sstevel@tonic-gate if (is_zone_rctl && priv_policy_global(cr) != 0) 16440Sstevel@tonic-gate return (EPERM); 16450Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 16460Sstevel@tonic-gate } 16470Sstevel@tonic-gate 16480Sstevel@tonic-gate int 16490Sstevel@tonic-gate secpolicy_resource(const cred_t *cr) 16500Sstevel@tonic-gate { 16510Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 16520Sstevel@tonic-gate } 16530Sstevel@tonic-gate 165410154SStan.Studzinski@Sun.COM int 165510154SStan.Studzinski@Sun.COM secpolicy_resource_anon_mem(const cred_t *cr) 165610154SStan.Studzinski@Sun.COM { 165710154SStan.Studzinski@Sun.COM return (PRIV_POLICY_ONLY(cr, PRIV_SYS_RESOURCE, B_FALSE)); 165810154SStan.Studzinski@Sun.COM } 165910154SStan.Studzinski@Sun.COM 16600Sstevel@tonic-gate /* 16610Sstevel@tonic-gate * Processes with a real uid of 0 escape any form of accounting, much 16620Sstevel@tonic-gate * like before. 16630Sstevel@tonic-gate */ 16640Sstevel@tonic-gate int 16650Sstevel@tonic-gate secpolicy_newproc(const cred_t *cr) 16660Sstevel@tonic-gate { 16670Sstevel@tonic-gate if (cr->cr_ruid == 0) 16680Sstevel@tonic-gate return (0); 16690Sstevel@tonic-gate 16700Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 16710Sstevel@tonic-gate } 16720Sstevel@tonic-gate 16730Sstevel@tonic-gate /* 16740Sstevel@tonic-gate * Networking 16750Sstevel@tonic-gate */ 16760Sstevel@tonic-gate int 16770Sstevel@tonic-gate secpolicy_net_rawaccess(const cred_t *cr) 16780Sstevel@tonic-gate { 16790Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_NET_RAWACCESS, B_FALSE, EACCES, NULL)); 16800Sstevel@tonic-gate } 16810Sstevel@tonic-gate 16820Sstevel@tonic-gate /* 16830Sstevel@tonic-gate * Need this privilege for accessing the ICMP device 16840Sstevel@tonic-gate */ 16850Sstevel@tonic-gate int 16860Sstevel@tonic-gate secpolicy_net_icmpaccess(const cred_t *cr) 16870Sstevel@tonic-gate { 16880Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_NET_ICMPACCESS, B_FALSE, EACCES, NULL)); 16890Sstevel@tonic-gate } 16900Sstevel@tonic-gate 16910Sstevel@tonic-gate /* 16920Sstevel@tonic-gate * There are a few rare cases where the kernel generates ioctls() from 16930Sstevel@tonic-gate * interrupt context with a credential of kcred rather than NULL. 16940Sstevel@tonic-gate * In those cases, we take the safe and cheap test. 16950Sstevel@tonic-gate */ 16960Sstevel@tonic-gate int 16970Sstevel@tonic-gate secpolicy_net_config(const cred_t *cr, boolean_t checkonly) 16980Sstevel@tonic-gate { 16990Sstevel@tonic-gate if (checkonly) { 17000Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE) ? 17010Sstevel@tonic-gate 0 : EPERM); 17020Sstevel@tonic-gate } else { 17030Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_NET_CONFIG, B_FALSE, EPERM, 17040Sstevel@tonic-gate NULL)); 17050Sstevel@tonic-gate } 17060Sstevel@tonic-gate } 17070Sstevel@tonic-gate 17080Sstevel@tonic-gate 17090Sstevel@tonic-gate /* 17104962Sdh155122 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG. 17113448Sdh155122 * 17123448Sdh155122 * There are a few rare cases where the kernel generates ioctls() from 17133448Sdh155122 * interrupt context with a credential of kcred rather than NULL. 17143448Sdh155122 * In those cases, we take the safe and cheap test. 17153448Sdh155122 */ 17163448Sdh155122 int 17173448Sdh155122 secpolicy_ip_config(const cred_t *cr, boolean_t checkonly) 17183448Sdh155122 { 17193448Sdh155122 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 17203448Sdh155122 return (secpolicy_net_config(cr, checkonly)); 17213448Sdh155122 17223448Sdh155122 if (checkonly) { 17233448Sdh155122 return (PRIV_POLICY_ONLY(cr, PRIV_SYS_IP_CONFIG, B_FALSE) ? 17243448Sdh155122 0 : EPERM); 17253448Sdh155122 } else { 17263448Sdh155122 return (PRIV_POLICY(cr, PRIV_SYS_IP_CONFIG, B_FALSE, EPERM, 17273448Sdh155122 NULL)); 17283448Sdh155122 } 17293448Sdh155122 } 17303448Sdh155122 17317408SSebastien.Roy@Sun.COM /* 17327408SSebastien.Roy@Sun.COM * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_DL_CONFIG. 17337408SSebastien.Roy@Sun.COM */ 17347408SSebastien.Roy@Sun.COM int 17357408SSebastien.Roy@Sun.COM secpolicy_dl_config(const cred_t *cr) 17367408SSebastien.Roy@Sun.COM { 17377408SSebastien.Roy@Sun.COM if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 17387408SSebastien.Roy@Sun.COM return (secpolicy_net_config(cr, B_FALSE)); 1739*10616SSebastien.Roy@Sun.COM return (PRIV_POLICY(cr, PRIV_SYS_DL_CONFIG, B_FALSE, EPERM, NULL)); 17407408SSebastien.Roy@Sun.COM } 17417408SSebastien.Roy@Sun.COM 1742*10616SSebastien.Roy@Sun.COM /* 1743*10616SSebastien.Roy@Sun.COM * PRIV_SYS_DL_CONFIG is a superset of PRIV_SYS_IPTUN_CONFIG. 1744*10616SSebastien.Roy@Sun.COM */ 1745*10616SSebastien.Roy@Sun.COM int 1746*10616SSebastien.Roy@Sun.COM secpolicy_iptun_config(const cred_t *cr) 1747*10616SSebastien.Roy@Sun.COM { 1748*10616SSebastien.Roy@Sun.COM if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 1749*10616SSebastien.Roy@Sun.COM return (secpolicy_net_config(cr, B_FALSE)); 1750*10616SSebastien.Roy@Sun.COM if (PRIV_POLICY_ONLY(cr, PRIV_SYS_DL_CONFIG, B_FALSE)) 1751*10616SSebastien.Roy@Sun.COM return (secpolicy_dl_config(cr)); 1752*10616SSebastien.Roy@Sun.COM return (PRIV_POLICY(cr, PRIV_SYS_IPTUN_CONFIG, B_FALSE, EPERM, NULL)); 1753*10616SSebastien.Roy@Sun.COM } 17543448Sdh155122 17553448Sdh155122 /* 17563448Sdh155122 * Map IP pseudo privileges to actual privileges. 17573448Sdh155122 * So we don't need to recompile IP when we change the privileges. 17583448Sdh155122 */ 17593448Sdh155122 int 17603448Sdh155122 secpolicy_ip(const cred_t *cr, int netpriv, boolean_t checkonly) 17613448Sdh155122 { 17623448Sdh155122 int priv = PRIV_ALL; 17633448Sdh155122 17643448Sdh155122 switch (netpriv) { 17653448Sdh155122 case OP_CONFIG: 17663448Sdh155122 priv = PRIV_SYS_IP_CONFIG; 17673448Sdh155122 break; 17683448Sdh155122 case OP_RAW: 17693448Sdh155122 priv = PRIV_NET_RAWACCESS; 17703448Sdh155122 break; 17713448Sdh155122 case OP_PRIVPORT: 17723448Sdh155122 priv = PRIV_NET_PRIVADDR; 17733448Sdh155122 break; 17743448Sdh155122 } 17753448Sdh155122 ASSERT(priv != PRIV_ALL); 17763448Sdh155122 if (checkonly) 17773448Sdh155122 return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM); 17783448Sdh155122 else 17793448Sdh155122 return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL)); 17803448Sdh155122 } 17813448Sdh155122 17823448Sdh155122 /* 17830Sstevel@tonic-gate * Map network pseudo privileges to actual privileges. 17840Sstevel@tonic-gate * So we don't need to recompile IP when we change the privileges. 17850Sstevel@tonic-gate */ 17860Sstevel@tonic-gate int 17870Sstevel@tonic-gate secpolicy_net(const cred_t *cr, int netpriv, boolean_t checkonly) 17880Sstevel@tonic-gate { 17890Sstevel@tonic-gate int priv = PRIV_ALL; 17900Sstevel@tonic-gate 17910Sstevel@tonic-gate switch (netpriv) { 17920Sstevel@tonic-gate case OP_CONFIG: 17930Sstevel@tonic-gate priv = PRIV_SYS_NET_CONFIG; 17940Sstevel@tonic-gate break; 17950Sstevel@tonic-gate case OP_RAW: 17960Sstevel@tonic-gate priv = PRIV_NET_RAWACCESS; 17970Sstevel@tonic-gate break; 17980Sstevel@tonic-gate case OP_PRIVPORT: 17990Sstevel@tonic-gate priv = PRIV_NET_PRIVADDR; 18000Sstevel@tonic-gate break; 18010Sstevel@tonic-gate } 18020Sstevel@tonic-gate ASSERT(priv != PRIV_ALL); 18030Sstevel@tonic-gate if (checkonly) 18040Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM); 18050Sstevel@tonic-gate else 18060Sstevel@tonic-gate return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL)); 18070Sstevel@tonic-gate } 18080Sstevel@tonic-gate 18090Sstevel@tonic-gate /* 18100Sstevel@tonic-gate * Checks for operations that are either client-only or are used by 18110Sstevel@tonic-gate * both clients and servers. 18120Sstevel@tonic-gate */ 18130Sstevel@tonic-gate int 18140Sstevel@tonic-gate secpolicy_nfs(const cred_t *cr) 18150Sstevel@tonic-gate { 18160Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_NFS, B_FALSE, EPERM, NULL)); 18170Sstevel@tonic-gate } 18180Sstevel@tonic-gate 18190Sstevel@tonic-gate /* 18200Sstevel@tonic-gate * Special case for opening rpcmod: have NFS privileges or network 18210Sstevel@tonic-gate * config privileges. 18220Sstevel@tonic-gate */ 18230Sstevel@tonic-gate int 18240Sstevel@tonic-gate secpolicy_rpcmod_open(const cred_t *cr) 18250Sstevel@tonic-gate { 18260Sstevel@tonic-gate if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NFS, B_FALSE)) 18270Sstevel@tonic-gate return (secpolicy_nfs(cr)); 18280Sstevel@tonic-gate else 18290Sstevel@tonic-gate return (secpolicy_net_config(cr, NULL)); 18300Sstevel@tonic-gate } 18310Sstevel@tonic-gate 18320Sstevel@tonic-gate int 18330Sstevel@tonic-gate secpolicy_chroot(const cred_t *cr) 18340Sstevel@tonic-gate { 18350Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_CHROOT, B_FALSE, EPERM, NULL)); 18360Sstevel@tonic-gate } 18370Sstevel@tonic-gate 18380Sstevel@tonic-gate int 18390Sstevel@tonic-gate secpolicy_tasksys(const cred_t *cr) 18400Sstevel@tonic-gate { 18410Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_TASKID, B_FALSE, EPERM, NULL)); 18420Sstevel@tonic-gate } 18430Sstevel@tonic-gate 18440Sstevel@tonic-gate /* 18450Sstevel@tonic-gate * Basic privilege checks. 18460Sstevel@tonic-gate */ 18470Sstevel@tonic-gate int 18486134Scasper secpolicy_basic_exec(const cred_t *cr, vnode_t *vp) 18490Sstevel@tonic-gate { 18506134Scasper return (priv_policy_va(cr, PRIV_PROC_EXEC, B_FALSE, EPERM, NULL, 18516134Scasper KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE)); 18520Sstevel@tonic-gate } 18530Sstevel@tonic-gate 18540Sstevel@tonic-gate int 18550Sstevel@tonic-gate secpolicy_basic_fork(const cred_t *cr) 18560Sstevel@tonic-gate { 18570Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_FORK, B_FALSE, EPERM, NULL)); 18580Sstevel@tonic-gate } 18590Sstevel@tonic-gate 18600Sstevel@tonic-gate int 18610Sstevel@tonic-gate secpolicy_basic_proc(const cred_t *cr) 18620Sstevel@tonic-gate { 18630Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_SESSION, B_FALSE, EPERM, NULL)); 18640Sstevel@tonic-gate } 18650Sstevel@tonic-gate 18660Sstevel@tonic-gate /* 18670Sstevel@tonic-gate * Slightly complicated because we don't want to trigger the policy too 18680Sstevel@tonic-gate * often. First we shortcircuit access to "self" (tp == sp) or if 18690Sstevel@tonic-gate * we don't have the privilege but if we have permission 18700Sstevel@tonic-gate * just return (0) and we don't flag the privilege as needed. 18710Sstevel@tonic-gate * Else, we test for the privilege because we either have it or need it. 18720Sstevel@tonic-gate */ 18730Sstevel@tonic-gate int 18740Sstevel@tonic-gate secpolicy_basic_procinfo(const cred_t *cr, proc_t *tp, proc_t *sp) 18750Sstevel@tonic-gate { 18760Sstevel@tonic-gate if (tp == sp || 18770Sstevel@tonic-gate !HAS_PRIVILEGE(cr, PRIV_PROC_INFO) && prochasprocperm(tp, sp, cr)) { 18780Sstevel@tonic-gate return (0); 18790Sstevel@tonic-gate } else { 18800Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_INFO, B_FALSE, EPERM, NULL)); 18810Sstevel@tonic-gate } 18820Sstevel@tonic-gate } 18830Sstevel@tonic-gate 18840Sstevel@tonic-gate int 18850Sstevel@tonic-gate secpolicy_basic_link(const cred_t *cr) 18860Sstevel@tonic-gate { 18870Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_LINK_ANY, B_FALSE, EPERM, NULL)); 18880Sstevel@tonic-gate } 18890Sstevel@tonic-gate 18900Sstevel@tonic-gate /* 18910Sstevel@tonic-gate * Additional device protection. 18920Sstevel@tonic-gate * 18930Sstevel@tonic-gate * Traditionally, a device has specific permissions on the node in 18940Sstevel@tonic-gate * the filesystem which govern which devices can be opened by what 18950Sstevel@tonic-gate * processes. In certain cases, it is desirable to add extra 18960Sstevel@tonic-gate * restrictions, as writing to certain devices is identical to 18970Sstevel@tonic-gate * having a complete run of the system. 18980Sstevel@tonic-gate * 18990Sstevel@tonic-gate * This mechanism is called the device policy. 19000Sstevel@tonic-gate * 19010Sstevel@tonic-gate * When a device is opened, its policy entry is looked up in the 19020Sstevel@tonic-gate * policy cache and checked. 19030Sstevel@tonic-gate */ 19040Sstevel@tonic-gate int 19050Sstevel@tonic-gate secpolicy_spec_open(const cred_t *cr, struct vnode *vp, int oflag) 19060Sstevel@tonic-gate { 19070Sstevel@tonic-gate devplcy_t *plcy; 19080Sstevel@tonic-gate int err; 19090Sstevel@tonic-gate struct snode *csp = VTOS(common_specvp(vp)); 19104962Sdh155122 priv_set_t pset; 19110Sstevel@tonic-gate 19120Sstevel@tonic-gate mutex_enter(&csp->s_lock); 19130Sstevel@tonic-gate 19140Sstevel@tonic-gate if (csp->s_plcy == NULL || csp->s_plcy->dp_gen != devplcy_gen) { 19150Sstevel@tonic-gate plcy = devpolicy_find(vp); 19160Sstevel@tonic-gate if (csp->s_plcy) 19170Sstevel@tonic-gate dpfree(csp->s_plcy); 19180Sstevel@tonic-gate csp->s_plcy = plcy; 19190Sstevel@tonic-gate ASSERT(plcy != NULL); 19200Sstevel@tonic-gate } else 19210Sstevel@tonic-gate plcy = csp->s_plcy; 19220Sstevel@tonic-gate 19230Sstevel@tonic-gate if (plcy == nullpolicy) { 19240Sstevel@tonic-gate mutex_exit(&csp->s_lock); 19250Sstevel@tonic-gate return (0); 19260Sstevel@tonic-gate } 19270Sstevel@tonic-gate 19280Sstevel@tonic-gate dphold(plcy); 19290Sstevel@tonic-gate 19300Sstevel@tonic-gate mutex_exit(&csp->s_lock); 19310Sstevel@tonic-gate 19324962Sdh155122 if (oflag & FWRITE) 19334962Sdh155122 pset = plcy->dp_wrp; 19344962Sdh155122 else 19354962Sdh155122 pset = plcy->dp_rdp; 19364962Sdh155122 /* 19374962Sdh155122 * Special case: 19384962Sdh155122 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG. 19394962Sdh155122 * If PRIV_SYS_NET_CONFIG is present and PRIV_SYS_IP_CONFIG is 19404962Sdh155122 * required, replace PRIV_SYS_IP_CONFIG with PRIV_SYS_NET_CONFIG 19414962Sdh155122 * in the required privilege set before doing the check. 19424962Sdh155122 */ 19434962Sdh155122 if (priv_ismember(&pset, PRIV_SYS_IP_CONFIG) && 19444962Sdh155122 priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_NET_CONFIG) && 19454962Sdh155122 !priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_IP_CONFIG)) { 19464962Sdh155122 priv_delset(&pset, PRIV_SYS_IP_CONFIG); 19474962Sdh155122 priv_addset(&pset, PRIV_SYS_NET_CONFIG); 19484962Sdh155122 } 19494962Sdh155122 19504962Sdh155122 err = secpolicy_require_set(cr, &pset, "devpolicy"); 19510Sstevel@tonic-gate dpfree(plcy); 19520Sstevel@tonic-gate 19530Sstevel@tonic-gate return (err); 19540Sstevel@tonic-gate } 19550Sstevel@tonic-gate 19560Sstevel@tonic-gate int 19570Sstevel@tonic-gate secpolicy_modctl(const cred_t *cr, int cmd) 19580Sstevel@tonic-gate { 19590Sstevel@tonic-gate switch (cmd) { 19600Sstevel@tonic-gate case MODINFO: 19612723Scth case MODGETMAJBIND: 19620Sstevel@tonic-gate case MODGETPATH: 19630Sstevel@tonic-gate case MODGETPATHLEN: 19642723Scth case MODGETNAME: 19650Sstevel@tonic-gate case MODGETFBNAME: 19660Sstevel@tonic-gate case MODGETDEVPOLICY: 19670Sstevel@tonic-gate case MODGETDEVPOLICYBYNAME: 19682723Scth case MODDEVT2INSTANCE: 19692723Scth case MODSIZEOF_DEVID: 19702723Scth case MODGETDEVID: 19712723Scth case MODSIZEOF_MINORNAME: 19722723Scth case MODGETMINORNAME: 19732723Scth case MODGETDEVFSPATH_LEN: 19742723Scth case MODGETDEVFSPATH: 19752723Scth case MODGETDEVFSPATH_MI_LEN: 19762723Scth case MODGETDEVFSPATH_MI: 19770Sstevel@tonic-gate /* Unprivileged */ 19780Sstevel@tonic-gate return (0); 19790Sstevel@tonic-gate case MODLOAD: 19800Sstevel@tonic-gate case MODSETDEVPOLICY: 19810Sstevel@tonic-gate return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 19820Sstevel@tonic-gate default: 19830Sstevel@tonic-gate return (secpolicy_sys_config(cr, B_FALSE)); 19840Sstevel@tonic-gate } 19850Sstevel@tonic-gate } 19860Sstevel@tonic-gate 19870Sstevel@tonic-gate int 19880Sstevel@tonic-gate secpolicy_console(const cred_t *cr) 19890Sstevel@tonic-gate { 19900Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 19910Sstevel@tonic-gate } 19920Sstevel@tonic-gate 19930Sstevel@tonic-gate int 19940Sstevel@tonic-gate secpolicy_power_mgmt(const cred_t *cr) 19950Sstevel@tonic-gate { 19960Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 19970Sstevel@tonic-gate } 19980Sstevel@tonic-gate 19990Sstevel@tonic-gate /* 20000Sstevel@tonic-gate * Simulate terminal input; another escalation of privileges avenue. 20010Sstevel@tonic-gate */ 20020Sstevel@tonic-gate 20030Sstevel@tonic-gate int 20040Sstevel@tonic-gate secpolicy_sti(const cred_t *cr) 20050Sstevel@tonic-gate { 20060Sstevel@tonic-gate return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 20070Sstevel@tonic-gate } 20080Sstevel@tonic-gate 20091676Sjpk boolean_t 20101676Sjpk secpolicy_net_reply_equal(const cred_t *cr) 20111676Sjpk { 20121676Sjpk return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 20131676Sjpk } 20141676Sjpk 20150Sstevel@tonic-gate int 20160Sstevel@tonic-gate secpolicy_swapctl(const cred_t *cr) 20170Sstevel@tonic-gate { 20180Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 20190Sstevel@tonic-gate } 20200Sstevel@tonic-gate 20210Sstevel@tonic-gate int 20220Sstevel@tonic-gate secpolicy_cpc_cpu(const cred_t *cr) 20230Sstevel@tonic-gate { 20240Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CPC_CPU, B_FALSE, EACCES, NULL)); 20250Sstevel@tonic-gate } 20260Sstevel@tonic-gate 20270Sstevel@tonic-gate /* 20286073Sacruz * secpolicy_contract_identity 20296073Sacruz * 20306073Sacruz * Determine if the subject may set the process contract FMRI value 20316073Sacruz */ 20326073Sacruz int 20336073Sacruz secpolicy_contract_identity(const cred_t *cr) 20346073Sacruz { 20356073Sacruz return (PRIV_POLICY(cr, PRIV_CONTRACT_IDENTITY, B_FALSE, EPERM, NULL)); 20366073Sacruz } 20376073Sacruz 20386073Sacruz /* 20390Sstevel@tonic-gate * secpolicy_contract_observer 20400Sstevel@tonic-gate * 20410Sstevel@tonic-gate * Determine if the subject may observe a specific contract's events. 20420Sstevel@tonic-gate */ 20430Sstevel@tonic-gate int 20440Sstevel@tonic-gate secpolicy_contract_observer(const cred_t *cr, struct contract *ct) 20450Sstevel@tonic-gate { 20460Sstevel@tonic-gate if (contract_owned(ct, cr, B_FALSE)) 20470Sstevel@tonic-gate return (0); 20480Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CONTRACT_OBSERVER, B_FALSE, EPERM, NULL)); 20490Sstevel@tonic-gate } 20500Sstevel@tonic-gate 20510Sstevel@tonic-gate /* 20520Sstevel@tonic-gate * secpolicy_contract_observer_choice 20530Sstevel@tonic-gate * 20540Sstevel@tonic-gate * Determine if the subject may observe any contract's events. Just 20550Sstevel@tonic-gate * tests privilege and audits on success. 20560Sstevel@tonic-gate */ 20570Sstevel@tonic-gate boolean_t 20580Sstevel@tonic-gate secpolicy_contract_observer_choice(const cred_t *cr) 20590Sstevel@tonic-gate { 20600Sstevel@tonic-gate return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_OBSERVER, B_FALSE)); 20610Sstevel@tonic-gate } 20620Sstevel@tonic-gate 20630Sstevel@tonic-gate /* 20640Sstevel@tonic-gate * secpolicy_contract_event 20650Sstevel@tonic-gate * 20660Sstevel@tonic-gate * Determine if the subject may request critical contract events or 20670Sstevel@tonic-gate * reliable contract event delivery. 20680Sstevel@tonic-gate */ 20690Sstevel@tonic-gate int 20700Sstevel@tonic-gate secpolicy_contract_event(const cred_t *cr) 20710Sstevel@tonic-gate { 20720Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CONTRACT_EVENT, B_FALSE, EPERM, NULL)); 20730Sstevel@tonic-gate } 20740Sstevel@tonic-gate 20750Sstevel@tonic-gate /* 20760Sstevel@tonic-gate * secpolicy_contract_event_choice 20770Sstevel@tonic-gate * 20780Sstevel@tonic-gate * Determine if the subject may retain contract events in its critical 20790Sstevel@tonic-gate * set when a change in other terms would normally require a change in 20800Sstevel@tonic-gate * the critical set. Just tests privilege and audits on success. 20810Sstevel@tonic-gate */ 20820Sstevel@tonic-gate boolean_t 20830Sstevel@tonic-gate secpolicy_contract_event_choice(const cred_t *cr) 20840Sstevel@tonic-gate { 20850Sstevel@tonic-gate return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_EVENT, B_FALSE)); 20860Sstevel@tonic-gate } 20870Sstevel@tonic-gate 20880Sstevel@tonic-gate /* 20891544Seschrock * secpolicy_gart_access 20900Sstevel@tonic-gate * 20911544Seschrock * Determine if the subject has sufficient priveleges to make ioctls to agpgart 20921544Seschrock * device. 20930Sstevel@tonic-gate */ 20940Sstevel@tonic-gate int 20950Sstevel@tonic-gate secpolicy_gart_access(const cred_t *cr) 20960Sstevel@tonic-gate { 20971862Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, NULL)); 20980Sstevel@tonic-gate } 20990Sstevel@tonic-gate 21000Sstevel@tonic-gate /* 21011544Seschrock * secpolicy_gart_map 21020Sstevel@tonic-gate * 21031544Seschrock * Determine if the subject has sufficient priveleges to map aperture range 21041544Seschrock * through agpgart driver. 21050Sstevel@tonic-gate */ 21060Sstevel@tonic-gate int 21070Sstevel@tonic-gate secpolicy_gart_map(const cred_t *cr) 21080Sstevel@tonic-gate { 21091862Scasper if (PRIV_POLICY_ONLY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE)) { 21101862Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, 21111862Scasper NULL)); 21121862Scasper } else { 21131862Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_MAP, B_FALSE, EPERM, 21141862Scasper NULL)); 21150Sstevel@tonic-gate } 21160Sstevel@tonic-gate } 2117789Sahrens 2118789Sahrens /* 21191544Seschrock * secpolicy_zinject 21201544Seschrock * 21211544Seschrock * Determine if the subject can inject faults in the ZFS fault injection 21221544Seschrock * framework. Requires all privileges. 21231544Seschrock */ 21241544Seschrock int 21251544Seschrock secpolicy_zinject(const cred_t *cr) 21261544Seschrock { 21271544Seschrock return (secpolicy_require_set(cr, PRIV_FULLSET, NULL)); 21281544Seschrock } 21291544Seschrock 21301544Seschrock /* 2131789Sahrens * secpolicy_zfs 2132789Sahrens * 21331544Seschrock * Determine if the subject has permission to manipulate ZFS datasets 21341544Seschrock * (not pools). Equivalent to the SYS_MOUNT privilege. 2135789Sahrens */ 2136789Sahrens int 2137789Sahrens secpolicy_zfs(const cred_t *cr) 2138789Sahrens { 2139789Sahrens return (PRIV_POLICY(cr, PRIV_SYS_MOUNT, B_FALSE, EPERM, NULL)); 2140789Sahrens } 21414321Scasper 21424321Scasper /* 21434321Scasper * secpolicy_idmap 21444321Scasper * 21454321Scasper * Determine if the calling process has permissions to register an SID 21464321Scasper * mapping daemon and allocate ephemeral IDs. 21474321Scasper */ 21484321Scasper int 21494321Scasper secpolicy_idmap(const cred_t *cr) 21504321Scasper { 21515771Sjp151216 return (PRIV_POLICY(cr, PRIV_FILE_SETID, B_TRUE, EPERM, NULL)); 21524321Scasper } 21534581Ssherrym 21544581Ssherrym /* 21554581Ssherrym * secpolicy_ucode_update 21564581Ssherrym * 21574581Ssherrym * Determine if the subject has sufficient privilege to update microcode. 21584581Ssherrym */ 21594581Ssherrym int 21604581Ssherrym secpolicy_ucode_update(const cred_t *scr) 21614581Ssherrym { 21624581Ssherrym return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 21634581Ssherrym } 21644962Sdh155122 21654962Sdh155122 /* 21664962Sdh155122 * secpolicy_sadopen 21674962Sdh155122 * 21684962Sdh155122 * Determine if the subject has sufficient privilege to access /dev/sad/admin. 21694962Sdh155122 * /dev/sad/admin appear in global zone and exclusive-IP zones only. 21704962Sdh155122 * In global zone, sys_config is required. 21714962Sdh155122 * In exclusive-IP zones, sys_ip_config is required. 21724962Sdh155122 * Note that sys_config is prohibited in non-global zones. 21734962Sdh155122 */ 21744962Sdh155122 int 21754962Sdh155122 secpolicy_sadopen(const cred_t *credp) 21764962Sdh155122 { 21774962Sdh155122 priv_set_t pset; 21784962Sdh155122 21794962Sdh155122 priv_emptyset(&pset); 21804962Sdh155122 21814962Sdh155122 if (crgetzoneid(credp) == GLOBAL_ZONEID) 21824962Sdh155122 priv_addset(&pset, PRIV_SYS_CONFIG); 21834962Sdh155122 else 21844962Sdh155122 priv_addset(&pset, PRIV_SYS_IP_CONFIG); 21854962Sdh155122 21864962Sdh155122 return (secpolicy_require_set(credp, &pset, "devpolicy")); 21874962Sdh155122 } 21885331Samw 21896134Scasper 21906134Scasper /* 21916134Scasper * Add privileges to a particular privilege set; this is called when the 21926134Scasper * current sets of privileges are not sufficient. I.e., we should always 21936134Scasper * call the policy override functions from here. 21946134Scasper * What we are allowed to have is in the Observed Permitted set; so 21956134Scasper * we compute the difference between that and the newset. 21966134Scasper */ 21976134Scasper int 21986134Scasper secpolicy_require_privs(const cred_t *cr, const priv_set_t *nset) 21996134Scasper { 22006134Scasper priv_set_t rqd; 22016134Scasper 22026134Scasper rqd = CR_OPPRIV(cr); 22036134Scasper 22046134Scasper priv_inverse(&rqd); 22056134Scasper priv_intersect(nset, &rqd); 22066134Scasper 22076134Scasper return (secpolicy_require_set(cr, &rqd, NULL)); 22086134Scasper } 22096134Scasper 22105331Samw /* 22115331Samw * secpolicy_smb 22125331Samw * 22135331Samw * Determine if the cred_t has PRIV_SYS_SMB privilege, indicating 22145331Samw * that it has permission to access the smbsrv kernel driver. 22155331Samw * PRIV_POLICY checks the privilege and audits the check. 22165331Samw * 22175331Samw * Returns: 22185331Samw * 0 Driver access is allowed. 22195331Samw * EPERM Driver access is NOT permitted. 22205331Samw */ 22215331Samw int 22225331Samw secpolicy_smb(const cred_t *cr) 22235331Samw { 22245331Samw return (PRIV_POLICY(cr, PRIV_SYS_SMB, B_FALSE, EPERM, NULL)); 22255331Samw } 22265440Sjm199354 22275440Sjm199354 /* 22285440Sjm199354 * secpolicy_vscan 22295440Sjm199354 * 22305440Sjm199354 * Determine if cred_t has the necessary privileges to access a file 22315440Sjm199354 * for virus scanning and update its extended system attributes. 22325440Sjm199354 * PRIV_FILE_DAC_SEARCH, PRIV_FILE_DAC_READ - file access 22335440Sjm199354 * PRIV_FILE_FLAG_SET - set extended system attributes 22345440Sjm199354 * 22355440Sjm199354 * PRIV_POLICY checks the privilege and audits the check. 22365440Sjm199354 * 22375440Sjm199354 * Returns: 22385440Sjm199354 * 0 file access for virus scanning allowed. 22395440Sjm199354 * EPERM file access for virus scanning is NOT permitted. 22405440Sjm199354 */ 22415440Sjm199354 int 22425440Sjm199354 secpolicy_vscan(const cred_t *cr) 22435440Sjm199354 { 22445440Sjm199354 if ((PRIV_POLICY(cr, PRIV_FILE_DAC_SEARCH, B_FALSE, EPERM, NULL)) || 22455440Sjm199354 (PRIV_POLICY(cr, PRIV_FILE_DAC_READ, B_FALSE, EPERM, NULL)) || 22465440Sjm199354 (PRIV_POLICY(cr, PRIV_FILE_FLAG_SET, B_FALSE, EPERM, NULL))) { 22475440Sjm199354 return (EPERM); 22485440Sjm199354 } 22495440Sjm199354 22505440Sjm199354 return (0); 22515440Sjm199354 } 22526007Sthurlow 22536007Sthurlow /* 22546007Sthurlow * secpolicy_smbfs_login 22556007Sthurlow * 22566007Sthurlow * Determines if the caller can add and delete the smbfs login 22576007Sthurlow * password in the the nsmb kernel module for the CIFS client. 22586007Sthurlow * 22596007Sthurlow * Returns: 22606007Sthurlow * 0 access is allowed. 22616007Sthurlow * EPERM access is NOT allowed. 22626007Sthurlow */ 22636007Sthurlow int 22646007Sthurlow secpolicy_smbfs_login(const cred_t *cr, uid_t uid) 22656007Sthurlow { 22666007Sthurlow uid_t cruid = crgetruid(cr); 22676007Sthurlow 22686007Sthurlow if (cruid == uid) 22696007Sthurlow return (0); 22706007Sthurlow return (PRIV_POLICY(cr, PRIV_PROC_OWNER, B_FALSE, 22716007Sthurlow EPERM, NULL)); 22726007Sthurlow } 22736784Sjohnlev 22746784Sjohnlev /* 22756784Sjohnlev * secpolicy_xvm_control 22766784Sjohnlev * 22776784Sjohnlev * Determines if a caller can control the xVM hypervisor and/or running 22786784Sjohnlev * domains (x86 specific). 22796784Sjohnlev * 22806784Sjohnlev * Returns: 22816784Sjohnlev * 0 access is allowed. 22826784Sjohnlev * EPERM access is NOT allowed. 22836784Sjohnlev */ 22846784Sjohnlev int 22856784Sjohnlev secpolicy_xvm_control(const cred_t *cr) 22866784Sjohnlev { 22876784Sjohnlev if (PRIV_POLICY(cr, PRIV_XVM_CONTROL, B_FALSE, EPERM, NULL)) 22886784Sjohnlev return (EPERM); 22896784Sjohnlev return (0); 22906784Sjohnlev } 22918275SEric Cheng 22928275SEric Cheng /* 22939751Sjames.d.carlson@sun.com * secpolicy_ppp_config 22949751Sjames.d.carlson@sun.com * 22959751Sjames.d.carlson@sun.com * Determine if the subject has sufficient privileges to configure PPP and 22969751Sjames.d.carlson@sun.com * PPP-related devices. 22979751Sjames.d.carlson@sun.com */ 22989751Sjames.d.carlson@sun.com int 22999751Sjames.d.carlson@sun.com secpolicy_ppp_config(const cred_t *cr) 23009751Sjames.d.carlson@sun.com { 23019751Sjames.d.carlson@sun.com if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 23029751Sjames.d.carlson@sun.com return (secpolicy_net_config(cr, B_FALSE)); 23039751Sjames.d.carlson@sun.com return (PRIV_POLICY(cr, PRIV_SYS_PPP_CONFIG, B_FALSE, EPERM, NULL)); 23049751Sjames.d.carlson@sun.com } 2305