ppriv.c revision d93c0b4cf0eaea69e1c297b8812a7474feb926b7
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/sysmacros.h>
#include <sys/cred_impl.h>
#include <sys/priv_impl.h>
/*
* System call support for manipulating privileges.
*
*
* setppriv(2) - set process privilege set
* getppriv(2) - get process privilege set
* getprivimplinfo(2) - get process privilege implementation information
* setpflags(2) - set process (privilege) flags
* getpflags(2) - get process (privilege) flags
*/
/*
* setppriv (priv_op_t, priv_ptype_t, priv_set_t)
*/
static int
{
proc_t *p;
mutex_enter(&p->p_crlock);
if (audit_active)
/*
* Filter out unallowed request (bad op and bad type)
*/
switch (op) {
case PRIV_ON:
case PRIV_SET:
/*
* Turning on privileges; the limit set cannot grow,
* other sets can but only as long as they remain subsets
* of P. Only immediately after exec holds that P <= L.
*/
if (type == PRIV_LIMIT &&
mutex_exit(&p->p_crlock);
}
mutex_exit(&p->p_crlock);
/* Policy override should not grow beyond L either */
if (type != PRIV_INHERITABLE ||
}
mutex_enter(&p->p_crlock);
goto retry;
}
break;
case PRIV_OFF:
/* PRIV_OFF is always allowed */
break;
}
/*
* OK! everything is cool.
* Do cred COW.
*/
/*
* If we change the effective, permitted or limit set, we attain
* "privilege awareness".
*/
if (type != PRIV_INHERITABLE)
switch (op) {
case PRIV_ON:
break;
case PRIV_OFF:
priv_inverse(&pset);
/*
* Fall-thru to set target and change other process
* privilege sets.
*/
/*FALLTHRU*/
case PRIV_SET:
/*
* Take privileges no longer permitted out
* of other effective sets as well.
* Limit set is enforced at exec() time.
*/
if (type == PRIV_PERMITTED)
break;
}
/*
* When we give up privileges not in the inheritable set,
* set SNOCD if not already set; first we compute the
* privileges removed from P using Diff = (~P') & P
* and then we check whether the removed privileges are
* a subset of I. If we retain uid 0, all privileges
* are required anyway so don't set SNOCD.
*/
priv_inverse(&diff);
}
mutex_exit(&p->p_crlock);
if (donocd) {
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
}
/*
* The basic_test privilege should not be removed from E;
* if that has happened, then some programmer typically set the E/P to
* empty. That is not portable.
*/
}
return (0);
}
/*
* getppriv (priv_ptype_t, priv_set_t *)
*/
static int
{
if (!PRIV_VALIDSET(type))
return (0);
}
static int
{
int err;
if (err)
return (0);
}
/*
* Set process flags in the given target cred. If NULL is specified, then
* CRED() is used; otherwise the cred is assumed to be modifiable (i.e. newly
* crdup'ed, or equivalent). Some flags are set in the proc rather than cred;
* for these, curproc is always used.
*
* For now we cheat: the flags are actually bit masks so we can simplify
* some; we do make sure that the arguments are valid, though.
*/
int
{
flag != PRIV_AWARE_RESET)) {
return (EINVAL);
}
if (flag == __PROC_PROTECT) {
mutex_enter(&p->p_lock);
if (val == 0)
else
mutex_exit(&p->p_lock);
return (0);
}
if (use_curcred) {
mutex_enter(&p->p_crlock);
} else {
}
if (val != 0) {
if (flag == PRIV_AWARE)
newflags &= ~PRIV_AWARE_RESET;
} else {
}
/* No change */
if (use_curcred) {
mutex_exit(&p->p_crlock);
}
return (0);
}
/*
* Setting either the NET_MAC_AWARE or NET_MAC_AWARE_INHERIT
* flags is a restricted operation.
*
* When invoked via the PRIVSYS_SETPFLAGS syscall
* we require that the current cred has the net_mac_aware
* privilege in its effective set.
*
* When called from within the kernel by label-aware
* services such as NFS, we don't require a privilege check.
*
*/
if (secpolicy_net_mac_aware(pcr) != 0) {
mutex_exit(&p->p_crlock);
return (EPERM);
}
}
/* Trying to unset PA; if we can't, return an error */
if (use_curcred) {
mutex_exit(&p->p_crlock);
}
return (EPERM);
}
/* Committed to changing the flag */
if (use_curcred)
if (flag == PRIV_AWARE) {
if (val != 0)
else
} else {
}
/*
* Unsetting the flag has as side effect getting rid of
* the per-credential policy.
*/
if (use_curcred) {
mutex_exit(&p->p_crlock);
}
return (0);
}
/*
* Getpflags. Currently only implements single bit flags.
*/
{
return ((uint_t)-1);
}
/*
* Privilege system call entry point
*/
int
int itype)
{
int retv;
extern int issetugid(void);
switch (code) {
case PRIVSYS_SETPPRIV:
if (bufsize < sizeof (priv_set_t))
case PRIVSYS_GETPPRIV:
if (bufsize < sizeof (priv_set_t))
case PRIVSYS_GETIMPLINFO:
case PRIVSYS_SETPFLAGS:
case PRIVSYS_GETPFLAGS:
case PRIVSYS_ISSETUGID:
return (issetugid());
case PRIVSYS_KLPD_REG:
if (bufsize < sizeof (priv_set_t))
buf));
case PRIVSYS_KLPD_UNREG:
}
}
#ifdef _SYSCALL32_IMPL
int
{
}
#endif