ugidfw_system.c revision 172930
1/*-
2 * Copyright (c) 1999-2002, 2007 Robert N. M. Watson
3 * Copyright (c) 2001-2005 Networks Associates Technology, Inc.
4 * Copyright (c) 2005 Tom Rhodes
5 * Copyright (c) 2006 SPARTA, Inc.
6 * All rights reserved.
7 *
8 * This software was developed by Robert Watson for the TrustedBSD Project.
9 * It was later enhanced by Tom Rhodes for the TrustedBSD Project.
10 *
11 * This software was developed for the FreeBSD Project in part by Network
12 * Associates Laboratories, the Security Research Division of Network
13 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
14 * as part of the DARPA CHATS research program.
15 *
16 * This software was enhanced by SPARTA ISSO under SPAWAR contract
17 * N66001-04-C-6019 ("SEFOS").
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 * 1. Redistributions of source code must retain the above copyright
23 *    notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 *    notice, this list of conditions and the following disclaimer in the
26 *    documentation and/or other materials provided with the distribution.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * $FreeBSD: head/sys/security/mac_bsdextended/mac_bsdextended.c 172930 2007-10-24 19:04:04Z rwatson $
41 */
42
43/*
44 * Developed by the TrustedBSD Project.
45 *
46 * "BSD Extended" MAC policy, allowing the administrator to impose mandatory
47 * firewall-like rules regarding users and file system objects.
48 */
49
50#include <sys/param.h>
51#include <sys/acl.h>
52#include <sys/kernel.h>
53#include <sys/jail.h>
54#include <sys/lock.h>
55#include <sys/malloc.h>
56#include <sys/module.h>
57#include <sys/mount.h>
58#include <sys/mutex.h>
59#include <sys/priv.h>
60#include <sys/systm.h>
61#include <sys/vnode.h>
62#include <sys/sysctl.h>
63#include <sys/syslog.h>
64
65#include <security/mac/mac_policy.h>
66#include <security/mac_bsdextended/mac_bsdextended.h>
67
68static struct mtx mac_bsdextended_mtx;
69
70SYSCTL_DECL(_security_mac);
71
72SYSCTL_NODE(_security_mac, OID_AUTO, bsdextended, CTLFLAG_RW, 0,
73    "TrustedBSD extended BSD MAC policy controls");
74
75static int	mac_bsdextended_enabled = 1;
76SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, enabled, CTLFLAG_RW,
77    &mac_bsdextended_enabled, 0, "Enforce extended BSD policy");
78TUNABLE_INT("security.mac.bsdextended.enabled", &mac_bsdextended_enabled);
79
80MALLOC_DEFINE(M_MACBSDEXTENDED, "mac_bsdextended", "BSD Extended MAC rule");
81
82#define	MAC_BSDEXTENDED_MAXRULES	250
83static struct mac_bsdextended_rule *rules[MAC_BSDEXTENDED_MAXRULES];
84static int rule_count = 0;
85static int rule_slots = 0;
86static int rule_version = MB_VERSION;
87
88SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, rule_count, CTLFLAG_RD,
89    &rule_count, 0, "Number of defined rules\n");
90SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, rule_slots, CTLFLAG_RD,
91    &rule_slots, 0, "Number of used rule slots\n");
92SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, rule_version, CTLFLAG_RD,
93    &rule_version, 0, "Version number for API\n");
94
95/*
96 * This is just used for logging purposes, eventually we would like to log
97 * much more then failed requests.
98 */
99static int mac_bsdextended_logging;
100SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, logging, CTLFLAG_RW,
101    &mac_bsdextended_logging, 0, "Log failed authorization requests");
102
103/*
104 * This tunable is here for compatibility.  It will allow the user to switch
105 * between the new mode (first rule matches) and the old functionality (all
106 * rules match).
107 */
108static int
109mac_bsdextended_firstmatch_enabled;
110SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, firstmatch_enabled,
111    CTLFLAG_RW, &mac_bsdextended_firstmatch_enabled, 1,
112    "Disable/enable match first rule functionality");
113
114static int
115mac_bsdextended_rule_valid(struct mac_bsdextended_rule *rule)
116{
117
118	if ((rule->mbr_subject.mbs_flags | MBS_ALL_FLAGS) != MBS_ALL_FLAGS)
119		return (EINVAL);
120	if ((rule->mbr_subject.mbs_neg | MBS_ALL_FLAGS) != MBS_ALL_FLAGS)
121		return (EINVAL);
122	if ((rule->mbr_object.mbo_flags | MBO_ALL_FLAGS) != MBO_ALL_FLAGS)
123		return (EINVAL);
124	if ((rule->mbr_object.mbo_neg | MBO_ALL_FLAGS) != MBO_ALL_FLAGS)
125		return (EINVAL);
126	if ((rule->mbr_object.mbo_neg | MBO_TYPE_DEFINED) &&
127	    (rule->mbr_object.mbo_type | MBO_ALL_TYPE) != MBO_ALL_TYPE)
128		return (EINVAL);
129	if ((rule->mbr_mode | MBI_ALLPERM) != MBI_ALLPERM)
130		return (EINVAL);
131	return (0);
132}
133
134static int
135sysctl_rule(SYSCTL_HANDLER_ARGS)
136{
137	struct mac_bsdextended_rule temprule, *ruleptr;
138	u_int namelen;
139	int error, index, *name;
140
141	error = 0;
142	name = (int *)arg1;
143	namelen = arg2;
144	if (namelen != 1)
145		return (EINVAL);
146	index = name[0];
147        if (index >= MAC_BSDEXTENDED_MAXRULES)
148		return (ENOENT);
149
150	ruleptr = NULL;
151	if (req->newptr && req->newlen != 0) {
152		error = SYSCTL_IN(req, &temprule, sizeof(temprule));
153		if (error)
154			return (error);
155		MALLOC(ruleptr, struct mac_bsdextended_rule *,
156		    sizeof(*ruleptr), M_MACBSDEXTENDED, M_WAITOK | M_ZERO);
157	}
158
159	mtx_lock(&mac_bsdextended_mtx);
160	if (req->oldptr) {
161		if (index < 0 || index > rule_slots + 1) {
162			error = ENOENT;
163			goto out;
164		}
165		if (rules[index] == NULL) {
166			error = ENOENT;
167			goto out;
168		}
169		temprule = *rules[index];
170	}
171	if (req->newptr && req->newlen == 0) {
172		KASSERT(ruleptr == NULL, ("sysctl_rule: ruleptr != NULL"));
173		ruleptr = rules[index];
174		if (ruleptr == NULL) {
175			error = ENOENT;
176			goto out;
177		}
178		rule_count--;
179		rules[index] = NULL;
180	} else if (req->newptr) {
181		error = mac_bsdextended_rule_valid(&temprule);
182		if (error)
183			goto out;
184		if (rules[index] == NULL) {
185			*ruleptr = temprule;
186			rules[index] = ruleptr;
187			ruleptr = NULL;
188			if (index + 1 > rule_slots)
189				rule_slots = index + 1;
190			rule_count++;
191		} else
192			*rules[index] = temprule;
193	}
194out:
195	mtx_unlock(&mac_bsdextended_mtx);
196	if (ruleptr != NULL)
197		FREE(ruleptr, M_MACBSDEXTENDED);
198	if (req->oldptr && error == 0)
199		error = SYSCTL_OUT(req, &temprule, sizeof(temprule));
200	return (error);
201}
202
203SYSCTL_NODE(_security_mac_bsdextended, OID_AUTO, rules, CTLFLAG_RW,
204    sysctl_rule, "BSD extended MAC rules");
205
206static void
207mac_bsdextended_init(struct mac_policy_conf *mpc)
208{
209
210	mtx_init(&mac_bsdextended_mtx, "mac_bsdextended lock", NULL, MTX_DEF);
211}
212
213static void
214mac_bsdextended_destroy(struct mac_policy_conf *mpc)
215{
216
217	mtx_destroy(&mac_bsdextended_mtx);
218}
219
220static int
221mac_bsdextended_rulecheck(struct mac_bsdextended_rule *rule,
222    struct ucred *cred, struct vnode *vp, struct vattr *vap, int acc_mode)
223{
224	int match;
225	int i;
226
227	/*
228	 * Is there a subject match?
229	 */
230	mtx_assert(&mac_bsdextended_mtx, MA_OWNED);
231	if (rule->mbr_subject.mbs_flags & MBS_UID_DEFINED) {
232		match =  ((cred->cr_uid <= rule->mbr_subject.mbs_uid_max &&
233		    cred->cr_uid >= rule->mbr_subject.mbs_uid_min) ||
234		    (cred->cr_ruid <= rule->mbr_subject.mbs_uid_max &&
235		    cred->cr_ruid >= rule->mbr_subject.mbs_uid_min) ||
236		    (cred->cr_svuid <= rule->mbr_subject.mbs_uid_max &&
237		    cred->cr_svuid >= rule->mbr_subject.mbs_uid_min));
238		if (rule->mbr_subject.mbs_neg & MBS_UID_DEFINED)
239			match = !match;
240		if (!match)
241			return (0);
242	}
243
244	if (rule->mbr_subject.mbs_flags & MBS_GID_DEFINED) {
245		match = ((cred->cr_rgid <= rule->mbr_subject.mbs_gid_max &&
246		    cred->cr_rgid >= rule->mbr_subject.mbs_gid_min) ||
247		    (cred->cr_svgid <= rule->mbr_subject.mbs_gid_max &&
248		    cred->cr_svgid >= rule->mbr_subject.mbs_gid_min));
249		if (!match) {
250			for (i = 0; i < cred->cr_ngroups; i++) {
251				if (cred->cr_groups[i]
252				    <= rule->mbr_subject.mbs_gid_max &&
253				    cred->cr_groups[i]
254				    >= rule->mbr_subject.mbs_gid_min) {
255					match = 1;
256					break;
257				}
258			}
259		}
260		if (rule->mbr_subject.mbs_neg & MBS_GID_DEFINED)
261			match = !match;
262		if (!match)
263			return (0);
264	}
265
266	if (rule->mbr_subject.mbs_flags & MBS_PRISON_DEFINED) {
267		match = (cred->cr_prison != NULL &&
268		    cred->cr_prison->pr_id == rule->mbr_subject.mbs_prison);
269		if (rule->mbr_subject.mbs_neg & MBS_PRISON_DEFINED)
270			match = !match;
271		if (!match)
272			return (0);
273	}
274
275	/*
276	 * Is there an object match?
277	 */
278	if (rule->mbr_object.mbo_flags & MBO_UID_DEFINED) {
279		match = (vap->va_uid <= rule->mbr_object.mbo_uid_max &&
280		    vap->va_uid >= rule->mbr_object.mbo_uid_min);
281		if (rule->mbr_object.mbo_neg & MBO_UID_DEFINED)
282			match = !match;
283		if (!match)
284			return (0);
285	}
286
287	if (rule->mbr_object.mbo_flags & MBO_GID_DEFINED) {
288		match = (vap->va_gid <= rule->mbr_object.mbo_gid_max &&
289		    vap->va_gid >= rule->mbr_object.mbo_gid_min);
290		if (rule->mbr_object.mbo_neg & MBO_GID_DEFINED)
291			match = !match;
292		if (!match)
293			return (0);
294	}
295
296	if (rule->mbr_object.mbo_flags & MBO_FSID_DEFINED) {
297		match = (bcmp(&(vp->v_mount->mnt_stat.f_fsid),
298		    &(rule->mbr_object.mbo_fsid),
299		    sizeof(rule->mbr_object.mbo_fsid)) == 0);
300		if (rule->mbr_object.mbo_neg & MBO_FSID_DEFINED)
301			match = !match;
302		if (!match)
303			return (0);
304	}
305
306	if (rule->mbr_object.mbo_flags & MBO_SUID) {
307		match = (vap->va_mode & VSUID);
308		if (rule->mbr_object.mbo_neg & MBO_SUID)
309			match = !match;
310		if (!match)
311			return (0);
312	}
313
314	if (rule->mbr_object.mbo_flags & MBO_SGID) {
315		match = (vap->va_mode & VSGID);
316		if (rule->mbr_object.mbo_neg & MBO_SGID)
317			match = !match;
318		if (!match)
319			return (0);
320	}
321
322	if (rule->mbr_object.mbo_flags & MBO_UID_SUBJECT) {
323		match = (vap->va_uid == cred->cr_uid ||
324		    vap->va_uid == cred->cr_ruid ||
325		    vap->va_uid == cred->cr_svuid);
326		if (rule->mbr_object.mbo_neg & MBO_UID_SUBJECT)
327			match = !match;
328		if (!match)
329			return (0);
330	}
331
332	if (rule->mbr_object.mbo_flags & MBO_GID_SUBJECT) {
333		match = (groupmember(vap->va_gid, cred) ||
334		    vap->va_gid == cred->cr_rgid ||
335		    vap->va_gid == cred->cr_svgid);
336		if (rule->mbr_object.mbo_neg & MBO_GID_SUBJECT)
337			match = !match;
338		if (!match)
339			return (0);
340	}
341
342	if (rule->mbr_object.mbo_flags & MBO_TYPE_DEFINED) {
343		switch (vap->va_type) {
344		case VREG:
345			match = (rule->mbr_object.mbo_type & MBO_TYPE_REG);
346			break;
347		case VDIR:
348			match = (rule->mbr_object.mbo_type & MBO_TYPE_DIR);
349			break;
350		case VBLK:
351			match = (rule->mbr_object.mbo_type & MBO_TYPE_BLK);
352			break;
353		case VCHR:
354			match = (rule->mbr_object.mbo_type & MBO_TYPE_CHR);
355			break;
356		case VLNK:
357			match = (rule->mbr_object.mbo_type & MBO_TYPE_LNK);
358			break;
359		case VSOCK:
360			match = (rule->mbr_object.mbo_type & MBO_TYPE_SOCK);
361			break;
362		case VFIFO:
363			match = (rule->mbr_object.mbo_type & MBO_TYPE_FIFO);
364			break;
365		default:
366			match = 0;
367		}
368		if (rule->mbr_object.mbo_neg & MBO_TYPE_DEFINED)
369			match = !match;
370		if (!match)
371			return (0);
372	}
373
374	/*
375	 * Is the access permitted?
376	 */
377	if ((rule->mbr_mode & acc_mode) != acc_mode) {
378		if (mac_bsdextended_logging)
379			log(LOG_AUTHPRIV, "mac_bsdextended: %d:%d request %d"
380			    " on %d:%d failed. \n", cred->cr_ruid,
381			    cred->cr_rgid, acc_mode, vap->va_uid,
382			    vap->va_gid);
383		return (EACCES);
384	}
385
386	/*
387	 * If the rule matched, permits access, and first match is enabled,
388	 * return success.
389	 */
390	if (mac_bsdextended_firstmatch_enabled)
391		return (EJUSTRETURN);
392	else
393		return (0);
394}
395
396static int
397mac_bsdextended_check(struct ucred *cred, struct vnode *vp, struct vattr *vap,
398    int acc_mode)
399{
400	int error, i;
401
402	/*
403	 * XXXRW: More specific privilege selection needed.
404	 */
405	if (suser_cred(cred, 0) == 0)
406		return (0);
407
408	/*
409	 * Since we do not separately handle append, map append to write.
410	 */
411	if (acc_mode & MBI_APPEND) {
412		acc_mode &= ~MBI_APPEND;
413		acc_mode |= MBI_WRITE;
414	}
415	mtx_lock(&mac_bsdextended_mtx);
416	for (i = 0; i < rule_slots; i++) {
417		if (rules[i] == NULL)
418			continue;
419		error = mac_bsdextended_rulecheck(rules[i], cred,
420		    vp, vap, acc_mode);
421		if (error == EJUSTRETURN)
422			break;
423		if (error) {
424			mtx_unlock(&mac_bsdextended_mtx);
425			return (error);
426		}
427	}
428	mtx_unlock(&mac_bsdextended_mtx);
429	return (0);
430}
431
432static int
433mac_bsdextended_check_vp(struct ucred *cred, struct vnode *vp, int acc_mode)
434{
435	int error;
436	struct vattr vap;
437
438	if (!mac_bsdextended_enabled)
439		return (0);
440	error = VOP_GETATTR(vp, &vap, cred, curthread);
441	if (error)
442		return (error);
443	return (mac_bsdextended_check(cred, vp, &vap, acc_mode));
444}
445
446static int
447mac_bsdextended_system_check_acct(struct ucred *cred, struct vnode *vp,
448    struct label *vplabel)
449{
450
451	return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE));
452}
453
454static int
455mac_bsdextended_system_check_auditctl(struct ucred *cred, struct vnode *vp,
456    struct label *vplabel)
457{
458
459	return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE));
460}
461
462static int
463mac_bsdextended_system_check_swapoff(struct ucred *cred, struct vnode *vp,
464    struct label *vplabel)
465{
466
467	return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE));
468}
469
470static int
471mac_bsdextended_system_check_swapon(struct ucred *cred, struct vnode *vp,
472    struct label *vplabel)
473{
474
475	return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE));
476}
477
478static int
479mac_bsdextended_vnode_check_access(struct ucred *cred, struct vnode *vp,
480    struct label *vplabel, int acc_mode)
481{
482
483	return (mac_bsdextended_check_vp(cred, vp, acc_mode));
484}
485
486static int
487mac_bsdextended_vnode_check_chdir(struct ucred *cred, struct vnode *dvp,
488    struct label *dvplabel)
489{
490
491	return (mac_bsdextended_check_vp(cred, dvp, MBI_EXEC));
492}
493
494static int
495mac_bsdextended_vnode_check_chroot(struct ucred *cred, struct vnode *dvp,
496    struct label *dvplabel)
497{
498
499	return (mac_bsdextended_check_vp(cred, dvp, MBI_EXEC));
500}
501
502static int
503mac_bsdextended_check_create_vnode(struct ucred *cred, struct vnode *dvp,
504    struct label *dvplabel, struct componentname *cnp, struct vattr *vap)
505{
506
507	return (mac_bsdextended_check_vp(cred, dvp, MBI_WRITE));
508}
509
510static int
511mac_bsdextended_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
512    struct label *vplabel, acl_type_t type)
513{
514
515	return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN));
516}
517
518static int
519mac_bsdextended_vnode_check_deleteextattr(struct ucred *cred,
520    struct vnode *vp, struct label *vplabel, int attrnamespace,
521    const char *name)
522{
523
524	return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE));
525}
526
527static int
528mac_bsdextended_vnode_check_exec(struct ucred *cred, struct vnode *vp,
529    struct label *vplabel, struct image_params *imgp,
530    struct label *execlabel)
531{
532
533	return (mac_bsdextended_check_vp(cred, vp, MBI_READ|MBI_EXEC));
534}
535
536static int
537mac_bsdextended_vnode_check_getacl(struct ucred *cred, struct vnode *vp,
538    struct label *vplabel, acl_type_t type)
539{
540
541	return (mac_bsdextended_check_vp(cred, vp, MBI_STAT));
542}
543
544static int
545mac_bsdextended_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
546    struct label *vplabel, int attrnamespace, const char *name,
547    struct uio *uio)
548{
549
550	return (mac_bsdextended_check_vp(cred, vp, MBI_READ));
551}
552
553static int
554mac_bsdextended_vnode_check_link(struct ucred *cred, struct vnode *dvp,
555    struct label *dvplabel, struct vnode *vp, struct label *label,
556    struct componentname *cnp)
557{
558	int error;
559
560	error = mac_bsdextended_check_vp(cred, dvp, MBI_WRITE);
561	if (error)
562		return (error);
563	error = mac_bsdextended_check_vp(cred, vp, MBI_WRITE);
564	if (error)
565		return (error);
566	return (0);
567}
568
569static int
570mac_bsdextended_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
571    struct label *vplabel, int attrnamespace)
572{
573
574	return (mac_bsdextended_check_vp(cred, vp, MBI_READ));
575}
576
577static int
578mac_bsdextended_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
579    struct label *dvplabel, struct componentname *cnp)
580{
581
582	return (mac_bsdextended_check_vp(cred, dvp, MBI_EXEC));
583}
584
585static int
586mac_bsdextended_vnode_check_open(struct ucred *cred, struct vnode *vp,
587    struct label *vplabel, int acc_mode)
588{
589
590	return (mac_bsdextended_check_vp(cred, vp, acc_mode));
591}
592
593static int
594mac_bsdextended_vnode_check_readdir(struct ucred *cred, struct vnode *dvp,
595    struct label *dvplabel)
596{
597
598	return (mac_bsdextended_check_vp(cred, dvp, MBI_READ));
599}
600
601static int
602mac_bsdextended_vnode_check_readdlink(struct ucred *cred, struct vnode *vp,
603    struct label *vplabel)
604{
605
606	return (mac_bsdextended_check_vp(cred, vp, MBI_READ));
607}
608
609static int
610mac_bsdextended_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
611    struct label *dvplabel, struct vnode *vp, struct label *vplabel,
612    struct componentname *cnp)
613{
614	int error;
615
616	error = mac_bsdextended_check_vp(cred, dvp, MBI_WRITE);
617	if (error)
618		return (error);
619	return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE));
620}
621
622static int
623mac_bsdextended_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
624    struct label *dvplabel, struct vnode *vp, struct label *vplabel,
625    int samedir, struct componentname *cnp)
626{
627	int error;
628
629	error = mac_bsdextended_check_vp(cred, dvp, MBI_WRITE);
630	if (error)
631		return (error);
632	if (vp != NULL)
633		error = mac_bsdextended_check_vp(cred, vp, MBI_WRITE);
634	return (error);
635}
636
637static int
638mac_bsdextended_vnode_check_revoke(struct ucred *cred, struct vnode *vp,
639    struct label *vplabel)
640{
641
642	return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN));
643}
644
645static int
646mac_bsdextended_check_setacl_vnode(struct ucred *cred, struct vnode *vp,
647    struct label *vplabel, acl_type_t type, struct acl *acl)
648{
649
650	return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN));
651}
652
653static int
654mac_bsdextended_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
655    struct label *vplabel, int attrnamespace, const char *name,
656    struct uio *uio)
657{
658
659	return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE));
660}
661
662static int
663mac_bsdextended_vnode_check_setflags(struct ucred *cred, struct vnode *vp,
664    struct label *vplabel, u_long flags)
665{
666
667	return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN));
668}
669
670static int
671mac_bsdextended_vnode_check_setmode(struct ucred *cred, struct vnode *vp,
672    struct label *vplabel, mode_t mode)
673{
674
675	return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN));
676}
677
678static int
679mac_bsdextended_vnode_check_setowner(struct ucred *cred, struct vnode *vp,
680    struct label *vplabel, uid_t uid, gid_t gid)
681{
682
683	return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN));
684}
685
686static int
687mac_bsdextended_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
688    struct label *vplabel, struct timespec atime, struct timespec utime)
689{
690
691	return (mac_bsdextended_check_vp(cred, vp, MBI_ADMIN));
692}
693
694static int
695mac_bsdextended_vnode_check_stat(struct ucred *active_cred,
696    struct ucred *file_cred, struct vnode *vp, struct label *vplabel)
697{
698
699	return (mac_bsdextended_check_vp(active_cred, vp, MBI_STAT));
700}
701
702static int
703mac_bsdextended_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
704    struct label *dvplabel, struct vnode *vp, struct label *vplabel,
705    struct componentname *cnp)
706{
707	int error;
708
709	error = mac_bsdextended_check_vp(cred, dvp, MBI_WRITE);
710	if (error)
711		return (error);
712	return (mac_bsdextended_check_vp(cred, vp, MBI_WRITE));
713}
714
715static struct mac_policy_ops mac_bsdextended_ops =
716{
717	.mpo_destroy = mac_bsdextended_destroy,
718	.mpo_init = mac_bsdextended_init,
719	.mpo_system_check_acct = mac_bsdextended_system_check_acct,
720	.mpo_system_check_auditctl = mac_bsdextended_system_check_auditctl,
721	.mpo_system_check_swapoff = mac_bsdextended_system_check_swapoff,
722	.mpo_system_check_swapon = mac_bsdextended_system_check_swapon,
723	.mpo_vnode_check_access = mac_bsdextended_vnode_check_access,
724	.mpo_vnode_check_chdir = mac_bsdextended_vnode_check_chdir,
725	.mpo_vnode_check_chroot = mac_bsdextended_vnode_check_chroot,
726	.mpo_vnode_check_create = mac_bsdextended_check_create_vnode,
727	.mpo_vnode_check_deleteacl = mac_bsdextended_vnode_check_deleteacl,
728	.mpo_vnode_check_deleteextattr = mac_bsdextended_vnode_check_deleteextattr,
729	.mpo_vnode_check_exec = mac_bsdextended_vnode_check_exec,
730	.mpo_vnode_check_getacl = mac_bsdextended_vnode_check_getacl,
731	.mpo_vnode_check_getextattr = mac_bsdextended_vnode_check_getextattr,
732	.mpo_vnode_check_link = mac_bsdextended_vnode_check_link,
733	.mpo_vnode_check_listextattr = mac_bsdextended_vnode_check_listextattr,
734	.mpo_vnode_check_lookup = mac_bsdextended_vnode_check_lookup,
735	.mpo_vnode_check_open = mac_bsdextended_vnode_check_open,
736	.mpo_vnode_check_readdir = mac_bsdextended_vnode_check_readdir,
737	.mpo_vnode_check_readlink = mac_bsdextended_vnode_check_readdlink,
738	.mpo_vnode_check_rename_from = mac_bsdextended_vnode_check_rename_from,
739	.mpo_vnode_check_rename_to = mac_bsdextended_vnode_check_rename_to,
740	.mpo_vnode_check_revoke = mac_bsdextended_vnode_check_revoke,
741	.mpo_vnode_check_setacl = mac_bsdextended_check_setacl_vnode,
742	.mpo_vnode_check_setextattr = mac_bsdextended_vnode_check_setextattr,
743	.mpo_vnode_check_setflags = mac_bsdextended_vnode_check_setflags,
744	.mpo_vnode_check_setmode = mac_bsdextended_vnode_check_setmode,
745	.mpo_vnode_check_setowner = mac_bsdextended_vnode_check_setowner,
746	.mpo_vnode_check_setutimes = mac_bsdextended_vnode_check_setutimes,
747	.mpo_vnode_check_stat = mac_bsdextended_vnode_check_stat,
748	.mpo_vnode_check_unlink = mac_bsdextended_vnode_check_unlink,
749};
750
751MAC_POLICY_SET(&mac_bsdextended_ops, mac_bsdextended,
752    "TrustedBSD MAC/BSD Extended", MPC_LOADTIME_FLAG_UNLOADOK, NULL);
753