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);
324bool smack_privileged_cred(int cap, const struct cred *cred);
325void smk_destroy_label_list(struct list_head *list);
326
327
328
329
330extern int smack_enabled;
331extern int smack_cipso_direct;
332extern int smack_cipso_mapped;
333extern struct smack_known *smack_net_ambient;
334extern struct smack_known *smack_syslog_label;
335#ifdef CONFIG_SECURITY_SMACK_BRINGUP
336extern struct smack_known *smack_unconfined;
337#endif
338extern int smack_ptrace_rule;
339
340extern struct smack_known smack_known_floor;
341extern struct smack_known smack_known_hat;
342extern struct smack_known smack_known_huh;
343extern struct smack_known smack_known_star;
344extern struct smack_known smack_known_web;
345
346extern struct mutex smack_known_lock;
347extern struct list_head smack_known_list;
348extern struct list_head smk_net4addr_list;
349#if IS_ENABLED(CONFIG_IPV6)
350extern struct list_head smk_net6addr_list;
351#endif
352
353extern struct mutex smack_onlycap_lock;
354extern struct list_head smack_onlycap_list;
355
356#define SMACK_HASH_SLOTS 16
357extern struct hlist_head smack_known_hash[SMACK_HASH_SLOTS];
358
359
360
361
362static inline int smk_inode_transmutable(const struct inode *isp)
363{
364 struct inode_smack *sip = isp->i_security;
365 return (sip->smk_flags & SMK_INODE_TRANSMUTE) != 0;
366}
367
368
369
370
371static inline struct smack_known *smk_of_inode(const struct inode *isp)
372{
373 struct inode_smack *sip = isp->i_security;
374 return sip->smk_inode;
375}
376
377
378
379
380static inline struct smack_known *smk_of_task(const struct task_smack *tsp)
381{
382 return tsp->smk_task;
383}
384
385static inline struct smack_known *smk_of_task_struct(const struct task_struct *t)
386{
387 struct smack_known *skp;
388
389 rcu_read_lock();
390 skp = smk_of_task(__task_cred(t)->security);
391 rcu_read_unlock();
392 return skp;
393}
394
395
396
397
398static inline struct smack_known *smk_of_forked(const struct task_smack *tsp)
399{
400 return tsp->smk_forked;
401}
402
403
404
405
406static inline struct smack_known *smk_of_current(void)
407{
408 return smk_of_task(current_security());
409}
410
411
412
413
414#define SMACK_AUDIT_DENIED 0x1
415#define SMACK_AUDIT_ACCEPT 0x2
416extern int log_policy;
417
418void smack_log(char *subject_label, char *object_label,
419 int request,
420 int result, struct smk_audit_info *auditdata);
421
422#ifdef CONFIG_AUDIT
423
424
425
426
427
428
429static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
430 char type)
431{
432 memset(&a->sad, 0, sizeof(a->sad));
433 a->a.type = type;
434 a->a.smack_audit_data = &a->sad;
435 a->a.smack_audit_data->function = func;
436}
437
438static inline void smk_ad_init_net(struct smk_audit_info *a, const char *func,
439 char type, struct lsm_network_audit *net)
440{
441 smk_ad_init(a, func, type);
442 memset(net, 0, sizeof(*net));
443 a->a.u.net = net;
444}
445
446static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
447 struct task_struct *t)
448{
449 a->a.u.tsk = t;
450}
451static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
452 struct dentry *d)
453{
454 a->a.u.dentry = d;
455}
456static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
457 struct inode *i)
458{
459 a->a.u.inode = i;
460}
461static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
462 struct path p)
463{
464 a->a.u.path = p;
465}
466static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
467 struct sock *sk)
468{
469 a->a.u.net->sk = sk;
470}
471
472#else
473
474static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
475 char type)
476{
477}
478static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
479 struct task_struct *t)
480{
481}
482static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
483 struct dentry *d)
484{
485}
486static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
487 struct vfsmount *m)
488{
489}
490static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
491 struct inode *i)
492{
493}
494static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
495 struct path p)
496{
497}
498static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
499 struct sock *sk)
500{
501}
502#endif
503
504#endif
505