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