17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5ea8dc4b6Seschrock * Common Development and Distribution License (the "License"). 6ea8dc4b6Seschrock * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22134a1f4eSCasper H.S. Dik * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #include <sys/types.h> 267c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 277c478bd9Sstevel@tonic-gate #include <sys/param.h> 287c478bd9Sstevel@tonic-gate #include <sys/systm.h> 297c478bd9Sstevel@tonic-gate #include <sys/cred_impl.h> 307c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 317c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 327c478bd9Sstevel@tonic-gate #include <sys/stat.h> 337c478bd9Sstevel@tonic-gate #include <sys/errno.h> 347c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 357c478bd9Sstevel@tonic-gate #include <sys/user.h> 367c478bd9Sstevel@tonic-gate #include <sys/proc.h> 377c478bd9Sstevel@tonic-gate #include <sys/acct.h> 387c478bd9Sstevel@tonic-gate #include <sys/ipc_impl.h> 397c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 407c478bd9Sstevel@tonic-gate #include <sys/debug.h> 417c478bd9Sstevel@tonic-gate #include <sys/policy.h> 427c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 437c478bd9Sstevel@tonic-gate #include <sys/msg.h> 447c478bd9Sstevel@tonic-gate #include <sys/devpolicy.h> 457c478bd9Sstevel@tonic-gate #include <c2/audit.h> 467c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 47ddf7fe95Scasper #include <sys/klpd.h> 487c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 497c478bd9Sstevel@tonic-gate #include <sys/disp.h> 507c478bd9Sstevel@tonic-gate #include <sys/zone.h> 517c478bd9Sstevel@tonic-gate #include <inet/optcom.h> 527c478bd9Sstevel@tonic-gate #include <sys/sdt.h> 537c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 547c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 557c478bd9Sstevel@tonic-gate #include <sys/contract_impl.h> 56da14cebeSEric Cheng #include <sys/dld_ioc.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * There are two possible layers of privilege routines and two possible 607c478bd9Sstevel@tonic-gate * levels of secpolicy. Plus one other we may not be interested in, so 617c478bd9Sstevel@tonic-gate * we may need as many as 6 but no more. 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate #define MAXPRIVSTACK 6 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate int priv_debug = 0; 66634e26ecSCasper H.S. Dik int priv_basic_test = -1; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * This file contains the majority of the policy routines. 707c478bd9Sstevel@tonic-gate * Since the policy routines are defined by function and not 717c478bd9Sstevel@tonic-gate * by privilege, there is quite a bit of duplication of 727c478bd9Sstevel@tonic-gate * functions. 737c478bd9Sstevel@tonic-gate * 74da6c28aaSamw * The secpolicy functions must not make assumptions about 757c478bd9Sstevel@tonic-gate * locks held or not held as any lock can be held while they're 767c478bd9Sstevel@tonic-gate * being called. 777c478bd9Sstevel@tonic-gate * 787c478bd9Sstevel@tonic-gate * Credentials are read-only so no special precautions need to 797c478bd9Sstevel@tonic-gate * be taken while locking them. 807c478bd9Sstevel@tonic-gate * 817c478bd9Sstevel@tonic-gate * When a new policy check needs to be added to the system the 827c478bd9Sstevel@tonic-gate * following procedure should be followed: 837c478bd9Sstevel@tonic-gate * 847c478bd9Sstevel@tonic-gate * Pick an appropriate secpolicy_*() function 857c478bd9Sstevel@tonic-gate * -> done if one exists. 867c478bd9Sstevel@tonic-gate * Create a new secpolicy function, preferably with 877c478bd9Sstevel@tonic-gate * a descriptive name using the standard template. 887c478bd9Sstevel@tonic-gate * Pick an appropriate privilege for the policy. 897c478bd9Sstevel@tonic-gate * If no appropraite privilege exists, define new one 907c478bd9Sstevel@tonic-gate * (this should be done with extreme care; in most cases 917c478bd9Sstevel@tonic-gate * little is gained by adding another privilege) 927c478bd9Sstevel@tonic-gate * 937c478bd9Sstevel@tonic-gate * WHY ROOT IS STILL SPECIAL. 947c478bd9Sstevel@tonic-gate * 957c478bd9Sstevel@tonic-gate * In a number of the policy functions, there are still explicit 967c478bd9Sstevel@tonic-gate * checks for uid 0. The rationale behind these is that many root 977c478bd9Sstevel@tonic-gate * owned files/objects hold configuration information which can give full 987c478bd9Sstevel@tonic-gate * privileges to the user once written to. To prevent escalation 997c478bd9Sstevel@tonic-gate * of privilege by allowing just a single privilege to modify root owned 1007c478bd9Sstevel@tonic-gate * objects, we've added these root specific checks where we considered 1017c478bd9Sstevel@tonic-gate * them necessary: modifying root owned files, changing uids to 0, etc. 1027c478bd9Sstevel@tonic-gate * 1037c478bd9Sstevel@tonic-gate * PRIVILEGE ESCALATION AND ZONES. 1047c478bd9Sstevel@tonic-gate * 1057c478bd9Sstevel@tonic-gate * A number of operations potentially allow the caller to achieve 1067c478bd9Sstevel@tonic-gate * privileges beyond the ones normally required to perform the operation. 1077c478bd9Sstevel@tonic-gate * For example, if allowed to create a setuid 0 executable, a process can 1087c478bd9Sstevel@tonic-gate * gain privileges beyond PRIV_FILE_SETID. Zones, however, place 1097c478bd9Sstevel@tonic-gate * restrictions on the ability to gain privileges beyond those available 1107c478bd9Sstevel@tonic-gate * within the zone through file and process manipulation. Hence, such 1117c478bd9Sstevel@tonic-gate * operations require that the caller have an effective set that includes 1127c478bd9Sstevel@tonic-gate * all privileges available within the current zone, or all privileges 1137c478bd9Sstevel@tonic-gate * if executing in the global zone. 1147c478bd9Sstevel@tonic-gate * 1157c478bd9Sstevel@tonic-gate * This is indicated in the priv_policy* policy checking functions 1167c478bd9Sstevel@tonic-gate * through a combination of parameters. The "priv" parameter indicates 1177c478bd9Sstevel@tonic-gate * the privilege that is required, and the "allzone" parameter indicates 1187c478bd9Sstevel@tonic-gate * whether or not all privileges in the zone are required. In addition, 1197c478bd9Sstevel@tonic-gate * priv can be set to PRIV_ALL to indicate that all privileges are 1207c478bd9Sstevel@tonic-gate * required (regardless of zone). There are three scenarios of interest: 1217c478bd9Sstevel@tonic-gate * (1) operation requires a specific privilege 1227c478bd9Sstevel@tonic-gate * (2) operation requires a specific privilege, and requires all 1237c478bd9Sstevel@tonic-gate * privileges available within the zone (or all privileges if in 1247c478bd9Sstevel@tonic-gate * the global zone) 1257c478bd9Sstevel@tonic-gate * (3) operation requires all privileges, regardless of zone 1267c478bd9Sstevel@tonic-gate * 1277c478bd9Sstevel@tonic-gate * For (1), priv should be set to the specific privilege, and allzone 1287c478bd9Sstevel@tonic-gate * should be set to B_FALSE. 1297c478bd9Sstevel@tonic-gate * For (2), priv should be set to the specific privilege, and allzone 1307c478bd9Sstevel@tonic-gate * should be set to B_TRUE. 1317c478bd9Sstevel@tonic-gate * For (3), priv should be set to PRIV_ALL, and allzone should be set 1327c478bd9Sstevel@tonic-gate * to B_FALSE. 1337c478bd9Sstevel@tonic-gate * 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * The privileges are checked against the Effective set for 1387c478bd9Sstevel@tonic-gate * ordinary processes and checked against the Limit set 1397c478bd9Sstevel@tonic-gate * for euid 0 processes that haven't manipulated their privilege 1407c478bd9Sstevel@tonic-gate * sets. 1417c478bd9Sstevel@tonic-gate */ 1427c478bd9Sstevel@tonic-gate #define HAS_ALLPRIVS(cr) priv_isfullset(&CR_OEPRIV(cr)) 1437c478bd9Sstevel@tonic-gate #define ZONEPRIVS(cr) ((cr)->cr_zone->zone_privset) 1447c478bd9Sstevel@tonic-gate #define HAS_ALLZONEPRIVS(cr) priv_issubset(ZONEPRIVS(cr), &CR_OEPRIV(cr)) 1457c478bd9Sstevel@tonic-gate #define HAS_PRIVILEGE(cr, pr) ((pr) == PRIV_ALL ? \ 1467c478bd9Sstevel@tonic-gate HAS_ALLPRIVS(cr) : \ 1477c478bd9Sstevel@tonic-gate PRIV_ISASSERT(&CR_OEPRIV(cr), pr)) 1487c478bd9Sstevel@tonic-gate 149134a1f4eSCasper H.S. Dik #define FAST_BASIC_CHECK(cr, priv) \ 150134a1f4eSCasper H.S. Dik if (PRIV_ISASSERT(&CR_OEPRIV(cr), priv)) { \ 151134a1f4eSCasper H.S. Dik DTRACE_PROBE2(priv__ok, int, priv, boolean_t, B_FALSE); \ 152134a1f4eSCasper H.S. Dik return (0); \ 153134a1f4eSCasper H.S. Dik } 154134a1f4eSCasper H.S. Dik 1557c478bd9Sstevel@tonic-gate /* 156ddf7fe95Scasper * Policy checking functions. 1577c478bd9Sstevel@tonic-gate * 158ddf7fe95Scasper * All of the system's policy should be implemented here. 1597c478bd9Sstevel@tonic-gate */ 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* 162ddf7fe95Scasper * Private functions which take an additional va_list argument to 163ddf7fe95Scasper * implement an object specific policy override. 164ddf7fe95Scasper */ 165ddf7fe95Scasper static int priv_policy_ap(const cred_t *, int, boolean_t, int, 166ddf7fe95Scasper const char *, va_list); 167ddf7fe95Scasper static int priv_policy_va(const cred_t *, int, boolean_t, int, 168ddf7fe95Scasper const char *, ...); 169ddf7fe95Scasper 170ddf7fe95Scasper /* 1717c478bd9Sstevel@tonic-gate * Generic policy calls 1727c478bd9Sstevel@tonic-gate * 1737c478bd9Sstevel@tonic-gate * The "bottom" functions of policy control 1747c478bd9Sstevel@tonic-gate */ 1757c478bd9Sstevel@tonic-gate static char * 1767c478bd9Sstevel@tonic-gate mprintf(const char *fmt, ...) 1777c478bd9Sstevel@tonic-gate { 1787c478bd9Sstevel@tonic-gate va_list args; 1797c478bd9Sstevel@tonic-gate char *buf; 1807c478bd9Sstevel@tonic-gate size_t len; 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate va_start(args, fmt); 1837c478bd9Sstevel@tonic-gate len = vsnprintf(NULL, 0, fmt, args) + 1; 1847c478bd9Sstevel@tonic-gate va_end(args); 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate buf = kmem_alloc(len, KM_NOSLEEP); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate if (buf == NULL) 1897c478bd9Sstevel@tonic-gate return (NULL); 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate va_start(args, fmt); 1927c478bd9Sstevel@tonic-gate (void) vsnprintf(buf, len, fmt, args); 1937c478bd9Sstevel@tonic-gate va_end(args); 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate return (buf); 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate /* 1997c478bd9Sstevel@tonic-gate * priv_policy_errmsg() 2007c478bd9Sstevel@tonic-gate * 2017c478bd9Sstevel@tonic-gate * Generate an error message if privilege debugging is enabled system wide 2027c478bd9Sstevel@tonic-gate * or for this particular process. 2037c478bd9Sstevel@tonic-gate */ 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate #define FMTHDR "%s[%d]: missing privilege \"%s\" (euid = %d, syscall = %d)" 2067c478bd9Sstevel@tonic-gate #define FMTMSG " for \"%s\"" 2077c478bd9Sstevel@tonic-gate #define FMTFUN " needed at %s+0x%lx" 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate /* The maximum size privilege format: the concatenation of the above */ 2107c478bd9Sstevel@tonic-gate #define FMTMAX FMTHDR FMTMSG FMTFUN "\n" 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate static void 2137c478bd9Sstevel@tonic-gate priv_policy_errmsg(const cred_t *cr, int priv, const char *msg) 2147c478bd9Sstevel@tonic-gate { 2157c478bd9Sstevel@tonic-gate struct proc *me; 2167c478bd9Sstevel@tonic-gate pc_t stack[MAXPRIVSTACK]; 2177c478bd9Sstevel@tonic-gate int depth; 2187c478bd9Sstevel@tonic-gate int i; 2197c478bd9Sstevel@tonic-gate char *sym; 2207c478bd9Sstevel@tonic-gate ulong_t off; 2217c478bd9Sstevel@tonic-gate const char *pname; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate char *cmd; 2247c478bd9Sstevel@tonic-gate char fmt[sizeof (FMTMAX)]; 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate if ((me = curproc) == &p0) 2277c478bd9Sstevel@tonic-gate return; 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* Privileges must be defined */ 2307c478bd9Sstevel@tonic-gate ASSERT(priv == PRIV_ALL || priv == PRIV_MULTIPLE || 2317c478bd9Sstevel@tonic-gate priv == PRIV_ALLZONE || priv == PRIV_GLOBAL || 2327c478bd9Sstevel@tonic-gate priv_getbynum(priv) != NULL); 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate if (priv == PRIV_ALLZONE && INGLOBALZONE(me)) 2357c478bd9Sstevel@tonic-gate priv = PRIV_ALL; 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate if (curthread->t_pre_sys) 2387c478bd9Sstevel@tonic-gate ttolwp(curthread)->lwp_badpriv = (short)priv; 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate if (priv_debug == 0 && (CR_FLAGS(cr) & PRIV_DEBUG) == 0) 2417c478bd9Sstevel@tonic-gate return; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate (void) strcpy(fmt, FMTHDR); 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate if (me->p_user.u_comm[0]) 2467c478bd9Sstevel@tonic-gate cmd = &me->p_user.u_comm[0]; 2477c478bd9Sstevel@tonic-gate else 2487c478bd9Sstevel@tonic-gate cmd = "priv_policy"; 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate if (msg != NULL && *msg != '\0') { 2517c478bd9Sstevel@tonic-gate (void) strcat(fmt, FMTMSG); 2527c478bd9Sstevel@tonic-gate } else { 2537c478bd9Sstevel@tonic-gate (void) strcat(fmt, "%s"); 2547c478bd9Sstevel@tonic-gate msg = ""; 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate sym = NULL; 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate depth = getpcstack(stack, MAXPRIVSTACK); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* 2627c478bd9Sstevel@tonic-gate * Try to find the first interesting function on the stack. 2637c478bd9Sstevel@tonic-gate * priv_policy* that's us, so completely uninteresting. 2647c478bd9Sstevel@tonic-gate * suser(), drv_priv(), secpolicy_* are also called from 2657c478bd9Sstevel@tonic-gate * too many locations to convey useful information. 2667c478bd9Sstevel@tonic-gate */ 2677c478bd9Sstevel@tonic-gate for (i = 0; i < depth; i++) { 2687c478bd9Sstevel@tonic-gate sym = kobj_getsymname((uintptr_t)stack[i], &off); 2697c478bd9Sstevel@tonic-gate if (sym != NULL && 2707c478bd9Sstevel@tonic-gate strstr(sym, "hasprocperm") == 0 && 2717c478bd9Sstevel@tonic-gate strcmp("suser", sym) != 0 && 2727c478bd9Sstevel@tonic-gate strcmp("ipcaccess", sym) != 0 && 2737c478bd9Sstevel@tonic-gate strcmp("drv_priv", sym) != 0 && 2747c478bd9Sstevel@tonic-gate strncmp("secpolicy_", sym, 10) != 0 && 2757c478bd9Sstevel@tonic-gate strncmp("priv_policy", sym, 11) != 0) 2767c478bd9Sstevel@tonic-gate break; 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate if (sym != NULL) 2807c478bd9Sstevel@tonic-gate (void) strcat(fmt, FMTFUN); 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate (void) strcat(fmt, "\n"); 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate switch (priv) { 2857c478bd9Sstevel@tonic-gate case PRIV_ALL: 2867c478bd9Sstevel@tonic-gate pname = "ALL"; 2877c478bd9Sstevel@tonic-gate break; 2887c478bd9Sstevel@tonic-gate case PRIV_MULTIPLE: 2897c478bd9Sstevel@tonic-gate pname = "MULTIPLE"; 2907c478bd9Sstevel@tonic-gate break; 2917c478bd9Sstevel@tonic-gate case PRIV_ALLZONE: 2927c478bd9Sstevel@tonic-gate pname = "ZONE"; 2937c478bd9Sstevel@tonic-gate break; 2947c478bd9Sstevel@tonic-gate case PRIV_GLOBAL: 2957c478bd9Sstevel@tonic-gate pname = "GLOBAL"; 2967c478bd9Sstevel@tonic-gate break; 2977c478bd9Sstevel@tonic-gate default: 2987c478bd9Sstevel@tonic-gate pname = priv_getbynum(priv); 2997c478bd9Sstevel@tonic-gate break; 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate if (CR_FLAGS(cr) & PRIV_DEBUG) { 3037c478bd9Sstevel@tonic-gate /* Remember last message, just like lwp_badpriv. */ 3047c478bd9Sstevel@tonic-gate if (curthread->t_pdmsg != NULL) { 3057c478bd9Sstevel@tonic-gate kmem_free(curthread->t_pdmsg, 3067c478bd9Sstevel@tonic-gate strlen(curthread->t_pdmsg) + 1); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate curthread->t_pdmsg = mprintf(fmt, cmd, me->p_pid, pname, 3107c478bd9Sstevel@tonic-gate cr->cr_uid, curthread->t_sysnum, msg, sym, off); 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate curthread->t_post_sys = 1; 313ddf7fe95Scasper } 314ddf7fe95Scasper if (priv_debug) { 3157c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, fmt, cmd, me->p_pid, pname, cr->cr_uid, 3167c478bd9Sstevel@tonic-gate curthread->t_sysnum, msg, sym, off); 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate } 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate /* 321ddf7fe95Scasper * Override the policy, if appropriate. Return 0 if the external 322ddf7fe95Scasper * policy engine approves. 323ddf7fe95Scasper */ 324ddf7fe95Scasper static int 325ddf7fe95Scasper priv_policy_override(const cred_t *cr, int priv, boolean_t allzone, va_list ap) 326ddf7fe95Scasper { 327ddf7fe95Scasper priv_set_t set; 328ddf7fe95Scasper int ret; 329ddf7fe95Scasper 330ddf7fe95Scasper if (!(CR_FLAGS(cr) & PRIV_XPOLICY)) 331ddf7fe95Scasper return (-1); 332ddf7fe95Scasper 333ddf7fe95Scasper if (priv == PRIV_ALL) { 334ddf7fe95Scasper priv_fillset(&set); 335ddf7fe95Scasper } else if (allzone) { 336ddf7fe95Scasper set = *ZONEPRIVS(cr); 337ddf7fe95Scasper } else { 338ddf7fe95Scasper priv_emptyset(&set); 339ddf7fe95Scasper priv_addset(&set, priv); 340ddf7fe95Scasper } 341ddf7fe95Scasper ret = klpd_call(cr, &set, ap); 342ddf7fe95Scasper return (ret); 343ddf7fe95Scasper } 344ddf7fe95Scasper 345ddf7fe95Scasper static int 346134a1f4eSCasper H.S. Dik priv_policy_override_set(const cred_t *cr, const priv_set_t *req, va_list ap) 347ddf7fe95Scasper { 348134a1f4eSCasper H.S. Dik if (CR_FLAGS(cr) & PRIV_PFEXEC) 349134a1f4eSCasper H.S. Dik return (check_user_privs(cr, req)); 350ddf7fe95Scasper if (CR_FLAGS(cr) & PRIV_XPOLICY) { 351ddf7fe95Scasper return (klpd_call(cr, req, ap)); 352ddf7fe95Scasper } 353ddf7fe95Scasper return (-1); 354ddf7fe95Scasper } 355ddf7fe95Scasper 356134a1f4eSCasper H.S. Dik static int 357134a1f4eSCasper H.S. Dik priv_policy_override_set_va(const cred_t *cr, const priv_set_t *req, ...) 358134a1f4eSCasper H.S. Dik { 359134a1f4eSCasper H.S. Dik va_list ap; 360134a1f4eSCasper H.S. Dik int ret; 361134a1f4eSCasper H.S. Dik 362134a1f4eSCasper H.S. Dik va_start(ap, req); 363134a1f4eSCasper H.S. Dik ret = priv_policy_override_set(cr, req, ap); 364134a1f4eSCasper H.S. Dik va_end(ap); 365134a1f4eSCasper H.S. Dik return (ret); 366134a1f4eSCasper H.S. Dik } 367134a1f4eSCasper H.S. Dik 368ddf7fe95Scasper /* 3697c478bd9Sstevel@tonic-gate * Audit failure, log error message. 3707c478bd9Sstevel@tonic-gate */ 3717c478bd9Sstevel@tonic-gate static void 3727c478bd9Sstevel@tonic-gate priv_policy_err(const cred_t *cr, int priv, boolean_t allzone, const char *msg) 3737c478bd9Sstevel@tonic-gate { 3747c478bd9Sstevel@tonic-gate 375005d3febSMarek Pospisil if (AU_AUDITING()) 3767c478bd9Sstevel@tonic-gate audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 0); 3777c478bd9Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || 3807c478bd9Sstevel@tonic-gate curthread->t_pre_sys) { 3817c478bd9Sstevel@tonic-gate if (allzone && !HAS_ALLZONEPRIVS(cr)) { 3827c478bd9Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_ALLZONE, msg); 3837c478bd9Sstevel@tonic-gate } else { 3847c478bd9Sstevel@tonic-gate ASSERT(!HAS_PRIVILEGE(cr, priv)); 3857c478bd9Sstevel@tonic-gate priv_policy_errmsg(cr, priv, msg); 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate /* 391ddf7fe95Scasper * priv_policy_ap() 3927c478bd9Sstevel@tonic-gate * return 0 or error. 3937c478bd9Sstevel@tonic-gate * See block comment above for a description of "priv" and "allzone" usage. 3947c478bd9Sstevel@tonic-gate */ 395ddf7fe95Scasper static int 396ddf7fe95Scasper priv_policy_ap(const cred_t *cr, int priv, boolean_t allzone, int err, 397ddf7fe95Scasper const char *msg, va_list ap) 3987c478bd9Sstevel@tonic-gate { 399ddf7fe95Scasper if ((HAS_PRIVILEGE(cr, priv) && (!allzone || HAS_ALLZONEPRIVS(cr))) || 400ddf7fe95Scasper (!servicing_interrupt() && 401ddf7fe95Scasper priv_policy_override(cr, priv, allzone, ap) == 0)) { 4027c478bd9Sstevel@tonic-gate if ((allzone || priv == PRIV_ALL || 4037c478bd9Sstevel@tonic-gate !PRIV_ISASSERT(priv_basic, priv)) && 4047c478bd9Sstevel@tonic-gate !servicing_interrupt()) { 405ae115bc7Smrj PTOU(curproc)->u_acflag |= ASU; /* Needed for SVVS */ 406005d3febSMarek Pospisil if (AU_AUDITING()) 4077c478bd9Sstevel@tonic-gate audit_priv(priv, 4087c478bd9Sstevel@tonic-gate allzone ? ZONEPRIVS(cr) : NULL, 1); 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate err = 0; 4117c478bd9Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 4127c478bd9Sstevel@tonic-gate } else if (!servicing_interrupt()) { 4137c478bd9Sstevel@tonic-gate /* Failure audited in this procedure */ 4147c478bd9Sstevel@tonic-gate priv_policy_err(cr, priv, allzone, msg); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate return (err); 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate 419ddf7fe95Scasper int 420ddf7fe95Scasper priv_policy_va(const cred_t *cr, int priv, boolean_t allzone, int err, 421ddf7fe95Scasper const char *msg, ...) 422ddf7fe95Scasper { 423ddf7fe95Scasper int ret; 424ddf7fe95Scasper va_list ap; 425ddf7fe95Scasper 426ddf7fe95Scasper va_start(ap, msg); 427ddf7fe95Scasper ret = priv_policy_ap(cr, priv, allzone, err, msg, ap); 428ddf7fe95Scasper va_end(ap); 429ddf7fe95Scasper 430ddf7fe95Scasper return (ret); 431ddf7fe95Scasper } 432ddf7fe95Scasper 433ddf7fe95Scasper int 434ddf7fe95Scasper priv_policy(const cred_t *cr, int priv, boolean_t allzone, int err, 435ddf7fe95Scasper const char *msg) 436ddf7fe95Scasper { 437134a1f4eSCasper H.S. Dik return (priv_policy_va(cr, priv, allzone, err, msg, KLPDARG_NONE)); 438ddf7fe95Scasper } 439ddf7fe95Scasper 4407c478bd9Sstevel@tonic-gate /* 4417c478bd9Sstevel@tonic-gate * Return B_TRUE for sufficient privileges, B_FALSE for insufficient privileges. 4427c478bd9Sstevel@tonic-gate */ 4437c478bd9Sstevel@tonic-gate boolean_t 4447c478bd9Sstevel@tonic-gate priv_policy_choice(const cred_t *cr, int priv, boolean_t allzone) 4457c478bd9Sstevel@tonic-gate { 4467c478bd9Sstevel@tonic-gate boolean_t res = HAS_PRIVILEGE(cr, priv) && 4477c478bd9Sstevel@tonic-gate (!allzone || HAS_ALLZONEPRIVS(cr)); 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate /* Audit success only */ 450005d3febSMarek Pospisil if (res && AU_AUDITING() && 4517c478bd9Sstevel@tonic-gate (allzone || priv == PRIV_ALL || !PRIV_ISASSERT(priv_basic, priv)) && 4527c478bd9Sstevel@tonic-gate !servicing_interrupt()) { 4537c478bd9Sstevel@tonic-gate audit_priv(priv, allzone ? ZONEPRIVS(cr) : NULL, 1); 4547c478bd9Sstevel@tonic-gate } 4557c478bd9Sstevel@tonic-gate if (res) { 4567c478bd9Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 4577c478bd9Sstevel@tonic-gate } else { 4587c478bd9Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate return (res); 4617c478bd9Sstevel@tonic-gate } 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate /* 4647c478bd9Sstevel@tonic-gate * Non-auditing variant of priv_policy_choice(). 4657c478bd9Sstevel@tonic-gate */ 4667c478bd9Sstevel@tonic-gate boolean_t 4677c478bd9Sstevel@tonic-gate priv_policy_only(const cred_t *cr, int priv, boolean_t allzone) 4687c478bd9Sstevel@tonic-gate { 4697c478bd9Sstevel@tonic-gate boolean_t res = HAS_PRIVILEGE(cr, priv) && 4707c478bd9Sstevel@tonic-gate (!allzone || HAS_ALLZONEPRIVS(cr)); 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate if (res) { 4737c478bd9Sstevel@tonic-gate DTRACE_PROBE2(priv__ok, int, priv, boolean_t, allzone); 4747c478bd9Sstevel@tonic-gate } else { 4757c478bd9Sstevel@tonic-gate DTRACE_PROBE2(priv__err, int, priv, boolean_t, allzone); 4767c478bd9Sstevel@tonic-gate } 4777c478bd9Sstevel@tonic-gate return (res); 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate /* 4817c478bd9Sstevel@tonic-gate * Check whether all privileges in the required set are present. 4827c478bd9Sstevel@tonic-gate */ 4837c478bd9Sstevel@tonic-gate static int 484134a1f4eSCasper H.S. Dik secpolicy_require_set(const cred_t *cr, const priv_set_t *req, 485134a1f4eSCasper H.S. Dik const char *msg, ...) 4867c478bd9Sstevel@tonic-gate { 4877c478bd9Sstevel@tonic-gate int priv; 4887c478bd9Sstevel@tonic-gate int pfound = -1; 4897c478bd9Sstevel@tonic-gate priv_set_t pset; 490134a1f4eSCasper H.S. Dik va_list ap; 491134a1f4eSCasper H.S. Dik int ret; 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate if (req == PRIV_FULLSET ? HAS_ALLPRIVS(cr) : priv_issubset(req, 4947c478bd9Sstevel@tonic-gate &CR_OEPRIV(cr))) { 4957c478bd9Sstevel@tonic-gate return (0); 4967c478bd9Sstevel@tonic-gate } 4977c478bd9Sstevel@tonic-gate 498134a1f4eSCasper H.S. Dik va_start(ap, msg); 499134a1f4eSCasper H.S. Dik ret = priv_policy_override_set(cr, req, ap); 500134a1f4eSCasper H.S. Dik va_end(ap); 501134a1f4eSCasper H.S. Dik if (ret == 0) 502ddf7fe95Scasper return (0); 503ddf7fe95Scasper 5047c478bd9Sstevel@tonic-gate if (req == PRIV_FULLSET || priv_isfullset(req)) { 5057c478bd9Sstevel@tonic-gate priv_policy_err(cr, PRIV_ALL, B_FALSE, msg); 5067c478bd9Sstevel@tonic-gate return (EACCES); 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate pset = CR_OEPRIV(cr); /* present privileges */ 5107c478bd9Sstevel@tonic-gate priv_inverse(&pset); /* all non present privileges */ 5117c478bd9Sstevel@tonic-gate priv_intersect(req, &pset); /* the actual missing privs */ 5127c478bd9Sstevel@tonic-gate 513005d3febSMarek Pospisil if (AU_AUDITING()) 5147c478bd9Sstevel@tonic-gate audit_priv(PRIV_NONE, &pset, 0); 5157c478bd9Sstevel@tonic-gate /* 5167c478bd9Sstevel@tonic-gate * Privilege debugging; special case "one privilege in set". 5177c478bd9Sstevel@tonic-gate */ 5187c478bd9Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || curthread->t_pre_sys) { 5197c478bd9Sstevel@tonic-gate for (priv = 0; priv < nprivs; priv++) { 5207c478bd9Sstevel@tonic-gate if (priv_ismember(&pset, priv)) { 5217c478bd9Sstevel@tonic-gate if (pfound != -1) { 5227c478bd9Sstevel@tonic-gate /* Multiple missing privs */ 5237c478bd9Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_MULTIPLE, 5247c478bd9Sstevel@tonic-gate msg); 5257c478bd9Sstevel@tonic-gate return (EACCES); 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate pfound = priv; 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate ASSERT(pfound != -1); 5317c478bd9Sstevel@tonic-gate /* Just the one missing privilege */ 5327c478bd9Sstevel@tonic-gate priv_policy_errmsg(cr, pfound, msg); 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate return (EACCES); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate /* 5397c478bd9Sstevel@tonic-gate * Called when an operation requires that the caller be in the 5407c478bd9Sstevel@tonic-gate * global zone, regardless of privilege. 5417c478bd9Sstevel@tonic-gate */ 5427c478bd9Sstevel@tonic-gate static int 5437c478bd9Sstevel@tonic-gate priv_policy_global(const cred_t *cr) 5447c478bd9Sstevel@tonic-gate { 5457c478bd9Sstevel@tonic-gate if (crgetzoneid(cr) == GLOBAL_ZONEID) 5467c478bd9Sstevel@tonic-gate return (0); /* success */ 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate if (priv_debug || (CR_FLAGS(cr) & PRIV_DEBUG) || 5497c478bd9Sstevel@tonic-gate curthread->t_pre_sys) { 5507c478bd9Sstevel@tonic-gate priv_policy_errmsg(cr, PRIV_GLOBAL, NULL); 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate return (EPERM); 5537c478bd9Sstevel@tonic-gate } 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate /* 5567c478bd9Sstevel@tonic-gate * Changing process priority 5577c478bd9Sstevel@tonic-gate */ 5587c478bd9Sstevel@tonic-gate int 5597c478bd9Sstevel@tonic-gate secpolicy_setpriority(const cred_t *cr) 5607c478bd9Sstevel@tonic-gate { 5617c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_PRIOCNTL, B_FALSE, EPERM, NULL)); 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate /* 5657c478bd9Sstevel@tonic-gate * Binding to a privileged port, port must be specified in host byte 5667c478bd9Sstevel@tonic-gate * order. 567134a1f4eSCasper H.S. Dik * When adding a new privilege which allows binding to currently privileged 568134a1f4eSCasper H.S. Dik * ports, then you MUST also allow processes with PRIV_NET_PRIVADDR bind 569134a1f4eSCasper H.S. Dik * to these ports because of backward compatibility. 5707c478bd9Sstevel@tonic-gate */ 5717c478bd9Sstevel@tonic-gate int 572ddf7fe95Scasper secpolicy_net_privaddr(const cred_t *cr, in_port_t port, int proto) 5737c478bd9Sstevel@tonic-gate { 574da6c28aaSamw char *reason; 575da6c28aaSamw int priv; 576da6c28aaSamw 577da6c28aaSamw switch (port) { 578da6c28aaSamw case 137: 579da6c28aaSamw case 138: 580da6c28aaSamw case 139: 581da6c28aaSamw case 445: 582da6c28aaSamw /* 583134a1f4eSCasper H.S. Dik * NBT and SMB ports, these are normal privileged ports, 584134a1f4eSCasper H.S. Dik * allow bind only if the SYS_SMB or NET_PRIVADDR privilege 585134a1f4eSCasper H.S. Dik * is present. 586134a1f4eSCasper H.S. Dik * Try both, if neither is present return an error for 587134a1f4eSCasper H.S. Dik * priv SYS_SMB. 588da6c28aaSamw */ 589134a1f4eSCasper H.S. Dik if (PRIV_POLICY_ONLY(cr, PRIV_NET_PRIVADDR, B_FALSE)) 590134a1f4eSCasper H.S. Dik priv = PRIV_NET_PRIVADDR; 591134a1f4eSCasper H.S. Dik else 592da6c28aaSamw priv = PRIV_SYS_SMB; 593da6c28aaSamw reason = "NBT or SMB port"; 594da6c28aaSamw break; 595da6c28aaSamw 596da6c28aaSamw case 2049: 597da6c28aaSamw case 4045: 5987c478bd9Sstevel@tonic-gate /* 5997c478bd9Sstevel@tonic-gate * NFS ports, these are extra privileged ports, allow bind 6007c478bd9Sstevel@tonic-gate * only if the SYS_NFS privilege is present. 6017c478bd9Sstevel@tonic-gate */ 602da6c28aaSamw priv = PRIV_SYS_NFS; 603da6c28aaSamw reason = "NFS port"; 604da6c28aaSamw break; 605da6c28aaSamw 606da6c28aaSamw default: 607da6c28aaSamw priv = PRIV_NET_PRIVADDR; 608da6c28aaSamw reason = NULL; 609da6c28aaSamw break; 610da6c28aaSamw 611da6c28aaSamw } 612da6c28aaSamw 613ddf7fe95Scasper return (priv_policy_va(cr, priv, B_FALSE, EACCES, reason, 614ddf7fe95Scasper KLPDARG_PORT, (int)proto, (int)port, KLPDARG_NOMORE)); 6157c478bd9Sstevel@tonic-gate } 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate /* 61845916cd2Sjpk * Binding to a multilevel port on a trusted (labeled) system. 61945916cd2Sjpk */ 62045916cd2Sjpk int 62145916cd2Sjpk secpolicy_net_bindmlp(const cred_t *cr) 62245916cd2Sjpk { 623ddf7fe95Scasper return (PRIV_POLICY(cr, PRIV_NET_BINDMLP, B_FALSE, EACCES, NULL)); 62445916cd2Sjpk } 62545916cd2Sjpk 62645916cd2Sjpk /* 62745916cd2Sjpk * Allow a communication between a zone and an unlabeled host when their 62845916cd2Sjpk * labels don't match. 62945916cd2Sjpk */ 63045916cd2Sjpk int 63145916cd2Sjpk secpolicy_net_mac_aware(const cred_t *cr) 63245916cd2Sjpk { 633ddf7fe95Scasper return (PRIV_POLICY(cr, PRIV_NET_MAC_AWARE, B_FALSE, EACCES, NULL)); 63445916cd2Sjpk } 63545916cd2Sjpk 63645916cd2Sjpk /* 6375d3b8cb7SBill Sommerfeld * Allow a privileged process to transmit traffic without explicit labels 6385d3b8cb7SBill Sommerfeld */ 6395d3b8cb7SBill Sommerfeld int 6405d3b8cb7SBill Sommerfeld secpolicy_net_mac_implicit(const cred_t *cr) 6415d3b8cb7SBill Sommerfeld { 6425d3b8cb7SBill Sommerfeld return (PRIV_POLICY(cr, PRIV_NET_MAC_IMPLICIT, B_FALSE, EACCES, NULL)); 6435d3b8cb7SBill Sommerfeld } 6445d3b8cb7SBill Sommerfeld 6455d3b8cb7SBill Sommerfeld /* 6467c478bd9Sstevel@tonic-gate * Common routine which determines whether a given credential can 6477c478bd9Sstevel@tonic-gate * act on a given mount. 6487c478bd9Sstevel@tonic-gate * When called through mount, the parameter needoptcheck is a pointer 6497c478bd9Sstevel@tonic-gate * to a boolean variable which will be set to either true or false, 6507c478bd9Sstevel@tonic-gate * depending on whether the mount policy should change the mount options. 6517c478bd9Sstevel@tonic-gate * In all other cases, needoptcheck should be a NULL pointer. 6527c478bd9Sstevel@tonic-gate */ 6537c478bd9Sstevel@tonic-gate static int 6547c478bd9Sstevel@tonic-gate secpolicy_fs_common(cred_t *cr, vnode_t *mvp, const vfs_t *vfsp, 6557c478bd9Sstevel@tonic-gate boolean_t *needoptcheck) 6567c478bd9Sstevel@tonic-gate { 6577c478bd9Sstevel@tonic-gate boolean_t allzone = B_FALSE; 6587c478bd9Sstevel@tonic-gate boolean_t mounting = needoptcheck != NULL; 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate /* 6617c478bd9Sstevel@tonic-gate * Short circuit the following cases: 6627c478bd9Sstevel@tonic-gate * vfsp == NULL or mvp == NULL (pure privilege check) 6637c478bd9Sstevel@tonic-gate * have all privileges - no further checks required 6647c478bd9Sstevel@tonic-gate * and no mount options need to be set. 6657c478bd9Sstevel@tonic-gate */ 6667c478bd9Sstevel@tonic-gate if (vfsp == NULL || mvp == NULL || HAS_ALLPRIVS(cr)) { 6677c478bd9Sstevel@tonic-gate if (mounting) 6687c478bd9Sstevel@tonic-gate *needoptcheck = B_FALSE; 6697c478bd9Sstevel@tonic-gate 670ddf7fe95Scasper return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM, 671ddf7fe95Scasper NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE)); 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate /* 6757c478bd9Sstevel@tonic-gate * When operating on an existing mount (either we're not mounting 6767c478bd9Sstevel@tonic-gate * or we're doing a remount and VFS_REMOUNT will be set), zones 6777c478bd9Sstevel@tonic-gate * can operate only on mounts established by the zone itself. 6787c478bd9Sstevel@tonic-gate */ 6797c478bd9Sstevel@tonic-gate if (!mounting || (vfsp->vfs_flag & VFS_REMOUNT) != 0) { 6807c478bd9Sstevel@tonic-gate zoneid_t zoneid = crgetzoneid(cr); 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate if (zoneid != GLOBAL_ZONEID && 6837c478bd9Sstevel@tonic-gate vfsp->vfs_zone->zone_id != zoneid) { 6847c478bd9Sstevel@tonic-gate return (EPERM); 6857c478bd9Sstevel@tonic-gate } 6867c478bd9Sstevel@tonic-gate } 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate if (mounting) 6897c478bd9Sstevel@tonic-gate *needoptcheck = B_TRUE; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate /* 6927c478bd9Sstevel@tonic-gate * Overlay mounts may hide important stuff; if you can't write to a 6937c478bd9Sstevel@tonic-gate * mount point but would be able to mount on top of it, you can 6947c478bd9Sstevel@tonic-gate * escalate your privileges. 6957c478bd9Sstevel@tonic-gate * So we go about asking the same questions namefs does when it 6967c478bd9Sstevel@tonic-gate * decides whether you can mount over a file or not but with the 6977c478bd9Sstevel@tonic-gate * added restriction that you can only mount on top of a regular 6987c478bd9Sstevel@tonic-gate * file or directory. 6997c478bd9Sstevel@tonic-gate * If we have all the zone's privileges, we skip all other checks, 7007c478bd9Sstevel@tonic-gate * or else we may actually get in trouble inside the automounter. 7017c478bd9Sstevel@tonic-gate */ 7027c478bd9Sstevel@tonic-gate if ((mvp->v_flag & VROOT) != 0 || 7037c478bd9Sstevel@tonic-gate (mvp->v_type != VDIR && mvp->v_type != VREG) || 7047c478bd9Sstevel@tonic-gate HAS_ALLZONEPRIVS(cr)) { 7057c478bd9Sstevel@tonic-gate allzone = B_TRUE; 7067c478bd9Sstevel@tonic-gate } else { 7077c478bd9Sstevel@tonic-gate vattr_t va; 7087c478bd9Sstevel@tonic-gate int err; 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate va.va_mask = AT_UID|AT_MODE; 711da6c28aaSamw err = VOP_GETATTR(mvp, &va, 0, cr, NULL); 7127c478bd9Sstevel@tonic-gate if (err != 0) 7137c478bd9Sstevel@tonic-gate return (err); 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate if ((err = secpolicy_vnode_owner(cr, va.va_uid)) != 0) 7167c478bd9Sstevel@tonic-gate return (err); 7177c478bd9Sstevel@tonic-gate 718134a1f4eSCasper H.S. Dik if (secpolicy_vnode_access2(cr, mvp, va.va_uid, va.va_mode, 719134a1f4eSCasper H.S. Dik VWRITE) != 0) { 7207c478bd9Sstevel@tonic-gate return (EACCES); 7217c478bd9Sstevel@tonic-gate } 7227c478bd9Sstevel@tonic-gate } 723ddf7fe95Scasper return (priv_policy_va(cr, PRIV_SYS_MOUNT, allzone, EPERM, 724ddf7fe95Scasper NULL, KLPDARG_VNODE, mvp, (char *)NULL, KLPDARG_NOMORE)); 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate 727ecd6cf80Smarks void 728ecd6cf80Smarks secpolicy_fs_mount_clearopts(cred_t *cr, struct vfs *vfsp) 7297c478bd9Sstevel@tonic-gate { 7307c478bd9Sstevel@tonic-gate boolean_t amsuper = HAS_ALLZONEPRIVS(cr); 7317c478bd9Sstevel@tonic-gate 7327c478bd9Sstevel@tonic-gate /* 733ecd6cf80Smarks * check; if we don't have either "nosuid" or 7347c478bd9Sstevel@tonic-gate * both "nosetuid" and "nodevices", then we add 7357c478bd9Sstevel@tonic-gate * "nosuid"; this depends on how the current 7367c478bd9Sstevel@tonic-gate * implementation works (it first checks nosuid). In a 7377c478bd9Sstevel@tonic-gate * zone, a user with all zone privileges can mount with 7387c478bd9Sstevel@tonic-gate * "setuid" but never with "devices". 7397c478bd9Sstevel@tonic-gate */ 7407c478bd9Sstevel@tonic-gate if (!vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL) && 7417c478bd9Sstevel@tonic-gate (!vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL) || 7427c478bd9Sstevel@tonic-gate !vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL))) { 7437c478bd9Sstevel@tonic-gate if (crgetzoneid(cr) == GLOBAL_ZONEID || !amsuper) 7447c478bd9Sstevel@tonic-gate vfs_setmntopt(vfsp, MNTOPT_NOSUID, NULL, 0); 7457c478bd9Sstevel@tonic-gate else 7467c478bd9Sstevel@tonic-gate vfs_setmntopt(vfsp, MNTOPT_NODEVICES, NULL, 0); 7477c478bd9Sstevel@tonic-gate } 7487c478bd9Sstevel@tonic-gate /* 7497c478bd9Sstevel@tonic-gate * If we're not the local super user, we set the "restrict" 7507c478bd9Sstevel@tonic-gate * option to indicate to automountd that this mount should 7517c478bd9Sstevel@tonic-gate * be handled with care. 7527c478bd9Sstevel@tonic-gate */ 7537c478bd9Sstevel@tonic-gate if (!amsuper) 7547c478bd9Sstevel@tonic-gate vfs_setmntopt(vfsp, MNTOPT_RESTRICT, NULL, 0); 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate } 757ecd6cf80Smarks 758ecd6cf80Smarks extern vnode_t *rootvp; 759ecd6cf80Smarks extern vfs_t *rootvfs; 760ecd6cf80Smarks 761ecd6cf80Smarks int 762ecd6cf80Smarks secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct vfs *vfsp) 763ecd6cf80Smarks { 764ecd6cf80Smarks boolean_t needoptchk; 765ecd6cf80Smarks int error; 766ecd6cf80Smarks 767ecd6cf80Smarks /* 768ecd6cf80Smarks * If it's a remount, get the underlying mount point, 769ecd6cf80Smarks * except for the root where we use the rootvp. 770ecd6cf80Smarks */ 771ecd6cf80Smarks if ((vfsp->vfs_flag & VFS_REMOUNT) != 0) { 772ecd6cf80Smarks if (vfsp == rootvfs) 773ecd6cf80Smarks mvp = rootvp; 774ecd6cf80Smarks else 775ecd6cf80Smarks mvp = vfsp->vfs_vnodecovered; 776ecd6cf80Smarks } 777ecd6cf80Smarks 778ecd6cf80Smarks error = secpolicy_fs_common(cr, mvp, vfsp, &needoptchk); 779ecd6cf80Smarks 780ecd6cf80Smarks if (error == 0 && needoptchk) { 781ecd6cf80Smarks secpolicy_fs_mount_clearopts(cr, vfsp); 782ecd6cf80Smarks } 783ecd6cf80Smarks 7847c478bd9Sstevel@tonic-gate return (error); 7857c478bd9Sstevel@tonic-gate } 7867c478bd9Sstevel@tonic-gate 7877c478bd9Sstevel@tonic-gate /* 7887c478bd9Sstevel@tonic-gate * Does the policy computations for "ownership" of a mount; 7897c478bd9Sstevel@tonic-gate * here ownership is defined as the ability to "mount" 7907c478bd9Sstevel@tonic-gate * the filesystem originally. The rootvfs doesn't cover any 7917c478bd9Sstevel@tonic-gate * vnodes; we attribute its ownership to the rootvp. 7927c478bd9Sstevel@tonic-gate */ 7937c478bd9Sstevel@tonic-gate static int 7947c478bd9Sstevel@tonic-gate secpolicy_fs_owner(cred_t *cr, const struct vfs *vfsp) 7957c478bd9Sstevel@tonic-gate { 7967c478bd9Sstevel@tonic-gate vnode_t *mvp; 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate if (vfsp == NULL) 7997c478bd9Sstevel@tonic-gate mvp = NULL; 8007c478bd9Sstevel@tonic-gate else if (vfsp == rootvfs) 8017c478bd9Sstevel@tonic-gate mvp = rootvp; 8027c478bd9Sstevel@tonic-gate else 8037c478bd9Sstevel@tonic-gate mvp = vfsp->vfs_vnodecovered; 8047c478bd9Sstevel@tonic-gate 8057c478bd9Sstevel@tonic-gate return (secpolicy_fs_common(cr, mvp, vfsp, NULL)); 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate int 8097c478bd9Sstevel@tonic-gate secpolicy_fs_unmount(cred_t *cr, struct vfs *vfsp) 8107c478bd9Sstevel@tonic-gate { 8117c478bd9Sstevel@tonic-gate return (secpolicy_fs_owner(cr, vfsp)); 8127c478bd9Sstevel@tonic-gate } 8137c478bd9Sstevel@tonic-gate 8147c478bd9Sstevel@tonic-gate /* 8157c478bd9Sstevel@tonic-gate * Quotas are a resource, but if one has the ability to mount a filesystem, he 8167c478bd9Sstevel@tonic-gate * should be able to modify quotas on it. 8177c478bd9Sstevel@tonic-gate */ 8187c478bd9Sstevel@tonic-gate int 8197c478bd9Sstevel@tonic-gate secpolicy_fs_quota(const cred_t *cr, const vfs_t *vfsp) 8207c478bd9Sstevel@tonic-gate { 8217c478bd9Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 8227c478bd9Sstevel@tonic-gate } 8237c478bd9Sstevel@tonic-gate 8247c478bd9Sstevel@tonic-gate /* 8257c478bd9Sstevel@tonic-gate * Exceeding minfree: also a per-mount resource constraint. 8267c478bd9Sstevel@tonic-gate */ 8277c478bd9Sstevel@tonic-gate int 8287c478bd9Sstevel@tonic-gate secpolicy_fs_minfree(const cred_t *cr, const vfs_t *vfsp) 8297c478bd9Sstevel@tonic-gate { 8307c478bd9Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 8317c478bd9Sstevel@tonic-gate } 8327c478bd9Sstevel@tonic-gate 8337c478bd9Sstevel@tonic-gate int 8347c478bd9Sstevel@tonic-gate secpolicy_fs_config(const cred_t *cr, const vfs_t *vfsp) 8357c478bd9Sstevel@tonic-gate { 8367c478bd9Sstevel@tonic-gate return (secpolicy_fs_owner((cred_t *)cr, vfsp)); 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate 8397c478bd9Sstevel@tonic-gate /* ARGSUSED */ 8407c478bd9Sstevel@tonic-gate int 8417c478bd9Sstevel@tonic-gate secpolicy_fs_linkdir(const cred_t *cr, const vfs_t *vfsp) 8427c478bd9Sstevel@tonic-gate { 8437c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_LINKDIR, B_FALSE, EPERM, NULL)); 8447c478bd9Sstevel@tonic-gate } 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate /* 8477c478bd9Sstevel@tonic-gate * Name: secpolicy_vnode_access() 8487c478bd9Sstevel@tonic-gate * 8497c478bd9Sstevel@tonic-gate * Parameters: Process credential 8507c478bd9Sstevel@tonic-gate * vnode 8517c478bd9Sstevel@tonic-gate * uid of owner of vnode 8527c478bd9Sstevel@tonic-gate * permission bits not granted to the caller when examining 8537c478bd9Sstevel@tonic-gate * file mode bits (i.e., when a process wants to open a 8547c478bd9Sstevel@tonic-gate * mode 444 file for VREAD|VWRITE, this function should be 8557c478bd9Sstevel@tonic-gate * called only with a VWRITE argument). 8567c478bd9Sstevel@tonic-gate * 8577c478bd9Sstevel@tonic-gate * Normal: Verifies that cred has the appropriate privileges to 8587c478bd9Sstevel@tonic-gate * override the mode bits that were denied. 8597c478bd9Sstevel@tonic-gate * 8607c478bd9Sstevel@tonic-gate * Override: file_dac_execute - if VEXEC bit was denied and vnode is 8617c478bd9Sstevel@tonic-gate * not a directory. 8627c478bd9Sstevel@tonic-gate * file_dac_read - if VREAD bit was denied. 8637c478bd9Sstevel@tonic-gate * file_dac_search - if VEXEC bit was denied and vnode is 8647c478bd9Sstevel@tonic-gate * a directory. 8657c478bd9Sstevel@tonic-gate * file_dac_write - if VWRITE bit was denied. 8667c478bd9Sstevel@tonic-gate * 8677c478bd9Sstevel@tonic-gate * Root owned files are special cased to protect system 8687c478bd9Sstevel@tonic-gate * configuration files and such. 8697c478bd9Sstevel@tonic-gate * 8707c478bd9Sstevel@tonic-gate * Output: EACCES - if privilege check fails. 8717c478bd9Sstevel@tonic-gate */ 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate int 8747c478bd9Sstevel@tonic-gate secpolicy_vnode_access(const cred_t *cr, vnode_t *vp, uid_t owner, mode_t mode) 8757c478bd9Sstevel@tonic-gate { 876ddf7fe95Scasper if ((mode & VREAD) && priv_policy_va(cr, PRIV_FILE_DAC_READ, B_FALSE, 877ddf7fe95Scasper EACCES, NULL, KLPDARG_VNODE, vp, (char *)NULL, 878ddf7fe95Scasper KLPDARG_NOMORE) != 0) { 8797c478bd9Sstevel@tonic-gate return (EACCES); 880ddf7fe95Scasper } 8817c478bd9Sstevel@tonic-gate 8827c478bd9Sstevel@tonic-gate if (mode & VWRITE) { 8837c478bd9Sstevel@tonic-gate boolean_t allzone; 8847c478bd9Sstevel@tonic-gate 8857c478bd9Sstevel@tonic-gate if (owner == 0 && cr->cr_uid != 0) 8867c478bd9Sstevel@tonic-gate allzone = B_TRUE; 8877c478bd9Sstevel@tonic-gate else 8887c478bd9Sstevel@tonic-gate allzone = B_FALSE; 889ddf7fe95Scasper if (priv_policy_va(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES, 890ddf7fe95Scasper NULL, KLPDARG_VNODE, vp, (char *)NULL, 891ddf7fe95Scasper KLPDARG_NOMORE) != 0) { 8927c478bd9Sstevel@tonic-gate return (EACCES); 8937c478bd9Sstevel@tonic-gate } 894ddf7fe95Scasper } 8957c478bd9Sstevel@tonic-gate 8967c478bd9Sstevel@tonic-gate if (mode & VEXEC) { 8977c478bd9Sstevel@tonic-gate /* 8987c478bd9Sstevel@tonic-gate * Directories use file_dac_search to override the execute bit. 8997c478bd9Sstevel@tonic-gate */ 900ddf7fe95Scasper int p = vp->v_type == VDIR ? PRIV_FILE_DAC_SEARCH : 901ddf7fe95Scasper PRIV_FILE_DAC_EXECUTE; 9027c478bd9Sstevel@tonic-gate 903ddf7fe95Scasper return (priv_policy_va(cr, p, B_FALSE, EACCES, NULL, 904ddf7fe95Scasper KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE)); 9057c478bd9Sstevel@tonic-gate } 9067c478bd9Sstevel@tonic-gate return (0); 9077c478bd9Sstevel@tonic-gate } 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate /* 910134a1f4eSCasper H.S. Dik * Like secpolicy_vnode_access() but we get the actual wanted mode and the 911134a1f4eSCasper H.S. Dik * current mode of the file, not the missing bits. 912134a1f4eSCasper H.S. Dik */ 913134a1f4eSCasper H.S. Dik int 914134a1f4eSCasper H.S. Dik secpolicy_vnode_access2(const cred_t *cr, vnode_t *vp, uid_t owner, 915134a1f4eSCasper H.S. Dik mode_t curmode, mode_t wantmode) 916134a1f4eSCasper H.S. Dik { 917134a1f4eSCasper H.S. Dik mode_t mode; 918134a1f4eSCasper H.S. Dik 919134a1f4eSCasper H.S. Dik /* Inline the basic privileges tests. */ 920134a1f4eSCasper H.S. Dik if ((wantmode & VREAD) && 921134a1f4eSCasper H.S. Dik !PRIV_ISASSERT(&CR_OEPRIV(cr), PRIV_FILE_READ) && 922134a1f4eSCasper H.S. Dik priv_policy_va(cr, PRIV_FILE_READ, B_FALSE, EACCES, NULL, 923134a1f4eSCasper H.S. Dik KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE) != 0) { 924134a1f4eSCasper H.S. Dik return (EACCES); 925134a1f4eSCasper H.S. Dik } 926134a1f4eSCasper H.S. Dik 927134a1f4eSCasper H.S. Dik if ((wantmode & VWRITE) && 928134a1f4eSCasper H.S. Dik !PRIV_ISASSERT(&CR_OEPRIV(cr), PRIV_FILE_WRITE) && 929134a1f4eSCasper H.S. Dik priv_policy_va(cr, PRIV_FILE_WRITE, B_FALSE, EACCES, NULL, 930134a1f4eSCasper H.S. Dik KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE) != 0) { 931134a1f4eSCasper H.S. Dik return (EACCES); 932134a1f4eSCasper H.S. Dik } 933134a1f4eSCasper H.S. Dik 934134a1f4eSCasper H.S. Dik mode = ~curmode & wantmode; 935134a1f4eSCasper H.S. Dik 936134a1f4eSCasper H.S. Dik if (mode == 0) 937134a1f4eSCasper H.S. Dik return (0); 938134a1f4eSCasper H.S. Dik 939134a1f4eSCasper H.S. Dik if ((mode & VREAD) && priv_policy_va(cr, PRIV_FILE_DAC_READ, B_FALSE, 940134a1f4eSCasper H.S. Dik EACCES, NULL, KLPDARG_VNODE, vp, (char *)NULL, 941134a1f4eSCasper H.S. Dik KLPDARG_NOMORE) != 0) { 942134a1f4eSCasper H.S. Dik return (EACCES); 943134a1f4eSCasper H.S. Dik } 944134a1f4eSCasper H.S. Dik 945134a1f4eSCasper H.S. Dik if (mode & VWRITE) { 946134a1f4eSCasper H.S. Dik boolean_t allzone; 947134a1f4eSCasper H.S. Dik 948134a1f4eSCasper H.S. Dik if (owner == 0 && cr->cr_uid != 0) 949134a1f4eSCasper H.S. Dik allzone = B_TRUE; 950134a1f4eSCasper H.S. Dik else 951134a1f4eSCasper H.S. Dik allzone = B_FALSE; 952134a1f4eSCasper H.S. Dik if (priv_policy_va(cr, PRIV_FILE_DAC_WRITE, allzone, EACCES, 953134a1f4eSCasper H.S. Dik NULL, KLPDARG_VNODE, vp, (char *)NULL, 954134a1f4eSCasper H.S. Dik KLPDARG_NOMORE) != 0) { 955134a1f4eSCasper H.S. Dik return (EACCES); 956134a1f4eSCasper H.S. Dik } 957134a1f4eSCasper H.S. Dik } 958134a1f4eSCasper H.S. Dik 959134a1f4eSCasper H.S. Dik if (mode & VEXEC) { 960134a1f4eSCasper H.S. Dik /* 961134a1f4eSCasper H.S. Dik * Directories use file_dac_search to override the execute bit. 962134a1f4eSCasper H.S. Dik */ 963134a1f4eSCasper H.S. Dik int p = vp->v_type == VDIR ? PRIV_FILE_DAC_SEARCH : 964134a1f4eSCasper H.S. Dik PRIV_FILE_DAC_EXECUTE; 965134a1f4eSCasper H.S. Dik 966134a1f4eSCasper H.S. Dik return (priv_policy_va(cr, p, B_FALSE, EACCES, NULL, 967134a1f4eSCasper H.S. Dik KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE)); 968134a1f4eSCasper H.S. Dik } 969134a1f4eSCasper H.S. Dik return (0); 970134a1f4eSCasper H.S. Dik } 971134a1f4eSCasper H.S. Dik 972134a1f4eSCasper H.S. Dik /* 973134a1f4eSCasper H.S. Dik * This is a special routine for ZFS; it is used to determine whether 974134a1f4eSCasper H.S. Dik * any of the privileges in effect allow any form of access to the 975134a1f4eSCasper H.S. Dik * file. There's no reason to audit this or any reason to record 976134a1f4eSCasper H.S. Dik * this. More work is needed to do the "KPLD" stuff. 977134a1f4eSCasper H.S. Dik */ 978134a1f4eSCasper H.S. Dik int 979134a1f4eSCasper H.S. Dik secpolicy_vnode_any_access(const cred_t *cr, vnode_t *vp, uid_t owner) 980134a1f4eSCasper H.S. Dik { 981134a1f4eSCasper H.S. Dik static int privs[] = { 982134a1f4eSCasper H.S. Dik PRIV_FILE_OWNER, 983*060fafacSCasper H.S. Dik PRIV_FILE_CHOWN, 984134a1f4eSCasper H.S. Dik PRIV_FILE_DAC_READ, 985134a1f4eSCasper H.S. Dik PRIV_FILE_DAC_WRITE, 986134a1f4eSCasper H.S. Dik PRIV_FILE_DAC_EXECUTE, 987134a1f4eSCasper H.S. Dik PRIV_FILE_DAC_SEARCH, 988134a1f4eSCasper H.S. Dik }; 989134a1f4eSCasper H.S. Dik int i; 990134a1f4eSCasper H.S. Dik 991134a1f4eSCasper H.S. Dik /* Same as secpolicy_vnode_setdac */ 992134a1f4eSCasper H.S. Dik if (owner == cr->cr_uid) 993134a1f4eSCasper H.S. Dik return (0); 994134a1f4eSCasper H.S. Dik 995134a1f4eSCasper H.S. Dik for (i = 0; i < sizeof (privs)/sizeof (int); i++) { 996134a1f4eSCasper H.S. Dik boolean_t allzone = B_FALSE; 997134a1f4eSCasper H.S. Dik int priv; 998134a1f4eSCasper H.S. Dik 999134a1f4eSCasper H.S. Dik switch (priv = privs[i]) { 1000134a1f4eSCasper H.S. Dik case PRIV_FILE_DAC_EXECUTE: 1001134a1f4eSCasper H.S. Dik if (vp->v_type == VDIR) 1002134a1f4eSCasper H.S. Dik continue; 1003134a1f4eSCasper H.S. Dik break; 1004134a1f4eSCasper H.S. Dik case PRIV_FILE_DAC_SEARCH: 1005134a1f4eSCasper H.S. Dik if (vp->v_type != VDIR) 1006134a1f4eSCasper H.S. Dik continue; 1007134a1f4eSCasper H.S. Dik break; 1008134a1f4eSCasper H.S. Dik case PRIV_FILE_DAC_WRITE: 1009134a1f4eSCasper H.S. Dik case PRIV_FILE_OWNER: 1010*060fafacSCasper H.S. Dik case PRIV_FILE_CHOWN: 1011134a1f4eSCasper H.S. Dik /* We know here that if owner == 0, that cr_uid != 0 */ 1012134a1f4eSCasper H.S. Dik allzone = owner == 0; 1013134a1f4eSCasper H.S. Dik break; 1014134a1f4eSCasper H.S. Dik } 1015134a1f4eSCasper H.S. Dik if (PRIV_POLICY_CHOICE(cr, priv, allzone)) 1016134a1f4eSCasper H.S. Dik return (0); 1017134a1f4eSCasper H.S. Dik } 1018134a1f4eSCasper H.S. Dik return (EPERM); 1019134a1f4eSCasper H.S. Dik } 1020134a1f4eSCasper H.S. Dik 1021134a1f4eSCasper H.S. Dik /* 10227c478bd9Sstevel@tonic-gate * Name: secpolicy_vnode_setid_modify() 10237c478bd9Sstevel@tonic-gate * 10247c478bd9Sstevel@tonic-gate * Normal: verify that subject can set the file setid flags. 10257c478bd9Sstevel@tonic-gate * 10267c478bd9Sstevel@tonic-gate * Output: EPERM - if not privileged. 10277c478bd9Sstevel@tonic-gate */ 10287c478bd9Sstevel@tonic-gate 10297c478bd9Sstevel@tonic-gate static int 10307c478bd9Sstevel@tonic-gate secpolicy_vnode_setid_modify(const cred_t *cr, uid_t owner) 10317c478bd9Sstevel@tonic-gate { 10327c478bd9Sstevel@tonic-gate /* If changing to suid root, must have all zone privs */ 10337c478bd9Sstevel@tonic-gate boolean_t allzone = B_TRUE; 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate if (owner != 0) { 10367c478bd9Sstevel@tonic-gate if (owner == cr->cr_uid) 10377c478bd9Sstevel@tonic-gate return (0); 10387c478bd9Sstevel@tonic-gate allzone = B_FALSE; 10397c478bd9Sstevel@tonic-gate } 10407c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_SETID, allzone, EPERM, NULL)); 10417c478bd9Sstevel@tonic-gate } 10427c478bd9Sstevel@tonic-gate 10437c478bd9Sstevel@tonic-gate /* 10447c478bd9Sstevel@tonic-gate * Are we allowed to retain the set-uid/set-gid bits when 10457c478bd9Sstevel@tonic-gate * changing ownership or when writing to a file? 10467c478bd9Sstevel@tonic-gate * "issuid" should be true when set-uid; only in that case 10477c478bd9Sstevel@tonic-gate * root ownership is checked (setgid is assumed). 10487c478bd9Sstevel@tonic-gate */ 10497c478bd9Sstevel@tonic-gate int 10507c478bd9Sstevel@tonic-gate secpolicy_vnode_setid_retain(const cred_t *cred, boolean_t issuidroot) 10517c478bd9Sstevel@tonic-gate { 10527c478bd9Sstevel@tonic-gate if (issuidroot && !HAS_ALLZONEPRIVS(cred)) 10537c478bd9Sstevel@tonic-gate return (EPERM); 10547c478bd9Sstevel@tonic-gate 10557c478bd9Sstevel@tonic-gate return (!PRIV_POLICY_CHOICE(cred, PRIV_FILE_SETID, B_FALSE)); 10567c478bd9Sstevel@tonic-gate } 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate /* 10597c478bd9Sstevel@tonic-gate * Name: secpolicy_vnode_setids_setgids() 10607c478bd9Sstevel@tonic-gate * 10617c478bd9Sstevel@tonic-gate * Normal: verify that subject can set the file setgid flag. 10627c478bd9Sstevel@tonic-gate * 10637c478bd9Sstevel@tonic-gate * Output: EPERM - if not privileged 10647c478bd9Sstevel@tonic-gate */ 10657c478bd9Sstevel@tonic-gate 10667c478bd9Sstevel@tonic-gate int 10677c478bd9Sstevel@tonic-gate secpolicy_vnode_setids_setgids(const cred_t *cred, gid_t gid) 10687c478bd9Sstevel@tonic-gate { 10697c478bd9Sstevel@tonic-gate if (!groupmember(gid, cred)) 10707c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_SETID, B_FALSE, EPERM, 10717c478bd9Sstevel@tonic-gate NULL)); 10727c478bd9Sstevel@tonic-gate return (0); 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate /* 107647def0dcSMark Shellenbaum * Name: secpolicy_vnode_chown 107747def0dcSMark Shellenbaum * 107847def0dcSMark Shellenbaum * Normal: Determine if subject can chown owner of a file. 107947def0dcSMark Shellenbaum * 108047def0dcSMark Shellenbaum * Output: EPERM - if access denied 10817c478bd9Sstevel@tonic-gate */ 108247def0dcSMark Shellenbaum 10837c478bd9Sstevel@tonic-gate int 1084e02bc683SMark Shellenbaum secpolicy_vnode_chown(const cred_t *cred, uid_t owner) 10857c478bd9Sstevel@tonic-gate { 1086e02bc683SMark Shellenbaum boolean_t is_owner = (owner == crgetuid(cred)); 1087e02bc683SMark Shellenbaum boolean_t allzone = B_FALSE; 1088e02bc683SMark Shellenbaum int priv; 1089e02bc683SMark Shellenbaum 1090e02bc683SMark Shellenbaum if (!is_owner) { 1091e02bc683SMark Shellenbaum allzone = (owner == 0); 1092e02bc683SMark Shellenbaum priv = PRIV_FILE_CHOWN; 1093e02bc683SMark Shellenbaum } else { 1094e02bc683SMark Shellenbaum priv = HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN) ? 1095e02bc683SMark Shellenbaum PRIV_FILE_CHOWN : PRIV_FILE_CHOWN_SELF; 1096e02bc683SMark Shellenbaum } 1097e02bc683SMark Shellenbaum 1098e02bc683SMark Shellenbaum return (PRIV_POLICY(cred, priv, allzone, EPERM, NULL)); 109947def0dcSMark Shellenbaum } 110047def0dcSMark Shellenbaum 110147def0dcSMark Shellenbaum /* 110247def0dcSMark Shellenbaum * Name: secpolicy_vnode_create_gid 110347def0dcSMark Shellenbaum * 110447def0dcSMark Shellenbaum * Normal: Determine if subject can change group ownership of a file. 110547def0dcSMark Shellenbaum * 110647def0dcSMark Shellenbaum * Output: EPERM - if access denied 110747def0dcSMark Shellenbaum */ 110847def0dcSMark Shellenbaum int 110947def0dcSMark Shellenbaum secpolicy_vnode_create_gid(const cred_t *cred) 111047def0dcSMark Shellenbaum { 1111e02bc683SMark Shellenbaum if (HAS_PRIVILEGE(cred, PRIV_FILE_CHOWN)) 1112e02bc683SMark Shellenbaum return (PRIV_POLICY(cred, PRIV_FILE_CHOWN, B_FALSE, EPERM, 1113e02bc683SMark Shellenbaum NULL)); 1114e02bc683SMark Shellenbaum else 1115e02bc683SMark Shellenbaum return (PRIV_POLICY(cred, PRIV_FILE_CHOWN_SELF, B_FALSE, EPERM, 1116e02bc683SMark Shellenbaum NULL)); 11177c478bd9Sstevel@tonic-gate } 11187c478bd9Sstevel@tonic-gate 11197c478bd9Sstevel@tonic-gate /* 11207c478bd9Sstevel@tonic-gate * Name: secpolicy_vnode_utime_modify() 11217c478bd9Sstevel@tonic-gate * 11227c478bd9Sstevel@tonic-gate * Normal: verify that subject can modify the utime on a file. 11237c478bd9Sstevel@tonic-gate * 11247c478bd9Sstevel@tonic-gate * Output: EPERM - if access denied. 11257c478bd9Sstevel@tonic-gate */ 11267c478bd9Sstevel@tonic-gate 11277c478bd9Sstevel@tonic-gate static int 11287c478bd9Sstevel@tonic-gate secpolicy_vnode_utime_modify(const cred_t *cred) 11297c478bd9Sstevel@tonic-gate { 11307c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_OWNER, B_FALSE, EPERM, 11317c478bd9Sstevel@tonic-gate "modify file times")); 11327c478bd9Sstevel@tonic-gate } 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate /* 11367c478bd9Sstevel@tonic-gate * Name: secpolicy_vnode_setdac() 11377c478bd9Sstevel@tonic-gate * 11387c478bd9Sstevel@tonic-gate * Normal: verify that subject can modify the mode of a file. 11397c478bd9Sstevel@tonic-gate * allzone privilege needed when modifying root owned object. 11407c478bd9Sstevel@tonic-gate * 11417c478bd9Sstevel@tonic-gate * Output: EPERM - if access denied. 11427c478bd9Sstevel@tonic-gate */ 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate int 11457c478bd9Sstevel@tonic-gate secpolicy_vnode_setdac(const cred_t *cred, uid_t owner) 11467c478bd9Sstevel@tonic-gate { 11477c478bd9Sstevel@tonic-gate if (owner == cred->cr_uid) 11487c478bd9Sstevel@tonic-gate return (0); 11497c478bd9Sstevel@tonic-gate 11507c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_FILE_OWNER, owner == 0, EPERM, NULL)); 11517c478bd9Sstevel@tonic-gate } 11527c478bd9Sstevel@tonic-gate /* 11537c478bd9Sstevel@tonic-gate * Name: secpolicy_vnode_stky_modify() 11547c478bd9Sstevel@tonic-gate * 11557c478bd9Sstevel@tonic-gate * Normal: verify that subject can make a file a "sticky". 11567c478bd9Sstevel@tonic-gate * 11577c478bd9Sstevel@tonic-gate * Output: EPERM - if access denied. 11587c478bd9Sstevel@tonic-gate */ 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate int 11617c478bd9Sstevel@tonic-gate secpolicy_vnode_stky_modify(const cred_t *cred) 11627c478bd9Sstevel@tonic-gate { 11637c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_SYS_CONFIG, B_FALSE, EPERM, 11647c478bd9Sstevel@tonic-gate "set file sticky")); 11657c478bd9Sstevel@tonic-gate } 11667c478bd9Sstevel@tonic-gate 11677c478bd9Sstevel@tonic-gate /* 11687c478bd9Sstevel@tonic-gate * Policy determines whether we can remove an entry from a directory, 11697c478bd9Sstevel@tonic-gate * regardless of permission bits. 11707c478bd9Sstevel@tonic-gate */ 11717c478bd9Sstevel@tonic-gate int 11727c478bd9Sstevel@tonic-gate secpolicy_vnode_remove(const cred_t *cr) 11737c478bd9Sstevel@tonic-gate { 11747c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_OWNER, B_FALSE, EACCES, 11757c478bd9Sstevel@tonic-gate "sticky directory")); 11767c478bd9Sstevel@tonic-gate } 11777c478bd9Sstevel@tonic-gate 11787c478bd9Sstevel@tonic-gate int 11797c478bd9Sstevel@tonic-gate secpolicy_vnode_owner(const cred_t *cr, uid_t owner) 11807c478bd9Sstevel@tonic-gate { 11817c478bd9Sstevel@tonic-gate boolean_t allzone = (owner == 0); 11827c478bd9Sstevel@tonic-gate 11837c478bd9Sstevel@tonic-gate if (owner == cr->cr_uid) 11847c478bd9Sstevel@tonic-gate return (0); 11857c478bd9Sstevel@tonic-gate 11867c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_OWNER, allzone, EPERM, NULL)); 11877c478bd9Sstevel@tonic-gate } 11887c478bd9Sstevel@tonic-gate 118913f9f30eSmarks void 119013f9f30eSmarks secpolicy_setid_clear(vattr_t *vap, cred_t *cr) 119113f9f30eSmarks { 119213f9f30eSmarks if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0 && 119313f9f30eSmarks secpolicy_vnode_setid_retain(cr, 119413f9f30eSmarks (vap->va_mode & S_ISUID) != 0 && 119513f9f30eSmarks (vap->va_mask & AT_UID) != 0 && vap->va_uid == 0) != 0) { 119613f9f30eSmarks vap->va_mask |= AT_MODE; 119713f9f30eSmarks vap->va_mode &= ~(S_ISUID|S_ISGID); 119813f9f30eSmarks } 119913f9f30eSmarks } 120013f9f30eSmarks 1201f92daba9Smarks int 1202f92daba9Smarks secpolicy_setid_setsticky_clear(vnode_t *vp, vattr_t *vap, const vattr_t *ovap, 1203f92daba9Smarks cred_t *cr) 1204f92daba9Smarks { 1205f92daba9Smarks int error; 1206f92daba9Smarks 1207f92daba9Smarks if ((vap->va_mode & S_ISUID) != 0 && 1208f92daba9Smarks (error = secpolicy_vnode_setid_modify(cr, 1209f92daba9Smarks ovap->va_uid)) != 0) { 1210f92daba9Smarks return (error); 1211f92daba9Smarks } 1212f92daba9Smarks 1213f92daba9Smarks /* 1214f92daba9Smarks * Check privilege if attempting to set the 1215f92daba9Smarks * sticky bit on a non-directory. 1216f92daba9Smarks */ 1217f92daba9Smarks if (vp->v_type != VDIR && (vap->va_mode & S_ISVTX) != 0 && 1218f92daba9Smarks secpolicy_vnode_stky_modify(cr) != 0) { 1219f92daba9Smarks vap->va_mode &= ~S_ISVTX; 1220f92daba9Smarks } 1221f92daba9Smarks 1222f92daba9Smarks /* 1223f92daba9Smarks * Check for privilege if attempting to set the 1224f92daba9Smarks * group-id bit. 1225f92daba9Smarks */ 1226f92daba9Smarks if ((vap->va_mode & S_ISGID) != 0 && 1227f92daba9Smarks secpolicy_vnode_setids_setgids(cr, ovap->va_gid) != 0) { 1228f92daba9Smarks vap->va_mode &= ~S_ISGID; 1229f92daba9Smarks } 1230f92daba9Smarks 1231f92daba9Smarks return (0); 1232f92daba9Smarks } 1233f92daba9Smarks 1234da6c28aaSamw #define ATTR_FLAG_PRIV(attr, value, cr) \ 1235da6c28aaSamw PRIV_POLICY(cr, value ? PRIV_FILE_FLAG_SET : PRIV_ALL, \ 1236da6c28aaSamw B_FALSE, EPERM, NULL) 1237da6c28aaSamw 1238da6c28aaSamw /* 1239da6c28aaSamw * Check privileges for setting xvattr attributes 1240da6c28aaSamw */ 1241da6c28aaSamw int 1242da6c28aaSamw secpolicy_xvattr(xvattr_t *xvap, uid_t owner, cred_t *cr, vtype_t vtype) 1243da6c28aaSamw { 1244da6c28aaSamw xoptattr_t *xoap; 1245da6c28aaSamw int error = 0; 1246da6c28aaSamw 1247da6c28aaSamw if ((xoap = xva_getxoptattr(xvap)) == NULL) 1248da6c28aaSamw return (EINVAL); 1249da6c28aaSamw 1250da6c28aaSamw /* 1251da6c28aaSamw * First process the DOS bits 1252da6c28aaSamw */ 1253da6c28aaSamw if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE) || 1254da6c28aaSamw XVA_ISSET_REQ(xvap, XAT_HIDDEN) || 1255da6c28aaSamw XVA_ISSET_REQ(xvap, XAT_READONLY) || 1256da6c28aaSamw XVA_ISSET_REQ(xvap, XAT_SYSTEM) || 1257da6c28aaSamw XVA_ISSET_REQ(xvap, XAT_CREATETIME)) { 1258da6c28aaSamw if ((error = secpolicy_vnode_owner(cr, owner)) != 0) 1259da6c28aaSamw return (error); 1260da6c28aaSamw } 1261da6c28aaSamw 1262da6c28aaSamw /* 1263da6c28aaSamw * Now handle special attributes 1264da6c28aaSamw */ 1265da6c28aaSamw 1266da6c28aaSamw if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) 1267da6c28aaSamw error = ATTR_FLAG_PRIV(XAT_IMMUTABLE, 1268da6c28aaSamw xoap->xoa_immutable, cr); 1269da6c28aaSamw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) 1270da6c28aaSamw error = ATTR_FLAG_PRIV(XAT_NOUNLINK, 1271da6c28aaSamw xoap->xoa_nounlink, cr); 1272da6c28aaSamw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) 1273da6c28aaSamw error = ATTR_FLAG_PRIV(XAT_APPENDONLY, 1274da6c28aaSamw xoap->xoa_appendonly, cr); 1275da6c28aaSamw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_NODUMP)) 1276da6c28aaSamw error = ATTR_FLAG_PRIV(XAT_NODUMP, 1277da6c28aaSamw xoap->xoa_nodump, cr); 1278da6c28aaSamw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_OPAQUE)) 1279da6c28aaSamw error = EPERM; 1280da6c28aaSamw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) { 1281da6c28aaSamw error = ATTR_FLAG_PRIV(XAT_AV_QUARANTINED, 1282da6c28aaSamw xoap->xoa_av_quarantined, cr); 1283e8f97327Smarks if (error == 0 && vtype != VREG && xoap->xoa_av_quarantined) 1284da6c28aaSamw error = EINVAL; 1285da6c28aaSamw } 1286da6c28aaSamw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) 1287da6c28aaSamw error = ATTR_FLAG_PRIV(XAT_AV_MODIFIED, 1288da6c28aaSamw xoap->xoa_av_modified, cr); 1289da6c28aaSamw if (error == 0 && XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) { 1290da6c28aaSamw error = ATTR_FLAG_PRIV(XAT_AV_SCANSTAMP, 1291da6c28aaSamw xoap->xoa_av_scanstamp, cr); 1292da6c28aaSamw if (error == 0 && vtype != VREG) 1293da6c28aaSamw error = EINVAL; 1294da6c28aaSamw } 1295da6c28aaSamw return (error); 1296da6c28aaSamw } 1297da6c28aaSamw 12987c478bd9Sstevel@tonic-gate /* 12997c478bd9Sstevel@tonic-gate * This function checks the policy decisions surrounding the 13007c478bd9Sstevel@tonic-gate * vop setattr call. 13017c478bd9Sstevel@tonic-gate * 13027c478bd9Sstevel@tonic-gate * It should be called after sufficient locks have been established 13037c478bd9Sstevel@tonic-gate * on the underlying data structures. No concurrent modifications 13047c478bd9Sstevel@tonic-gate * should be allowed. 13057c478bd9Sstevel@tonic-gate * 13067c478bd9Sstevel@tonic-gate * The caller must pass in unlocked version of its vaccess function 13077c478bd9Sstevel@tonic-gate * this is required because vop_access function should lock the 13087c478bd9Sstevel@tonic-gate * node for reading. A three argument function should be defined 13097c478bd9Sstevel@tonic-gate * which accepts the following argument: 13107c478bd9Sstevel@tonic-gate * A pointer to the internal "node" type (inode *) 13117c478bd9Sstevel@tonic-gate * vnode access bits (VREAD|VWRITE|VEXEC) 13127c478bd9Sstevel@tonic-gate * a pointer to the credential 13137c478bd9Sstevel@tonic-gate * 13147c478bd9Sstevel@tonic-gate * This function makes the following policy decisions: 13157c478bd9Sstevel@tonic-gate * 13167c478bd9Sstevel@tonic-gate * - change permissions 13177c478bd9Sstevel@tonic-gate * - permission to change file mode if not owner 13187c478bd9Sstevel@tonic-gate * - permission to add sticky bit to non-directory 13197c478bd9Sstevel@tonic-gate * - permission to add set-gid bit 13207c478bd9Sstevel@tonic-gate * 13217c478bd9Sstevel@tonic-gate * The ovap argument should include AT_MODE|AT_UID|AT_GID. 13227c478bd9Sstevel@tonic-gate * 13237c478bd9Sstevel@tonic-gate * If the vap argument does not include AT_MODE, the mode will be copied from 13247c478bd9Sstevel@tonic-gate * ovap. In certain situations set-uid/set-gid bits need to be removed; 13257c478bd9Sstevel@tonic-gate * this is done by marking vap->va_mask to include AT_MODE and va_mode 13267c478bd9Sstevel@tonic-gate * is updated to the newly computed mode. 13277c478bd9Sstevel@tonic-gate */ 13287c478bd9Sstevel@tonic-gate 13297c478bd9Sstevel@tonic-gate int 13307c478bd9Sstevel@tonic-gate secpolicy_vnode_setattr(cred_t *cr, struct vnode *vp, struct vattr *vap, 13317c478bd9Sstevel@tonic-gate const struct vattr *ovap, int flags, 13327c478bd9Sstevel@tonic-gate int unlocked_access(void *, int, cred_t *), 13337c478bd9Sstevel@tonic-gate void *node) 13347c478bd9Sstevel@tonic-gate { 13357c478bd9Sstevel@tonic-gate int mask = vap->va_mask; 13367c478bd9Sstevel@tonic-gate int error = 0; 1337da6c28aaSamw boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE; 13387c478bd9Sstevel@tonic-gate 13397c478bd9Sstevel@tonic-gate if (mask & AT_SIZE) { 13407c478bd9Sstevel@tonic-gate if (vp->v_type == VDIR) { 13417c478bd9Sstevel@tonic-gate error = EISDIR; 13427c478bd9Sstevel@tonic-gate goto out; 13437c478bd9Sstevel@tonic-gate } 1344da6c28aaSamw 1345da6c28aaSamw /* 1346da6c28aaSamw * If ATTR_NOACLCHECK is set in the flags, then we don't 1347da6c28aaSamw * perform the secondary unlocked_access() call since the 1348da6c28aaSamw * ACL (if any) is being checked there. 1349da6c28aaSamw */ 1350da6c28aaSamw if (skipaclchk == B_FALSE) { 13517c478bd9Sstevel@tonic-gate error = unlocked_access(node, VWRITE, cr); 13527c478bd9Sstevel@tonic-gate if (error) 13537c478bd9Sstevel@tonic-gate goto out; 13547c478bd9Sstevel@tonic-gate } 1355da6c28aaSamw } 13567c478bd9Sstevel@tonic-gate if (mask & AT_MODE) { 13577c478bd9Sstevel@tonic-gate /* 13587c478bd9Sstevel@tonic-gate * If not the owner of the file then check privilege 13597c478bd9Sstevel@tonic-gate * for two things: the privilege to set the mode at all 13607c478bd9Sstevel@tonic-gate * and, if we're setting setuid, we also need permissions 13617c478bd9Sstevel@tonic-gate * to add the set-uid bit, if we're not the owner. 13627c478bd9Sstevel@tonic-gate * In the specific case of creating a set-uid root 13637c478bd9Sstevel@tonic-gate * file, we need even more permissions. 13647c478bd9Sstevel@tonic-gate */ 13657c478bd9Sstevel@tonic-gate if ((error = secpolicy_vnode_setdac(cr, ovap->va_uid)) != 0) 13667c478bd9Sstevel@tonic-gate goto out; 13677c478bd9Sstevel@tonic-gate 1368f92daba9Smarks if ((error = secpolicy_setid_setsticky_clear(vp, vap, 1369f92daba9Smarks ovap, cr)) != 0) 13707c478bd9Sstevel@tonic-gate goto out; 13717c478bd9Sstevel@tonic-gate } else 13727c478bd9Sstevel@tonic-gate vap->va_mode = ovap->va_mode; 13737c478bd9Sstevel@tonic-gate 13747c478bd9Sstevel@tonic-gate if (mask & (AT_UID|AT_GID)) { 13757c478bd9Sstevel@tonic-gate boolean_t checkpriv = B_FALSE; 13767c478bd9Sstevel@tonic-gate 13777c478bd9Sstevel@tonic-gate /* 13787c478bd9Sstevel@tonic-gate * Chowning files. 13797c478bd9Sstevel@tonic-gate * 13807c478bd9Sstevel@tonic-gate * If you are the file owner: 13817c478bd9Sstevel@tonic-gate * chown to other uid FILE_CHOWN_SELF 13827c478bd9Sstevel@tonic-gate * chown to gid (non-member) FILE_CHOWN_SELF 13837c478bd9Sstevel@tonic-gate * chown to gid (member) <none> 13847c478bd9Sstevel@tonic-gate * 13857c478bd9Sstevel@tonic-gate * Instead of PRIV_FILE_CHOWN_SELF, FILE_CHOWN is also 13867c478bd9Sstevel@tonic-gate * acceptable but the first one is reported when debugging. 13877c478bd9Sstevel@tonic-gate * 13887c478bd9Sstevel@tonic-gate * If you are not the file owner: 13897c478bd9Sstevel@tonic-gate * chown from root PRIV_FILE_CHOWN + zone 13907c478bd9Sstevel@tonic-gate * chown from other to any PRIV_FILE_CHOWN 13917c478bd9Sstevel@tonic-gate * 13927c478bd9Sstevel@tonic-gate */ 13937c478bd9Sstevel@tonic-gate if (cr->cr_uid != ovap->va_uid) { 13947c478bd9Sstevel@tonic-gate checkpriv = B_TRUE; 13957c478bd9Sstevel@tonic-gate } else { 13967c478bd9Sstevel@tonic-gate if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) || 13977c478bd9Sstevel@tonic-gate ((mask & AT_GID) && vap->va_gid != ovap->va_gid && 13987c478bd9Sstevel@tonic-gate !groupmember(vap->va_gid, cr))) { 13997c478bd9Sstevel@tonic-gate checkpriv = B_TRUE; 14007c478bd9Sstevel@tonic-gate } 14017c478bd9Sstevel@tonic-gate } 14027c478bd9Sstevel@tonic-gate /* 14037c478bd9Sstevel@tonic-gate * If necessary, check privilege to see if update can be done. 14047c478bd9Sstevel@tonic-gate */ 14057c478bd9Sstevel@tonic-gate if (checkpriv && 1406e02bc683SMark Shellenbaum (error = secpolicy_vnode_chown(cr, ovap->va_uid)) != 0) { 14077c478bd9Sstevel@tonic-gate goto out; 14087c478bd9Sstevel@tonic-gate } 14097c478bd9Sstevel@tonic-gate 14107c478bd9Sstevel@tonic-gate /* 14117c478bd9Sstevel@tonic-gate * If the file has either the set UID or set GID bits 14127c478bd9Sstevel@tonic-gate * set and the caller can set the bits, then leave them. 14137c478bd9Sstevel@tonic-gate */ 141413f9f30eSmarks secpolicy_setid_clear(vap, cr); 14157c478bd9Sstevel@tonic-gate } 14167c478bd9Sstevel@tonic-gate if (mask & (AT_ATIME|AT_MTIME)) { 14177c478bd9Sstevel@tonic-gate /* 14187c478bd9Sstevel@tonic-gate * If not the file owner and not otherwise privileged, 14197c478bd9Sstevel@tonic-gate * always return an error when setting the 14207c478bd9Sstevel@tonic-gate * time other than the current (ATTR_UTIME flag set). 14217c478bd9Sstevel@tonic-gate * If setting the current time (ATTR_UTIME not set) then 14227c478bd9Sstevel@tonic-gate * unlocked_access will check permissions according to policy. 14237c478bd9Sstevel@tonic-gate */ 14247c478bd9Sstevel@tonic-gate if (cr->cr_uid != ovap->va_uid) { 14257c478bd9Sstevel@tonic-gate if (flags & ATTR_UTIME) 14267c478bd9Sstevel@tonic-gate error = secpolicy_vnode_utime_modify(cr); 1427da6c28aaSamw else if (skipaclchk == B_FALSE) { 14287c478bd9Sstevel@tonic-gate error = unlocked_access(node, VWRITE, cr); 14297c478bd9Sstevel@tonic-gate if (error == EACCES && 14307c478bd9Sstevel@tonic-gate secpolicy_vnode_utime_modify(cr) == 0) 14317c478bd9Sstevel@tonic-gate error = 0; 14327c478bd9Sstevel@tonic-gate } 14337c478bd9Sstevel@tonic-gate if (error) 14347c478bd9Sstevel@tonic-gate goto out; 14357c478bd9Sstevel@tonic-gate } 14367c478bd9Sstevel@tonic-gate } 1437da6c28aaSamw 1438da6c28aaSamw /* 1439da6c28aaSamw * Check for optional attributes here by checking the following: 1440da6c28aaSamw */ 1441da6c28aaSamw if (mask & AT_XVATTR) 1442da6c28aaSamw error = secpolicy_xvattr((xvattr_t *)vap, ovap->va_uid, cr, 1443da6c28aaSamw vp->v_type); 14447c478bd9Sstevel@tonic-gate out: 14457c478bd9Sstevel@tonic-gate return (error); 14467c478bd9Sstevel@tonic-gate } 14477c478bd9Sstevel@tonic-gate 14487c478bd9Sstevel@tonic-gate /* 14497c478bd9Sstevel@tonic-gate * Name: secpolicy_pcfs_modify_bootpartition() 14507c478bd9Sstevel@tonic-gate * 14517c478bd9Sstevel@tonic-gate * Normal: verify that subject can modify a pcfs boot partition. 14527c478bd9Sstevel@tonic-gate * 14537c478bd9Sstevel@tonic-gate * Output: EACCES - if privilege check failed. 14547c478bd9Sstevel@tonic-gate */ 14557c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 14567c478bd9Sstevel@tonic-gate int 14577c478bd9Sstevel@tonic-gate secpolicy_pcfs_modify_bootpartition(const cred_t *cred) 14587c478bd9Sstevel@tonic-gate { 14597c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cred, PRIV_ALL, B_FALSE, EACCES, 14607c478bd9Sstevel@tonic-gate "modify pcfs boot partition")); 14617c478bd9Sstevel@tonic-gate } 14627c478bd9Sstevel@tonic-gate 14637c478bd9Sstevel@tonic-gate /* 14647c478bd9Sstevel@tonic-gate * System V IPC routines 14657c478bd9Sstevel@tonic-gate */ 14667c478bd9Sstevel@tonic-gate int 14677c478bd9Sstevel@tonic-gate secpolicy_ipc_owner(const cred_t *cr, const struct kipc_perm *ip) 14687c478bd9Sstevel@tonic-gate { 14697c478bd9Sstevel@tonic-gate if (crgetzoneid(cr) != ip->ipc_zoneid || 14707c478bd9Sstevel@tonic-gate (cr->cr_uid != ip->ipc_uid && cr->cr_uid != ip->ipc_cuid)) { 14717c478bd9Sstevel@tonic-gate boolean_t allzone = B_FALSE; 14727c478bd9Sstevel@tonic-gate if (ip->ipc_uid == 0 || ip->ipc_cuid == 0) 14737c478bd9Sstevel@tonic-gate allzone = B_TRUE; 14747c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_OWNER, allzone, EPERM, NULL)); 14757c478bd9Sstevel@tonic-gate } 14767c478bd9Sstevel@tonic-gate return (0); 14777c478bd9Sstevel@tonic-gate } 14787c478bd9Sstevel@tonic-gate 14797c478bd9Sstevel@tonic-gate int 14807c478bd9Sstevel@tonic-gate secpolicy_ipc_config(const cred_t *cr) 14817c478bd9Sstevel@tonic-gate { 14827c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_IPC_CONFIG, B_FALSE, EPERM, NULL)); 14837c478bd9Sstevel@tonic-gate } 14847c478bd9Sstevel@tonic-gate 14857c478bd9Sstevel@tonic-gate int 14867c478bd9Sstevel@tonic-gate secpolicy_ipc_access(const cred_t *cr, const struct kipc_perm *ip, mode_t mode) 14877c478bd9Sstevel@tonic-gate { 14887c478bd9Sstevel@tonic-gate 14897c478bd9Sstevel@tonic-gate boolean_t allzone = B_FALSE; 14907c478bd9Sstevel@tonic-gate 14917c478bd9Sstevel@tonic-gate ASSERT((mode & (MSG_R|MSG_W)) != 0); 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate if ((mode & MSG_R) && 14947c478bd9Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0) 14957c478bd9Sstevel@tonic-gate return (EACCES); 14967c478bd9Sstevel@tonic-gate 14977c478bd9Sstevel@tonic-gate if (mode & MSG_W) { 14987c478bd9Sstevel@tonic-gate if (cr->cr_uid != 0 && (ip->ipc_uid == 0 || ip->ipc_cuid == 0)) 14997c478bd9Sstevel@tonic-gate allzone = B_TRUE; 15007c478bd9Sstevel@tonic-gate 15017c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES, 15027c478bd9Sstevel@tonic-gate NULL)); 15037c478bd9Sstevel@tonic-gate } 15047c478bd9Sstevel@tonic-gate return (0); 15057c478bd9Sstevel@tonic-gate } 15067c478bd9Sstevel@tonic-gate 15077c478bd9Sstevel@tonic-gate int 15087c478bd9Sstevel@tonic-gate secpolicy_rsm_access(const cred_t *cr, uid_t owner, mode_t mode) 15097c478bd9Sstevel@tonic-gate { 15107c478bd9Sstevel@tonic-gate boolean_t allzone = B_FALSE; 15117c478bd9Sstevel@tonic-gate 15127c478bd9Sstevel@tonic-gate ASSERT((mode & (MSG_R|MSG_W)) != 0); 15137c478bd9Sstevel@tonic-gate 15147c478bd9Sstevel@tonic-gate if ((mode & MSG_R) && 15157c478bd9Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_IPC_DAC_READ, allzone, EACCES, NULL) != 0) 15167c478bd9Sstevel@tonic-gate return (EACCES); 15177c478bd9Sstevel@tonic-gate 15187c478bd9Sstevel@tonic-gate if (mode & MSG_W) { 15197c478bd9Sstevel@tonic-gate if (cr->cr_uid != 0 && owner == 0) 15207c478bd9Sstevel@tonic-gate allzone = B_TRUE; 15217c478bd9Sstevel@tonic-gate 15227c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_IPC_DAC_WRITE, allzone, EACCES, 15237c478bd9Sstevel@tonic-gate NULL)); 15247c478bd9Sstevel@tonic-gate } 15257c478bd9Sstevel@tonic-gate return (0); 15267c478bd9Sstevel@tonic-gate } 15277c478bd9Sstevel@tonic-gate 15287c478bd9Sstevel@tonic-gate /* 15297c478bd9Sstevel@tonic-gate * Audit configuration. 15307c478bd9Sstevel@tonic-gate */ 15317c478bd9Sstevel@tonic-gate int 15327c478bd9Sstevel@tonic-gate secpolicy_audit_config(const cred_t *cr) 15337c478bd9Sstevel@tonic-gate { 15347c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_AUDIT, B_FALSE, EPERM, NULL)); 15357c478bd9Sstevel@tonic-gate } 15367c478bd9Sstevel@tonic-gate 15377c478bd9Sstevel@tonic-gate /* 15387c478bd9Sstevel@tonic-gate * Audit record generation. 15397c478bd9Sstevel@tonic-gate */ 15407c478bd9Sstevel@tonic-gate int 15417c478bd9Sstevel@tonic-gate secpolicy_audit_modify(const cred_t *cr) 15427c478bd9Sstevel@tonic-gate { 15437c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_AUDIT, B_FALSE, EPERM, NULL)); 15447c478bd9Sstevel@tonic-gate } 15457c478bd9Sstevel@tonic-gate 15467c478bd9Sstevel@tonic-gate /* 15477c478bd9Sstevel@tonic-gate * Get audit attributes. 15487c478bd9Sstevel@tonic-gate * Either PRIV_SYS_AUDIT or PRIV_PROC_AUDIT required; report the 15497c478bd9Sstevel@tonic-gate * "Least" of the two privileges on error. 15507c478bd9Sstevel@tonic-gate */ 15517c478bd9Sstevel@tonic-gate int 1552134a1f4eSCasper H.S. Dik secpolicy_audit_getattr(const cred_t *cr, boolean_t checkonly) 15537c478bd9Sstevel@tonic-gate { 1554134a1f4eSCasper H.S. Dik int priv; 1555134a1f4eSCasper H.S. Dik 1556134a1f4eSCasper H.S. Dik if (PRIV_POLICY_ONLY(cr, PRIV_SYS_AUDIT, B_FALSE)) 1557134a1f4eSCasper H.S. Dik priv = PRIV_SYS_AUDIT; 1558134a1f4eSCasper H.S. Dik else 1559134a1f4eSCasper H.S. Dik priv = PRIV_PROC_AUDIT; 1560134a1f4eSCasper H.S. Dik 1561134a1f4eSCasper H.S. Dik if (checkonly) 1562134a1f4eSCasper H.S. Dik return (!PRIV_POLICY_ONLY(cr, priv, B_FALSE)); 1563134a1f4eSCasper H.S. Dik else 1564134a1f4eSCasper H.S. Dik return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL)); 15657c478bd9Sstevel@tonic-gate } 15667c478bd9Sstevel@tonic-gate 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate /* 15697c478bd9Sstevel@tonic-gate * Locking physical memory 15707c478bd9Sstevel@tonic-gate */ 15717c478bd9Sstevel@tonic-gate int 15727c478bd9Sstevel@tonic-gate secpolicy_lock_memory(const cred_t *cr) 15737c478bd9Sstevel@tonic-gate { 15747c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_LOCK_MEMORY, B_FALSE, EPERM, NULL)); 15757c478bd9Sstevel@tonic-gate } 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate /* 15787c478bd9Sstevel@tonic-gate * Accounting (both acct(2) and exacct). 15797c478bd9Sstevel@tonic-gate */ 15807c478bd9Sstevel@tonic-gate int 15817c478bd9Sstevel@tonic-gate secpolicy_acct(const cred_t *cr) 15827c478bd9Sstevel@tonic-gate { 15837c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ACCT, B_FALSE, EPERM, NULL)); 15847c478bd9Sstevel@tonic-gate } 15857c478bd9Sstevel@tonic-gate 15867c478bd9Sstevel@tonic-gate /* 15877c478bd9Sstevel@tonic-gate * Is this process privileged to change its uids at will? 15887c478bd9Sstevel@tonic-gate * Uid 0 is still considered "special" and having the SETID 15897c478bd9Sstevel@tonic-gate * privilege is not sufficient to get uid 0. 15907c478bd9Sstevel@tonic-gate * Files are owned by root, so the privilege would give 15917c478bd9Sstevel@tonic-gate * full access and euid 0 is still effective. 15927c478bd9Sstevel@tonic-gate * 15937c478bd9Sstevel@tonic-gate * If you have the privilege and euid 0 only then do you 15947c478bd9Sstevel@tonic-gate * get the powers of root wrt uid 0. 15957c478bd9Sstevel@tonic-gate * 15967c478bd9Sstevel@tonic-gate * For gid manipulations, this is should be called with an 15977c478bd9Sstevel@tonic-gate * uid of -1. 15987c478bd9Sstevel@tonic-gate * 15997c478bd9Sstevel@tonic-gate */ 16007c478bd9Sstevel@tonic-gate int 16017c478bd9Sstevel@tonic-gate secpolicy_allow_setid(const cred_t *cr, uid_t newuid, boolean_t checkonly) 16027c478bd9Sstevel@tonic-gate { 16037c478bd9Sstevel@tonic-gate boolean_t allzone = B_FALSE; 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate if (newuid == 0 && cr->cr_uid != 0 && cr->cr_suid != 0 && 16067c478bd9Sstevel@tonic-gate cr->cr_ruid != 0) { 16077c478bd9Sstevel@tonic-gate allzone = B_TRUE; 16087c478bd9Sstevel@tonic-gate } 16097c478bd9Sstevel@tonic-gate 16107c478bd9Sstevel@tonic-gate return (checkonly ? !PRIV_POLICY_ONLY(cr, PRIV_PROC_SETID, allzone) : 16117c478bd9Sstevel@tonic-gate PRIV_POLICY(cr, PRIV_PROC_SETID, allzone, EPERM, NULL)); 16127c478bd9Sstevel@tonic-gate } 16137c478bd9Sstevel@tonic-gate 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate /* 16167c478bd9Sstevel@tonic-gate * Acting on a different process: if the mode is for writing, 16177c478bd9Sstevel@tonic-gate * the restrictions are more severe. This is called after 16187c478bd9Sstevel@tonic-gate * we've verified that the uids do not match. 16197c478bd9Sstevel@tonic-gate */ 16207c478bd9Sstevel@tonic-gate int 16217c478bd9Sstevel@tonic-gate secpolicy_proc_owner(const cred_t *scr, const cred_t *tcr, int mode) 16227c478bd9Sstevel@tonic-gate { 16237c478bd9Sstevel@tonic-gate boolean_t allzone = B_FALSE; 16247c478bd9Sstevel@tonic-gate 16257c478bd9Sstevel@tonic-gate if ((mode & VWRITE) && scr->cr_uid != 0 && 16267c478bd9Sstevel@tonic-gate (tcr->cr_uid == 0 || tcr->cr_ruid == 0 || tcr->cr_suid == 0)) 16277c478bd9Sstevel@tonic-gate allzone = B_TRUE; 16287c478bd9Sstevel@tonic-gate 16297c478bd9Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, allzone, EPERM, NULL)); 16307c478bd9Sstevel@tonic-gate } 16317c478bd9Sstevel@tonic-gate 16327c478bd9Sstevel@tonic-gate int 16337c478bd9Sstevel@tonic-gate secpolicy_proc_access(const cred_t *scr) 16347c478bd9Sstevel@tonic-gate { 16357c478bd9Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EACCES, NULL)); 16367c478bd9Sstevel@tonic-gate } 16377c478bd9Sstevel@tonic-gate 16387c478bd9Sstevel@tonic-gate int 16397c478bd9Sstevel@tonic-gate secpolicy_proc_excl_open(const cred_t *scr) 16407c478bd9Sstevel@tonic-gate { 16417c478bd9Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_OWNER, B_FALSE, EBUSY, NULL)); 16427c478bd9Sstevel@tonic-gate } 16437c478bd9Sstevel@tonic-gate 16447c478bd9Sstevel@tonic-gate int 16457c478bd9Sstevel@tonic-gate secpolicy_proc_zone(const cred_t *scr) 16467c478bd9Sstevel@tonic-gate { 16477c478bd9Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_PROC_ZONE, B_FALSE, EPERM, NULL)); 16487c478bd9Sstevel@tonic-gate } 16497c478bd9Sstevel@tonic-gate 16507c478bd9Sstevel@tonic-gate /* 16517c478bd9Sstevel@tonic-gate * Destroying the system 16527c478bd9Sstevel@tonic-gate */ 16537c478bd9Sstevel@tonic-gate 16547c478bd9Sstevel@tonic-gate int 16557c478bd9Sstevel@tonic-gate secpolicy_kmdb(const cred_t *scr) 16567c478bd9Sstevel@tonic-gate { 16577c478bd9Sstevel@tonic-gate return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 16587c478bd9Sstevel@tonic-gate } 16597c478bd9Sstevel@tonic-gate 16607aec1d6eScindi int 16617aec1d6eScindi secpolicy_error_inject(const cred_t *scr) 16627aec1d6eScindi { 16637aec1d6eScindi return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 16647aec1d6eScindi } 16657aec1d6eScindi 16667c478bd9Sstevel@tonic-gate /* 16677c478bd9Sstevel@tonic-gate * Processor sets, cpu configuration, resource pools. 16687c478bd9Sstevel@tonic-gate */ 16697c478bd9Sstevel@tonic-gate int 16707c478bd9Sstevel@tonic-gate secpolicy_pset(const cred_t *cr) 16717c478bd9Sstevel@tonic-gate { 16727c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 16737c478bd9Sstevel@tonic-gate } 16747c478bd9Sstevel@tonic-gate 16757c478bd9Sstevel@tonic-gate int 16767c478bd9Sstevel@tonic-gate secpolicy_ponline(const cred_t *cr) 16777c478bd9Sstevel@tonic-gate { 16787c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate 16817c478bd9Sstevel@tonic-gate int 16827c478bd9Sstevel@tonic-gate secpolicy_pool(const cred_t *cr) 16837c478bd9Sstevel@tonic-gate { 16847c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 16857c478bd9Sstevel@tonic-gate } 16867c478bd9Sstevel@tonic-gate 16877c478bd9Sstevel@tonic-gate int 16887c478bd9Sstevel@tonic-gate secpolicy_blacklist(const cred_t *cr) 16897c478bd9Sstevel@tonic-gate { 16907c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RES_CONFIG, B_FALSE, EPERM, NULL)); 16917c478bd9Sstevel@tonic-gate } 16927c478bd9Sstevel@tonic-gate 16937c478bd9Sstevel@tonic-gate /* 16947c478bd9Sstevel@tonic-gate * Catch all system configuration. 16957c478bd9Sstevel@tonic-gate */ 16967c478bd9Sstevel@tonic-gate int 16977c478bd9Sstevel@tonic-gate secpolicy_sys_config(const cred_t *cr, boolean_t checkonly) 16987c478bd9Sstevel@tonic-gate { 16997c478bd9Sstevel@tonic-gate if (checkonly) { 17007c478bd9Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_CONFIG, B_FALSE) ? 0 : 17017c478bd9Sstevel@tonic-gate EPERM); 17027c478bd9Sstevel@tonic-gate } else { 17037c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 17047c478bd9Sstevel@tonic-gate } 17057c478bd9Sstevel@tonic-gate } 17067c478bd9Sstevel@tonic-gate 17077c478bd9Sstevel@tonic-gate /* 17087c478bd9Sstevel@tonic-gate * Zone administration (halt, reboot, etc.) from within zone. 17097c478bd9Sstevel@tonic-gate */ 17107c478bd9Sstevel@tonic-gate int 17117c478bd9Sstevel@tonic-gate secpolicy_zone_admin(const cred_t *cr, boolean_t checkonly) 17127c478bd9Sstevel@tonic-gate { 17137c478bd9Sstevel@tonic-gate if (checkonly) { 17147c478bd9Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_ADMIN, B_FALSE) ? 0 : 17157c478bd9Sstevel@tonic-gate EPERM); 17167c478bd9Sstevel@tonic-gate } else { 17177c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, 17187c478bd9Sstevel@tonic-gate NULL)); 17197c478bd9Sstevel@tonic-gate } 17207c478bd9Sstevel@tonic-gate } 17217c478bd9Sstevel@tonic-gate 17227c478bd9Sstevel@tonic-gate /* 17237c478bd9Sstevel@tonic-gate * Zone configuration (create, halt, enter). 17247c478bd9Sstevel@tonic-gate */ 17257c478bd9Sstevel@tonic-gate int 17267c478bd9Sstevel@tonic-gate secpolicy_zone_config(const cred_t *cr) 17277c478bd9Sstevel@tonic-gate { 17287c478bd9Sstevel@tonic-gate /* 17297c478bd9Sstevel@tonic-gate * Require all privileges to avoid possibility of privilege 17307c478bd9Sstevel@tonic-gate * escalation. 17317c478bd9Sstevel@tonic-gate */ 1732134a1f4eSCasper H.S. Dik return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE)); 17337c478bd9Sstevel@tonic-gate } 17347c478bd9Sstevel@tonic-gate 17357c478bd9Sstevel@tonic-gate /* 17367c478bd9Sstevel@tonic-gate * Various other system configuration calls 17377c478bd9Sstevel@tonic-gate */ 17387c478bd9Sstevel@tonic-gate int 17397c478bd9Sstevel@tonic-gate secpolicy_coreadm(const cred_t *cr) 17407c478bd9Sstevel@tonic-gate { 17417c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL)); 17427c478bd9Sstevel@tonic-gate } 17437c478bd9Sstevel@tonic-gate 17447c478bd9Sstevel@tonic-gate int 17457c478bd9Sstevel@tonic-gate secpolicy_systeminfo(const cred_t *cr) 17467c478bd9Sstevel@tonic-gate { 17477c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_FALSE, EPERM, NULL)); 17487c478bd9Sstevel@tonic-gate } 17497c478bd9Sstevel@tonic-gate 17507c478bd9Sstevel@tonic-gate int 17517c478bd9Sstevel@tonic-gate secpolicy_dispadm(const cred_t *cr) 17527c478bd9Sstevel@tonic-gate { 17537c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 17547c478bd9Sstevel@tonic-gate } 17557c478bd9Sstevel@tonic-gate 17567c478bd9Sstevel@tonic-gate int 17577c478bd9Sstevel@tonic-gate secpolicy_settime(const cred_t *cr) 17587c478bd9Sstevel@tonic-gate { 17597c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_TIME, B_FALSE, EPERM, NULL)); 17607c478bd9Sstevel@tonic-gate } 17617c478bd9Sstevel@tonic-gate 17627c478bd9Sstevel@tonic-gate /* 17637c478bd9Sstevel@tonic-gate * For realtime users: high resolution clock. 17647c478bd9Sstevel@tonic-gate */ 17657c478bd9Sstevel@tonic-gate int 17667c478bd9Sstevel@tonic-gate secpolicy_clock_highres(const cred_t *cr) 17677c478bd9Sstevel@tonic-gate { 17687c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_CLOCK_HIGHRES, B_FALSE, EPERM, 17697c478bd9Sstevel@tonic-gate NULL)); 17707c478bd9Sstevel@tonic-gate } 17717c478bd9Sstevel@tonic-gate 17727c478bd9Sstevel@tonic-gate /* 17737c478bd9Sstevel@tonic-gate * drv_priv() is documented as callable from interrupt context, not that 17747c478bd9Sstevel@tonic-gate * anyone ever does, but still. No debugging or auditing can be done when 17757c478bd9Sstevel@tonic-gate * it is called from interrupt context. 17767c478bd9Sstevel@tonic-gate * returns 0 on succes, EPERM on failure. 17777c478bd9Sstevel@tonic-gate */ 17787c478bd9Sstevel@tonic-gate int 17797c478bd9Sstevel@tonic-gate drv_priv(cred_t *cr) 17807c478bd9Sstevel@tonic-gate { 17817c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 17827c478bd9Sstevel@tonic-gate } 17837c478bd9Sstevel@tonic-gate 17847c478bd9Sstevel@tonic-gate int 17857c478bd9Sstevel@tonic-gate secpolicy_sys_devices(const cred_t *cr) 17867c478bd9Sstevel@tonic-gate { 17877c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 17887c478bd9Sstevel@tonic-gate } 17897c478bd9Sstevel@tonic-gate 17907c478bd9Sstevel@tonic-gate int 17917c478bd9Sstevel@tonic-gate secpolicy_excl_open(const cred_t *cr) 17927c478bd9Sstevel@tonic-gate { 17937c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EBUSY, NULL)); 17947c478bd9Sstevel@tonic-gate } 17957c478bd9Sstevel@tonic-gate 17967c478bd9Sstevel@tonic-gate int 17977c478bd9Sstevel@tonic-gate secpolicy_rctlsys(const cred_t *cr, boolean_t is_zone_rctl) 17987c478bd9Sstevel@tonic-gate { 17997c478bd9Sstevel@tonic-gate /* zone.* rctls can only be set from the global zone */ 18007c478bd9Sstevel@tonic-gate if (is_zone_rctl && priv_policy_global(cr) != 0) 18017c478bd9Sstevel@tonic-gate return (EPERM); 18027c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 18037c478bd9Sstevel@tonic-gate } 18047c478bd9Sstevel@tonic-gate 18057c478bd9Sstevel@tonic-gate int 18067c478bd9Sstevel@tonic-gate secpolicy_resource(const cred_t *cr) 18077c478bd9Sstevel@tonic-gate { 18087c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 18097c478bd9Sstevel@tonic-gate } 18107c478bd9Sstevel@tonic-gate 18111c7cef2bSStan Studzinski int 18121c7cef2bSStan Studzinski secpolicy_resource_anon_mem(const cred_t *cr) 18131c7cef2bSStan Studzinski { 18141c7cef2bSStan Studzinski return (PRIV_POLICY_ONLY(cr, PRIV_SYS_RESOURCE, B_FALSE)); 18151c7cef2bSStan Studzinski } 18161c7cef2bSStan Studzinski 18177c478bd9Sstevel@tonic-gate /* 18187c478bd9Sstevel@tonic-gate * Processes with a real uid of 0 escape any form of accounting, much 18197c478bd9Sstevel@tonic-gate * like before. 18207c478bd9Sstevel@tonic-gate */ 18217c478bd9Sstevel@tonic-gate int 18227c478bd9Sstevel@tonic-gate secpolicy_newproc(const cred_t *cr) 18237c478bd9Sstevel@tonic-gate { 18247c478bd9Sstevel@tonic-gate if (cr->cr_ruid == 0) 18257c478bd9Sstevel@tonic-gate return (0); 18267c478bd9Sstevel@tonic-gate 18277c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_RESOURCE, B_FALSE, EPERM, NULL)); 18287c478bd9Sstevel@tonic-gate } 18297c478bd9Sstevel@tonic-gate 18307c478bd9Sstevel@tonic-gate /* 18317c478bd9Sstevel@tonic-gate * Networking 18327c478bd9Sstevel@tonic-gate */ 18337c478bd9Sstevel@tonic-gate int 18347c478bd9Sstevel@tonic-gate secpolicy_net_rawaccess(const cred_t *cr) 18357c478bd9Sstevel@tonic-gate { 18367c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_NET_RAWACCESS, B_FALSE, EACCES, NULL)); 18377c478bd9Sstevel@tonic-gate } 18387c478bd9Sstevel@tonic-gate 18390a0e9771SDarren Reed int 18400a0e9771SDarren Reed secpolicy_net_observability(const cred_t *cr) 18410a0e9771SDarren Reed { 18420a0e9771SDarren Reed return (PRIV_POLICY(cr, PRIV_NET_OBSERVABILITY, B_FALSE, EACCES, NULL)); 18430a0e9771SDarren Reed } 18440a0e9771SDarren Reed 18457c478bd9Sstevel@tonic-gate /* 18467c478bd9Sstevel@tonic-gate * Need this privilege for accessing the ICMP device 18477c478bd9Sstevel@tonic-gate */ 18487c478bd9Sstevel@tonic-gate int 18497c478bd9Sstevel@tonic-gate secpolicy_net_icmpaccess(const cred_t *cr) 18507c478bd9Sstevel@tonic-gate { 18517c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_NET_ICMPACCESS, B_FALSE, EACCES, NULL)); 18527c478bd9Sstevel@tonic-gate } 18537c478bd9Sstevel@tonic-gate 18547c478bd9Sstevel@tonic-gate /* 18557c478bd9Sstevel@tonic-gate * There are a few rare cases where the kernel generates ioctls() from 18567c478bd9Sstevel@tonic-gate * interrupt context with a credential of kcred rather than NULL. 18577c478bd9Sstevel@tonic-gate * In those cases, we take the safe and cheap test. 18587c478bd9Sstevel@tonic-gate */ 18597c478bd9Sstevel@tonic-gate int 18607c478bd9Sstevel@tonic-gate secpolicy_net_config(const cred_t *cr, boolean_t checkonly) 18617c478bd9Sstevel@tonic-gate { 18627c478bd9Sstevel@tonic-gate if (checkonly) { 18637c478bd9Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE) ? 18647c478bd9Sstevel@tonic-gate 0 : EPERM); 18657c478bd9Sstevel@tonic-gate } else { 18667c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_NET_CONFIG, B_FALSE, EPERM, 18677c478bd9Sstevel@tonic-gate NULL)); 18687c478bd9Sstevel@tonic-gate } 18697c478bd9Sstevel@tonic-gate } 18707c478bd9Sstevel@tonic-gate 18717c478bd9Sstevel@tonic-gate 18727c478bd9Sstevel@tonic-gate /* 1873e6bdcbd5Sdh155122 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG. 1874f4b3ec61Sdh155122 * 1875f4b3ec61Sdh155122 * There are a few rare cases where the kernel generates ioctls() from 1876f4b3ec61Sdh155122 * interrupt context with a credential of kcred rather than NULL. 1877f4b3ec61Sdh155122 * In those cases, we take the safe and cheap test. 1878f4b3ec61Sdh155122 */ 1879f4b3ec61Sdh155122 int 1880f4b3ec61Sdh155122 secpolicy_ip_config(const cred_t *cr, boolean_t checkonly) 1881f4b3ec61Sdh155122 { 1882f4b3ec61Sdh155122 if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 1883f4b3ec61Sdh155122 return (secpolicy_net_config(cr, checkonly)); 1884f4b3ec61Sdh155122 1885f4b3ec61Sdh155122 if (checkonly) { 1886f4b3ec61Sdh155122 return (PRIV_POLICY_ONLY(cr, PRIV_SYS_IP_CONFIG, B_FALSE) ? 1887f4b3ec61Sdh155122 0 : EPERM); 1888f4b3ec61Sdh155122 } else { 1889f4b3ec61Sdh155122 return (PRIV_POLICY(cr, PRIV_SYS_IP_CONFIG, B_FALSE, EPERM, 1890f4b3ec61Sdh155122 NULL)); 1891f4b3ec61Sdh155122 } 1892f4b3ec61Sdh155122 } 1893f4b3ec61Sdh155122 1894eae72b5bSSebastien Roy /* 1895eae72b5bSSebastien Roy * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_DL_CONFIG. 1896eae72b5bSSebastien Roy */ 1897eae72b5bSSebastien Roy int 1898eae72b5bSSebastien Roy secpolicy_dl_config(const cred_t *cr) 1899eae72b5bSSebastien Roy { 1900eae72b5bSSebastien Roy if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 1901eae72b5bSSebastien Roy return (secpolicy_net_config(cr, B_FALSE)); 19022b24ab6bSSebastien Roy return (PRIV_POLICY(cr, PRIV_SYS_DL_CONFIG, B_FALSE, EPERM, NULL)); 1903eae72b5bSSebastien Roy } 1904eae72b5bSSebastien Roy 19052b24ab6bSSebastien Roy /* 19062b24ab6bSSebastien Roy * PRIV_SYS_DL_CONFIG is a superset of PRIV_SYS_IPTUN_CONFIG. 19072b24ab6bSSebastien Roy */ 19082b24ab6bSSebastien Roy int 19092b24ab6bSSebastien Roy secpolicy_iptun_config(const cred_t *cr) 19102b24ab6bSSebastien Roy { 19112b24ab6bSSebastien Roy if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 19122b24ab6bSSebastien Roy return (secpolicy_net_config(cr, B_FALSE)); 19132b24ab6bSSebastien Roy if (PRIV_POLICY_ONLY(cr, PRIV_SYS_DL_CONFIG, B_FALSE)) 19142b24ab6bSSebastien Roy return (secpolicy_dl_config(cr)); 19152b24ab6bSSebastien Roy return (PRIV_POLICY(cr, PRIV_SYS_IPTUN_CONFIG, B_FALSE, EPERM, NULL)); 19162b24ab6bSSebastien Roy } 1917f4b3ec61Sdh155122 1918f4b3ec61Sdh155122 /* 1919f4b3ec61Sdh155122 * Map IP pseudo privileges to actual privileges. 1920f4b3ec61Sdh155122 * So we don't need to recompile IP when we change the privileges. 1921f4b3ec61Sdh155122 */ 1922f4b3ec61Sdh155122 int 1923f4b3ec61Sdh155122 secpolicy_ip(const cred_t *cr, int netpriv, boolean_t checkonly) 1924f4b3ec61Sdh155122 { 1925f4b3ec61Sdh155122 int priv = PRIV_ALL; 1926f4b3ec61Sdh155122 1927f4b3ec61Sdh155122 switch (netpriv) { 1928f4b3ec61Sdh155122 case OP_CONFIG: 1929f4b3ec61Sdh155122 priv = PRIV_SYS_IP_CONFIG; 1930f4b3ec61Sdh155122 break; 1931f4b3ec61Sdh155122 case OP_RAW: 1932f4b3ec61Sdh155122 priv = PRIV_NET_RAWACCESS; 1933f4b3ec61Sdh155122 break; 1934f4b3ec61Sdh155122 case OP_PRIVPORT: 1935f4b3ec61Sdh155122 priv = PRIV_NET_PRIVADDR; 1936f4b3ec61Sdh155122 break; 1937f4b3ec61Sdh155122 } 1938f4b3ec61Sdh155122 ASSERT(priv != PRIV_ALL); 1939f4b3ec61Sdh155122 if (checkonly) 1940f4b3ec61Sdh155122 return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM); 1941f4b3ec61Sdh155122 else 1942f4b3ec61Sdh155122 return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL)); 1943f4b3ec61Sdh155122 } 1944f4b3ec61Sdh155122 1945f4b3ec61Sdh155122 /* 19467c478bd9Sstevel@tonic-gate * Map network pseudo privileges to actual privileges. 19477c478bd9Sstevel@tonic-gate * So we don't need to recompile IP when we change the privileges. 19487c478bd9Sstevel@tonic-gate */ 19497c478bd9Sstevel@tonic-gate int 19507c478bd9Sstevel@tonic-gate secpolicy_net(const cred_t *cr, int netpriv, boolean_t checkonly) 19517c478bd9Sstevel@tonic-gate { 19527c478bd9Sstevel@tonic-gate int priv = PRIV_ALL; 19537c478bd9Sstevel@tonic-gate 19547c478bd9Sstevel@tonic-gate switch (netpriv) { 19557c478bd9Sstevel@tonic-gate case OP_CONFIG: 19567c478bd9Sstevel@tonic-gate priv = PRIV_SYS_NET_CONFIG; 19577c478bd9Sstevel@tonic-gate break; 19587c478bd9Sstevel@tonic-gate case OP_RAW: 19597c478bd9Sstevel@tonic-gate priv = PRIV_NET_RAWACCESS; 19607c478bd9Sstevel@tonic-gate break; 19617c478bd9Sstevel@tonic-gate case OP_PRIVPORT: 19627c478bd9Sstevel@tonic-gate priv = PRIV_NET_PRIVADDR; 19637c478bd9Sstevel@tonic-gate break; 19647c478bd9Sstevel@tonic-gate } 19657c478bd9Sstevel@tonic-gate ASSERT(priv != PRIV_ALL); 19667c478bd9Sstevel@tonic-gate if (checkonly) 19677c478bd9Sstevel@tonic-gate return (PRIV_POLICY_ONLY(cr, priv, B_FALSE) ? 0 : EPERM); 19687c478bd9Sstevel@tonic-gate else 19697c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, priv, B_FALSE, EPERM, NULL)); 19707c478bd9Sstevel@tonic-gate } 19717c478bd9Sstevel@tonic-gate 19727c478bd9Sstevel@tonic-gate /* 19737c478bd9Sstevel@tonic-gate * Checks for operations that are either client-only or are used by 19747c478bd9Sstevel@tonic-gate * both clients and servers. 19757c478bd9Sstevel@tonic-gate */ 19767c478bd9Sstevel@tonic-gate int 19777c478bd9Sstevel@tonic-gate secpolicy_nfs(const cred_t *cr) 19787c478bd9Sstevel@tonic-gate { 19797c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_NFS, B_FALSE, EPERM, NULL)); 19807c478bd9Sstevel@tonic-gate } 19817c478bd9Sstevel@tonic-gate 19827c478bd9Sstevel@tonic-gate /* 19837c478bd9Sstevel@tonic-gate * Special case for opening rpcmod: have NFS privileges or network 19847c478bd9Sstevel@tonic-gate * config privileges. 19857c478bd9Sstevel@tonic-gate */ 19867c478bd9Sstevel@tonic-gate int 19877c478bd9Sstevel@tonic-gate secpolicy_rpcmod_open(const cred_t *cr) 19887c478bd9Sstevel@tonic-gate { 19897c478bd9Sstevel@tonic-gate if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NFS, B_FALSE)) 19907c478bd9Sstevel@tonic-gate return (secpolicy_nfs(cr)); 19917c478bd9Sstevel@tonic-gate else 19927c478bd9Sstevel@tonic-gate return (secpolicy_net_config(cr, NULL)); 19937c478bd9Sstevel@tonic-gate } 19947c478bd9Sstevel@tonic-gate 19957c478bd9Sstevel@tonic-gate int 19967c478bd9Sstevel@tonic-gate secpolicy_chroot(const cred_t *cr) 19977c478bd9Sstevel@tonic-gate { 19987c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_CHROOT, B_FALSE, EPERM, NULL)); 19997c478bd9Sstevel@tonic-gate } 20007c478bd9Sstevel@tonic-gate 20017c478bd9Sstevel@tonic-gate int 20027c478bd9Sstevel@tonic-gate secpolicy_tasksys(const cred_t *cr) 20037c478bd9Sstevel@tonic-gate { 20047c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_TASKID, B_FALSE, EPERM, NULL)); 20057c478bd9Sstevel@tonic-gate } 20067c478bd9Sstevel@tonic-gate 2007134a1f4eSCasper H.S. Dik int 2008134a1f4eSCasper H.S. Dik secpolicy_pfexec_register(const cred_t *cr) 2009134a1f4eSCasper H.S. Dik { 2010134a1f4eSCasper H.S. Dik return (PRIV_POLICY(cr, PRIV_SYS_ADMIN, B_TRUE, EPERM, NULL)); 2011134a1f4eSCasper H.S. Dik } 2012134a1f4eSCasper H.S. Dik 20137c478bd9Sstevel@tonic-gate /* 20147c478bd9Sstevel@tonic-gate * Basic privilege checks. 20157c478bd9Sstevel@tonic-gate */ 20167c478bd9Sstevel@tonic-gate int 2017ddf7fe95Scasper secpolicy_basic_exec(const cred_t *cr, vnode_t *vp) 20187c478bd9Sstevel@tonic-gate { 2019134a1f4eSCasper H.S. Dik FAST_BASIC_CHECK(cr, PRIV_PROC_EXEC); 2020134a1f4eSCasper H.S. Dik 2021ddf7fe95Scasper return (priv_policy_va(cr, PRIV_PROC_EXEC, B_FALSE, EPERM, NULL, 2022ddf7fe95Scasper KLPDARG_VNODE, vp, (char *)NULL, KLPDARG_NOMORE)); 20237c478bd9Sstevel@tonic-gate } 20247c478bd9Sstevel@tonic-gate 20257c478bd9Sstevel@tonic-gate int 20267c478bd9Sstevel@tonic-gate secpolicy_basic_fork(const cred_t *cr) 20277c478bd9Sstevel@tonic-gate { 2028134a1f4eSCasper H.S. Dik FAST_BASIC_CHECK(cr, PRIV_PROC_FORK); 2029134a1f4eSCasper H.S. Dik 20307c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_FORK, B_FALSE, EPERM, NULL)); 20317c478bd9Sstevel@tonic-gate } 20327c478bd9Sstevel@tonic-gate 20337c478bd9Sstevel@tonic-gate int 20347c478bd9Sstevel@tonic-gate secpolicy_basic_proc(const cred_t *cr) 20357c478bd9Sstevel@tonic-gate { 2036134a1f4eSCasper H.S. Dik FAST_BASIC_CHECK(cr, PRIV_PROC_SESSION); 2037134a1f4eSCasper H.S. Dik 20387c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_SESSION, B_FALSE, EPERM, NULL)); 20397c478bd9Sstevel@tonic-gate } 20407c478bd9Sstevel@tonic-gate 20417c478bd9Sstevel@tonic-gate /* 20427c478bd9Sstevel@tonic-gate * Slightly complicated because we don't want to trigger the policy too 20437c478bd9Sstevel@tonic-gate * often. First we shortcircuit access to "self" (tp == sp) or if 20447c478bd9Sstevel@tonic-gate * we don't have the privilege but if we have permission 20457c478bd9Sstevel@tonic-gate * just return (0) and we don't flag the privilege as needed. 20467c478bd9Sstevel@tonic-gate * Else, we test for the privilege because we either have it or need it. 20477c478bd9Sstevel@tonic-gate */ 20487c478bd9Sstevel@tonic-gate int 20497c478bd9Sstevel@tonic-gate secpolicy_basic_procinfo(const cred_t *cr, proc_t *tp, proc_t *sp) 20507c478bd9Sstevel@tonic-gate { 20517c478bd9Sstevel@tonic-gate if (tp == sp || 20527c478bd9Sstevel@tonic-gate !HAS_PRIVILEGE(cr, PRIV_PROC_INFO) && prochasprocperm(tp, sp, cr)) { 20537c478bd9Sstevel@tonic-gate return (0); 20547c478bd9Sstevel@tonic-gate } else { 20557c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_PROC_INFO, B_FALSE, EPERM, NULL)); 20567c478bd9Sstevel@tonic-gate } 20577c478bd9Sstevel@tonic-gate } 20587c478bd9Sstevel@tonic-gate 20597c478bd9Sstevel@tonic-gate int 20607c478bd9Sstevel@tonic-gate secpolicy_basic_link(const cred_t *cr) 20617c478bd9Sstevel@tonic-gate { 2062134a1f4eSCasper H.S. Dik FAST_BASIC_CHECK(cr, PRIV_FILE_LINK_ANY); 2063134a1f4eSCasper H.S. Dik 20647c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_FILE_LINK_ANY, B_FALSE, EPERM, NULL)); 20657c478bd9Sstevel@tonic-gate } 20667c478bd9Sstevel@tonic-gate 2067634e26ecSCasper H.S. Dik int 2068634e26ecSCasper H.S. Dik secpolicy_basic_net_access(const cred_t *cr) 2069634e26ecSCasper H.S. Dik { 2070134a1f4eSCasper H.S. Dik FAST_BASIC_CHECK(cr, PRIV_NET_ACCESS); 2071134a1f4eSCasper H.S. Dik 2072634e26ecSCasper H.S. Dik return (PRIV_POLICY(cr, PRIV_NET_ACCESS, B_FALSE, EACCES, NULL)); 2073634e26ecSCasper H.S. Dik } 2074634e26ecSCasper H.S. Dik 2075134a1f4eSCasper H.S. Dik /* ARGSUSED */ 2076134a1f4eSCasper H.S. Dik int 2077134a1f4eSCasper H.S. Dik secpolicy_basic_file_read(const cred_t *cr, vnode_t *vp, const char *pn) 2078134a1f4eSCasper H.S. Dik { 2079134a1f4eSCasper H.S. Dik FAST_BASIC_CHECK(cr, PRIV_FILE_READ); 2080134a1f4eSCasper H.S. Dik 2081134a1f4eSCasper H.S. Dik return (priv_policy_va(cr, PRIV_FILE_READ, B_FALSE, EACCES, NULL, 2082134a1f4eSCasper H.S. Dik KLPDARG_VNODE, vp, (char *)pn, KLPDARG_NOMORE)); 2083134a1f4eSCasper H.S. Dik } 2084134a1f4eSCasper H.S. Dik 2085134a1f4eSCasper H.S. Dik /* ARGSUSED */ 2086134a1f4eSCasper H.S. Dik int 2087134a1f4eSCasper H.S. Dik secpolicy_basic_file_write(const cred_t *cr, vnode_t *vp, const char *pn) 2088134a1f4eSCasper H.S. Dik { 2089134a1f4eSCasper H.S. Dik FAST_BASIC_CHECK(cr, PRIV_FILE_WRITE); 2090134a1f4eSCasper H.S. Dik 2091134a1f4eSCasper H.S. Dik return (priv_policy_va(cr, PRIV_FILE_WRITE, B_FALSE, EACCES, NULL, 2092134a1f4eSCasper H.S. Dik KLPDARG_VNODE, vp, (char *)pn, KLPDARG_NOMORE)); 2093134a1f4eSCasper H.S. Dik } 2094134a1f4eSCasper H.S. Dik 20957c478bd9Sstevel@tonic-gate /* 20967c478bd9Sstevel@tonic-gate * Additional device protection. 20977c478bd9Sstevel@tonic-gate * 20987c478bd9Sstevel@tonic-gate * Traditionally, a device has specific permissions on the node in 20997c478bd9Sstevel@tonic-gate * the filesystem which govern which devices can be opened by what 21007c478bd9Sstevel@tonic-gate * processes. In certain cases, it is desirable to add extra 21017c478bd9Sstevel@tonic-gate * restrictions, as writing to certain devices is identical to 21027c478bd9Sstevel@tonic-gate * having a complete run of the system. 21037c478bd9Sstevel@tonic-gate * 21047c478bd9Sstevel@tonic-gate * This mechanism is called the device policy. 21057c478bd9Sstevel@tonic-gate * 21067c478bd9Sstevel@tonic-gate * When a device is opened, its policy entry is looked up in the 21077c478bd9Sstevel@tonic-gate * policy cache and checked. 21087c478bd9Sstevel@tonic-gate */ 21097c478bd9Sstevel@tonic-gate int 21107c478bd9Sstevel@tonic-gate secpolicy_spec_open(const cred_t *cr, struct vnode *vp, int oflag) 21117c478bd9Sstevel@tonic-gate { 21127c478bd9Sstevel@tonic-gate devplcy_t *plcy; 21137c478bd9Sstevel@tonic-gate int err; 21147c478bd9Sstevel@tonic-gate struct snode *csp = VTOS(common_specvp(vp)); 2115e6bdcbd5Sdh155122 priv_set_t pset; 21167c478bd9Sstevel@tonic-gate 21177c478bd9Sstevel@tonic-gate mutex_enter(&csp->s_lock); 21187c478bd9Sstevel@tonic-gate 21197c478bd9Sstevel@tonic-gate if (csp->s_plcy == NULL || csp->s_plcy->dp_gen != devplcy_gen) { 21207c478bd9Sstevel@tonic-gate plcy = devpolicy_find(vp); 21217c478bd9Sstevel@tonic-gate if (csp->s_plcy) 21227c478bd9Sstevel@tonic-gate dpfree(csp->s_plcy); 21237c478bd9Sstevel@tonic-gate csp->s_plcy = plcy; 21247c478bd9Sstevel@tonic-gate ASSERT(plcy != NULL); 21257c478bd9Sstevel@tonic-gate } else 21267c478bd9Sstevel@tonic-gate plcy = csp->s_plcy; 21277c478bd9Sstevel@tonic-gate 21287c478bd9Sstevel@tonic-gate if (plcy == nullpolicy) { 21297c478bd9Sstevel@tonic-gate mutex_exit(&csp->s_lock); 21307c478bd9Sstevel@tonic-gate return (0); 21317c478bd9Sstevel@tonic-gate } 21327c478bd9Sstevel@tonic-gate 21337c478bd9Sstevel@tonic-gate dphold(plcy); 21347c478bd9Sstevel@tonic-gate 21357c478bd9Sstevel@tonic-gate mutex_exit(&csp->s_lock); 21367c478bd9Sstevel@tonic-gate 2137e6bdcbd5Sdh155122 if (oflag & FWRITE) 2138e6bdcbd5Sdh155122 pset = plcy->dp_wrp; 2139e6bdcbd5Sdh155122 else 2140e6bdcbd5Sdh155122 pset = plcy->dp_rdp; 2141e6bdcbd5Sdh155122 /* 2142e6bdcbd5Sdh155122 * Special case: 2143e6bdcbd5Sdh155122 * PRIV_SYS_NET_CONFIG is a superset of PRIV_SYS_IP_CONFIG. 2144e6bdcbd5Sdh155122 * If PRIV_SYS_NET_CONFIG is present and PRIV_SYS_IP_CONFIG is 2145e6bdcbd5Sdh155122 * required, replace PRIV_SYS_IP_CONFIG with PRIV_SYS_NET_CONFIG 2146e6bdcbd5Sdh155122 * in the required privilege set before doing the check. 2147e6bdcbd5Sdh155122 */ 2148e6bdcbd5Sdh155122 if (priv_ismember(&pset, PRIV_SYS_IP_CONFIG) && 2149e6bdcbd5Sdh155122 priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_NET_CONFIG) && 2150e6bdcbd5Sdh155122 !priv_ismember(&CR_OEPRIV(cr), PRIV_SYS_IP_CONFIG)) { 2151e6bdcbd5Sdh155122 priv_delset(&pset, PRIV_SYS_IP_CONFIG); 2152e6bdcbd5Sdh155122 priv_addset(&pset, PRIV_SYS_NET_CONFIG); 2153e6bdcbd5Sdh155122 } 2154e6bdcbd5Sdh155122 2155134a1f4eSCasper H.S. Dik err = secpolicy_require_set(cr, &pset, "devpolicy", KLPDARG_NONE); 21567c478bd9Sstevel@tonic-gate dpfree(plcy); 21577c478bd9Sstevel@tonic-gate 21587c478bd9Sstevel@tonic-gate return (err); 21597c478bd9Sstevel@tonic-gate } 21607c478bd9Sstevel@tonic-gate 21617c478bd9Sstevel@tonic-gate int 21627c478bd9Sstevel@tonic-gate secpolicy_modctl(const cred_t *cr, int cmd) 21637c478bd9Sstevel@tonic-gate { 21647c478bd9Sstevel@tonic-gate switch (cmd) { 21657c478bd9Sstevel@tonic-gate case MODINFO: 2166a08731ecScth case MODGETMAJBIND: 21677c478bd9Sstevel@tonic-gate case MODGETPATH: 21687c478bd9Sstevel@tonic-gate case MODGETPATHLEN: 21697c478bd9Sstevel@tonic-gate case MODGETNAME: 2170a08731ecScth case MODGETFBNAME: 21717c478bd9Sstevel@tonic-gate case MODGETDEVPOLICY: 21727c478bd9Sstevel@tonic-gate case MODGETDEVPOLICYBYNAME: 2173a08731ecScth case MODDEVT2INSTANCE: 2174a08731ecScth case MODSIZEOF_DEVID: 2175a08731ecScth case MODGETDEVID: 2176a08731ecScth case MODSIZEOF_MINORNAME: 2177a08731ecScth case MODGETMINORNAME: 2178a08731ecScth case MODGETDEVFSPATH_LEN: 2179a08731ecScth case MODGETDEVFSPATH: 2180a08731ecScth case MODGETDEVFSPATH_MI_LEN: 2181a08731ecScth case MODGETDEVFSPATH_MI: 21827c478bd9Sstevel@tonic-gate /* Unprivileged */ 21837c478bd9Sstevel@tonic-gate return (0); 21847c478bd9Sstevel@tonic-gate case MODLOAD: 21857c478bd9Sstevel@tonic-gate case MODSETDEVPOLICY: 2186134a1f4eSCasper H.S. Dik return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, 2187134a1f4eSCasper H.S. Dik KLPDARG_NONE)); 21887c478bd9Sstevel@tonic-gate default: 21897c478bd9Sstevel@tonic-gate return (secpolicy_sys_config(cr, B_FALSE)); 21907c478bd9Sstevel@tonic-gate } 21917c478bd9Sstevel@tonic-gate } 21927c478bd9Sstevel@tonic-gate 21937c478bd9Sstevel@tonic-gate int 21947c478bd9Sstevel@tonic-gate secpolicy_console(const cred_t *cr) 21957c478bd9Sstevel@tonic-gate { 21967c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 21977c478bd9Sstevel@tonic-gate } 21987c478bd9Sstevel@tonic-gate 21997c478bd9Sstevel@tonic-gate int 22007c478bd9Sstevel@tonic-gate secpolicy_power_mgmt(const cred_t *cr) 22017c478bd9Sstevel@tonic-gate { 22027c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_DEVICES, B_FALSE, EPERM, NULL)); 22037c478bd9Sstevel@tonic-gate } 22047c478bd9Sstevel@tonic-gate 22057c478bd9Sstevel@tonic-gate /* 22067c478bd9Sstevel@tonic-gate * Simulate terminal input; another escalation of privileges avenue. 22077c478bd9Sstevel@tonic-gate */ 22087c478bd9Sstevel@tonic-gate 22097c478bd9Sstevel@tonic-gate int 22107c478bd9Sstevel@tonic-gate secpolicy_sti(const cred_t *cr) 22117c478bd9Sstevel@tonic-gate { 2212134a1f4eSCasper H.S. Dik return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE)); 22137c478bd9Sstevel@tonic-gate } 22147c478bd9Sstevel@tonic-gate 221545916cd2Sjpk boolean_t 221645916cd2Sjpk secpolicy_net_reply_equal(const cred_t *cr) 221745916cd2Sjpk { 221845916cd2Sjpk return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 221945916cd2Sjpk } 222045916cd2Sjpk 22217c478bd9Sstevel@tonic-gate int 22227c478bd9Sstevel@tonic-gate secpolicy_swapctl(const cred_t *cr) 22237c478bd9Sstevel@tonic-gate { 22247c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_SYS_CONFIG, B_FALSE, EPERM, NULL)); 22257c478bd9Sstevel@tonic-gate } 22267c478bd9Sstevel@tonic-gate 22277c478bd9Sstevel@tonic-gate int 22287c478bd9Sstevel@tonic-gate secpolicy_cpc_cpu(const cred_t *cr) 22297c478bd9Sstevel@tonic-gate { 22307c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CPC_CPU, B_FALSE, EACCES, NULL)); 22317c478bd9Sstevel@tonic-gate } 22327c478bd9Sstevel@tonic-gate 22337c478bd9Sstevel@tonic-gate /* 22347b209c2cSacruz * secpolicy_contract_identity 22357b209c2cSacruz * 22367b209c2cSacruz * Determine if the subject may set the process contract FMRI value 22377b209c2cSacruz */ 22387b209c2cSacruz int 22397b209c2cSacruz secpolicy_contract_identity(const cred_t *cr) 22407b209c2cSacruz { 22417b209c2cSacruz return (PRIV_POLICY(cr, PRIV_CONTRACT_IDENTITY, B_FALSE, EPERM, NULL)); 22427b209c2cSacruz } 22437b209c2cSacruz 22447b209c2cSacruz /* 22457c478bd9Sstevel@tonic-gate * secpolicy_contract_observer 22467c478bd9Sstevel@tonic-gate * 22477c478bd9Sstevel@tonic-gate * Determine if the subject may observe a specific contract's events. 22487c478bd9Sstevel@tonic-gate */ 22497c478bd9Sstevel@tonic-gate int 22507c478bd9Sstevel@tonic-gate secpolicy_contract_observer(const cred_t *cr, struct contract *ct) 22517c478bd9Sstevel@tonic-gate { 22527c478bd9Sstevel@tonic-gate if (contract_owned(ct, cr, B_FALSE)) 22537c478bd9Sstevel@tonic-gate return (0); 22547c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CONTRACT_OBSERVER, B_FALSE, EPERM, NULL)); 22557c478bd9Sstevel@tonic-gate } 22567c478bd9Sstevel@tonic-gate 22577c478bd9Sstevel@tonic-gate /* 22587c478bd9Sstevel@tonic-gate * secpolicy_contract_observer_choice 22597c478bd9Sstevel@tonic-gate * 22607c478bd9Sstevel@tonic-gate * Determine if the subject may observe any contract's events. Just 22617c478bd9Sstevel@tonic-gate * tests privilege and audits on success. 22627c478bd9Sstevel@tonic-gate */ 22637c478bd9Sstevel@tonic-gate boolean_t 22647c478bd9Sstevel@tonic-gate secpolicy_contract_observer_choice(const cred_t *cr) 22657c478bd9Sstevel@tonic-gate { 22667c478bd9Sstevel@tonic-gate return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_OBSERVER, B_FALSE)); 22677c478bd9Sstevel@tonic-gate } 22687c478bd9Sstevel@tonic-gate 22697c478bd9Sstevel@tonic-gate /* 22707c478bd9Sstevel@tonic-gate * secpolicy_contract_event 22717c478bd9Sstevel@tonic-gate * 22727c478bd9Sstevel@tonic-gate * Determine if the subject may request critical contract events or 22737c478bd9Sstevel@tonic-gate * reliable contract event delivery. 22747c478bd9Sstevel@tonic-gate */ 22757c478bd9Sstevel@tonic-gate int 22767c478bd9Sstevel@tonic-gate secpolicy_contract_event(const cred_t *cr) 22777c478bd9Sstevel@tonic-gate { 22787c478bd9Sstevel@tonic-gate return (PRIV_POLICY(cr, PRIV_CONTRACT_EVENT, B_FALSE, EPERM, NULL)); 22797c478bd9Sstevel@tonic-gate } 22807c478bd9Sstevel@tonic-gate 22817c478bd9Sstevel@tonic-gate /* 22827c478bd9Sstevel@tonic-gate * secpolicy_contract_event_choice 22837c478bd9Sstevel@tonic-gate * 22847c478bd9Sstevel@tonic-gate * Determine if the subject may retain contract events in its critical 22857c478bd9Sstevel@tonic-gate * set when a change in other terms would normally require a change in 22867c478bd9Sstevel@tonic-gate * the critical set. Just tests privilege and audits on success. 22877c478bd9Sstevel@tonic-gate */ 22887c478bd9Sstevel@tonic-gate boolean_t 22897c478bd9Sstevel@tonic-gate secpolicy_contract_event_choice(const cred_t *cr) 22907c478bd9Sstevel@tonic-gate { 22917c478bd9Sstevel@tonic-gate return (PRIV_POLICY_CHOICE(cr, PRIV_CONTRACT_EVENT, B_FALSE)); 22927c478bd9Sstevel@tonic-gate } 22937c478bd9Sstevel@tonic-gate 22947c478bd9Sstevel@tonic-gate /* 2295ea8dc4b6Seschrock * secpolicy_gart_access 22967c478bd9Sstevel@tonic-gate * 2297ea8dc4b6Seschrock * Determine if the subject has sufficient priveleges to make ioctls to agpgart 2298ea8dc4b6Seschrock * device. 22997c478bd9Sstevel@tonic-gate */ 23007c478bd9Sstevel@tonic-gate int 23017c478bd9Sstevel@tonic-gate secpolicy_gart_access(const cred_t *cr) 23027c478bd9Sstevel@tonic-gate { 230326f24838Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, NULL)); 23047c478bd9Sstevel@tonic-gate } 23057c478bd9Sstevel@tonic-gate 23067c478bd9Sstevel@tonic-gate /* 2307ea8dc4b6Seschrock * secpolicy_gart_map 23087c478bd9Sstevel@tonic-gate * 2309ea8dc4b6Seschrock * Determine if the subject has sufficient priveleges to map aperture range 2310ea8dc4b6Seschrock * through agpgart driver. 23117c478bd9Sstevel@tonic-gate */ 23127c478bd9Sstevel@tonic-gate int 23137c478bd9Sstevel@tonic-gate secpolicy_gart_map(const cred_t *cr) 23147c478bd9Sstevel@tonic-gate { 231526f24838Scasper if (PRIV_POLICY_ONLY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE)) { 231626f24838Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_ACCESS, B_FALSE, EPERM, 231726f24838Scasper NULL)); 231826f24838Scasper } else { 231926f24838Scasper return (PRIV_POLICY(cr, PRIV_GRAPHICS_MAP, B_FALSE, EPERM, 232026f24838Scasper NULL)); 23217c478bd9Sstevel@tonic-gate } 23227c478bd9Sstevel@tonic-gate } 2323fa9e4066Sahrens 2324fa9e4066Sahrens /* 2325ea8dc4b6Seschrock * secpolicy_zinject 2326ea8dc4b6Seschrock * 2327ea8dc4b6Seschrock * Determine if the subject can inject faults in the ZFS fault injection 2328ea8dc4b6Seschrock * framework. Requires all privileges. 2329ea8dc4b6Seschrock */ 2330ea8dc4b6Seschrock int 2331ea8dc4b6Seschrock secpolicy_zinject(const cred_t *cr) 2332ea8dc4b6Seschrock { 2333134a1f4eSCasper H.S. Dik return (secpolicy_require_set(cr, PRIV_FULLSET, NULL, KLPDARG_NONE)); 2334ea8dc4b6Seschrock } 2335ea8dc4b6Seschrock 2336ea8dc4b6Seschrock /* 2337fa9e4066Sahrens * secpolicy_zfs 2338fa9e4066Sahrens * 2339ea8dc4b6Seschrock * Determine if the subject has permission to manipulate ZFS datasets 2340ea8dc4b6Seschrock * (not pools). Equivalent to the SYS_MOUNT privilege. 2341fa9e4066Sahrens */ 2342fa9e4066Sahrens int 2343fa9e4066Sahrens secpolicy_zfs(const cred_t *cr) 2344fa9e4066Sahrens { 2345fa9e4066Sahrens return (PRIV_POLICY(cr, PRIV_SYS_MOUNT, B_FALSE, EPERM, NULL)); 2346fa9e4066Sahrens } 2347f48205beScasper 2348f48205beScasper /* 2349f48205beScasper * secpolicy_idmap 2350f48205beScasper * 2351f48205beScasper * Determine if the calling process has permissions to register an SID 2352f48205beScasper * mapping daemon and allocate ephemeral IDs. 2353f48205beScasper */ 2354f48205beScasper int 2355f48205beScasper secpolicy_idmap(const cred_t *cr) 2356f48205beScasper { 2357bda89588Sjp151216 return (PRIV_POLICY(cr, PRIV_FILE_SETID, B_TRUE, EPERM, NULL)); 2358f48205beScasper } 23592449e17fSsherrym 23602449e17fSsherrym /* 23612449e17fSsherrym * secpolicy_ucode_update 23622449e17fSsherrym * 23632449e17fSsherrym * Determine if the subject has sufficient privilege to update microcode. 23642449e17fSsherrym */ 23652449e17fSsherrym int 23662449e17fSsherrym secpolicy_ucode_update(const cred_t *scr) 23672449e17fSsherrym { 23682449e17fSsherrym return (PRIV_POLICY(scr, PRIV_ALL, B_FALSE, EPERM, NULL)); 23692449e17fSsherrym } 2370e6bdcbd5Sdh155122 2371e6bdcbd5Sdh155122 /* 2372e6bdcbd5Sdh155122 * secpolicy_sadopen 2373e6bdcbd5Sdh155122 * 2374e6bdcbd5Sdh155122 * Determine if the subject has sufficient privilege to access /dev/sad/admin. 2375e6bdcbd5Sdh155122 * /dev/sad/admin appear in global zone and exclusive-IP zones only. 2376e6bdcbd5Sdh155122 * In global zone, sys_config is required. 2377e6bdcbd5Sdh155122 * In exclusive-IP zones, sys_ip_config is required. 2378e6bdcbd5Sdh155122 * Note that sys_config is prohibited in non-global zones. 2379e6bdcbd5Sdh155122 */ 2380e6bdcbd5Sdh155122 int 2381e6bdcbd5Sdh155122 secpolicy_sadopen(const cred_t *credp) 2382e6bdcbd5Sdh155122 { 2383e6bdcbd5Sdh155122 priv_set_t pset; 2384e6bdcbd5Sdh155122 2385e6bdcbd5Sdh155122 priv_emptyset(&pset); 2386e6bdcbd5Sdh155122 2387e6bdcbd5Sdh155122 if (crgetzoneid(credp) == GLOBAL_ZONEID) 2388e6bdcbd5Sdh155122 priv_addset(&pset, PRIV_SYS_CONFIG); 2389e6bdcbd5Sdh155122 else 2390e6bdcbd5Sdh155122 priv_addset(&pset, PRIV_SYS_IP_CONFIG); 2391e6bdcbd5Sdh155122 2392134a1f4eSCasper H.S. Dik return (secpolicy_require_set(credp, &pset, "devpolicy", KLPDARG_NONE)); 2393e6bdcbd5Sdh155122 } 2394da6c28aaSamw 2395ddf7fe95Scasper 2396ddf7fe95Scasper /* 2397ddf7fe95Scasper * Add privileges to a particular privilege set; this is called when the 2398ddf7fe95Scasper * current sets of privileges are not sufficient. I.e., we should always 2399ddf7fe95Scasper * call the policy override functions from here. 2400ddf7fe95Scasper * What we are allowed to have is in the Observed Permitted set; so 2401ddf7fe95Scasper * we compute the difference between that and the newset. 2402ddf7fe95Scasper */ 2403ddf7fe95Scasper int 2404ddf7fe95Scasper secpolicy_require_privs(const cred_t *cr, const priv_set_t *nset) 2405ddf7fe95Scasper { 2406ddf7fe95Scasper priv_set_t rqd; 2407ddf7fe95Scasper 2408ddf7fe95Scasper rqd = CR_OPPRIV(cr); 2409ddf7fe95Scasper 2410ddf7fe95Scasper priv_inverse(&rqd); 2411ddf7fe95Scasper priv_intersect(nset, &rqd); 2412ddf7fe95Scasper 2413134a1f4eSCasper H.S. Dik return (secpolicy_require_set(cr, &rqd, NULL, KLPDARG_NONE)); 2414ddf7fe95Scasper } 2415ddf7fe95Scasper 2416da6c28aaSamw /* 2417da6c28aaSamw * secpolicy_smb 2418da6c28aaSamw * 2419da6c28aaSamw * Determine if the cred_t has PRIV_SYS_SMB privilege, indicating 2420da6c28aaSamw * that it has permission to access the smbsrv kernel driver. 2421da6c28aaSamw * PRIV_POLICY checks the privilege and audits the check. 2422da6c28aaSamw * 2423da6c28aaSamw * Returns: 2424da6c28aaSamw * 0 Driver access is allowed. 2425da6c28aaSamw * EPERM Driver access is NOT permitted. 2426da6c28aaSamw */ 2427da6c28aaSamw int 2428da6c28aaSamw secpolicy_smb(const cred_t *cr) 2429da6c28aaSamw { 2430da6c28aaSamw return (PRIV_POLICY(cr, PRIV_SYS_SMB, B_FALSE, EPERM, NULL)); 2431da6c28aaSamw } 2432911106dfSjm199354 2433911106dfSjm199354 /* 2434911106dfSjm199354 * secpolicy_vscan 2435911106dfSjm199354 * 2436911106dfSjm199354 * Determine if cred_t has the necessary privileges to access a file 2437911106dfSjm199354 * for virus scanning and update its extended system attributes. 2438911106dfSjm199354 * PRIV_FILE_DAC_SEARCH, PRIV_FILE_DAC_READ - file access 2439911106dfSjm199354 * PRIV_FILE_FLAG_SET - set extended system attributes 2440911106dfSjm199354 * 2441911106dfSjm199354 * PRIV_POLICY checks the privilege and audits the check. 2442911106dfSjm199354 * 2443911106dfSjm199354 * Returns: 2444911106dfSjm199354 * 0 file access for virus scanning allowed. 2445911106dfSjm199354 * EPERM file access for virus scanning is NOT permitted. 2446911106dfSjm199354 */ 2447911106dfSjm199354 int 2448911106dfSjm199354 secpolicy_vscan(const cred_t *cr) 2449911106dfSjm199354 { 2450911106dfSjm199354 if ((PRIV_POLICY(cr, PRIV_FILE_DAC_SEARCH, B_FALSE, EPERM, NULL)) || 2451911106dfSjm199354 (PRIV_POLICY(cr, PRIV_FILE_DAC_READ, B_FALSE, EPERM, NULL)) || 2452911106dfSjm199354 (PRIV_POLICY(cr, PRIV_FILE_FLAG_SET, B_FALSE, EPERM, NULL))) { 2453911106dfSjm199354 return (EPERM); 2454911106dfSjm199354 } 2455911106dfSjm199354 2456911106dfSjm199354 return (0); 2457911106dfSjm199354 } 24584bff34e3Sthurlow 24594bff34e3Sthurlow /* 24604bff34e3Sthurlow * secpolicy_smbfs_login 24614bff34e3Sthurlow * 24624bff34e3Sthurlow * Determines if the caller can add and delete the smbfs login 24634bff34e3Sthurlow * password in the the nsmb kernel module for the CIFS client. 24644bff34e3Sthurlow * 24654bff34e3Sthurlow * Returns: 24664bff34e3Sthurlow * 0 access is allowed. 24674bff34e3Sthurlow * EPERM access is NOT allowed. 24684bff34e3Sthurlow */ 24694bff34e3Sthurlow int 24704bff34e3Sthurlow secpolicy_smbfs_login(const cred_t *cr, uid_t uid) 24714bff34e3Sthurlow { 24724bff34e3Sthurlow uid_t cruid = crgetruid(cr); 24734bff34e3Sthurlow 24744bff34e3Sthurlow if (cruid == uid) 24754bff34e3Sthurlow return (0); 24764bff34e3Sthurlow return (PRIV_POLICY(cr, PRIV_PROC_OWNER, B_FALSE, 24774bff34e3Sthurlow EPERM, NULL)); 24784bff34e3Sthurlow } 2479b26a64aeSjohnlev 2480b26a64aeSjohnlev /* 2481b26a64aeSjohnlev * secpolicy_xvm_control 2482b26a64aeSjohnlev * 2483b26a64aeSjohnlev * Determines if a caller can control the xVM hypervisor and/or running 2484b26a64aeSjohnlev * domains (x86 specific). 2485b26a64aeSjohnlev * 2486b26a64aeSjohnlev * Returns: 2487b26a64aeSjohnlev * 0 access is allowed. 2488b26a64aeSjohnlev * EPERM access is NOT allowed. 2489b26a64aeSjohnlev */ 2490b26a64aeSjohnlev int 2491b26a64aeSjohnlev secpolicy_xvm_control(const cred_t *cr) 2492b26a64aeSjohnlev { 2493b26a64aeSjohnlev if (PRIV_POLICY(cr, PRIV_XVM_CONTROL, B_FALSE, EPERM, NULL)) 2494b26a64aeSjohnlev return (EPERM); 2495b26a64aeSjohnlev return (0); 2496b26a64aeSjohnlev } 2497da14cebeSEric Cheng 2498da14cebeSEric Cheng /* 2499f53eecf5SJames Carlson * secpolicy_ppp_config 2500f53eecf5SJames Carlson * 2501f53eecf5SJames Carlson * Determine if the subject has sufficient privileges to configure PPP and 2502f53eecf5SJames Carlson * PPP-related devices. 2503f53eecf5SJames Carlson */ 2504f53eecf5SJames Carlson int 2505f53eecf5SJames Carlson secpolicy_ppp_config(const cred_t *cr) 2506f53eecf5SJames Carlson { 2507f53eecf5SJames Carlson if (PRIV_POLICY_ONLY(cr, PRIV_SYS_NET_CONFIG, B_FALSE)) 2508f53eecf5SJames Carlson return (secpolicy_net_config(cr, B_FALSE)); 2509f53eecf5SJames Carlson return (PRIV_POLICY(cr, PRIV_SYS_PPP_CONFIG, B_FALSE, EPERM, NULL)); 2510f53eecf5SJames Carlson } 2511