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/lsm_hooks.h>
19#include <linux/in.h>
20#if IS_ENABLED(CONFIG_IPV6)
21#include <linux/in6.h>
22#endif
23#include <net/netlabel.h>
24#include <linux/list.h>
25#include <linux/rculist.h>
26#include <linux/lsm_audit.h>
27
28
29
30
31
32#if IS_ENABLED(CONFIG_IPV6) && !defined(CONFIG_SECURITY_SMACK_NETFILTER)
33#define SMACK_IPV6_PORT_LABELING 1
34#endif
35
36#if IS_ENABLED(CONFIG_IPV6) && defined(CONFIG_SECURITY_SMACK_NETFILTER)
37#define SMACK_IPV6_SECMARK_LABELING 1
38#endif
39
40
41
42
43#define SMK_LABELLEN 24
44#define SMK_LONGLABEL 256
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69struct smack_known {
70 struct list_head list;
71 struct hlist_node smk_hashed;
72 char *smk_known;
73 u32 smk_secid;
74 struct netlbl_lsm_secattr smk_netlabel;
75 struct list_head smk_rules;
76 struct mutex smk_rules_lock;
77};
78
79
80
81
82
83
84
85
86#define SMK_CIPSOLEN 24
87
88struct superblock_smack {
89 struct smack_known *smk_root;
90 struct smack_known *smk_floor;
91 struct smack_known *smk_hat;
92 struct smack_known *smk_default;
93 int smk_flags;
94};
95
96
97
98
99#define SMK_SB_INITIALIZED 0x01
100#define SMK_SB_UNTRUSTED 0x02
101
102struct socket_smack {
103 struct smack_known *smk_out;
104 struct smack_known *smk_in;
105 struct smack_known *smk_packet;
106};
107
108
109
110
111struct inode_smack {
112 struct smack_known *smk_inode;
113 struct smack_known *smk_task;
114 struct smack_known *smk_mmap;
115 struct mutex smk_lock;
116 int smk_flags;
117 struct rcu_head smk_rcu;
118};
119
120struct task_smack {
121 struct smack_known *smk_task;
122 struct smack_known *smk_forked;
123 struct list_head smk_rules;
124 struct mutex smk_rules_lock;
125 struct list_head smk_relabel;
126};
127
128#define SMK_INODE_INSTANT 0x01
129#define SMK_INODE_TRANSMUTE 0x02
130#define SMK_INODE_CHANGED 0x04
131#define SMK_INODE_IMPURE 0x08
132
133
134
135
136struct smack_rule {
137 struct list_head list;
138 struct smack_known *smk_subject;
139 struct smack_known *smk_object;
140 int smk_access;
141};
142
143
144
145
146struct smk_net4addr {
147 struct list_head list;
148 struct in_addr smk_host;
149 struct in_addr smk_mask;
150 int smk_masks;
151 struct smack_known *smk_label;
152};
153
154#if IS_ENABLED(CONFIG_IPV6)
155
156
157
158struct smk_net6addr {
159 struct list_head list;
160 struct in6_addr smk_host;
161 struct in6_addr smk_mask;
162 int smk_masks;
163 struct smack_known *smk_label;
164};
165#endif
166
167#ifdef SMACK_IPV6_PORT_LABELING
168
169
170
171struct smk_port_label {
172 struct list_head list;
173 struct sock *smk_sock;
174 unsigned short smk_port;
175 struct smack_known *smk_in;
176 struct smack_known *smk_out;
177 short smk_sock_type;
178 short smk_can_reuse;
179};
180#endif
181
182struct smack_known_list_elem {
183 struct list_head list;
184 struct smack_known *smk_label;
185};
186
187
188#define FSDEFAULT_MNT 0x01
189#define FSFLOOR_MNT 0x02
190#define FSHAT_MNT 0x04
191#define FSROOT_MNT 0x08
192#define FSTRANS_MNT 0x10
193
194#define NUM_SMK_MNT_OPTS 5
195
196enum {
197 Opt_error = -1,
198 Opt_fsdefault = 1,
199 Opt_fsfloor = 2,
200 Opt_fshat = 3,
201 Opt_fsroot = 4,
202 Opt_fstransmute = 5,
203};
204
205
206
207
208#define SMK_FSDEFAULT "smackfsdef="
209#define SMK_FSFLOOR "smackfsfloor="
210#define SMK_FSHAT "smackfshat="
211#define SMK_FSROOT "smackfsroot="
212#define SMK_FSTRANS "smackfstransmute="
213
214#define SMACK_DELETE_OPTION "-DELETE"
215#define SMACK_CIPSO_OPTION "-CIPSO"
216
217
218
219
220
221
222
223
224
225
226
227#define SMACK_UNLABELED_SOCKET 0
228#define SMACK_CIPSO_SOCKET 1
229
230
231
232
233#define SMACK_CIPSO_DOI_DEFAULT 3
234#define SMACK_CIPSO_DOI_INVALID -1
235#define SMACK_CIPSO_DIRECT_DEFAULT 250
236#define SMACK_CIPSO_MAPPED_DEFAULT 251
237#define SMACK_CIPSO_MAXLEVEL 255
238
239
240
241
242
243#define SMACK_CIPSO_MAXCATNUM 184
244
245
246
247
248#define SMACK_PTRACE_DEFAULT 0
249#define SMACK_PTRACE_EXACT 1
250#define SMACK_PTRACE_DRACONIAN 2
251#define SMACK_PTRACE_MAX SMACK_PTRACE_DRACONIAN
252
253
254
255
256
257
258#define MAY_TRANSMUTE 0x00001000
259#define MAY_LOCK 0x00002000
260#define MAY_BRINGUP 0x00004000
261
262
263
264
265
266#ifdef CONFIG_SECURITY_SMACK_APPEND_SIGNALS
267#define MAY_DELIVER MAY_APPEND
268#else
269#define MAY_DELIVER MAY_WRITE
270#endif
271
272#define SMACK_BRINGUP_ALLOW 1
273#define SMACK_UNCONFINED_SUBJECT 2
274#define SMACK_UNCONFINED_OBJECT 3
275
276
277
278
279#define MAY_ANYREAD (MAY_READ | MAY_EXEC)
280#define MAY_READWRITE (MAY_READ | MAY_WRITE)
281#define MAY_NOT 0
282
283
284
285
286#define SMK_NUM_ACCESS_TYPE 7
287
288
289struct smack_audit_data {
290 const char *function;
291 char *subject;
292 char *object;
293 char *request;
294 int result;
295};
296
297
298
299
300
301struct smk_audit_info {
302#ifdef CONFIG_AUDIT
303 struct common_audit_data a;
304 struct smack_audit_data sad;
305#endif
306};
307
308
309
310
311int smk_access_entry(char *, char *, struct list_head *);
312int smk_access(struct smack_known *, struct smack_known *,
313 int, struct smk_audit_info *);
314int smk_tskacc(struct task_smack *, struct smack_known *,
315 u32, struct smk_audit_info *);
316int smk_curacc(struct smack_known *, u32, struct smk_audit_info *);
317struct smack_known *smack_from_secid(const u32);
318char *smk_parse_smack(const char *string, int len);
319int smk_netlbl_mls(int, char *, struct netlbl_lsm_secattr *, int);
320struct smack_known *smk_import_entry(const char *, int);
321void smk_insert_entry(struct smack_known *skp);
322struct smack_known *smk_find_entry(const char *);
323bool smack_privileged(int cap);
324void smk_destroy_label_list(struct list_head *list);
325
326
327
328
329extern int smack_enabled;
330extern int smack_cipso_direct;
331extern int smack_cipso_mapped;
332extern struct smack_known *smack_net_ambient;
333extern struct smack_known *smack_syslog_label;
334#ifdef CONFIG_SECURITY_SMACK_BRINGUP
335extern struct smack_known *smack_unconfined;
336#endif
337extern int smack_ptrace_rule;
338
339extern struct smack_known smack_known_floor;
340extern struct smack_known smack_known_hat;
341extern struct smack_known smack_known_huh;
342extern struct smack_known smack_known_star;
343extern struct smack_known smack_known_web;
344
345extern struct mutex smack_known_lock;
346extern struct list_head smack_known_list;
347extern struct list_head smk_net4addr_list;
348#if IS_ENABLED(CONFIG_IPV6)
349extern struct list_head smk_net6addr_list;
350#endif
351
352extern struct mutex smack_onlycap_lock;
353extern struct list_head smack_onlycap_list;
354
355#define SMACK_HASH_SLOTS 16
356extern struct hlist_head smack_known_hash[SMACK_HASH_SLOTS];
357
358
359
360
361static inline int smk_inode_transmutable(const struct inode *isp)
362{
363 struct inode_smack *sip = isp->i_security;
364 return (sip->smk_flags & SMK_INODE_TRANSMUTE) != 0;
365}
366
367
368
369
370static inline struct smack_known *smk_of_inode(const struct inode *isp)
371{
372 struct inode_smack *sip = isp->i_security;
373 return sip->smk_inode;
374}
375
376
377
378
379static inline struct smack_known *smk_of_task(const struct task_smack *tsp)
380{
381 return tsp->smk_task;
382}
383
384static inline struct smack_known *smk_of_task_struct(const struct task_struct *t)
385{
386 struct smack_known *skp;
387
388 rcu_read_lock();
389 skp = smk_of_task(__task_cred(t)->security);
390 rcu_read_unlock();
391 return skp;
392}
393
394
395
396
397static inline struct smack_known *smk_of_forked(const struct task_smack *tsp)
398{
399 return tsp->smk_forked;
400}
401
402
403
404
405static inline struct smack_known *smk_of_current(void)
406{
407 return smk_of_task(current_security());
408}
409
410
411
412
413#define SMACK_AUDIT_DENIED 0x1
414#define SMACK_AUDIT_ACCEPT 0x2
415extern int log_policy;
416
417void smack_log(char *subject_label, char *object_label,
418 int request,
419 int result, struct smk_audit_info *auditdata);
420
421#ifdef CONFIG_AUDIT
422
423
424
425
426
427
428static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
429 char type)
430{
431 memset(&a->sad, 0, sizeof(a->sad));
432 a->a.type = type;
433 a->a.smack_audit_data = &a->sad;
434 a->a.smack_audit_data->function = func;
435}
436
437static inline void smk_ad_init_net(struct smk_audit_info *a, const char *func,
438 char type, struct lsm_network_audit *net)
439{
440 smk_ad_init(a, func, type);
441 memset(net, 0, sizeof(*net));
442 a->a.u.net = net;
443}
444
445static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
446 struct task_struct *t)
447{
448 a->a.u.tsk = t;
449}
450static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
451 struct dentry *d)
452{
453 a->a.u.dentry = d;
454}
455static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
456 struct inode *i)
457{
458 a->a.u.inode = i;
459}
460static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
461 struct path p)
462{
463 a->a.u.path = p;
464}
465static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
466 struct sock *sk)
467{
468 a->a.u.net->sk = sk;
469}
470
471#else
472
473static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
474 char type)
475{
476}
477static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
478 struct task_struct *t)
479{
480}
481static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
482 struct dentry *d)
483{
484}
485static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
486 struct vfsmount *m)
487{
488}
489static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
490 struct inode *i)
491{
492}
493static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
494 struct path p)
495{
496}
497static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
498 struct sock *sk)
499{
500}
501#endif
502
503#endif
504