mac_cred.c revision 175202
1100894Srwatson/*-
2126097Srwatson * Copyright (c) 1999-2002 Robert N. M. Watson
3100894Srwatson * Copyright (c) 2001 Ilmar S. Habibulin
4126097Srwatson * Copyright (c) 2001-2003 Networks Associates Technology, Inc.
5145147Srwatson * Copyright (c) 2005 Samy Al Bahra
6172930Srwatson * Copyright (c) 2006 SPARTA, Inc.
7100894Srwatson * All rights reserved.
8100894Srwatson *
9100894Srwatson * This software was developed by Robert Watson and Ilmar Habibulin for the
10100894Srwatson * TrustedBSD Project.
11100894Srwatson *
12106392Srwatson * This software was developed for the FreeBSD Project in part by Network
13106392Srwatson * Associates Laboratories, the Security Research Division of Network
14106392Srwatson * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
15106392Srwatson * as part of the DARPA CHATS research program.
16100894Srwatson *
17172930Srwatson * This software was enhanced by SPARTA ISSO under SPAWAR contract
18172930Srwatson * N66001-04-C-6019 ("SEFOS").
19172930Srwatson *
20100894Srwatson * Redistribution and use in source and binary forms, with or without
21100894Srwatson * modification, are permitted provided that the following conditions
22100894Srwatson * are met:
23100894Srwatson * 1. Redistributions of source code must retain the above copyright
24100894Srwatson *    notice, this list of conditions and the following disclaimer.
25100894Srwatson * 2. Redistributions in binary form must reproduce the above copyright
26100894Srwatson *    notice, this list of conditions and the following disclaimer in the
27100894Srwatson *    documentation and/or other materials provided with the distribution.
28100894Srwatson *
29100894Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
30100894Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31100894Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32100894Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
33100894Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34100894Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35100894Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36100894Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37100894Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38100894Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39100894Srwatson * SUCH DAMAGE.
40100894Srwatson */
41116182Sobrien
42116182Sobrien#include <sys/cdefs.h>
43116182Sobrien__FBSDID("$FreeBSD: head/sys/security/mac/mac_process.c 175202 2008-01-10 01:10:58Z attilio $");
44116182Sobrien
45100894Srwatson#include "opt_mac.h"
46101173Srwatson
47100894Srwatson#include <sys/param.h>
48106856Srwatson#include <sys/condvar.h>
49106468Srwatson#include <sys/imgact.h>
50100979Srwatson#include <sys/kernel.h>
51100979Srwatson#include <sys/lock.h>
52102949Sbde#include <sys/malloc.h>
53100979Srwatson#include <sys/mutex.h>
54100979Srwatson#include <sys/mac.h>
55100979Srwatson#include <sys/proc.h>
56116701Srwatson#include <sys/sbuf.h>
57100979Srwatson#include <sys/systm.h>
58100979Srwatson#include <sys/vnode.h>
59100979Srwatson#include <sys/mount.h>
60100979Srwatson#include <sys/file.h>
61100979Srwatson#include <sys/namei.h>
62100979Srwatson#include <sys/sysctl.h>
63100894Srwatson
64100979Srwatson#include <vm/vm.h>
65100979Srwatson#include <vm/pmap.h>
66100979Srwatson#include <vm/vm_map.h>
67100979Srwatson#include <vm/vm_object.h>
68100979Srwatson
69163606Srwatson#include <security/mac/mac_framework.h>
70121361Srwatson#include <security/mac/mac_internal.h>
71165469Srwatson#include <security/mac/mac_policy.h>
72100979Srwatson
73103136Srwatsonstatic int	mac_mmap_revocation = 1;
74103136SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW,
75103136Srwatson    &mac_mmap_revocation, 0, "Revoke mmap access to files on subject "
76103136Srwatson    "relabel");
77121361Srwatson
78101892Srwatsonstatic int	mac_mmap_revocation_via_cow = 0;
79100979SrwatsonSYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW,
80100979Srwatson    &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via "
81100979Srwatson    "copy-on-write semantics, or by removing all write access");
82100979Srwatson
83100979Srwatsonstatic void	mac_cred_mmapped_drop_perms_recurse(struct thread *td,
84100979Srwatson		    struct ucred *cred, struct vm_map *map);
85100979Srwatson
86122524Srwatsonstruct label *
87122524Srwatsonmac_cred_label_alloc(void)
88104521Srwatson{
89122524Srwatson	struct label *label;
90104521Srwatson
91122524Srwatson	label = mac_labelzone_alloc(M_WAITOK);
92172930Srwatson	MAC_PERFORM(cred_init_label, label);
93122524Srwatson	return (label);
94104521Srwatson}
95104521Srwatson
96104521Srwatsonvoid
97172930Srwatsonmac_cred_init(struct ucred *cred)
98105694Srwatson{
99105694Srwatson
100122524Srwatson	cred->cr_label = mac_cred_label_alloc();
101105694Srwatson}
102105694Srwatson
103122524Srwatsonstatic struct label *
104122524Srwatsonmac_proc_label_alloc(void)
105122524Srwatson{
106122524Srwatson	struct label *label;
107122524Srwatson
108122524Srwatson	label = mac_labelzone_alloc(M_WAITOK);
109172930Srwatson	MAC_PERFORM(proc_init_label, label);
110122524Srwatson	return (label);
111122524Srwatson}
112122524Srwatson
113105694Srwatsonvoid
114172930Srwatsonmac_proc_init(struct proc *p)
115107105Srwatson{
116107105Srwatson
117122524Srwatson	p->p_label = mac_proc_label_alloc();
118107105Srwatson}
119107105Srwatson
120105988Srwatsonvoid
121122524Srwatsonmac_cred_label_free(struct label *label)
122104521Srwatson{
123104521Srwatson
124172930Srwatson	MAC_PERFORM(cred_destroy_label, label);
125122524Srwatson	mac_labelzone_free(label);
126104521Srwatson}
127104521Srwatson
128104521Srwatsonvoid
129172930Srwatsonmac_cred_destroy(struct ucred *cred)
130105694Srwatson{
131105694Srwatson
132122524Srwatson	mac_cred_label_free(cred->cr_label);
133122524Srwatson	cred->cr_label = NULL;
134105694Srwatson}
135105694Srwatson
136122524Srwatsonstatic void
137122524Srwatsonmac_proc_label_free(struct label *label)
138122524Srwatson{
139122524Srwatson
140172930Srwatson	MAC_PERFORM(proc_destroy_label, label);
141122524Srwatson	mac_labelzone_free(label);
142122524Srwatson}
143122524Srwatson
144105694Srwatsonvoid
145172930Srwatsonmac_proc_destroy(struct proc *p)
146107105Srwatson{
147107105Srwatson
148122524Srwatson	mac_proc_label_free(p->p_label);
149122524Srwatson	p->p_label = NULL;
150107105Srwatson}
151107105Srwatson
152121361Srwatsonint
153172930Srwatsonmac_cred_externalize_label(struct label *label, char *elements,
154122159Srwatson    char *outbuf, size_t outbuflen)
155105694Srwatson{
156104522Srwatson	int error;
157104522Srwatson
158121507Srwatson	MAC_EXTERNALIZE(cred, label, elements, outbuf, outbuflen);
159104522Srwatson
160104522Srwatson	return (error);
161104522Srwatson}
162104522Srwatson
163121361Srwatsonint
164172930Srwatsonmac_cred_internalize_label(struct label *label, char *string)
165105694Srwatson{
166105694Srwatson	int error;
167105694Srwatson
168121507Srwatson	MAC_INTERNALIZE(cred, label, string);
169105694Srwatson
170105694Srwatson	return (error);
171105694Srwatson}
172105694Srwatson
173104522Srwatson/*
174165425Srwatson * Initialize MAC label for the first kernel process, from which other kernel
175165425Srwatson * processes and threads are spawned.
176104522Srwatson */
177104521Srwatsonvoid
178172930Srwatsonmac_proc_create_swapper(struct ucred *cred)
179104522Srwatson{
180104522Srwatson
181172930Srwatson	MAC_PERFORM(proc_create_swapper, cred);
182104522Srwatson}
183104522Srwatson
184104522Srwatson/*
185104522Srwatson * Initialize MAC label for the first userland process, from which other
186104522Srwatson * userland processes and threads are spawned.
187104522Srwatson */
188104522Srwatsonvoid
189172930Srwatsonmac_proc_create_init(struct ucred *cred)
190104522Srwatson{
191104522Srwatson
192172930Srwatson	MAC_PERFORM(proc_create_init, cred);
193104522Srwatson}
194104522Srwatson
195172957Srwatson/*
196172957Srwatson * When a thread becomes an NFS server daemon, its credential may need to be
197172957Srwatson * updated to reflect this so that policies can recognize when file system
198172957Srwatson * operations originate from the network.
199172957Srwatson *
200172957Srwatson * At some point, it would be desirable if the credential used for each NFS
201172957Srwatson * RPC could be set based on the RPC context (i.e., source system, etc) to
202172957Srwatson * provide more fine-grained access control.
203172957Srwatson */
204104522Srwatsonvoid
205172957Srwatsonmac_proc_associate_nfsd(struct ucred *cred)
206172957Srwatson{
207172957Srwatson
208172957Srwatson	MAC_PERFORM(proc_associate_nfsd, cred);
209172957Srwatson}
210172957Srwatson
211172957Srwatsonvoid
212104522Srwatsonmac_thread_userret(struct thread *td)
213104522Srwatson{
214104522Srwatson
215104522Srwatson	MAC_PERFORM(thread_userret, td);
216104522Srwatson}
217104522Srwatson
218104522Srwatson/*
219104522Srwatson * When a new process is created, its label must be initialized.  Generally,
220165425Srwatson * this involves inheritence from the parent process, modulo possible deltas.
221165425Srwatson * This function allows that processing to take place.
222104522Srwatson */
223104522Srwatsonvoid
224172930Srwatsonmac_cred_copy(struct ucred *src, struct ucred *dest)
225104522Srwatson{
226104522Srwatson
227172930Srwatson	MAC_PERFORM(cred_copy_label, src->cr_label, dest->cr_label);
228104522Srwatson}
229104522Srwatson
230105988Srwatsonint
231122524Srwatsonmac_execve_enter(struct image_params *imgp, struct mac *mac_p)
232106468Srwatson{
233122524Srwatson	struct label *label;
234106468Srwatson	struct mac mac;
235106468Srwatson	char *buffer;
236106468Srwatson	int error;
237106468Srwatson
238106468Srwatson	if (mac_p == NULL)
239106468Srwatson		return (0);
240106468Srwatson
241106468Srwatson	error = copyin(mac_p, &mac, sizeof(mac));
242106468Srwatson	if (error)
243106468Srwatson		return (error);
244106468Srwatson
245106468Srwatson	error = mac_check_structmac_consistent(&mac);
246106468Srwatson	if (error)
247106468Srwatson		return (error);
248106468Srwatson
249111119Simp	buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
250106468Srwatson	error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
251106468Srwatson	if (error) {
252106468Srwatson		free(buffer, M_MACTEMP);
253106468Srwatson		return (error);
254106468Srwatson	}
255106468Srwatson
256122524Srwatson	label = mac_cred_label_alloc();
257172930Srwatson	error = mac_cred_internalize_label(label, buffer);
258106468Srwatson	free(buffer, M_MACTEMP);
259106468Srwatson	if (error) {
260122524Srwatson		mac_cred_label_free(label);
261106468Srwatson		return (error);
262106468Srwatson	}
263122524Srwatson	imgp->execlabel = label;
264106468Srwatson	return (0);
265106468Srwatson}
266106468Srwatson
267100979Srwatsonvoid
268106468Srwatsonmac_execve_exit(struct image_params *imgp)
269100979Srwatson{
270122524Srwatson	if (imgp->execlabel != NULL) {
271122524Srwatson		mac_cred_label_free(imgp->execlabel);
272122524Srwatson		imgp->execlabel = NULL;
273122524Srwatson	}
274106468Srwatson}
275100979Srwatson
276100979Srwatson/*
277100979Srwatson * When relabeling a process, call out to the policies for the maximum
278165425Srwatson * permission allowed for each object type we know about in its memory space,
279165425Srwatson * and revoke access (in the least surprising ways we know) when necessary.
280165425Srwatson * The process lock is not held here.
281100979Srwatson */
282107271Srwatsonvoid
283100979Srwatsonmac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred)
284100979Srwatson{
285100979Srwatson
286100979Srwatson	/* XXX freeze all other threads */
287100979Srwatson	mac_cred_mmapped_drop_perms_recurse(td, cred,
288100979Srwatson	    &td->td_proc->p_vmspace->vm_map);
289100979Srwatson	/* XXX allow other threads to continue */
290100979Srwatson}
291100979Srwatson
292100979Srwatsonstatic __inline const char *
293100979Srwatsonprot2str(vm_prot_t prot)
294100979Srwatson{
295100979Srwatson
296100979Srwatson	switch (prot & VM_PROT_ALL) {
297100979Srwatson	case VM_PROT_READ:
298100979Srwatson		return ("r--");
299100979Srwatson	case VM_PROT_READ | VM_PROT_WRITE:
300100979Srwatson		return ("rw-");
301100979Srwatson	case VM_PROT_READ | VM_PROT_EXECUTE:
302100979Srwatson		return ("r-x");
303100979Srwatson	case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
304100979Srwatson		return ("rwx");
305100979Srwatson	case VM_PROT_WRITE:
306100979Srwatson		return ("-w-");
307100979Srwatson	case VM_PROT_EXECUTE:
308100979Srwatson		return ("--x");
309100979Srwatson	case VM_PROT_WRITE | VM_PROT_EXECUTE:
310100979Srwatson		return ("-wx");
311100979Srwatson	default:
312100979Srwatson		return ("---");
313100979Srwatson	}
314100979Srwatson}
315100979Srwatson
316100979Srwatsonstatic void
317100979Srwatsonmac_cred_mmapped_drop_perms_recurse(struct thread *td, struct ucred *cred,
318100979Srwatson    struct vm_map *map)
319100979Srwatson{
320100979Srwatson	struct vm_map_entry *vme;
321150913Scsjp	int vfslocked, result;
322104546Srwatson	vm_prot_t revokeperms;
323151115Scsjp	vm_object_t backing_object, object;
324100979Srwatson	vm_ooffset_t offset;
325100979Srwatson	struct vnode *vp;
326156225Stegge	struct mount *mp;
327100979Srwatson
328103136Srwatson	if (!mac_mmap_revocation)
329103136Srwatson		return;
330103136Srwatson
331100979Srwatson	vm_map_lock_read(map);
332100979Srwatson	for (vme = map->header.next; vme != &map->header; vme = vme->next) {
333100979Srwatson		if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) {
334100979Srwatson			mac_cred_mmapped_drop_perms_recurse(td, cred,
335100979Srwatson			    vme->object.sub_map);
336100979Srwatson			continue;
337100979Srwatson		}
338100979Srwatson		/*
339100979Srwatson		 * Skip over entries that obviously are not shared.
340100979Srwatson		 */
341100979Srwatson		if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) ||
342100979Srwatson		    !vme->max_protection)
343100979Srwatson			continue;
344100979Srwatson		/*
345100979Srwatson		 * Drill down to the deepest backing object.
346100979Srwatson		 */
347100979Srwatson		offset = vme->offset;
348100979Srwatson		object = vme->object.vm_object;
349100979Srwatson		if (object == NULL)
350100979Srwatson			continue;
351151115Scsjp		VM_OBJECT_LOCK(object);
352151115Scsjp		while ((backing_object = object->backing_object) != NULL) {
353151115Scsjp			VM_OBJECT_LOCK(backing_object);
354150923Scsjp			offset += object->backing_object_offset;
355151115Scsjp			VM_OBJECT_UNLOCK(object);
356151115Scsjp			object = backing_object;
357100979Srwatson		}
358151115Scsjp		VM_OBJECT_UNLOCK(object);
359100979Srwatson		/*
360165425Srwatson		 * At the moment, vm_maps and objects aren't considered by
361165425Srwatson		 * the MAC system, so only things with backing by a normal
362165425Srwatson		 * object (read: vnodes) are checked.
363100979Srwatson		 */
364100979Srwatson		if (object->type != OBJT_VNODE)
365100979Srwatson			continue;
366100979Srwatson		vp = (struct vnode *)object->handle;
367150913Scsjp		vfslocked = VFS_LOCK_GIANT(vp->v_mount);
368175202Sattilio		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
369104546Srwatson		result = vme->max_protection;
370172930Srwatson		mac_vnode_check_mmap_downgrade(cred, vp, &result);
371100979Srwatson		VOP_UNLOCK(vp, 0, td);
372100979Srwatson		/*
373165425Srwatson		 * Find out what maximum protection we may be allowing now
374165425Srwatson		 * but a policy needs to get removed.
375100979Srwatson		 */
376100979Srwatson		revokeperms = vme->max_protection & ~result;
377150913Scsjp		if (!revokeperms) {
378150913Scsjp			VFS_UNLOCK_GIANT(vfslocked);
379100979Srwatson			continue;
380150913Scsjp		}
381102949Sbde		printf("pid %ld: revoking %s perms from %#lx:%ld "
382102949Sbde		    "(max %s/cur %s)\n", (long)td->td_proc->p_pid,
383102949Sbde		    prot2str(revokeperms), (u_long)vme->start,
384102949Sbde		    (long)(vme->end - vme->start),
385100979Srwatson		    prot2str(vme->max_protection), prot2str(vme->protection));
386100979Srwatson		vm_map_lock_upgrade(map);
387100979Srwatson		/*
388100979Srwatson		 * This is the really simple case: if a map has more
389100979Srwatson		 * max_protection than is allowed, but it's not being
390165425Srwatson		 * actually used (that is, the current protection is still
391165425Srwatson		 * allowed), we can just wipe it out and do nothing more.
392100979Srwatson		 */
393100979Srwatson		if ((vme->protection & revokeperms) == 0) {
394100979Srwatson			vme->max_protection -= revokeperms;
395100979Srwatson		} else {
396100979Srwatson			if (revokeperms & VM_PROT_WRITE) {
397100979Srwatson				/*
398100979Srwatson				 * In the more complicated case, flush out all
399100979Srwatson				 * pending changes to the object then turn it
400100979Srwatson				 * copy-on-write.
401100979Srwatson				 */
402100979Srwatson				vm_object_reference(object);
403156225Stegge				(void) vn_start_write(vp, &mp, V_WAIT);
404175202Sattilio				vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
405113955Salc				VM_OBJECT_LOCK(object);
406100979Srwatson				vm_object_page_clean(object,
407100979Srwatson				    OFF_TO_IDX(offset),
408100979Srwatson				    OFF_TO_IDX(offset + vme->end - vme->start +
409100979Srwatson					PAGE_MASK),
410100979Srwatson				    OBJPC_SYNC);
411113955Salc				VM_OBJECT_UNLOCK(object);
412100979Srwatson				VOP_UNLOCK(vp, 0, td);
413156225Stegge				vn_finished_write(mp);
414100979Srwatson				vm_object_deallocate(object);
415100979Srwatson				/*
416100979Srwatson				 * Why bother if there's no read permissions
417100979Srwatson				 * anymore?  For the rest, we need to leave
418100979Srwatson				 * the write permissions on for COW, or
419100979Srwatson				 * remove them entirely if configured to.
420100979Srwatson				 */
421100979Srwatson				if (!mac_mmap_revocation_via_cow) {
422100979Srwatson					vme->max_protection &= ~VM_PROT_WRITE;
423100979Srwatson					vme->protection &= ~VM_PROT_WRITE;
424100979Srwatson				} if ((revokeperms & VM_PROT_READ) == 0)
425100979Srwatson					vme->eflags |= MAP_ENTRY_COW |
426100979Srwatson					    MAP_ENTRY_NEEDS_COPY;
427100979Srwatson			}
428100979Srwatson			if (revokeperms & VM_PROT_EXECUTE) {
429100979Srwatson				vme->max_protection &= ~VM_PROT_EXECUTE;
430100979Srwatson				vme->protection &= ~VM_PROT_EXECUTE;
431100979Srwatson			}
432100979Srwatson			if (revokeperms & VM_PROT_READ) {
433100979Srwatson				vme->max_protection = 0;
434100979Srwatson				vme->protection = 0;
435100979Srwatson			}
436100979Srwatson			pmap_protect(map->pmap, vme->start, vme->end,
437100979Srwatson			    vme->protection & ~revokeperms);
438100979Srwatson			vm_map_simplify_entry(map, vme);
439100979Srwatson		}
440100979Srwatson		vm_map_lock_downgrade(map);
441150913Scsjp		VFS_UNLOCK_GIANT(vfslocked);
442100979Srwatson	}
443100979Srwatson	vm_map_unlock_read(map);
444100979Srwatson}
445100979Srwatson
446100979Srwatson/*
447100979Srwatson * When the subject's label changes, it may require revocation of privilege
448100979Srwatson * to mapped objects.  This can't be done on-the-fly later with a unified
449100979Srwatson * buffer cache.
450100979Srwatson */
451121361Srwatsonvoid
452172930Srwatsonmac_cred_relabel(struct ucred *cred, struct label *newlabel)
453100979Srwatson{
454100979Srwatson
455172930Srwatson	MAC_PERFORM(cred_relabel, cred, newlabel);
456100979Srwatson}
457100979Srwatson
458100979Srwatsonint
459172930Srwatsonmac_cred_check_relabel(struct ucred *cred, struct label *newlabel)
460100979Srwatson{
461100979Srwatson	int error;
462100979Srwatson
463172930Srwatson	MAC_CHECK(cred_check_relabel, cred, newlabel);
464100979Srwatson
465100979Srwatson	return (error);
466100979Srwatson}
467100979Srwatson
468100979Srwatsonint
469172930Srwatsonmac_cred_check_visible(struct ucred *cr1, struct ucred *cr2)
470100979Srwatson{
471100979Srwatson	int error;
472100979Srwatson
473172930Srwatson	MAC_CHECK(cred_check_visible, cr1, cr2);
474100979Srwatson
475100979Srwatson	return (error);
476100979Srwatson}
477100979Srwatson
478100979Srwatsonint
479172930Srwatsonmac_proc_check_debug(struct ucred *cred, struct proc *p)
480100979Srwatson{
481100979Srwatson	int error;
482100979Srwatson
483168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
484102103Srwatson
485172930Srwatson	MAC_CHECK(proc_check_debug, cred, p);
486100979Srwatson
487100979Srwatson	return (error);
488100979Srwatson}
489100979Srwatson
490100979Srwatsonint
491172930Srwatsonmac_proc_check_sched(struct ucred *cred, struct proc *p)
492100979Srwatson{
493100979Srwatson	int error;
494100979Srwatson
495168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
496102103Srwatson
497172930Srwatson	MAC_CHECK(proc_check_sched, cred, p);
498100979Srwatson
499100979Srwatson	return (error);
500100979Srwatson}
501100979Srwatson
502100979Srwatsonint
503172930Srwatsonmac_proc_check_signal(struct ucred *cred, struct proc *p, int signum)
504100979Srwatson{
505100979Srwatson	int error;
506100979Srwatson
507168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
508102103Srwatson
509172930Srwatson	MAC_CHECK(proc_check_signal, cred, p, signum);
510100979Srwatson
511100979Srwatson	return (error);
512100979Srwatson}
513145147Srwatson
514145147Srwatsonint
515172930Srwatsonmac_proc_check_setuid(struct proc *p, struct ucred *cred, uid_t uid)
516145147Srwatson{
517145147Srwatson	int error;
518145147Srwatson
519168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
520145147Srwatson
521172930Srwatson	MAC_CHECK(proc_check_setuid, cred, uid);
522145147Srwatson	return (error);
523145147Srwatson}
524145147Srwatson
525145147Srwatsonint
526172930Srwatsonmac_proc_check_seteuid(struct proc *p, struct ucred *cred, uid_t euid)
527145147Srwatson{
528145147Srwatson	int error;
529145147Srwatson
530168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
531145147Srwatson
532172930Srwatson	MAC_CHECK(proc_check_seteuid, cred, euid);
533145147Srwatson	return (error);
534145147Srwatson}
535145147Srwatson
536145147Srwatsonint
537172930Srwatsonmac_proc_check_setgid(struct proc *p, struct ucred *cred, gid_t gid)
538145147Srwatson{
539145147Srwatson	int error;
540145147Srwatson
541168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
542145147Srwatson
543172930Srwatson	MAC_CHECK(proc_check_setgid, cred, gid);
544168955Srwatson
545145147Srwatson	return (error);
546145147Srwatson}
547145147Srwatson
548145147Srwatsonint
549172930Srwatsonmac_proc_check_setegid(struct proc *p, struct ucred *cred, gid_t egid)
550145147Srwatson{
551145147Srwatson	int error;
552145147Srwatson
553168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
554145147Srwatson
555172930Srwatson	MAC_CHECK(proc_check_setegid, cred, egid);
556168955Srwatson
557145147Srwatson	return (error);
558145147Srwatson}
559145147Srwatson
560145147Srwatsonint
561172930Srwatsonmac_proc_check_setgroups(struct proc *p, struct ucred *cred, int ngroups,
562168955Srwatson    gid_t *gidset)
563145147Srwatson{
564145147Srwatson	int error;
565145147Srwatson
566168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
567145147Srwatson
568172930Srwatson	MAC_CHECK(proc_check_setgroups, cred, ngroups, gidset);
569145147Srwatson	return (error);
570145147Srwatson}
571145147Srwatson
572145147Srwatsonint
573172930Srwatsonmac_proc_check_setreuid(struct proc *p, struct ucred *cred, uid_t ruid,
574168955Srwatson    uid_t euid)
575145147Srwatson{
576145147Srwatson	int error;
577145147Srwatson
578168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
579145147Srwatson
580172930Srwatson	MAC_CHECK(proc_check_setreuid, cred, ruid, euid);
581168955Srwatson
582145147Srwatson	return (error);
583145147Srwatson}
584145147Srwatson
585145147Srwatsonint
586172930Srwatsonmac_proc_check_setregid(struct proc *proc, struct ucred *cred, gid_t rgid,
587168955Srwatson    gid_t egid)
588145147Srwatson{
589145147Srwatson	int error;
590145147Srwatson
591145147Srwatson	PROC_LOCK_ASSERT(proc, MA_OWNED);
592145147Srwatson
593172930Srwatson	MAC_CHECK(proc_check_setregid, cred, rgid, egid);
594168955Srwatson
595145147Srwatson	return (error);
596145147Srwatson}
597145147Srwatson
598145147Srwatsonint
599172930Srwatsonmac_proc_check_setresuid(struct proc *p, struct ucred *cred, uid_t ruid,
600168955Srwatson    uid_t euid, uid_t suid)
601145147Srwatson{
602145147Srwatson	int error;
603145147Srwatson
604168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
605145147Srwatson
606172930Srwatson	MAC_CHECK(proc_check_setresuid, cred, ruid, euid, suid);
607145147Srwatson	return (error);
608145147Srwatson}
609145147Srwatson
610145147Srwatsonint
611172930Srwatsonmac_proc_check_setresgid(struct proc *p, struct ucred *cred, gid_t rgid,
612168955Srwatson    gid_t egid, gid_t sgid)
613145147Srwatson{
614145147Srwatson	int error;
615145147Srwatson
616168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
617145147Srwatson
618172930Srwatson	MAC_CHECK(proc_check_setresgid, cred, rgid, egid, sgid);
619168955Srwatson
620145147Srwatson	return (error);
621145147Srwatson}
622145234Srwatson
623145234Srwatsonint
624172930Srwatsonmac_proc_check_wait(struct ucred *cred, struct proc *p)
625145234Srwatson{
626145234Srwatson	int error;
627145234Srwatson
628168955Srwatson	PROC_LOCK_ASSERT(p, MA_OWNED);
629145234Srwatson
630172930Srwatson	MAC_CHECK(proc_check_wait, cred, p);
631145234Srwatson
632145234Srwatson	return (error);
633145234Srwatson}
634