VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / security / selinux / include / avc.h
1 /*
2  * Access vector cache interface for object managers.
3  *
4  * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
5  */
6 #ifndef _SELINUX_AVC_H_
7 #define _SELINUX_AVC_H_
8
9 #include <linux/stddef.h>
10 #include <linux/errno.h>
11 #include <linux/kernel.h>
12 #include <linux/kdev_t.h>
13 #include <linux/spinlock.h>
14 #include <linux/init.h>
15 #include <linux/in6.h>
16 #include <asm/system.h>
17 #include "flask.h"
18 #include "av_permissions.h"
19 #include "security.h"
20
21 #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
22 extern int selinux_enforcing;
23 #else
24 #define selinux_enforcing 1
25 #endif
26
27 /*
28  * An entry in the AVC.
29  */
30 struct avc_entry;
31
32 /*
33  * A reference to an AVC entry.
34  */
35 struct avc_entry_ref {
36         struct avc_entry *ae;
37 };
38
39 /* Initialize an AVC entry reference before first use. */
40 static inline void avc_entry_ref_init(struct avc_entry_ref *h)
41 {
42         h->ae = NULL;
43 }
44
45 struct task_struct;
46 struct vfsmount;
47 struct dentry;
48 struct inode;
49 struct sock;
50 struct sk_buff;
51
52 /* Auxiliary data to use in generating the audit record. */
53 struct avc_audit_data {
54         char    type;
55 #define AVC_AUDIT_DATA_FS   1
56 #define AVC_AUDIT_DATA_NET  2
57 #define AVC_AUDIT_DATA_CAP  3
58 #define AVC_AUDIT_DATA_IPC  4
59         struct task_struct *tsk;
60         union   {
61                 struct {
62                         struct vfsmount *mnt;
63                         struct dentry *dentry;
64                         struct inode *inode;
65                 } fs;
66                 struct {
67                         char *netif;
68                         struct sock *sk;
69                         u16 family;
70                         u16 dport;
71                         u16 sport;
72                         union {
73                                 struct {
74                                         u32 daddr;
75                                         u32 saddr;
76                                 } v4;
77                                 struct {
78                                         struct in6_addr daddr;
79                                         struct in6_addr saddr;
80                                 } v6;
81                         } fam;
82                 } net;
83                 int cap;
84                 int ipc_id;
85         } u;
86 };
87
88 #define v4info fam.v4
89 #define v6info fam.v6
90
91 /* Initialize an AVC audit data structure. */
92 #define AVC_AUDIT_DATA_INIT(_d,_t) \
93         { memset((_d), 0, sizeof(struct avc_audit_data)); (_d)->type = AVC_AUDIT_DATA_##_t; }
94
95 /*
96  * AVC statistics
97  */
98 #define AVC_ENTRY_LOOKUPS        0
99 #define AVC_ENTRY_HITS           1
100 #define AVC_ENTRY_MISSES         2
101 #define AVC_ENTRY_DISCARDS       3
102 #define AVC_CAV_LOOKUPS          4
103 #define AVC_CAV_HITS             5
104 #define AVC_CAV_PROBES           6
105 #define AVC_CAV_MISSES           7
106 #define AVC_NSTATS               8
107
108 /*
109  * AVC display support
110  */
111 struct audit_buffer;
112 void avc_dump_av(struct audit_buffer *ab, u16 tclass, u32 av);
113 void avc_dump_query(struct audit_buffer *ab, u32 ssid, u32 tsid, u16 tclass);
114 void avc_dump_cache(struct audit_buffer *ab, char *tag);
115
116 /*
117  * AVC operations
118  */
119
120 void __init avc_init(void);
121
122 int avc_lookup(u32 ssid, u32 tsid, u16 tclass,
123                u32 requested, struct avc_entry_ref *aeref);
124
125 int avc_insert(u32 ssid, u32 tsid, u16 tclass,
126                struct avc_entry *ae, struct avc_entry_ref *out_aeref);
127
128 void avc_audit(u32 ssid, u32 tsid,
129                u16 tclass, u32 requested,
130                struct av_decision *avd, int result, struct avc_audit_data *auditdata);
131
132 int avc_has_perm_noaudit(u32 ssid, u32 tsid,
133                          u16 tclass, u32 requested,
134                          struct avc_entry_ref *aeref, struct av_decision *avd);
135
136 int avc_has_perm(u32 ssid, u32 tsid,
137                  u16 tclass, u32 requested,
138                  struct avc_entry_ref *aeref, struct avc_audit_data *auditdata);
139
140 #define AVC_CALLBACK_GRANT              1
141 #define AVC_CALLBACK_TRY_REVOKE         2
142 #define AVC_CALLBACK_REVOKE             4
143 #define AVC_CALLBACK_RESET              8
144 #define AVC_CALLBACK_AUDITALLOW_ENABLE  16
145 #define AVC_CALLBACK_AUDITALLOW_DISABLE 32
146 #define AVC_CALLBACK_AUDITDENY_ENABLE   64
147 #define AVC_CALLBACK_AUDITDENY_DISABLE  128
148
149 int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid,
150                                      u16 tclass, u32 perms,
151                                      u32 *out_retained),
152                      u32 events, u32 ssid, u32 tsid,
153                      u16 tclass, u32 perms);
154
155 #endif /* _SELINUX_AVC_H_ */
156