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
545916cd2Sjpk * Common Development and Distribution License (the "License").
645916cd2Sjpk * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*134a1f4eSCasper 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/param.h>
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
287c478bd9Sstevel@tonic-gate #include <sys/systm.h>
297c478bd9Sstevel@tonic-gate #include <sys/cred_impl.h>
307c478bd9Sstevel@tonic-gate #include <sys/errno.h>
31ddf7fe95Scasper #include <sys/klpd.h>
327c478bd9Sstevel@tonic-gate #include <sys/proc.h>
337c478bd9Sstevel@tonic-gate #include <sys/priv_impl.h>
347c478bd9Sstevel@tonic-gate #include <sys/policy.h>
357c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
367c478bd9Sstevel@tonic-gate #include <sys/thread.h>
37634e26ecSCasper H.S. Dik #include <sys/cmn_err.h>
387c478bd9Sstevel@tonic-gate #include <c2/audit.h>
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate * System call support for manipulating privileges.
427c478bd9Sstevel@tonic-gate *
437c478bd9Sstevel@tonic-gate *
447c478bd9Sstevel@tonic-gate * setppriv(2) - set process privilege set
457c478bd9Sstevel@tonic-gate * getppriv(2) - get process privilege set
467c478bd9Sstevel@tonic-gate * getprivimplinfo(2) - get process privilege implementation information
477c478bd9Sstevel@tonic-gate * setpflags(2) - set process (privilege) flags
487c478bd9Sstevel@tonic-gate * getpflags(2) - get process (privilege) flags
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate * setppriv (priv_op_t, priv_ptype_t, priv_set_t)
537c478bd9Sstevel@tonic-gate */
547c478bd9Sstevel@tonic-gate static int
setppriv(priv_op_t op,priv_ptype_t type,priv_set_t * in_pset)557c478bd9Sstevel@tonic-gate setppriv(priv_op_t op, priv_ptype_t type, priv_set_t *in_pset)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate priv_set_t pset, *target;
587c478bd9Sstevel@tonic-gate cred_t *cr, *pcr;
597c478bd9Sstevel@tonic-gate proc_t *p;
60ddf7fe95Scasper boolean_t donocd = B_FALSE;
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate if (!PRIV_VALIDSET(type) || !PRIV_VALIDOP(op))
637c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate if (copyin(in_pset, &pset, sizeof (priv_set_t)))
667c478bd9Sstevel@tonic-gate return (set_errno(EFAULT));
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate p = ttoproc(curthread);
697c478bd9Sstevel@tonic-gate cr = cralloc();
707c478bd9Sstevel@tonic-gate mutex_enter(&p->p_crlock);
717c478bd9Sstevel@tonic-gate
72ddf7fe95Scasper retry:
737c478bd9Sstevel@tonic-gate pcr = p->p_cred;
747c478bd9Sstevel@tonic-gate
75005d3febSMarek Pospisil if (AU_AUDITING())
767c478bd9Sstevel@tonic-gate audit_setppriv(op, type, &pset, pcr);
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate * Filter out unallowed request (bad op and bad type)
807c478bd9Sstevel@tonic-gate */
817c478bd9Sstevel@tonic-gate switch (op) {
827c478bd9Sstevel@tonic-gate case PRIV_ON:
837c478bd9Sstevel@tonic-gate case PRIV_SET:
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate * Turning on privileges; the limit set cannot grow,
867c478bd9Sstevel@tonic-gate * other sets can but only as long as they remain subsets
877c478bd9Sstevel@tonic-gate * of P. Only immediately after exec holds that P <= L.
887c478bd9Sstevel@tonic-gate */
89ddf7fe95Scasper if (type == PRIV_LIMIT &&
90ddf7fe95Scasper !priv_issubset(&pset, &CR_LPRIV(pcr))) {
9105db633cScasper mutex_exit(&p->p_crlock);
927c478bd9Sstevel@tonic-gate crfree(cr);
937c478bd9Sstevel@tonic-gate return (set_errno(EPERM));
947c478bd9Sstevel@tonic-gate }
95ddf7fe95Scasper if (!priv_issubset(&pset, &CR_OPPRIV(pcr)) &&
96ddf7fe95Scasper !priv_issubset(&pset, priv_getset(pcr, type))) {
97ddf7fe95Scasper mutex_exit(&p->p_crlock);
98ddf7fe95Scasper /* Policy override should not grow beyond L either */
99ddf7fe95Scasper if (type != PRIV_INHERITABLE ||
100ddf7fe95Scasper !priv_issubset(&pset, &CR_LPRIV(pcr)) ||
101ddf7fe95Scasper secpolicy_require_privs(CRED(), &pset) != 0) {
102ddf7fe95Scasper crfree(cr);
103ddf7fe95Scasper return (set_errno(EPERM));
104ddf7fe95Scasper }
105ddf7fe95Scasper mutex_enter(&p->p_crlock);
106ddf7fe95Scasper if (pcr != p->p_cred)
107ddf7fe95Scasper goto retry;
108ddf7fe95Scasper donocd = B_TRUE;
109ddf7fe95Scasper }
1107c478bd9Sstevel@tonic-gate break;
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate case PRIV_OFF:
1137c478bd9Sstevel@tonic-gate /* PRIV_OFF is always allowed */
1147c478bd9Sstevel@tonic-gate break;
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate * OK! everything is cool.
1197c478bd9Sstevel@tonic-gate * Do cred COW.
1207c478bd9Sstevel@tonic-gate */
1217c478bd9Sstevel@tonic-gate crcopy_to(pcr, cr);
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * If we change the effective, permitted or limit set, we attain
1257c478bd9Sstevel@tonic-gate * "privilege awareness".
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate if (type != PRIV_INHERITABLE)
1287c478bd9Sstevel@tonic-gate priv_set_PA(cr);
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate target = &(CR_PRIVS(cr)->crprivs[type]);
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate switch (op) {
1337c478bd9Sstevel@tonic-gate case PRIV_ON:
1347c478bd9Sstevel@tonic-gate priv_union(&pset, target);
1357c478bd9Sstevel@tonic-gate break;
1367c478bd9Sstevel@tonic-gate case PRIV_OFF:
1377c478bd9Sstevel@tonic-gate priv_inverse(&pset);
1387c478bd9Sstevel@tonic-gate priv_intersect(target, &pset);
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate * Fall-thru to set target and change other process
1427c478bd9Sstevel@tonic-gate * privilege sets.
1437c478bd9Sstevel@tonic-gate */
1447c478bd9Sstevel@tonic-gate /*FALLTHRU*/
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate case PRIV_SET:
1477c478bd9Sstevel@tonic-gate *target = pset;
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate * Take privileges no longer permitted out
1517c478bd9Sstevel@tonic-gate * of other effective sets as well.
1527c478bd9Sstevel@tonic-gate * Limit set is enforced at exec() time.
1537c478bd9Sstevel@tonic-gate */
1547c478bd9Sstevel@tonic-gate if (type == PRIV_PERMITTED)
1557c478bd9Sstevel@tonic-gate priv_intersect(&pset, &CR_EPRIV(cr));
1567c478bd9Sstevel@tonic-gate break;
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate * When we give up privileges not in the inheritable set,
1617c478bd9Sstevel@tonic-gate * set SNOCD if not already set; first we compute the
1627c478bd9Sstevel@tonic-gate * privileges removed from P using Diff = (~P') & P
1637c478bd9Sstevel@tonic-gate * and then we check whether the removed privileges are
1647c478bd9Sstevel@tonic-gate * a subset of I. If we retain uid 0, all privileges
1657c478bd9Sstevel@tonic-gate * are required anyway so don't set SNOCD.
1667c478bd9Sstevel@tonic-gate */
1677c478bd9Sstevel@tonic-gate if (type == PRIV_PERMITTED && (p->p_flag & SNOCD) == 0 &&
1687c478bd9Sstevel@tonic-gate cr->cr_uid != 0 && cr->cr_ruid != 0 && cr->cr_suid != 0) {
1697c478bd9Sstevel@tonic-gate priv_set_t diff = CR_OPPRIV(cr);
1707c478bd9Sstevel@tonic-gate priv_inverse(&diff);
1717c478bd9Sstevel@tonic-gate priv_intersect(&CR_OPPRIV(pcr), &diff);
1727c478bd9Sstevel@tonic-gate donocd = !priv_issubset(&diff, &CR_IPRIV(cr));
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate p->p_cred = cr;
1767c478bd9Sstevel@tonic-gate mutex_exit(&p->p_crlock);
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate if (donocd) {
1797c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock);
1807c478bd9Sstevel@tonic-gate p->p_flag |= SNOCD;
1817c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate
184634e26ecSCasper H.S. Dik /*
185634e26ecSCasper H.S. Dik * The basic_test privilege should not be removed from E;
186634e26ecSCasper H.S. Dik * if that has happened, then some programmer typically set the E/P to
187634e26ecSCasper H.S. Dik * empty. That is not portable.
188634e26ecSCasper H.S. Dik */
189d93c0b4cSCasper H.S. Dik if ((type == PRIV_EFFECTIVE || type == PRIV_PERMITTED) &&
190634e26ecSCasper H.S. Dik priv_basic_test >= 0 && !PRIV_ISASSERT(target, priv_basic_test)) {
191634e26ecSCasper H.S. Dik proc_t *p = curproc;
192634e26ecSCasper H.S. Dik pid_t pid = p->p_pid;
193634e26ecSCasper H.S. Dik char *fn = PTOU(p)->u_comm;
194634e26ecSCasper H.S. Dik
195634e26ecSCasper H.S. Dik cmn_err(CE_WARN, "%s[%d]: setppriv: basic_test privilege "
196634e26ecSCasper H.S. Dik "removed from E/P", fn, pid);
197634e26ecSCasper H.S. Dik }
198634e26ecSCasper H.S. Dik
1997c478bd9Sstevel@tonic-gate crset(p, cr); /* broadcast to process threads */
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate return (0);
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate * getppriv (priv_ptype_t, priv_set_t *)
2067c478bd9Sstevel@tonic-gate */
2077c478bd9Sstevel@tonic-gate static int
getppriv(priv_ptype_t type,priv_set_t * pset)2087c478bd9Sstevel@tonic-gate getppriv(priv_ptype_t type, priv_set_t *pset)
2097c478bd9Sstevel@tonic-gate {
2107c478bd9Sstevel@tonic-gate if (!PRIV_VALIDSET(type))
2117c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate if (copyout(priv_getset(CRED(), type), pset, sizeof (priv_set_t)) != 0)
2147c478bd9Sstevel@tonic-gate return (set_errno(EFAULT));
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate return (0);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate static int
getprivimplinfo(void * buf,size_t bufsize)2207c478bd9Sstevel@tonic-gate getprivimplinfo(void *buf, size_t bufsize)
2217c478bd9Sstevel@tonic-gate {
2227c478bd9Sstevel@tonic-gate int err;
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate err = copyout(priv_hold_implinfo(), buf, min(bufsize, privinfosize));
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate priv_release_implinfo();
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate if (err)
2297c478bd9Sstevel@tonic-gate return (set_errno(EFAULT));
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate return (0);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate /*
23545916cd2Sjpk * Set process flags in the given target cred. If NULL is specified, then
23645916cd2Sjpk * CRED() is used; otherwise the cred is assumed to be modifiable (i.e. newly
23745916cd2Sjpk * crdup'ed, or equivalent). Some flags are set in the proc rather than cred;
23845916cd2Sjpk * for these, curproc is always used.
2397c478bd9Sstevel@tonic-gate *
2407c478bd9Sstevel@tonic-gate * For now we cheat: the flags are actually bit masks so we can simplify
2417c478bd9Sstevel@tonic-gate * some; we do make sure that the arguments are valid, though.
2427c478bd9Sstevel@tonic-gate */
2437c478bd9Sstevel@tonic-gate
24445916cd2Sjpk int
setpflags(uint_t flag,uint_t val,cred_t * tcr)24545916cd2Sjpk setpflags(uint_t flag, uint_t val, cred_t *tcr)
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate cred_t *cr, *pcr;
2487c478bd9Sstevel@tonic-gate proc_t *p = curproc;
2497c478bd9Sstevel@tonic-gate uint_t newflags;
25045916cd2Sjpk boolean_t use_curcred = (tcr == NULL);
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate if (val > 1 || (flag != PRIV_DEBUG && flag != PRIV_AWARE &&
25345916cd2Sjpk flag != NET_MAC_AWARE && flag != NET_MAC_AWARE_INHERIT &&
254982b4ad2SCasper H.S. Dik flag != __PROC_PROTECT && flag != PRIV_XPOLICY &&
255*134a1f4eSCasper H.S. Dik flag != PRIV_AWARE_RESET && flag != PRIV_PFEXEC)) {
25645916cd2Sjpk return (EINVAL);
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate if (flag == __PROC_PROTECT) {
2607c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock);
2617c478bd9Sstevel@tonic-gate if (val == 0)
2627c478bd9Sstevel@tonic-gate p->p_flag &= ~SNOCD;
2637c478bd9Sstevel@tonic-gate else
2647c478bd9Sstevel@tonic-gate p->p_flag |= SNOCD;
2657c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock);
2667c478bd9Sstevel@tonic-gate return (0);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate
26945916cd2Sjpk if (use_curcred) {
2707c478bd9Sstevel@tonic-gate cr = cralloc();
2717c478bd9Sstevel@tonic-gate mutex_enter(&p->p_crlock);
2727c478bd9Sstevel@tonic-gate pcr = p->p_cred;
27345916cd2Sjpk } else {
27445916cd2Sjpk cr = pcr = tcr;
27545916cd2Sjpk }
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate newflags = CR_FLAGS(pcr);
2787c478bd9Sstevel@tonic-gate
279982b4ad2SCasper H.S. Dik if (val != 0) {
280982b4ad2SCasper H.S. Dik if (flag == PRIV_AWARE)
281982b4ad2SCasper H.S. Dik newflags &= ~PRIV_AWARE_RESET;
2827c478bd9Sstevel@tonic-gate newflags |= flag;
283982b4ad2SCasper H.S. Dik } else {
2847c478bd9Sstevel@tonic-gate newflags &= ~flag;
285982b4ad2SCasper H.S. Dik }
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate /* No change */
2887c478bd9Sstevel@tonic-gate if (CR_FLAGS(pcr) == newflags) {
28945916cd2Sjpk if (use_curcred) {
2907c478bd9Sstevel@tonic-gate mutex_exit(&p->p_crlock);
2917c478bd9Sstevel@tonic-gate crfree(cr);
29245916cd2Sjpk }
2937c478bd9Sstevel@tonic-gate return (0);
2947c478bd9Sstevel@tonic-gate }
2957c478bd9Sstevel@tonic-gate
29645916cd2Sjpk /*
29797bedc9aSgfaden * Setting either the NET_MAC_AWARE or NET_MAC_AWARE_INHERIT
29897bedc9aSgfaden * flags is a restricted operation.
29997bedc9aSgfaden *
30097bedc9aSgfaden * When invoked via the PRIVSYS_SETPFLAGS syscall
30197bedc9aSgfaden * we require that the current cred has the net_mac_aware
30297bedc9aSgfaden * privilege in its effective set.
30397bedc9aSgfaden *
30497bedc9aSgfaden * When called from within the kernel by label-aware
30597bedc9aSgfaden * services such as NFS, we don't require a privilege check.
30697bedc9aSgfaden *
30745916cd2Sjpk */
30845916cd2Sjpk if ((flag == NET_MAC_AWARE || flag == NET_MAC_AWARE_INHERIT) &&
30945916cd2Sjpk (val == 1) && use_curcred) {
31097bedc9aSgfaden if (secpolicy_net_mac_aware(pcr) != 0) {
31145916cd2Sjpk mutex_exit(&p->p_crlock);
31245916cd2Sjpk crfree(cr);
31345916cd2Sjpk return (EPERM);
31445916cd2Sjpk }
31545916cd2Sjpk }
31645916cd2Sjpk
3177c478bd9Sstevel@tonic-gate /* Trying to unset PA; if we can't, return an error */
3187c478bd9Sstevel@tonic-gate if (flag == PRIV_AWARE && val == 0 && !priv_can_clear_PA(pcr)) {
31945916cd2Sjpk if (use_curcred) {
3207c478bd9Sstevel@tonic-gate mutex_exit(&p->p_crlock);
3217c478bd9Sstevel@tonic-gate crfree(cr);
32245916cd2Sjpk }
32345916cd2Sjpk return (EPERM);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate /* Committed to changing the flag */
32745916cd2Sjpk if (use_curcred)
3287c478bd9Sstevel@tonic-gate crcopy_to(pcr, cr);
3297c478bd9Sstevel@tonic-gate if (flag == PRIV_AWARE) {
3307c478bd9Sstevel@tonic-gate if (val != 0)
3317c478bd9Sstevel@tonic-gate priv_set_PA(cr);
3327c478bd9Sstevel@tonic-gate else
3337c478bd9Sstevel@tonic-gate priv_adjust_PA(cr);
3347c478bd9Sstevel@tonic-gate } else {
3357c478bd9Sstevel@tonic-gate CR_FLAGS(cr) = newflags;
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate
338ddf7fe95Scasper /*
339ddf7fe95Scasper * Unsetting the flag has as side effect getting rid of
340ddf7fe95Scasper * the per-credential policy.
341ddf7fe95Scasper */
342ddf7fe95Scasper if (flag == PRIV_XPOLICY && val == 0)
343ddf7fe95Scasper crsetcrklpd(cr, NULL);
344ddf7fe95Scasper
34545916cd2Sjpk if (use_curcred) {
3467c478bd9Sstevel@tonic-gate p->p_cred = cr;
3477c478bd9Sstevel@tonic-gate mutex_exit(&p->p_crlock);
3487c478bd9Sstevel@tonic-gate crset(p, cr);
34945916cd2Sjpk }
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate return (0);
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate /*
3557c478bd9Sstevel@tonic-gate * Getpflags. Currently only implements single bit flags.
3567c478bd9Sstevel@tonic-gate */
35745916cd2Sjpk uint_t
getpflags(uint_t flag,const cred_t * cr)35845916cd2Sjpk getpflags(uint_t flag, const cred_t *cr)
3597c478bd9Sstevel@tonic-gate {
36045916cd2Sjpk if (flag != PRIV_DEBUG && flag != PRIV_AWARE &&
361ddf7fe95Scasper flag != NET_MAC_AWARE && flag != NET_MAC_AWARE_INHERIT &&
362*134a1f4eSCasper H.S. Dik flag != PRIV_XPOLICY && flag != PRIV_PFEXEC &&
363*134a1f4eSCasper H.S. Dik flag != PRIV_AWARE_RESET)
36445916cd2Sjpk return ((uint_t)-1);
3657c478bd9Sstevel@tonic-gate
36645916cd2Sjpk return ((CR_FLAGS(cr) & flag) != 0);
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate * Privilege system call entry point
3717c478bd9Sstevel@tonic-gate */
3727c478bd9Sstevel@tonic-gate int
privsys(int code,priv_op_t op,priv_ptype_t type,void * buf,size_t bufsize,int itype)373ddf7fe95Scasper privsys(int code, priv_op_t op, priv_ptype_t type, void *buf, size_t bufsize,
374ddf7fe95Scasper int itype)
3757c478bd9Sstevel@tonic-gate {
37645916cd2Sjpk int retv;
377f48205beScasper extern int issetugid(void);
37845916cd2Sjpk
3797c478bd9Sstevel@tonic-gate switch (code) {
3807c478bd9Sstevel@tonic-gate case PRIVSYS_SETPPRIV:
3817c478bd9Sstevel@tonic-gate if (bufsize < sizeof (priv_set_t))
3827c478bd9Sstevel@tonic-gate return (set_errno(ENOMEM));
3837c478bd9Sstevel@tonic-gate return (setppriv(op, type, buf));
3847c478bd9Sstevel@tonic-gate case PRIVSYS_GETPPRIV:
3857c478bd9Sstevel@tonic-gate if (bufsize < sizeof (priv_set_t))
3867c478bd9Sstevel@tonic-gate return (set_errno(ENOMEM));
3877c478bd9Sstevel@tonic-gate return (getppriv(type, buf));
3887c478bd9Sstevel@tonic-gate case PRIVSYS_GETIMPLINFO:
3897c478bd9Sstevel@tonic-gate return (getprivimplinfo(buf, bufsize));
3907c478bd9Sstevel@tonic-gate case PRIVSYS_SETPFLAGS:
39145916cd2Sjpk retv = setpflags((uint_t)op, (uint_t)type, NULL);
39245916cd2Sjpk return (retv != 0 ? set_errno(retv) : 0);
3937c478bd9Sstevel@tonic-gate case PRIVSYS_GETPFLAGS:
39445916cd2Sjpk retv = (int)getpflags((uint_t)op, CRED());
39545916cd2Sjpk return (retv == -1 ? set_errno(EINVAL) : retv);
396f48205beScasper case PRIVSYS_ISSETUGID:
397f48205beScasper return (issetugid());
398ddf7fe95Scasper case PRIVSYS_KLPD_REG:
399ddf7fe95Scasper if (bufsize < sizeof (priv_set_t))
400ddf7fe95Scasper return (set_errno(ENOMEM));
401ddf7fe95Scasper return ((int)klpd_reg((int)op, (idtype_t)itype, (id_t)type,
402ddf7fe95Scasper buf));
403ddf7fe95Scasper case PRIVSYS_KLPD_UNREG:
404ddf7fe95Scasper return ((int)klpd_unreg((int)op, (idtype_t)itype, (id_t)type));
405*134a1f4eSCasper H.S. Dik case PRIVSYS_PFEXEC_REG:
406*134a1f4eSCasper H.S. Dik return ((int)pfexec_reg((int)op));
407*134a1f4eSCasper H.S. Dik case PRIVSYS_PFEXEC_UNREG:
408*134a1f4eSCasper H.S. Dik return ((int)pfexec_unreg((int)op));
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate return (set_errno(EINVAL));
4117c478bd9Sstevel@tonic-gate }
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
4147c478bd9Sstevel@tonic-gate int
privsys32(int code,priv_op_t op,priv_ptype_t type,caddr32_t buf,size32_t bufsize,int itype)415ddf7fe95Scasper privsys32(int code, priv_op_t op, priv_ptype_t type, caddr32_t buf,
416ddf7fe95Scasper size32_t bufsize, int itype)
4177c478bd9Sstevel@tonic-gate {
418ddf7fe95Scasper return (privsys(code, op, type, (void *)(uintptr_t)buf,
419ddf7fe95Scasper (size_t)bufsize, itype));
4207c478bd9Sstevel@tonic-gate }
4217c478bd9Sstevel@tonic-gate #endif
422