1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef _SECURITY_SMACK_H
14#define _SECURITY_SMACK_H
15
16#include <linux/capability.h>
17#include <linux/spinlock.h>
18#include <linux/security.h>
19#include <linux/in.h>
20#include <net/netlabel.h>
21#include <linux/list.h>
22#include <linux/rculist.h>
23#include <linux/lsm_audit.h>
24
25
26
27
28
29
30
31#define SMK_MAXLEN 23
32#define SMK_LABELLEN (SMK_MAXLEN+1)
33
34struct superblock_smack {
35 char *smk_root;
36 char *smk_floor;
37 char *smk_hat;
38 char *smk_default;
39 int smk_initialized;
40 spinlock_t smk_sblock;
41};
42
43struct socket_smack {
44 char *smk_out;
45 char *smk_in;
46 char *smk_packet;
47};
48
49
50
51
52struct inode_smack {
53 char *smk_inode;
54 char *smk_task;
55 char *smk_mmap;
56 struct mutex smk_lock;
57 int smk_flags;
58};
59
60struct task_smack {
61 char *smk_task;
62 char *smk_forked;
63 struct list_head smk_rules;
64 struct mutex smk_rules_lock;
65};
66
67#define SMK_INODE_INSTANT 0x01
68#define SMK_INODE_TRANSMUTE 0x02
69
70
71
72
73struct smack_rule {
74 struct list_head list;
75 char *smk_subject;
76 char *smk_object;
77 int smk_access;
78};
79
80
81
82
83
84struct smack_cipso {
85 int smk_level;
86 char smk_catset[SMK_LABELLEN];
87};
88
89
90
91
92struct smk_netlbladdr {
93 struct list_head list;
94 struct sockaddr_in smk_host;
95 struct in_addr smk_mask;
96 char *smk_label;
97};
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124struct smack_known {
125 struct list_head list;
126 char smk_known[SMK_LABELLEN];
127 u32 smk_secid;
128 struct smack_cipso *smk_cipso;
129 spinlock_t smk_cipsolock;
130 struct list_head smk_rules;
131 struct mutex smk_rules_lock;
132};
133
134
135
136
137#define SMK_FSDEFAULT "smackfsdef="
138#define SMK_FSFLOOR "smackfsfloor="
139#define SMK_FSHAT "smackfshat="
140#define SMK_FSROOT "smackfsroot="
141
142#define SMACK_CIPSO_OPTION "-CIPSO"
143
144
145
146
147
148
149
150
151
152
153
154#define SMACK_UNLABELED_SOCKET 0
155#define SMACK_CIPSO_SOCKET 1
156
157
158
159
160#define SMACK_MAGIC 0x43415d53
161
162
163
164
165#define SMACK_CIPSO_DOI_DEFAULT 3
166#define SMACK_CIPSO_DOI_INVALID -1
167#define SMACK_CIPSO_DIRECT_DEFAULT 250
168#define SMACK_CIPSO_MAXCATVAL 63
169#define SMACK_CIPSO_MAXLEVEL 255
170#define SMACK_CIPSO_MAXCATNUM 239
171
172
173
174
175#define MAY_TRANSMUTE 64
176
177
178
179#define MAY_ANYREAD (MAY_READ | MAY_EXEC)
180#define MAY_READWRITE (MAY_READ | MAY_WRITE)
181#define MAY_NOT 0
182
183
184
185
186#define SMK_NUM_ACCESS_TYPE 5
187
188
189
190
191
192struct smk_audit_info {
193#ifdef CONFIG_AUDIT
194 struct common_audit_data a;
195#endif
196};
197
198
199
200struct inode_smack *new_inode_smack(char *);
201
202
203
204
205int smk_access_entry(char *, char *, struct list_head *);
206int smk_access(char *, char *, int, struct smk_audit_info *);
207int smk_curacc(char *, u32, struct smk_audit_info *);
208int smack_to_cipso(const char *, struct smack_cipso *);
209char *smack_from_cipso(u32, char *);
210char *smack_from_secid(const u32);
211void smk_parse_smack(const char *string, int len, char *smack);
212char *smk_import(const char *, int);
213struct smack_known *smk_import_entry(const char *, int);
214struct smack_known *smk_find_entry(const char *);
215u32 smack_to_secid(const char *);
216
217
218
219
220extern int smack_cipso_direct;
221extern char *smack_net_ambient;
222extern char *smack_onlycap;
223extern const char *smack_cipso_option;
224
225extern struct smack_known smack_known_floor;
226extern struct smack_known smack_known_hat;
227extern struct smack_known smack_known_huh;
228extern struct smack_known smack_known_invalid;
229extern struct smack_known smack_known_star;
230extern struct smack_known smack_known_web;
231
232extern struct list_head smack_known_list;
233extern struct list_head smk_netlbladdr_list;
234
235extern struct security_operations smack_ops;
236
237
238
239
240
241static inline void smack_catset_bit(int cat, char *catsetp)
242{
243 if (cat > SMK_LABELLEN * 8)
244 return;
245
246 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
247}
248
249
250
251
252static inline int smk_inode_transmutable(const struct inode *isp)
253{
254 struct inode_smack *sip = isp->i_security;
255 return (sip->smk_flags & SMK_INODE_TRANSMUTE) != 0;
256}
257
258
259
260
261static inline char *smk_of_inode(const struct inode *isp)
262{
263 struct inode_smack *sip = isp->i_security;
264 return sip->smk_inode;
265}
266
267
268
269
270static inline char *smk_of_task(const struct task_smack *tsp)
271{
272 return tsp->smk_task;
273}
274
275
276
277
278static inline char *smk_of_forked(const struct task_smack *tsp)
279{
280 return tsp->smk_forked;
281}
282
283
284
285
286static inline char *smk_of_current(void)
287{
288 return smk_of_task(current_security());
289}
290
291
292
293
294#define SMACK_AUDIT_DENIED 0x1
295#define SMACK_AUDIT_ACCEPT 0x2
296extern int log_policy;
297
298void smack_log(char *subject_label, char *object_label,
299 int request,
300 int result, struct smk_audit_info *auditdata);
301
302#ifdef CONFIG_AUDIT
303
304
305
306
307
308
309static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
310 char type)
311{
312 memset(a, 0, sizeof(*a));
313 a->a.type = type;
314 a->a.smack_audit_data.function = func;
315}
316
317static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
318 struct task_struct *t)
319{
320 a->a.u.tsk = t;
321}
322static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
323 struct dentry *d)
324{
325 a->a.u.dentry = d;
326}
327static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
328 struct inode *i)
329{
330 a->a.u.inode = i;
331}
332static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
333 struct path p)
334{
335 a->a.u.path = p;
336}
337static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
338 struct sock *sk)
339{
340 a->a.u.net.sk = sk;
341}
342
343#else
344
345static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
346 char type)
347{
348}
349static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
350 struct task_struct *t)
351{
352}
353static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
354 struct dentry *d)
355{
356}
357static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
358 struct vfsmount *m)
359{
360}
361static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
362 struct inode *i)
363{
364}
365static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
366 struct path p)
367{
368}
369static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
370 struct sock *sk)
371{
372}
373#endif
374
375#endif
376