2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
12 /* Copyright 2015, Richard Lowe. */
15 #include <sys/errno.h>
16 #include <sys/policy.h>
18 #include <sys/procset.h>
19 #include <sys/systm.h>
20 #include <sys/types.h>
24 psecflagwhich_t which
;
25 const secflagdelta_t
*delta
;
29 secflags_apply_delta(secflagset_t
*set
, const secflagdelta_t
*delta
)
31 if (delta
->psd_ass_active
) {
32 secflags_copy(set
, &delta
->psd_assign
);
34 if (!secflags_isempty(delta
->psd_add
)) {
35 secflags_union(set
, &delta
->psd_add
);
37 if (!secflags_isempty(delta
->psd_rem
)) {
38 secflags_difference(set
, &delta
->psd_rem
);
45 psecdo(proc_t
*p
, struct psdargs
*args
)
50 mutex_enter(&p
->p_lock
);
52 if (secpolicy_psecflags(CRED(), p
, curproc
) != 0) {
57 ASSERT(args
->which
!= PSF_EFFECTIVE
);
59 if (!psecflags_validate_delta(&p
->p_secflags
, args
->delta
)) {
65 audit_psecflags(p
, args
->which
, args
->delta
);
67 switch (args
->which
) {
69 set
= &p
->p_secflags
.psf_inherit
;
72 set
= &p
->p_secflags
.psf_lower
;
75 set
= &p
->p_secflags
.psf_upper
;
79 secflags_apply_delta(set
, args
->delta
);
82 * Add any flag now in the lower that is not in the inheritable.
84 secflags_union(&p
->p_secflags
.psf_inherit
, &p
->p_secflags
.psf_lower
);
87 mutex_exit(&p
->p_lock
);
92 psecflags(procset_t
*psp
, psecflagwhich_t which
, secflagdelta_t
*ap
)
97 struct psdargs psd
= {
101 /* Can never change the effective flags */
102 if (psd
.which
== PSF_EFFECTIVE
)
105 if (copyin(psp
, &procset
, sizeof (procset
)) != 0)
106 return (set_errno(EFAULT
));
108 if (copyin(ap
, &args
, sizeof (secflagdelta_t
)) != 0)
109 return (set_errno(EFAULT
));
113 /* secflags are per-process, procset must be in terms of processes */
114 if ((procset
.p_lidtype
== P_LWPID
) ||
115 (procset
.p_ridtype
== P_LWPID
))
116 return (set_errno(EINVAL
));
118 rv
= dotoprocs(&procset
, psecdo
, (caddr_t
)&psd
);
120 return (rv
? set_errno(rv
) : 0);