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 163606 2006-10-22 11:52:19Z 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_MAC_FRAMEWORK_H_
48
49#ifndef _KERNEL
50#error "no user-serviceable parts inside"
51#endif
52
53#include <sys/_label.h>
54
55struct bpf_d;
56struct cdev;
57struct componentname;
58struct devfs_dirent;
59struct ifnet;
60struct ifreq;
61struct image_params;
62struct inpcb;
63struct ipq;
64struct ksem;
65struct m_tag;
66struct mac;
67struct mbuf;
68struct mount;
69struct msg;
70struct msqid_kernel;
71struct proc;
72struct semid_kernel;
73struct shmid_kernel;
74struct sockaddr;
75struct socket;
76struct sysctl_oid;
77struct sysctl_req;
78struct pipepair;
79struct thread;
80struct timespec;
81struct ucred;
82struct uio;
83struct vattr;
84struct vnode;
85struct vop_setlabel_args;
86
87#include <sys/acl.h> /* XXX acl_type_t */
88
89/*
90 * Kernel functions to manage and evaluate labels.
91 */
92
93void mac_init_bpfdesc(struct bpf_d *);
94void mac_init_cred(struct ucred *);
95void mac_init_devfsdirent(struct devfs_dirent *);
96void mac_init_ifnet(struct ifnet *);
97int mac_init_inpcb(struct inpcb *, int flag);
98void mac_init_sysv_msgmsg(struct msg *);
99void mac_init_sysv_msgqueue(struct msqid_kernel*);
100void mac_init_sysv_sem(struct semid_kernel*);
101void mac_init_sysv_shm(struct shmid_kernel*);
102int mac_init_ipq(struct ipq *, int flag);
103int mac_init_socket(struct socket *, int flag);
104void mac_init_pipe(struct pipepair *);
105void mac_init_posix_sem(struct ksem *);
106int mac_init_mbuf(struct mbuf *mbuf, int flag);
107int mac_init_mbuf_tag(struct m_tag *, int flag);
108void mac_init_mount(struct mount *);
109void mac_init_proc(struct proc *);
110void mac_init_vnode(struct vnode *);
111void mac_copy_mbuf(struct mbuf *m_from, struct mbuf *m_to);
112void mac_copy_mbuf_tag(struct m_tag *, struct m_tag *);
113void mac_copy_vnode_label(struct label *, struct label *label);
114void mac_destroy_bpfdesc(struct bpf_d *);
115void mac_destroy_cred(struct ucred *);
116void mac_destroy_devfsdirent(struct devfs_dirent *);
117void mac_destroy_ifnet(struct ifnet *);
118void mac_destroy_inpcb(struct inpcb *);
119void mac_destroy_sysv_msgmsg(struct msg *);
120void mac_destroy_sysv_msgqueue(struct msqid_kernel *);
121void mac_destroy_sysv_sem(struct semid_kernel *);
122void mac_destroy_sysv_shm(struct shmid_kernel *);
123void mac_destroy_ipq(struct ipq *);
124void mac_destroy_socket(struct socket *);
125void mac_destroy_pipe(struct pipepair *);
126void mac_destroy_posix_sem(struct ksem *);
127void mac_destroy_proc(struct proc *);
128void mac_destroy_mbuf_tag(struct m_tag *);
129void mac_destroy_mount(struct mount *);
130void mac_destroy_vnode(struct vnode *);
131
132struct label *mac_cred_label_alloc(void);
133void mac_cred_label_free(struct label *label);
134struct label *mac_vnode_label_alloc(void);
135void mac_vnode_label_free(struct label *label);
136
137/*
138 * Labeling event operations: file system objects, and things that
139 * look a lot like file system objects.
140 */
141void mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
142 struct vnode *vp);
143int mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp);
144void mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp);
145void mac_create_devfs_device(struct ucred *cred, struct mount *mp,
146 struct cdev *dev, struct devfs_dirent *de);
147void mac_create_devfs_directory(struct mount *mp, char *dirname,
148 int dirnamelen, struct devfs_dirent *de);
149void mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
150 struct devfs_dirent *dd, struct devfs_dirent *de);
151int mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
152 struct vnode *dvp, struct vnode *vp, struct componentname *cnp);
153void mac_create_mount(struct ucred *cred, struct mount *mp);
154void mac_relabel_vnode(struct ucred *cred, struct vnode *vp,
155 struct label *newlabel);
156void mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
157 struct vnode *vp);
158
159/*
160 * Labeling event operations: IPC objects.
161 */
162void mac_create_mbuf_from_socket(struct socket *so, struct mbuf *m);
163void mac_create_socket(struct ucred *cred, struct socket *socket);
164void mac_create_socket_from_socket(struct socket *oldsocket,
165 struct socket *newsocket);
166void mac_set_socket_peer_from_mbuf(struct mbuf *mbuf,
167 struct socket *socket);
168void mac_set_socket_peer_from_socket(struct socket *oldsocket,
169 struct socket *newsocket);
170void mac_create_pipe(struct ucred *cred, struct pipepair *pp);
171
172/*
173 * Labeling event operations: System V IPC primitives
174 */
175void mac_create_sysv_msgmsg(struct ucred *cred,
176 struct msqid_kernel *msqkptr, struct msg *msgptr);
177void mac_create_sysv_msgqueue(struct ucred *cred,
178 struct msqid_kernel *msqkptr);
179void mac_create_sysv_sem(struct ucred *cred,
180 struct semid_kernel *semakptr);
181void mac_create_sysv_shm(struct ucred *cred,
182 struct shmid_kernel *shmsegptr);
183
184/*
185 * Labeling event operations: POSIX (global/inter-process) semaphores.
186 */
187void mac_create_posix_sem(struct ucred *cred, struct ksem *ksemptr);
188
189
190/*
191 * Labeling event operations: network objects.
192 */
193void mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d);
194void mac_create_ifnet(struct ifnet *ifp);
195void mac_create_inpcb_from_socket(struct socket *so, struct inpcb *inp);
196void mac_create_ipq(struct mbuf *fragment, struct ipq *ipq);
197void mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram);
198void mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment);
199void mac_create_mbuf_from_inpcb(struct inpcb *inp, struct mbuf *m);
200void mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *m);
201void mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *m);
202void mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *m);
203void mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf,
204 struct ifnet *ifnet, struct mbuf *newmbuf);
205void mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf);
206int mac_fragment_match(struct mbuf *fragment, struct ipq *ipq);
207void mac_reflect_mbuf_icmp(struct mbuf *m);
208void mac_reflect_mbuf_tcp(struct mbuf *m);
209void mac_update_ipq(struct mbuf *fragment, struct ipq *ipq);
210void mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp);
211
212void mac_create_mbuf_from_firewall(struct mbuf *m);
213/*
214 * Labeling event operations: processes.
215 */
216void mac_copy_cred(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_execve_transition(struct ucred *old, struct ucred *new,
220 struct vnode *vp, struct label *interpvnodelabel,
221 struct image_params *imgp);
222int mac_execve_will_transition(struct ucred *old, struct vnode *vp,
223 struct label *interpvnodelabel, struct image_params *imgp);
224void mac_create_proc0(struct ucred *cred);
225void mac_create_proc1(struct ucred *cred);
226void mac_thread_userret(struct thread *td);
227
228/*
229 * Label cleanup operation: This is the inverse complement for the
230 * mac_create and associate type of hooks. This hook lets the policy
231 * module(s) perform a cleanup/flushing operation on the label
232 * associated with the objects, without freeing up the space allocated.
233 * This hook is useful in cases where it is desirable to remove any
234 * labeling reference when recycling any object to a pool. This hook
235 * does not replace the mac_destroy hooks.
236 */
237void mac_cleanup_sysv_msgmsg(struct msg *msgptr);
238void mac_cleanup_sysv_msgqueue(struct msqid_kernel *msqkptr);
239void mac_cleanup_sysv_sem(struct semid_kernel *semakptr);
240void mac_cleanup_sysv_shm(struct shmid_kernel *shmsegptr);
241
242/* Access control checks. */
243int mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet);
244int mac_check_cred_visible(struct ucred *u1, struct ucred *u2);
245int mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *m);
246int mac_check_inpcb_deliver(struct inpcb *inp, struct mbuf *m);
247int mac_check_sysv_msgmsq(struct ucred *cred, struct msg *msgptr,
248 struct msqid_kernel *msqkptr);
249int mac_check_sysv_msgrcv(struct ucred *cred, struct msg *msgptr);
250int mac_check_sysv_msgrmid(struct ucred *cred, struct msg *msgptr);
251int mac_check_sysv_msqget(struct ucred *cred,
252 struct msqid_kernel *msqkptr);
253int mac_check_sysv_msqsnd(struct ucred *cred,
254 struct msqid_kernel *msqkptr);
255int mac_check_sysv_msqrcv(struct ucred *cred,
256 struct msqid_kernel *msqkptr);
257int mac_check_sysv_msqctl(struct ucred *cred,
258 struct msqid_kernel *msqkptr, int cmd);
259int mac_check_sysv_semctl(struct ucred *cred,
260 struct semid_kernel *semakptr, int cmd);
261int mac_check_sysv_semget(struct ucred *cred,
262 struct semid_kernel *semakptr);
263int mac_check_sysv_semop(struct ucred *cred,struct semid_kernel *semakptr,
264 size_t accesstype);
265int mac_check_sysv_shmat(struct ucred *cred,
266 struct shmid_kernel *shmsegptr, int shmflg);
267int mac_check_sysv_shmctl(struct ucred *cred,
268 struct shmid_kernel *shmsegptr, int cmd);
269int mac_check_sysv_shmdt(struct ucred *cred,
270 struct shmid_kernel *shmsegptr);
271int mac_check_sysv_shmget(struct ucred *cred,
272 struct shmid_kernel *shmsegptr, int shmflg);
273int mac_check_kenv_dump(struct ucred *cred);
274int mac_check_kenv_get(struct ucred *cred, char *name);
275int mac_check_kenv_set(struct ucred *cred, char *name, char *value);
276int mac_check_kenv_unset(struct ucred *cred, char *name);
277int mac_check_kld_load(struct ucred *cred, struct vnode *vp);
278int mac_check_kld_stat(struct ucred *cred);
279int mac_check_kld_unload(struct ucred *cred);
280int mac_check_mount_stat(struct ucred *cred, struct mount *mp);
281int mac_check_pipe_ioctl(struct ucred *cred, struct pipepair *pp,
282 unsigned long cmd, void *data);
283int mac_check_pipe_poll(struct ucred *cred, struct pipepair *pp);
284int mac_check_pipe_read(struct ucred *cred, struct pipepair *pp);
285int mac_check_pipe_stat(struct ucred *cred, struct pipepair *pp);
286int mac_check_pipe_write(struct ucred *cred, struct pipepair *pp);
287int mac_check_posix_sem_destroy(struct ucred *cred, struct ksem *ksemptr);
288int mac_check_posix_sem_getvalue(struct ucred *cred,struct ksem *ksemptr);
289int mac_check_posix_sem_open(struct ucred *cred, struct ksem *ksemptr);
290int mac_check_posix_sem_post(struct ucred *cred, struct ksem *ksemptr);
291int mac_check_posix_sem_unlink(struct ucred *cred, struct ksem *ksemptr);
292int mac_check_posix_sem_wait(struct ucred *cred, struct ksem *ksemptr);
293int mac_check_proc_debug(struct ucred *cred, struct proc *proc);
294int mac_check_proc_sched(struct ucred *cred, struct proc *proc);
295int mac_check_proc_setuid(struct proc *proc, struct ucred *cred,
296 uid_t uid);
297int mac_check_proc_seteuid(struct proc *proc, struct ucred *cred,
298 uid_t euid);
299int mac_check_proc_setgid(struct proc *proc, struct ucred *cred,
300 gid_t gid);
301int mac_check_proc_setegid(struct proc *proc, struct ucred *cred,
302 gid_t egid);
303int mac_check_proc_setgroups(struct proc *proc, struct ucred *cred,
304 int ngroups, gid_t *gidset);
305int mac_check_proc_setreuid(struct proc *proc, struct ucred *cred,
306 uid_t ruid, uid_t euid);
307int mac_check_proc_setregid(struct proc *proc, struct ucred *cred,
308 gid_t rgid, gid_t egid);
309int mac_check_proc_setresuid(struct proc *proc, struct ucred *cred,
310 uid_t ruid, uid_t euid, uid_t suid);
311int mac_check_proc_setresgid(struct proc *proc, struct ucred *cred,
312 gid_t rgid, gid_t egid, gid_t sgid);
313int mac_check_proc_signal(struct ucred *cred, struct proc *proc,
314 int signum);
315int mac_check_proc_wait(struct ucred *cred, struct proc *proc);
316int mac_check_socket_accept(struct ucred *cred, struct socket *so);
317int mac_check_socket_bind(struct ucred *cred, struct socket *so,
318 struct sockaddr *sockaddr);
319int mac_check_socket_connect(struct ucred *cred, struct socket *so,
320 struct sockaddr *sockaddr);
321int mac_check_socket_create(struct ucred *cred, int domain, int type,
322 int protocol);
323int mac_check_socket_deliver(struct socket *so, struct mbuf *m);
324int mac_check_socket_listen(struct ucred *cred, struct socket *so);
325int mac_check_socket_poll(struct ucred *cred, struct socket *so);
326int mac_check_socket_receive(struct ucred *cred, struct socket *so);
327int mac_check_socket_send(struct ucred *cred, struct socket *so);
328int mac_check_socket_stat(struct ucred *cred, struct socket *so);
329int mac_check_socket_visible(struct ucred *cred, struct socket *so);
330int mac_check_sysarch_ioperm(struct ucred *cred);
331int mac_check_system_acct(struct ucred *cred, struct vnode *vp);
332int mac_check_system_nfsd(struct ucred *cred);
333int mac_check_system_reboot(struct ucred *cred, int howto);
334int mac_check_system_settime(struct ucred *cred);
335int mac_check_system_swapon(struct ucred *cred, struct vnode *vp);
336int mac_check_system_swapoff(struct ucred *cred, struct vnode *vp);
337int mac_check_system_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
338 void *arg1, int arg2, struct sysctl_req *req);
339int mac_check_vnode_access(struct ucred *cred, struct vnode *vp,
340 int acc_mode);
341int mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp);
342int mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp);
343int mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
344 struct componentname *cnp, struct vattr *vap);
345int mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp,
346 struct vnode *vp, struct componentname *cnp);
347int mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
348 acl_type_t type);
349int mac_check_vnode_deleteextattr(struct ucred *cred, struct vnode *vp,
350 int attrnamespace, const char *name);
351int mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
352 struct image_params *imgp);
353int mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp,
354 acl_type_t type);
355int mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
356 int attrnamespace, const char *name, struct uio *uio);
357int mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
358 struct vnode *vp, struct componentname *cnp);
359int mac_check_vnode_listextattr(struct ucred *cred, struct vnode *vp,
360 int attrnamespace);
361int mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
362 struct componentname *cnp);
363int mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp,
364 int prot, int flags);
365int mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp,
366 int prot);
367int mac_check_vnode_open(struct ucred *cred, struct vnode *vp,
368 int acc_mode);
369int mac_check_vnode_poll(struct ucred *active_cred,
370 struct ucred *file_cred, struct vnode *vp);
371int mac_check_vnode_read(struct ucred *active_cred,
372 struct ucred *file_cred, struct vnode *vp);
373int mac_check_vnode_readdir(struct ucred *cred, struct vnode *vp);
374int mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp);
375int mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
376 struct vnode *vp, struct componentname *cnp);
377int mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
378 struct vnode *vp, int samedir, struct componentname *cnp);
379int mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp);
380int mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp,
381 acl_type_t type, struct acl *acl);
382int mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
383 int attrnamespace, const char *name, struct uio *uio);
384int mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp,
385 u_long flags);
386int mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp,
387 mode_t mode);
388int mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp,
389 uid_t uid, gid_t gid);
390int mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
391 struct timespec atime, struct timespec mtime);
392int mac_check_vnode_stat(struct ucred *active_cred,
393 struct ucred *file_cred, struct vnode *vp);
394int mac_check_vnode_write(struct ucred *active_cred,
395 struct ucred *file_cred, struct vnode *vp);
396int mac_getsockopt_label(struct ucred *cred, struct socket *so,
397 struct mac *extmac);
398int mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so,
399 struct mac *extmac);
400int mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
401 struct ifnet *ifnet);
402int mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
403 struct ifnet *ifnet);
404int mac_setsockopt_label(struct ucred *cred, struct socket *so,
405 struct mac *extmac);
406int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp,
407 struct label *label);
408void mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred);
409void mac_associate_nfsd_label(struct ucred *cred);
410
411/*
412 * Calls to help various file systems implement labeling functionality
413 * using their existing EA implementation.
414 */
415int vop_stdsetlabel_ea(struct vop_setlabel_args *ap);
416
417#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 163606 2006-10-22 11:52:19Z 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_MAC_FRAMEWORK_H_
48
49#ifndef _KERNEL
50#error "no user-serviceable parts inside"
51#endif
52
53#include <sys/_label.h>
54
55struct bpf_d;
56struct cdev;
57struct componentname;
58struct devfs_dirent;
59struct ifnet;
60struct ifreq;
61struct image_params;
62struct inpcb;
63struct ipq;
64struct ksem;
65struct m_tag;
66struct mac;
67struct mbuf;
68struct mount;
69struct msg;
70struct msqid_kernel;
71struct proc;
72struct semid_kernel;
73struct shmid_kernel;
74struct sockaddr;
75struct socket;
76struct sysctl_oid;
77struct sysctl_req;
78struct pipepair;
79struct thread;
80struct timespec;
81struct ucred;
82struct uio;
83struct vattr;
84struct vnode;
85struct vop_setlabel_args;
86
87#include <sys/acl.h> /* XXX acl_type_t */
88
89/*
90 * Kernel functions to manage and evaluate labels.
91 */
92
93void mac_init_bpfdesc(struct bpf_d *);
94void mac_init_cred(struct ucred *);
95void mac_init_devfsdirent(struct devfs_dirent *);
96void mac_init_ifnet(struct ifnet *);
97int mac_init_inpcb(struct inpcb *, int flag);
98void mac_init_sysv_msgmsg(struct msg *);
99void mac_init_sysv_msgqueue(struct msqid_kernel*);
100void mac_init_sysv_sem(struct semid_kernel*);
101void mac_init_sysv_shm(struct shmid_kernel*);
102int mac_init_ipq(struct ipq *, int flag);
103int mac_init_socket(struct socket *, int flag);
104void mac_init_pipe(struct pipepair *);
105void mac_init_posix_sem(struct ksem *);
106int mac_init_mbuf(struct mbuf *mbuf, int flag);
107int mac_init_mbuf_tag(struct m_tag *, int flag);
108void mac_init_mount(struct mount *);
109void mac_init_proc(struct proc *);
110void mac_init_vnode(struct vnode *);
111void mac_copy_mbuf(struct mbuf *m_from, struct mbuf *m_to);
112void mac_copy_mbuf_tag(struct m_tag *, struct m_tag *);
113void mac_copy_vnode_label(struct label *, struct label *label);
114void mac_destroy_bpfdesc(struct bpf_d *);
115void mac_destroy_cred(struct ucred *);
116void mac_destroy_devfsdirent(struct devfs_dirent *);
117void mac_destroy_ifnet(struct ifnet *);
118void mac_destroy_inpcb(struct inpcb *);
119void mac_destroy_sysv_msgmsg(struct msg *);
120void mac_destroy_sysv_msgqueue(struct msqid_kernel *);
121void mac_destroy_sysv_sem(struct semid_kernel *);
122void mac_destroy_sysv_shm(struct shmid_kernel *);
123void mac_destroy_ipq(struct ipq *);
124void mac_destroy_socket(struct socket *);
125void mac_destroy_pipe(struct pipepair *);
126void mac_destroy_posix_sem(struct ksem *);
127void mac_destroy_proc(struct proc *);
128void mac_destroy_mbuf_tag(struct m_tag *);
129void mac_destroy_mount(struct mount *);
130void mac_destroy_vnode(struct vnode *);
131
132struct label *mac_cred_label_alloc(void);
133void mac_cred_label_free(struct label *label);
134struct label *mac_vnode_label_alloc(void);
135void mac_vnode_label_free(struct label *label);
136
137/*
138 * Labeling event operations: file system objects, and things that
139 * look a lot like file system objects.
140 */
141void mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de,
142 struct vnode *vp);
143int mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp);
144void mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp);
145void mac_create_devfs_device(struct ucred *cred, struct mount *mp,
146 struct cdev *dev, struct devfs_dirent *de);
147void mac_create_devfs_directory(struct mount *mp, char *dirname,
148 int dirnamelen, struct devfs_dirent *de);
149void mac_create_devfs_symlink(struct ucred *cred, struct mount *mp,
150 struct devfs_dirent *dd, struct devfs_dirent *de);
151int mac_create_vnode_extattr(struct ucred *cred, struct mount *mp,
152 struct vnode *dvp, struct vnode *vp, struct componentname *cnp);
153void mac_create_mount(struct ucred *cred, struct mount *mp);
154void mac_relabel_vnode(struct ucred *cred, struct vnode *vp,
155 struct label *newlabel);
156void mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de,
157 struct vnode *vp);
158
159/*
160 * Labeling event operations: IPC objects.
161 */
162void mac_create_mbuf_from_socket(struct socket *so, struct mbuf *m);
163void mac_create_socket(struct ucred *cred, struct socket *socket);
164void mac_create_socket_from_socket(struct socket *oldsocket,
165 struct socket *newsocket);
166void mac_set_socket_peer_from_mbuf(struct mbuf *mbuf,
167 struct socket *socket);
168void mac_set_socket_peer_from_socket(struct socket *oldsocket,
169 struct socket *newsocket);
170void mac_create_pipe(struct ucred *cred, struct pipepair *pp);
171
172/*
173 * Labeling event operations: System V IPC primitives
174 */
175void mac_create_sysv_msgmsg(struct ucred *cred,
176 struct msqid_kernel *msqkptr, struct msg *msgptr);
177void mac_create_sysv_msgqueue(struct ucred *cred,
178 struct msqid_kernel *msqkptr);
179void mac_create_sysv_sem(struct ucred *cred,
180 struct semid_kernel *semakptr);
181void mac_create_sysv_shm(struct ucred *cred,
182 struct shmid_kernel *shmsegptr);
183
184/*
185 * Labeling event operations: POSIX (global/inter-process) semaphores.
186 */
187void mac_create_posix_sem(struct ucred *cred, struct ksem *ksemptr);
188
189
190/*
191 * Labeling event operations: network objects.
192 */
193void mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d);
194void mac_create_ifnet(struct ifnet *ifp);
195void mac_create_inpcb_from_socket(struct socket *so, struct inpcb *inp);
196void mac_create_ipq(struct mbuf *fragment, struct ipq *ipq);
197void mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram);
198void mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment);
199void mac_create_mbuf_from_inpcb(struct inpcb *inp, struct mbuf *m);
200void mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *m);
201void mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *m);
202void mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *m);
203void mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf,
204 struct ifnet *ifnet, struct mbuf *newmbuf);
205void mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf);
206int mac_fragment_match(struct mbuf *fragment, struct ipq *ipq);
207void mac_reflect_mbuf_icmp(struct mbuf *m);
208void mac_reflect_mbuf_tcp(struct mbuf *m);
209void mac_update_ipq(struct mbuf *fragment, struct ipq *ipq);
210void mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp);
211
212void mac_create_mbuf_from_firewall(struct mbuf *m);
213/*
214 * Labeling event operations: processes.
215 */
216void mac_copy_cred(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_execve_transition(struct ucred *old, struct ucred *new,
220 struct vnode *vp, struct label *interpvnodelabel,
221 struct image_params *imgp);
222int mac_execve_will_transition(struct ucred *old, struct vnode *vp,
223 struct label *interpvnodelabel, struct image_params *imgp);
224void mac_create_proc0(struct ucred *cred);
225void mac_create_proc1(struct ucred *cred);
226void mac_thread_userret(struct thread *td);
227
228/*
229 * Label cleanup operation: This is the inverse complement for the
230 * mac_create and associate type of hooks. This hook lets the policy
231 * module(s) perform a cleanup/flushing operation on the label
232 * associated with the objects, without freeing up the space allocated.
233 * This hook is useful in cases where it is desirable to remove any
234 * labeling reference when recycling any object to a pool. This hook
235 * does not replace the mac_destroy hooks.
236 */
237void mac_cleanup_sysv_msgmsg(struct msg *msgptr);
238void mac_cleanup_sysv_msgqueue(struct msqid_kernel *msqkptr);
239void mac_cleanup_sysv_sem(struct semid_kernel *semakptr);
240void mac_cleanup_sysv_shm(struct shmid_kernel *shmsegptr);
241
242/* Access control checks. */
243int mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet);
244int mac_check_cred_visible(struct ucred *u1, struct ucred *u2);
245int mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *m);
246int mac_check_inpcb_deliver(struct inpcb *inp, struct mbuf *m);
247int mac_check_sysv_msgmsq(struct ucred *cred, struct msg *msgptr,
248 struct msqid_kernel *msqkptr);
249int mac_check_sysv_msgrcv(struct ucred *cred, struct msg *msgptr);
250int mac_check_sysv_msgrmid(struct ucred *cred, struct msg *msgptr);
251int mac_check_sysv_msqget(struct ucred *cred,
252 struct msqid_kernel *msqkptr);
253int mac_check_sysv_msqsnd(struct ucred *cred,
254 struct msqid_kernel *msqkptr);
255int mac_check_sysv_msqrcv(struct ucred *cred,
256 struct msqid_kernel *msqkptr);
257int mac_check_sysv_msqctl(struct ucred *cred,
258 struct msqid_kernel *msqkptr, int cmd);
259int mac_check_sysv_semctl(struct ucred *cred,
260 struct semid_kernel *semakptr, int cmd);
261int mac_check_sysv_semget(struct ucred *cred,
262 struct semid_kernel *semakptr);
263int mac_check_sysv_semop(struct ucred *cred,struct semid_kernel *semakptr,
264 size_t accesstype);
265int mac_check_sysv_shmat(struct ucred *cred,
266 struct shmid_kernel *shmsegptr, int shmflg);
267int mac_check_sysv_shmctl(struct ucred *cred,
268 struct shmid_kernel *shmsegptr, int cmd);
269int mac_check_sysv_shmdt(struct ucred *cred,
270 struct shmid_kernel *shmsegptr);
271int mac_check_sysv_shmget(struct ucred *cred,
272 struct shmid_kernel *shmsegptr, int shmflg);
273int mac_check_kenv_dump(struct ucred *cred);
274int mac_check_kenv_get(struct ucred *cred, char *name);
275int mac_check_kenv_set(struct ucred *cred, char *name, char *value);
276int mac_check_kenv_unset(struct ucred *cred, char *name);
277int mac_check_kld_load(struct ucred *cred, struct vnode *vp);
278int mac_check_kld_stat(struct ucred *cred);
279int mac_check_kld_unload(struct ucred *cred);
280int mac_check_mount_stat(struct ucred *cred, struct mount *mp);
281int mac_check_pipe_ioctl(struct ucred *cred, struct pipepair *pp,
282 unsigned long cmd, void *data);
283int mac_check_pipe_poll(struct ucred *cred, struct pipepair *pp);
284int mac_check_pipe_read(struct ucred *cred, struct pipepair *pp);
285int mac_check_pipe_stat(struct ucred *cred, struct pipepair *pp);
286int mac_check_pipe_write(struct ucred *cred, struct pipepair *pp);
287int mac_check_posix_sem_destroy(struct ucred *cred, struct ksem *ksemptr);
288int mac_check_posix_sem_getvalue(struct ucred *cred,struct ksem *ksemptr);
289int mac_check_posix_sem_open(struct ucred *cred, struct ksem *ksemptr);
290int mac_check_posix_sem_post(struct ucred *cred, struct ksem *ksemptr);
291int mac_check_posix_sem_unlink(struct ucred *cred, struct ksem *ksemptr);
292int mac_check_posix_sem_wait(struct ucred *cred, struct ksem *ksemptr);
293int mac_check_proc_debug(struct ucred *cred, struct proc *proc);
294int mac_check_proc_sched(struct ucred *cred, struct proc *proc);
295int mac_check_proc_setuid(struct proc *proc, struct ucred *cred,
296 uid_t uid);
297int mac_check_proc_seteuid(struct proc *proc, struct ucred *cred,
298 uid_t euid);
299int mac_check_proc_setgid(struct proc *proc, struct ucred *cred,
300 gid_t gid);
301int mac_check_proc_setegid(struct proc *proc, struct ucred *cred,
302 gid_t egid);
303int mac_check_proc_setgroups(struct proc *proc, struct ucred *cred,
304 int ngroups, gid_t *gidset);
305int mac_check_proc_setreuid(struct proc *proc, struct ucred *cred,
306 uid_t ruid, uid_t euid);
307int mac_check_proc_setregid(struct proc *proc, struct ucred *cred,
308 gid_t rgid, gid_t egid);
309int mac_check_proc_setresuid(struct proc *proc, struct ucred *cred,
310 uid_t ruid, uid_t euid, uid_t suid);
311int mac_check_proc_setresgid(struct proc *proc, struct ucred *cred,
312 gid_t rgid, gid_t egid, gid_t sgid);
313int mac_check_proc_signal(struct ucred *cred, struct proc *proc,
314 int signum);
315int mac_check_proc_wait(struct ucred *cred, struct proc *proc);
316int mac_check_socket_accept(struct ucred *cred, struct socket *so);
317int mac_check_socket_bind(struct ucred *cred, struct socket *so,
318 struct sockaddr *sockaddr);
319int mac_check_socket_connect(struct ucred *cred, struct socket *so,
320 struct sockaddr *sockaddr);
321int mac_check_socket_create(struct ucred *cred, int domain, int type,
322 int protocol);
323int mac_check_socket_deliver(struct socket *so, struct mbuf *m);
324int mac_check_socket_listen(struct ucred *cred, struct socket *so);
325int mac_check_socket_poll(struct ucred *cred, struct socket *so);
326int mac_check_socket_receive(struct ucred *cred, struct socket *so);
327int mac_check_socket_send(struct ucred *cred, struct socket *so);
328int mac_check_socket_stat(struct ucred *cred, struct socket *so);
329int mac_check_socket_visible(struct ucred *cred, struct socket *so);
330int mac_check_sysarch_ioperm(struct ucred *cred);
331int mac_check_system_acct(struct ucred *cred, struct vnode *vp);
332int mac_check_system_nfsd(struct ucred *cred);
333int mac_check_system_reboot(struct ucred *cred, int howto);
334int mac_check_system_settime(struct ucred *cred);
335int mac_check_system_swapon(struct ucred *cred, struct vnode *vp);
336int mac_check_system_swapoff(struct ucred *cred, struct vnode *vp);
337int mac_check_system_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
338 void *arg1, int arg2, struct sysctl_req *req);
339int mac_check_vnode_access(struct ucred *cred, struct vnode *vp,
340 int acc_mode);
341int mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp);
342int mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp);
343int mac_check_vnode_create(struct ucred *cred, struct vnode *dvp,
344 struct componentname *cnp, struct vattr *vap);
345int mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp,
346 struct vnode *vp, struct componentname *cnp);
347int mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp,
348 acl_type_t type);
349int mac_check_vnode_deleteextattr(struct ucred *cred, struct vnode *vp,
350 int attrnamespace, const char *name);
351int mac_check_vnode_exec(struct ucred *cred, struct vnode *vp,
352 struct image_params *imgp);
353int mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp,
354 acl_type_t type);
355int mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp,
356 int attrnamespace, const char *name, struct uio *uio);
357int mac_check_vnode_link(struct ucred *cred, struct vnode *dvp,
358 struct vnode *vp, struct componentname *cnp);
359int mac_check_vnode_listextattr(struct ucred *cred, struct vnode *vp,
360 int attrnamespace);
361int mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp,
362 struct componentname *cnp);
363int mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp,
364 int prot, int flags);
365int mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp,
366 int prot);
367int mac_check_vnode_open(struct ucred *cred, struct vnode *vp,
368 int acc_mode);
369int mac_check_vnode_poll(struct ucred *active_cred,
370 struct ucred *file_cred, struct vnode *vp);
371int mac_check_vnode_read(struct ucred *active_cred,
372 struct ucred *file_cred, struct vnode *vp);
373int mac_check_vnode_readdir(struct ucred *cred, struct vnode *vp);
374int mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp);
375int mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp,
376 struct vnode *vp, struct componentname *cnp);
377int mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp,
378 struct vnode *vp, int samedir, struct componentname *cnp);
379int mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp);
380int mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp,
381 acl_type_t type, struct acl *acl);
382int mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp,
383 int attrnamespace, const char *name, struct uio *uio);
384int mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp,
385 u_long flags);
386int mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp,
387 mode_t mode);
388int mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp,
389 uid_t uid, gid_t gid);
390int mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp,
391 struct timespec atime, struct timespec mtime);
392int mac_check_vnode_stat(struct ucred *active_cred,
393 struct ucred *file_cred, struct vnode *vp);
394int mac_check_vnode_write(struct ucred *active_cred,
395 struct ucred *file_cred, struct vnode *vp);
396int mac_getsockopt_label(struct ucred *cred, struct socket *so,
397 struct mac *extmac);
398int mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so,
399 struct mac *extmac);
400int mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr,
401 struct ifnet *ifnet);
402int mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr,
403 struct ifnet *ifnet);
404int mac_setsockopt_label(struct ucred *cred, struct socket *so,
405 struct mac *extmac);
406int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp,
407 struct label *label);
408void mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred);
409void mac_associate_nfsd_label(struct ucred *cred);
410
411/*
412 * Calls to help various file systems implement labeling functionality
413 * using their existing EA implementation.
414 */
415int vop_stdsetlabel_ea(struct vop_setlabel_args *ap);
416
417#endif /* !_SYS_SECURITY_MAC_MAC_FRAMEWORK_H_ */