]> bbs.cooldavid.org Git - net-next-2.6.git/blame - security/smack/smack.h
3c59x: fix build failure on !CONFIG_PCI
[net-next-2.6.git] / security / smack / smack.h
CommitLineData
e114e473
CS
1/*
2 * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 2.
7 *
8 * Author:
9 * Casey Schaufler <casey@schaufler-ca.com>
10 *
11 */
12
13#ifndef _SECURITY_SMACK_H
14#define _SECURITY_SMACK_H
15
16#include <linux/capability.h>
17#include <linux/spinlock.h>
076c54c5 18#include <linux/security.h>
6d3dc07c 19#include <linux/in.h>
e114e473 20#include <net/netlabel.h>
7198e2ee
EB
21#include <linux/list.h>
22#include <linux/rculist.h>
ecfcc53f 23#include <linux/lsm_audit.h>
e114e473
CS
24
25/*
26 * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
27 * bigger than can be used, and 24 is the next lower multiple
28 * of 8, and there are too many issues if there isn't space set
29 * aside for the terminating null byte.
30 */
31#define SMK_MAXLEN 23
32#define SMK_LABELLEN (SMK_MAXLEN+1)
33
e114e473
CS
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; /* for initialization */
41};
42
43struct socket_smack {
44 char *smk_out; /* outbound label */
45 char *smk_in; /* inbound label */
46 char smk_packet[SMK_LABELLEN]; /* TCP peer label */
47};
48
49/*
50 * Inode smack data
51 */
52struct inode_smack {
53 char *smk_inode; /* label of the fso */
54 struct mutex smk_lock; /* initialization lock */
55 int smk_flags; /* smack inode flags */
56};
57
58#define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
59
60/*
61 * A label access rule.
62 */
63struct smack_rule {
7198e2ee
EB
64 struct list_head list;
65 char *smk_subject;
66 char *smk_object;
67 int smk_access;
e114e473
CS
68};
69
70/*
71 * An entry in the table mapping smack values to
72 * CIPSO level/category-set values.
73 */
74struct smack_cipso {
75 int smk_level;
76 char smk_catset[SMK_LABELLEN];
77};
78
6d3dc07c
CS
79/*
80 * An entry in the table identifying hosts.
81 */
82struct smk_netlbladdr {
7198e2ee 83 struct list_head list;
6d3dc07c
CS
84 struct sockaddr_in smk_host; /* network address */
85 struct in_addr smk_mask; /* network mask */
86 char *smk_label; /* label */
87};
88
e114e473
CS
89/*
90 * This is the repository for labels seen so that it is
91 * not necessary to keep allocating tiny chuncks of memory
92 * and so that they can be shared.
93 *
94 * Labels are never modified in place. Anytime a label
95 * is imported (e.g. xattrset on a file) the list is checked
96 * for it and it is added if it doesn't exist. The address
97 * is passed out in either case. Entries are added, but
98 * never deleted.
99 *
100 * Since labels are hanging around anyway it doesn't
101 * hurt to maintain a secid for those awkward situations
102 * where kernel components that ought to use LSM independent
103 * interfaces don't. The secid should go away when all of
104 * these components have been repaired.
105 *
106 * If there is a cipso value associated with the label it
107 * gets stored here, too. This will most likely be rare as
108 * the cipso direct mapping in used internally.
109 */
110struct smack_known {
7198e2ee 111 struct list_head list;
e114e473
CS
112 char smk_known[SMK_LABELLEN];
113 u32 smk_secid;
114 struct smack_cipso *smk_cipso;
115 spinlock_t smk_cipsolock; /* for changing cipso map */
116};
117
118/*
119 * Mount options
120 */
121#define SMK_FSDEFAULT "smackfsdef="
122#define SMK_FSFLOOR "smackfsfloor="
123#define SMK_FSHAT "smackfshat="
124#define SMK_FSROOT "smackfsroot="
125
4303154e
EB
126#define SMACK_CIPSO_OPTION "-CIPSO"
127
e114e473 128/*
6d3dc07c
CS
129 * How communications on this socket are treated.
130 * Usually it's determined by the underlying netlabel code
131 * but there are certain cases, including single label hosts
132 * and potentially single label interfaces for which the
133 * treatment can not be known in advance.
134 *
135 * The possibility of additional labeling schemes being
136 * introduced in the future exists as well.
137 */
138#define SMACK_UNLABELED_SOCKET 0
139#define SMACK_CIPSO_SOCKET 1
140
141/*
142 * smackfs magic number
e114e473
CS
143 * smackfs macic number
144 */
145#define SMACK_MAGIC 0x43415d53 /* "SMAC" */
146
147/*
148 * A limit on the number of entries in the lists
149 * makes some of the list administration easier.
150 */
151#define SMACK_LIST_MAX 10000
152
153/*
154 * CIPSO defaults.
155 */
156#define SMACK_CIPSO_DOI_DEFAULT 3 /* Historical */
6d3dc07c 157#define SMACK_CIPSO_DOI_INVALID -1 /* Not a DOI */
e114e473
CS
158#define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
159#define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
160#define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
161#define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
162
163/*
164 * Just to make the common cases easier to deal with
165 */
166#define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
167#define MAY_ANYREAD (MAY_READ | MAY_EXEC)
168#define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
169#define MAY_READWRITE (MAY_READ | MAY_WRITE)
170#define MAY_NOT 0
171
ecfcc53f
EB
172/*
173 * Number of access types used by Smack (rwxa)
174 */
175#define SMK_NUM_ACCESS_TYPE 4
176
177/*
178 * Smack audit data; is empty if CONFIG_AUDIT not set
179 * to save some stack
180 */
181struct smk_audit_info {
182#ifdef CONFIG_AUDIT
183 struct common_audit_data a;
184#endif
185};
e114e473
CS
186/*
187 * These functions are in smack_lsm.c
188 */
189struct inode_smack *new_inode_smack(char *);
190
191/*
192 * These functions are in smack_access.c
193 */
ecfcc53f
EB
194int smk_access(char *, char *, int, struct smk_audit_info *);
195int smk_curacc(char *, u32, struct smk_audit_info *);
e114e473
CS
196int smack_to_cipso(const char *, struct smack_cipso *);
197void smack_from_cipso(u32, char *, char *);
198char *smack_from_secid(const u32);
199char *smk_import(const char *, int);
200struct smack_known *smk_import_entry(const char *, int);
201u32 smack_to_secid(const char *);
202
203/*
204 * Shared data.
205 */
206extern int smack_cipso_direct;
e114e473 207extern char *smack_net_ambient;
15446235 208extern char *smack_onlycap;
4303154e 209extern const char *smack_cipso_option;
e114e473 210
e114e473
CS
211extern struct smack_known smack_known_floor;
212extern struct smack_known smack_known_hat;
213extern struct smack_known smack_known_huh;
214extern struct smack_known smack_known_invalid;
215extern struct smack_known smack_known_star;
6d3dc07c 216extern struct smack_known smack_known_web;
e114e473 217
7198e2ee
EB
218extern struct list_head smack_known_list;
219extern struct list_head smack_rule_list;
220extern struct list_head smk_netlbladdr_list;
221
076c54c5 222extern struct security_operations smack_ops;
e114e473
CS
223
224/*
225 * Stricly for CIPSO level manipulation.
226 * Set the category bit number in a smack label sized buffer.
227 */
228static inline void smack_catset_bit(int cat, char *catsetp)
229{
230 if (cat > SMK_LABELLEN * 8)
231 return;
232
233 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
234}
235
236/*
237 * Present a pointer to the smack label in an inode blob.
238 */
239static inline char *smk_of_inode(const struct inode *isp)
240{
241 struct inode_smack *sip = isp->i_security;
242 return sip->smk_inode;
243}
244
ecfcc53f
EB
245/*
246 * logging functions
247 */
248#define SMACK_AUDIT_DENIED 0x1
249#define SMACK_AUDIT_ACCEPT 0x2
250extern int log_policy;
251
252void smack_log(char *subject_label, char *object_label,
253 int request,
254 int result, struct smk_audit_info *auditdata);
255
256#ifdef CONFIG_AUDIT
257
258/*
259 * some inline functions to set up audit data
260 * they do nothing if CONFIG_AUDIT is not set
261 *
262 */
263static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
264 char type)
265{
266 memset(a, 0, sizeof(*a));
267 a->a.type = type;
d4131ded 268 a->a.smack_audit_data.function = func;
ecfcc53f
EB
269}
270
271static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
272 struct task_struct *t)
273{
274 a->a.u.tsk = t;
275}
276static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
277 struct dentry *d)
278{
279 a->a.u.fs.path.dentry = d;
280}
281static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
282 struct vfsmount *m)
283{
284 a->a.u.fs.path.mnt = m;
285}
286static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
287 struct inode *i)
288{
289 a->a.u.fs.inode = i;
290}
291static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
292 struct path p)
293{
294 a->a.u.fs.path = p;
295}
296static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
297 struct sock *sk)
298{
299 a->a.u.net.sk = sk;
300}
301
302#else /* no AUDIT */
303
304static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
305 char type)
306{
307}
308static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
309 struct task_struct *t)
310{
311}
312static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
313 struct dentry *d)
314{
315}
316static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
317 struct vfsmount *m)
318{
319}
320static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
321 struct inode *i)
322{
323}
324static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
325 struct path p)
326{
327}
328static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
329 struct sock *sk)
330{
331}
332#endif
333
e114e473 334#endif /* _SECURITY_SMACK_H */