1/*-
2 * Copyright (c) 1999-2002 Robert N. M. Watson
3 * Copyright (c) 2001-2005 Networks Associates Technology, Inc.
4 * Copyright (c) 2005-2006 SPARTA, Inc.
5 * All rights reserved.
6 *
7 * This software was developed by Robert Watson for the TrustedBSD Project.
8 *
9 * This software was developed for the FreeBSD Project in part by Network
10 * Associates Laboratories, the Security Research Division of Network
11 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
12 * as part of the DARPA CHATS research program.
13 *
14 * This software was enhanced by SPARTA ISSO under SPAWAR contract
15 * N66001-04-C-6019 ("SEFOS").
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * $FreeBSD: head/sys/security/mac/mac_framework.h 172953 2007-10-25 07:49:47Z rwatson $
39 */
40
41/*
42 * Kernel interface for Mandatory Access Control -- how kernel services
43 * interact with the TrustedBSD MAC Framework.
44 */
45
46#ifndef _SYS_SECURITY_MAC_MAC_FRAMEWORK_H_
47#define _SYS_SECURITY_MAC_MAC_FRAMEWORK_H_
48
49#ifndef _KERNEL
50#error "no user-serviceable parts inside"
51#endif
52
53struct auditinfo;
54struct auditinfo_addr;
55struct bpf_d;
56struct cdev;
57struct componentname;
58struct devfs_dirent;
59struct ifnet;
60struct ifreq;
61struct image_params;
62struct inpcb;
63struct ipq;
64struct ksem;
65struct label;
66struct m_tag;
67struct mac;
68struct mbuf;
69struct mount;
70struct msg;
71struct msqid_kernel;
72struct proc;
73struct semid_kernel;
74struct shmid_kernel;
75struct sockaddr;
76struct socket;
77struct sysctl_oid;
78struct sysctl_req;
79struct pipepair;
80struct thread;
81struct timespec;
82struct ucred;
83struct uio;
84struct vattr;
85struct vnode;
86struct vop_setlabel_args;
87
88#include <sys/acl.h> /* XXX acl_type_t */
89
90/*
91 * Kernel functions to manage and evaluate labels.
92 */
93void mac_bpfdesc_init(struct bpf_d *);
94void mac_cred_init(struct ucred *);
95void mac_devfs_init(struct devfs_dirent *);
96void mac_ifnet_init(struct ifnet *);
97int mac_inpcb_init(struct inpcb *, int);
98void mac_sysvmsg_init(struct msg *);
99void mac_sysvmsq_init(struct msqid_kernel *);
100void mac_sysvsem_init(struct semid_kernel *);
101void mac_sysvshm_init(struct shmid_kernel *);
102int mac_ipq_init(struct ipq *, int);
103int mac_socket_init(struct socket *, int);
104void mac_pipe_init(struct pipepair *);
105void mac_posixsem_init(struct ksem *);
106int mac_mbuf_init(struct mbuf *, int);
107int mac_mbuf_tag_init(struct m_tag *, int);
108void mac_mount_init(struct mount *);
109void mac_proc_init(struct proc *);
110void mac_vnode_init(struct vnode *);
111void mac_mbuf_copy(struct mbuf *, struct mbuf *);
112void mac_mbuf_tag_copy(struct m_tag *, struct m_tag *);
113void mac_vnode_copy_label(struct label *, struct label *);
114void mac_bpfdesc_destroy(struct bpf_d *);
115void mac_cred_destroy(struct ucred *);
116void mac_devfs_destroy(struct devfs_dirent *);
117void mac_ifnet_destroy(struct ifnet *);
118void mac_inpcb_destroy(struct inpcb *);
119void mac_sysvmsg_destroy(struct msg *);
120void mac_sysvmsq_destroy(struct msqid_kernel *);
121void mac_sysvsem_destroy(struct semid_kernel *);
122void mac_sysvshm_destroy(struct shmid_kernel *);
123void mac_ipq_destroy(struct ipq *);
124void mac_socket_destroy(struct socket *);
125void mac_pipe_destroy(struct pipepair *);
126void mac_posixsem_destroy(struct ksem *);
127void mac_proc_destroy(struct proc *);
128void mac_mbuf_tag_destroy(struct m_tag *);
129void mac_mount_destroy(struct mount *);
130void mac_vnode_destroy(struct vnode *);
131
132struct label *mac_cred_label_alloc(void);
133void mac_cred_label_free(struct label *);
134struct label *mac_vnode_label_alloc(void);
135void mac_vnode_label_free(struct label *);
136
137/*
138 * Labeling event operations: file system objects, and things that look a lot
139 * like file system objects.
140 */
141void mac_devfs_vnode_associate(struct mount *mp, struct devfs_dirent *de,
142 struct vnode *vp);
143int mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp);
144void mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp);
145void mac_devfs_create_device(struct ucred *cred, struct mount *mp,
146 struct cdev *dev, struct devfs_dirent *de);
147void mac_devfs_create_directory(struct mount *mp, char *dirname,
148 int dirnamelen, struct devfs_dirent *de);
149void mac_devfs_create_symlink(struct ucred *cred, struct mount *mp,
150 struct devfs_dirent *dd, struct devfs_dirent *de);
151int mac_vnode_create_extattr(struct ucred *cred, struct mount *mp,
152 struct vnode *dvp, struct vnode *vp, struct componentname *cnp);
153void mac_mount_create(struct ucred *cred, struct mount *mp);
154void mac_vnode_relabel(struct ucred *cred, struct vnode *vp,
155 struct label *newlabel);
156void mac_devfs_update(struct mount *mp, struct devfs_dirent *de,
157 struct vnode *vp);
158
159/*
160 * Labeling event operations: IPC objects.
161 */
162void mac_socket_create_mbuf(struct socket *so, struct mbuf *m);
163void mac_socket_create(struct ucred *cred, struct socket *so);
164void mac_socket_newconn(struct socket *oldso, struct socket *newso);
165void mac_socketpeer_set_from_mbuf(struct mbuf *m, struct socket *so);
166void mac_socketpeer_set_from_socket(struct socket *oldso,
167 struct socket *newso);
168void mac_pipe_create(struct ucred *cred, struct pipepair *pp);
169
170/*
171 * Labeling event operations: System V IPC primitives
172 */
173void mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr,
174 struct msg *msgptr);
175void mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr);
176void mac_sysvsem_create(struct ucred *cred,
177 struct semid_kernel *semakptr);
178void mac_sysvshm_create(struct ucred *cred,
179 struct shmid_kernel *shmsegptr);
180
181/*
182 * Labeling event operations: POSIX (global/inter-process) semaphores.
183 */
184void mac_posixsem_create(struct ucred *cred, struct ksem *ks);
185
186/*
187 * Labeling event operations: network objects.
188 */
189void mac_bpfdesc_create(struct ucred *cred, struct bpf_d *d);
190void mac_ifnet_create(struct ifnet *ifp);
191void mac_inpcb_create(struct socket *so, struct inpcb *inp);
192void mac_ipq_create(struct mbuf *m, struct ipq *ipq);
193void mac_ipq_reassemble(struct ipq *ipq, struct mbuf *m);
194void mac_netinet_fragment(struct mbuf *m, struct mbuf *frag);
195void mac_inpcb_create_mbuf(struct inpcb *inp, struct mbuf *m);
196void mac_create_mbuf_linklayer(struct ifnet *ifp, struct mbuf *m);
197void mac_bpfdesc_create_mbuf(struct bpf_d *d, struct mbuf *m);
198void mac_ifnet_create_mbuf(struct ifnet *ifp, struct mbuf *m);
199void mac_mbuf_create_multicast_encap(struct mbuf *m, struct ifnet *ifp,
200 struct mbuf *mnew);
201void mac_mbuf_create_netlayer(struct mbuf *m, struct mbuf *mnew);
202int mac_ipq_match(struct mbuf *m, struct ipq *ipq);
203void mac_netinet_icmp_reply(struct mbuf *m);
204void mac_netinet_tcp_reply(struct mbuf *m);
205void mac_ipq_update(struct mbuf *m, struct ipq *ipq);
206void mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp);
207void mac_mbuf_create_from_firewall(struct mbuf *m);
208void mac_destroy_syncache(struct label **l);
209int mac_init_syncache(struct label **l);
210void mac_init_syncache_from_inpcb(struct label *l, struct inpcb *inp);
211void mac_create_mbuf_from_syncache(struct label *l, struct mbuf *m);
212
213/*
214 * Labeling event operations: processes.
215 */
216void mac_cred_copy(struct ucred *cr1, struct ucred *cr2);
217int mac_execve_enter(struct image_params *imgp, struct mac *mac_p);
218void mac_execve_exit(struct image_params *imgp);
219void mac_vnode_execve_transition(struct ucred *oldcred,
220 struct ucred *newcred, struct vnode *vp,
221 struct label *interpvplabel, struct image_params *imgp);
222int mac_vnode_execve_will_transition(struct ucred *cred,
223 struct vnode *vp, struct label *interpvplabel,
224 struct image_params *imgp);
225void mac_proc_create_swapper(struct ucred *cred);
226void mac_proc_create_init(struct ucred *cred);
227void mac_thread_userret(struct thread *td);
228
229/*
230 * Label cleanup operation: This is the inverse complement for the mac_create
231 * and associate type of hooks. This hook lets the policy module(s) perform a
232 * cleanup/flushing operation on the label associated with the objects,
233 * without freeing up the space allocated. This hook is useful in cases
234 * where it is desirable to remove any labeling reference when recycling any
235 * object to a pool. This hook does not replace the mac_destroy hooks.
236 *
237 * XXXRW: These object methods are inconsistent with the life cycles of other
238 * objects, and likely should be revised to be more consistent.
239 */
240void mac_sysvmsg_cleanup(struct msg *msgptr);
241void mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr);
242void mac_sysvsem_cleanup(struct semid_kernel *semakptr);
243void mac_sysvshm_cleanup(struct shmid_kernel *shmsegptr);
244
245/*
246 * Access control checks.
247 */
248int mac_bpfdesc_check_receive(struct bpf_d *d, struct ifnet *ifp);
249int mac_cred_check_visible(struct ucred *cr1, struct ucred *cr2);
250int mac_ifnet_check_transmit(struct ifnet *ifp, struct mbuf *m);
251int mac_inpcb_check_deliver(struct inpcb *inp, struct mbuf *m);
252int mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr,
253 struct msqid_kernel *msqkptr);
254int mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr);
255int mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr);
256int mac_sysvmsq_check_msqget(struct ucred *cred,
257 struct msqid_kernel *msqkptr);
258int mac_sysvmsq_check_msqsnd(struct ucred *cred,
259 struct msqid_kernel *msqkptr);
260int mac_sysvmsq_check_msqrcv(struct ucred *cred,
261 struct msqid_kernel *msqkptr);
262int mac_sysvmsq_check_msqctl(struct ucred *cred,
263 struct msqid_kernel *msqkptr, int cmd);
264int mac_sysvsem_check_semctl(struct ucred *cred,
265 struct semid_kernel *semakptr, int cmd);
266int mac_sysvsem_check_semget(struct ucred *cred,
267 struct semid_kernel *semakptr);
268int mac_sysvsem_check_semop(struct ucred *cred,
269 struct semid_kernel *semakptr, size_t accesstype);
270int mac_sysvshm_check_shmat(struct ucred *cred,
271 struct shmid_kernel *shmsegptr, int shmflg);
272int mac_sysvshm_check_shmctl(struct ucred *cred,
273 struct shmid_kernel *shmsegptr, int cmd);
274int mac_sysvshm_check_shmdt(struct ucred *cred,
275 struct shmid_kernel *shmsegptr);
276int mac_sysvshm_check_shmget(struct ucred *cred,
277 struct shmid_kernel *shmsegptr, int shmflg);
278int mac_kenv_check_dump(struct ucred *cred);
279int mac_kenv_check_get(struct ucred *cred, char *name);
280int mac_kenv_check_set(struct ucred *cred, char *name, char *value);
281int mac_kenv_check_unset(struct ucred *cred, char *name);
282int mac_kld_check_load(struct ucred *cred, struct vnode *vp);
283int mac_kld_check_stat(struct ucred *cred);
284int mac_mount_check_stat(struct ucred *cred, struct mount *mp);
285int mac_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp,
286 unsigned long cmd, void *data);
287int mac_pipe_check_poll(struct ucred *cred, struct pipepair *pp);
288int mac_pipe_check_read(struct ucred *cred, struct pipepair *pp);
289int mac_pipe_check_stat(struct ucred *cred, struct pipepair *pp);
290int mac_pipe_check_write(struct ucred *cred, struct pipepair *pp);
291int mac_posixsem_check_destroy(struct ucred *cred, struct ksem *ks);
292int mac_posixsem_check_getvalue(struct ucred *cred,struct ksem *ks);
293int mac_posixsem_check_open(struct ucred *cred, struct ksem *ks);
294int mac_posixsem_check_post(struct ucred *cred, struct ksem *ks);
295int mac_posixsem_check_unlink(struct ucred *cred, struct ksem *ks);
296int mac_posixsem_check_wait(struct ucred *cred, struct ksem *ks);
297int mac_proc_check_debug(struct ucred *cred, struct proc *p);
298int mac_proc_check_sched(struct ucred *cred, struct proc *p);
299int mac_proc_check_setaudit(struct ucred *cred, struct auditinfo *ai);
300int mac_proc_check_setaudit_addr(struct ucred *cred,
301 struct auditinfo_addr *aia);
302int mac_proc_check_setauid(struct ucred *cred, uid_t auid);
303int mac_proc_check_setuid(struct proc *p, struct ucred *cred,
304 uid_t uid);
305int mac_proc_check_seteuid(struct proc *p, struct ucred *cred,
306 uid_t euid);
307int mac_proc_check_setgid(struct proc *p, struct ucred *cred,
308 gid_t gid);
309int mac_proc_check_setegid(struct proc *p, struct ucred *cred,
310 gid_t egid);
311int mac_proc_check_setgroups(struct proc *p, struct ucred *cred,
312 int ngroups, gid_t *gidset);
313int mac_proc_check_setreuid(struct proc *p, struct ucred *cred,
314 uid_t ruid, uid_t euid);
315int mac_proc_check_setregid(struct proc *p, struct ucred *cred,
316 gid_t rgid, gid_t egid);
317int mac_proc_check_setresuid(struct proc *p, struct ucred *cred,
318 uid_t ruid, uid_t euid, uid_t suid);
319int mac_proc_check_setresgid(struct proc *p, struct ucred *cred,
320 gid_t rgid, gid_t egid, gid_t sgid);
321int mac_proc_check_signal(struct ucred *cred, struct proc *p,
322 int signum);
323int mac_proc_check_wait(struct ucred *cred, struct proc *p);
324int mac_socket_check_accept(struct ucred *cred, struct socket *so);
325int mac_socket_check_bind(struct ucred *cred, struct socket *so,
326 struct sockaddr *sa);
327int mac_socket_check_connect(struct ucred *cred, struct socket *so,
328 struct sockaddr *sa);
329int mac_socket_check_create(struct ucred *cred, int domain, int type,
330 int proto);
331int mac_socket_check_deliver(struct socket *so, struct mbuf *m);
332int mac_socket_check_listen(struct ucred *cred, struct socket *so);
333int mac_socket_check_poll(struct ucred *cred, struct socket *so);
334int mac_socket_check_receive(struct ucred *cred, struct socket *so);
335int mac_socket_check_send(struct ucred *cred, struct socket *so);
336int mac_socket_check_stat(struct ucred *cred, struct socket *so);
337int mac_socket_check_visible(struct ucred *cred, struct socket *so);
338int mac_system_check_acct(struct ucred *cred, struct vnode *vp);
339int mac_system_check_audit(struct ucred *cred, void *record, int length);
340int mac_system_check_auditctl(struct ucred *cred, struct vnode *vp);
341int mac_system_check_auditon(struct ucred *cred, int cmd);
342int mac_system_check_reboot(struct ucred *cred, int howto);
343int mac_system_check_swapon(struct ucred *cred, struct vnode *vp);
344int mac_system_check_swapoff(struct ucred *cred, struct vnode *vp);
345int mac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
346 void *arg1, int arg2, struct sysctl_req *req);
347int mac_vnode_check_access(struct ucred *cred, struct vnode *vp,
348 int acc_mode);
349int mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp);
350int mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp);
351int mac_vnode_check_create(struct ucred *cred, struct vnode *dvp,
352 struct componentname *cnp, struct vattr *vap);
353int mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
354 acl_type_t type);
355int mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
356 int attrnamespace, const char *name);
357int mac_vnode_check_exec(struct ucred *cred, struct vnode *vp,
358 struct image_params *imgp);
359int mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp,
360 acl_type_t type);
361int mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
362 int attrnamespace, const char *name, struct uio *uio);
363int mac_vnode_check_link(struct ucred *cred, struct vnode *dvp,
364 struct vnode *vp, struct componentname *cnp);
365int mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
366 int attrnamespace);
367int mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
368 struct componentname *cnp);
369int mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot,
370 int flags);
371int mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp,
372 int prot);
373int mac_vnode_check_open(struct ucred *cred, struct vnode *vp,
374 int acc_mode);
375int mac_vnode_check_poll(struct ucred *active_cred,
376 struct ucred *file_cred, struct vnode *vp);
377int mac_vnode_check_read(struct ucred *active_cred,
378 struct ucred *file_cred, struct vnode *vp);
379int mac_vnode_check_readdir(struct ucred *cred, struct vnode *vp);
380int mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp);
381int mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
382 struct vnode *vp, struct componentname *cnp);
383int mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
384 struct vnode *vp, int samedir, struct componentname *cnp);
385int mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp);
386int mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp,
387 acl_type_t type, struct acl *acl);
388int mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
389 int attrnamespace, const char *name, struct uio *uio);
390int mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp,
391 u_long flags);
392int mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp,
393 mode_t mode);
394int mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp,
395 uid_t uid, gid_t gid);
396int mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
397 struct timespec atime, struct timespec mtime);
398int mac_vnode_check_stat(struct ucred *active_cred,
399 struct ucred *file_cred, struct vnode *vp);
400int mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
401 struct vnode *vp, struct componentname *cnp);
402int mac_vnode_check_write(struct ucred *active_cred,
403 struct ucred *file_cred, struct vnode *vp);
404int mac_getsockopt_label(struct ucred *cred, struct socket *so,
405 struct mac *extmac);
406int mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so,
407 struct mac *extmac);
408int mac_ifnet_ioctl_get(struct ucred *cred, struct ifreq *ifr,
409 struct ifnet *ifp);
410int mac_ifnet_ioctl_set(struct ucred *cred, struct ifreq *ifr,
411 struct ifnet *ifp);
412int mac_setsockopt_label(struct ucred *cred, struct socket *so,
413 struct mac *extmac);
414int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp,
415 struct label *label);
416void mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred);
417void mac_associate_nfsd_label(struct ucred *cred);
418int mac_priv_check(struct ucred *cred, int priv);
419int mac_priv_grant(struct ucred *cred, int priv);
420
421/*
422 * Calls to help various file systems implement labeling functionality using
423 * their existing EA implementation.
424 */
425int vop_stdsetlabel_ea(struct vop_setlabel_args *ap);
426
427#endif /* !_SYS_SECURITY_MAC_MAC_FRAMEWORK_H_ */
2 * Copyright (c) 1999-2002 Robert N. M. Watson
3 * Copyright (c) 2001-2005 Networks Associates Technology, Inc.
4 * Copyright (c) 2005-2006 SPARTA, Inc.
5 * All rights reserved.
6 *
7 * This software was developed by Robert Watson for the TrustedBSD Project.
8 *
9 * This software was developed for the FreeBSD Project in part by Network
10 * Associates Laboratories, the Security Research Division of Network
11 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
12 * as part of the DARPA CHATS research program.
13 *
14 * This software was enhanced by SPARTA ISSO under SPAWAR contract
15 * N66001-04-C-6019 ("SEFOS").
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * $FreeBSD: head/sys/security/mac/mac_framework.h 172953 2007-10-25 07:49:47Z rwatson $
39 */
40
41/*
42 * Kernel interface for Mandatory Access Control -- how kernel services
43 * interact with the TrustedBSD MAC Framework.
44 */
45
46#ifndef _SYS_SECURITY_MAC_MAC_FRAMEWORK_H_
47#define _SYS_SECURITY_MAC_MAC_FRAMEWORK_H_
48
49#ifndef _KERNEL
50#error "no user-serviceable parts inside"
51#endif
52
53struct auditinfo;
54struct auditinfo_addr;
55struct bpf_d;
56struct cdev;
57struct componentname;
58struct devfs_dirent;
59struct ifnet;
60struct ifreq;
61struct image_params;
62struct inpcb;
63struct ipq;
64struct ksem;
65struct label;
66struct m_tag;
67struct mac;
68struct mbuf;
69struct mount;
70struct msg;
71struct msqid_kernel;
72struct proc;
73struct semid_kernel;
74struct shmid_kernel;
75struct sockaddr;
76struct socket;
77struct sysctl_oid;
78struct sysctl_req;
79struct pipepair;
80struct thread;
81struct timespec;
82struct ucred;
83struct uio;
84struct vattr;
85struct vnode;
86struct vop_setlabel_args;
87
88#include <sys/acl.h> /* XXX acl_type_t */
89
90/*
91 * Kernel functions to manage and evaluate labels.
92 */
93void mac_bpfdesc_init(struct bpf_d *);
94void mac_cred_init(struct ucred *);
95void mac_devfs_init(struct devfs_dirent *);
96void mac_ifnet_init(struct ifnet *);
97int mac_inpcb_init(struct inpcb *, int);
98void mac_sysvmsg_init(struct msg *);
99void mac_sysvmsq_init(struct msqid_kernel *);
100void mac_sysvsem_init(struct semid_kernel *);
101void mac_sysvshm_init(struct shmid_kernel *);
102int mac_ipq_init(struct ipq *, int);
103int mac_socket_init(struct socket *, int);
104void mac_pipe_init(struct pipepair *);
105void mac_posixsem_init(struct ksem *);
106int mac_mbuf_init(struct mbuf *, int);
107int mac_mbuf_tag_init(struct m_tag *, int);
108void mac_mount_init(struct mount *);
109void mac_proc_init(struct proc *);
110void mac_vnode_init(struct vnode *);
111void mac_mbuf_copy(struct mbuf *, struct mbuf *);
112void mac_mbuf_tag_copy(struct m_tag *, struct m_tag *);
113void mac_vnode_copy_label(struct label *, struct label *);
114void mac_bpfdesc_destroy(struct bpf_d *);
115void mac_cred_destroy(struct ucred *);
116void mac_devfs_destroy(struct devfs_dirent *);
117void mac_ifnet_destroy(struct ifnet *);
118void mac_inpcb_destroy(struct inpcb *);
119void mac_sysvmsg_destroy(struct msg *);
120void mac_sysvmsq_destroy(struct msqid_kernel *);
121void mac_sysvsem_destroy(struct semid_kernel *);
122void mac_sysvshm_destroy(struct shmid_kernel *);
123void mac_ipq_destroy(struct ipq *);
124void mac_socket_destroy(struct socket *);
125void mac_pipe_destroy(struct pipepair *);
126void mac_posixsem_destroy(struct ksem *);
127void mac_proc_destroy(struct proc *);
128void mac_mbuf_tag_destroy(struct m_tag *);
129void mac_mount_destroy(struct mount *);
130void mac_vnode_destroy(struct vnode *);
131
132struct label *mac_cred_label_alloc(void);
133void mac_cred_label_free(struct label *);
134struct label *mac_vnode_label_alloc(void);
135void mac_vnode_label_free(struct label *);
136
137/*
138 * Labeling event operations: file system objects, and things that look a lot
139 * like file system objects.
140 */
141void mac_devfs_vnode_associate(struct mount *mp, struct devfs_dirent *de,
142 struct vnode *vp);
143int mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp);
144void mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp);
145void mac_devfs_create_device(struct ucred *cred, struct mount *mp,
146 struct cdev *dev, struct devfs_dirent *de);
147void mac_devfs_create_directory(struct mount *mp, char *dirname,
148 int dirnamelen, struct devfs_dirent *de);
149void mac_devfs_create_symlink(struct ucred *cred, struct mount *mp,
150 struct devfs_dirent *dd, struct devfs_dirent *de);
151int mac_vnode_create_extattr(struct ucred *cred, struct mount *mp,
152 struct vnode *dvp, struct vnode *vp, struct componentname *cnp);
153void mac_mount_create(struct ucred *cred, struct mount *mp);
154void mac_vnode_relabel(struct ucred *cred, struct vnode *vp,
155 struct label *newlabel);
156void mac_devfs_update(struct mount *mp, struct devfs_dirent *de,
157 struct vnode *vp);
158
159/*
160 * Labeling event operations: IPC objects.
161 */
162void mac_socket_create_mbuf(struct socket *so, struct mbuf *m);
163void mac_socket_create(struct ucred *cred, struct socket *so);
164void mac_socket_newconn(struct socket *oldso, struct socket *newso);
165void mac_socketpeer_set_from_mbuf(struct mbuf *m, struct socket *so);
166void mac_socketpeer_set_from_socket(struct socket *oldso,
167 struct socket *newso);
168void mac_pipe_create(struct ucred *cred, struct pipepair *pp);
169
170/*
171 * Labeling event operations: System V IPC primitives
172 */
173void mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr,
174 struct msg *msgptr);
175void mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr);
176void mac_sysvsem_create(struct ucred *cred,
177 struct semid_kernel *semakptr);
178void mac_sysvshm_create(struct ucred *cred,
179 struct shmid_kernel *shmsegptr);
180
181/*
182 * Labeling event operations: POSIX (global/inter-process) semaphores.
183 */
184void mac_posixsem_create(struct ucred *cred, struct ksem *ks);
185
186/*
187 * Labeling event operations: network objects.
188 */
189void mac_bpfdesc_create(struct ucred *cred, struct bpf_d *d);
190void mac_ifnet_create(struct ifnet *ifp);
191void mac_inpcb_create(struct socket *so, struct inpcb *inp);
192void mac_ipq_create(struct mbuf *m, struct ipq *ipq);
193void mac_ipq_reassemble(struct ipq *ipq, struct mbuf *m);
194void mac_netinet_fragment(struct mbuf *m, struct mbuf *frag);
195void mac_inpcb_create_mbuf(struct inpcb *inp, struct mbuf *m);
196void mac_create_mbuf_linklayer(struct ifnet *ifp, struct mbuf *m);
197void mac_bpfdesc_create_mbuf(struct bpf_d *d, struct mbuf *m);
198void mac_ifnet_create_mbuf(struct ifnet *ifp, struct mbuf *m);
199void mac_mbuf_create_multicast_encap(struct mbuf *m, struct ifnet *ifp,
200 struct mbuf *mnew);
201void mac_mbuf_create_netlayer(struct mbuf *m, struct mbuf *mnew);
202int mac_ipq_match(struct mbuf *m, struct ipq *ipq);
203void mac_netinet_icmp_reply(struct mbuf *m);
204void mac_netinet_tcp_reply(struct mbuf *m);
205void mac_ipq_update(struct mbuf *m, struct ipq *ipq);
206void mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp);
207void mac_mbuf_create_from_firewall(struct mbuf *m);
208void mac_destroy_syncache(struct label **l);
209int mac_init_syncache(struct label **l);
210void mac_init_syncache_from_inpcb(struct label *l, struct inpcb *inp);
211void mac_create_mbuf_from_syncache(struct label *l, struct mbuf *m);
212
213/*
214 * Labeling event operations: processes.
215 */
216void mac_cred_copy(struct ucred *cr1, struct ucred *cr2);
217int mac_execve_enter(struct image_params *imgp, struct mac *mac_p);
218void mac_execve_exit(struct image_params *imgp);
219void mac_vnode_execve_transition(struct ucred *oldcred,
220 struct ucred *newcred, struct vnode *vp,
221 struct label *interpvplabel, struct image_params *imgp);
222int mac_vnode_execve_will_transition(struct ucred *cred,
223 struct vnode *vp, struct label *interpvplabel,
224 struct image_params *imgp);
225void mac_proc_create_swapper(struct ucred *cred);
226void mac_proc_create_init(struct ucred *cred);
227void mac_thread_userret(struct thread *td);
228
229/*
230 * Label cleanup operation: This is the inverse complement for the mac_create
231 * and associate type of hooks. This hook lets the policy module(s) perform a
232 * cleanup/flushing operation on the label associated with the objects,
233 * without freeing up the space allocated. This hook is useful in cases
234 * where it is desirable to remove any labeling reference when recycling any
235 * object to a pool. This hook does not replace the mac_destroy hooks.
236 *
237 * XXXRW: These object methods are inconsistent with the life cycles of other
238 * objects, and likely should be revised to be more consistent.
239 */
240void mac_sysvmsg_cleanup(struct msg *msgptr);
241void mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr);
242void mac_sysvsem_cleanup(struct semid_kernel *semakptr);
243void mac_sysvshm_cleanup(struct shmid_kernel *shmsegptr);
244
245/*
246 * Access control checks.
247 */
248int mac_bpfdesc_check_receive(struct bpf_d *d, struct ifnet *ifp);
249int mac_cred_check_visible(struct ucred *cr1, struct ucred *cr2);
250int mac_ifnet_check_transmit(struct ifnet *ifp, struct mbuf *m);
251int mac_inpcb_check_deliver(struct inpcb *inp, struct mbuf *m);
252int mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr,
253 struct msqid_kernel *msqkptr);
254int mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr);
255int mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr);
256int mac_sysvmsq_check_msqget(struct ucred *cred,
257 struct msqid_kernel *msqkptr);
258int mac_sysvmsq_check_msqsnd(struct ucred *cred,
259 struct msqid_kernel *msqkptr);
260int mac_sysvmsq_check_msqrcv(struct ucred *cred,
261 struct msqid_kernel *msqkptr);
262int mac_sysvmsq_check_msqctl(struct ucred *cred,
263 struct msqid_kernel *msqkptr, int cmd);
264int mac_sysvsem_check_semctl(struct ucred *cred,
265 struct semid_kernel *semakptr, int cmd);
266int mac_sysvsem_check_semget(struct ucred *cred,
267 struct semid_kernel *semakptr);
268int mac_sysvsem_check_semop(struct ucred *cred,
269 struct semid_kernel *semakptr, size_t accesstype);
270int mac_sysvshm_check_shmat(struct ucred *cred,
271 struct shmid_kernel *shmsegptr, int shmflg);
272int mac_sysvshm_check_shmctl(struct ucred *cred,
273 struct shmid_kernel *shmsegptr, int cmd);
274int mac_sysvshm_check_shmdt(struct ucred *cred,
275 struct shmid_kernel *shmsegptr);
276int mac_sysvshm_check_shmget(struct ucred *cred,
277 struct shmid_kernel *shmsegptr, int shmflg);
278int mac_kenv_check_dump(struct ucred *cred);
279int mac_kenv_check_get(struct ucred *cred, char *name);
280int mac_kenv_check_set(struct ucred *cred, char *name, char *value);
281int mac_kenv_check_unset(struct ucred *cred, char *name);
282int mac_kld_check_load(struct ucred *cred, struct vnode *vp);
283int mac_kld_check_stat(struct ucred *cred);
284int mac_mount_check_stat(struct ucred *cred, struct mount *mp);
285int mac_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp,
286 unsigned long cmd, void *data);
287int mac_pipe_check_poll(struct ucred *cred, struct pipepair *pp);
288int mac_pipe_check_read(struct ucred *cred, struct pipepair *pp);
289int mac_pipe_check_stat(struct ucred *cred, struct pipepair *pp);
290int mac_pipe_check_write(struct ucred *cred, struct pipepair *pp);
291int mac_posixsem_check_destroy(struct ucred *cred, struct ksem *ks);
292int mac_posixsem_check_getvalue(struct ucred *cred,struct ksem *ks);
293int mac_posixsem_check_open(struct ucred *cred, struct ksem *ks);
294int mac_posixsem_check_post(struct ucred *cred, struct ksem *ks);
295int mac_posixsem_check_unlink(struct ucred *cred, struct ksem *ks);
296int mac_posixsem_check_wait(struct ucred *cred, struct ksem *ks);
297int mac_proc_check_debug(struct ucred *cred, struct proc *p);
298int mac_proc_check_sched(struct ucred *cred, struct proc *p);
299int mac_proc_check_setaudit(struct ucred *cred, struct auditinfo *ai);
300int mac_proc_check_setaudit_addr(struct ucred *cred,
301 struct auditinfo_addr *aia);
302int mac_proc_check_setauid(struct ucred *cred, uid_t auid);
303int mac_proc_check_setuid(struct proc *p, struct ucred *cred,
304 uid_t uid);
305int mac_proc_check_seteuid(struct proc *p, struct ucred *cred,
306 uid_t euid);
307int mac_proc_check_setgid(struct proc *p, struct ucred *cred,
308 gid_t gid);
309int mac_proc_check_setegid(struct proc *p, struct ucred *cred,
310 gid_t egid);
311int mac_proc_check_setgroups(struct proc *p, struct ucred *cred,
312 int ngroups, gid_t *gidset);
313int mac_proc_check_setreuid(struct proc *p, struct ucred *cred,
314 uid_t ruid, uid_t euid);
315int mac_proc_check_setregid(struct proc *p, struct ucred *cred,
316 gid_t rgid, gid_t egid);
317int mac_proc_check_setresuid(struct proc *p, struct ucred *cred,
318 uid_t ruid, uid_t euid, uid_t suid);
319int mac_proc_check_setresgid(struct proc *p, struct ucred *cred,
320 gid_t rgid, gid_t egid, gid_t sgid);
321int mac_proc_check_signal(struct ucred *cred, struct proc *p,
322 int signum);
323int mac_proc_check_wait(struct ucred *cred, struct proc *p);
324int mac_socket_check_accept(struct ucred *cred, struct socket *so);
325int mac_socket_check_bind(struct ucred *cred, struct socket *so,
326 struct sockaddr *sa);
327int mac_socket_check_connect(struct ucred *cred, struct socket *so,
328 struct sockaddr *sa);
329int mac_socket_check_create(struct ucred *cred, int domain, int type,
330 int proto);
331int mac_socket_check_deliver(struct socket *so, struct mbuf *m);
332int mac_socket_check_listen(struct ucred *cred, struct socket *so);
333int mac_socket_check_poll(struct ucred *cred, struct socket *so);
334int mac_socket_check_receive(struct ucred *cred, struct socket *so);
335int mac_socket_check_send(struct ucred *cred, struct socket *so);
336int mac_socket_check_stat(struct ucred *cred, struct socket *so);
337int mac_socket_check_visible(struct ucred *cred, struct socket *so);
338int mac_system_check_acct(struct ucred *cred, struct vnode *vp);
339int mac_system_check_audit(struct ucred *cred, void *record, int length);
340int mac_system_check_auditctl(struct ucred *cred, struct vnode *vp);
341int mac_system_check_auditon(struct ucred *cred, int cmd);
342int mac_system_check_reboot(struct ucred *cred, int howto);
343int mac_system_check_swapon(struct ucred *cred, struct vnode *vp);
344int mac_system_check_swapoff(struct ucred *cred, struct vnode *vp);
345int mac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
346 void *arg1, int arg2, struct sysctl_req *req);
347int mac_vnode_check_access(struct ucred *cred, struct vnode *vp,
348 int acc_mode);
349int mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp);
350int mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp);
351int mac_vnode_check_create(struct ucred *cred, struct vnode *dvp,
352 struct componentname *cnp, struct vattr *vap);
353int mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
354 acl_type_t type);
355int mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
356 int attrnamespace, const char *name);
357int mac_vnode_check_exec(struct ucred *cred, struct vnode *vp,
358 struct image_params *imgp);
359int mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp,
360 acl_type_t type);
361int mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
362 int attrnamespace, const char *name, struct uio *uio);
363int mac_vnode_check_link(struct ucred *cred, struct vnode *dvp,
364 struct vnode *vp, struct componentname *cnp);
365int mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
366 int attrnamespace);
367int mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
368 struct componentname *cnp);
369int mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot,
370 int flags);
371int mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp,
372 int prot);
373int mac_vnode_check_open(struct ucred *cred, struct vnode *vp,
374 int acc_mode);
375int mac_vnode_check_poll(struct ucred *active_cred,
376 struct ucred *file_cred, struct vnode *vp);
377int mac_vnode_check_read(struct ucred *active_cred,
378 struct ucred *file_cred, struct vnode *vp);
379int mac_vnode_check_readdir(struct ucred *cred, struct vnode *vp);
380int mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp);
381int mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
382 struct vnode *vp, struct componentname *cnp);
383int mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
384 struct vnode *vp, int samedir, struct componentname *cnp);
385int mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp);
386int mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp,
387 acl_type_t type, struct acl *acl);
388int mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
389 int attrnamespace, const char *name, struct uio *uio);
390int mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp,
391 u_long flags);
392int mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp,
393 mode_t mode);
394int mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp,
395 uid_t uid, gid_t gid);
396int mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
397 struct timespec atime, struct timespec mtime);
398int mac_vnode_check_stat(struct ucred *active_cred,
399 struct ucred *file_cred, struct vnode *vp);
400int mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
401 struct vnode *vp, struct componentname *cnp);
402int mac_vnode_check_write(struct ucred *active_cred,
403 struct ucred *file_cred, struct vnode *vp);
404int mac_getsockopt_label(struct ucred *cred, struct socket *so,
405 struct mac *extmac);
406int mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so,
407 struct mac *extmac);
408int mac_ifnet_ioctl_get(struct ucred *cred, struct ifreq *ifr,
409 struct ifnet *ifp);
410int mac_ifnet_ioctl_set(struct ucred *cred, struct ifreq *ifr,
411 struct ifnet *ifp);
412int mac_setsockopt_label(struct ucred *cred, struct socket *so,
413 struct mac *extmac);
414int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp,
415 struct label *label);
416void mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred);
417void mac_associate_nfsd_label(struct ucred *cred);
418int mac_priv_check(struct ucred *cred, int priv);
419int mac_priv_grant(struct ucred *cred, int priv);
420
421/*
422 * Calls to help various file systems implement labeling functionality using
423 * their existing EA implementation.
424 */
425int vop_stdsetlabel_ea(struct vop_setlabel_args *ap);
426
427#endif /* !_SYS_SECURITY_MAC_MAC_FRAMEWORK_H_ */