Merge branches 'perf-fixes-for-linus', 'x86-fixes-for-linus' and 'timers-fixes-for...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / security / smack / smack.h
blob129c4eb8ffb10cbba9dce59ef4e5761624d19f7e
1 /*
2 * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
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.
8 * Author:
9 * Casey Schaufler <casey@schaufler-ca.com>
13 #ifndef _SECURITY_SMACK_H
14 #define _SECURITY_SMACK_H
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>
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.
31 #define SMK_MAXLEN 23
32 #define SMK_LABELLEN (SMK_MAXLEN+1)
34 struct 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 */
43 struct socket_smack {
44 char *smk_out; /* outbound label */
45 char *smk_in; /* inbound label */
46 char smk_packet[SMK_LABELLEN]; /* TCP peer label */
50 * Inode smack data
52 struct inode_smack {
53 char *smk_inode; /* label of the fso */
54 char *smk_task; /* label of the task */
55 struct mutex smk_lock; /* initialization lock */
56 int smk_flags; /* smack inode flags */
59 struct task_smack {
60 char *smk_task; /* label used for access control */
61 char *smk_forked; /* label when forked */
64 #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
65 #define SMK_INODE_TRANSMUTE 0x02 /* directory is transmuting */
68 * A label access rule.
70 struct smack_rule {
71 struct list_head list;
72 char *smk_subject;
73 char *smk_object;
74 int smk_access;
78 * An entry in the table mapping smack values to
79 * CIPSO level/category-set values.
81 struct smack_cipso {
82 int smk_level;
83 char smk_catset[SMK_LABELLEN];
87 * An entry in the table identifying hosts.
89 struct smk_netlbladdr {
90 struct list_head list;
91 struct sockaddr_in smk_host; /* network address */
92 struct in_addr smk_mask; /* network mask */
93 char *smk_label; /* label */
97 * This is the repository for labels seen so that it is
98 * not necessary to keep allocating tiny chuncks of memory
99 * and so that they can be shared.
101 * Labels are never modified in place. Anytime a label
102 * is imported (e.g. xattrset on a file) the list is checked
103 * for it and it is added if it doesn't exist. The address
104 * is passed out in either case. Entries are added, but
105 * never deleted.
107 * Since labels are hanging around anyway it doesn't
108 * hurt to maintain a secid for those awkward situations
109 * where kernel components that ought to use LSM independent
110 * interfaces don't. The secid should go away when all of
111 * these components have been repaired.
113 * If there is a cipso value associated with the label it
114 * gets stored here, too. This will most likely be rare as
115 * the cipso direct mapping in used internally.
117 struct smack_known {
118 struct list_head list;
119 char smk_known[SMK_LABELLEN];
120 u32 smk_secid;
121 struct smack_cipso *smk_cipso;
122 spinlock_t smk_cipsolock; /* for changing cipso map */
126 * Mount options
128 #define SMK_FSDEFAULT "smackfsdef="
129 #define SMK_FSFLOOR "smackfsfloor="
130 #define SMK_FSHAT "smackfshat="
131 #define SMK_FSROOT "smackfsroot="
133 #define SMACK_CIPSO_OPTION "-CIPSO"
136 * How communications on this socket are treated.
137 * Usually it's determined by the underlying netlabel code
138 * but there are certain cases, including single label hosts
139 * and potentially single label interfaces for which the
140 * treatment can not be known in advance.
142 * The possibility of additional labeling schemes being
143 * introduced in the future exists as well.
145 #define SMACK_UNLABELED_SOCKET 0
146 #define SMACK_CIPSO_SOCKET 1
149 * smackfs magic number
150 * smackfs macic number
152 #define SMACK_MAGIC 0x43415d53 /* "SMAC" */
155 * A limit on the number of entries in the lists
156 * makes some of the list administration easier.
158 #define SMACK_LIST_MAX 10000
161 * CIPSO defaults.
163 #define SMACK_CIPSO_DOI_DEFAULT 3 /* Historical */
164 #define SMACK_CIPSO_DOI_INVALID -1 /* Not a DOI */
165 #define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
166 #define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
167 #define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
168 #define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
171 * Flag for transmute access
173 #define MAY_TRANSMUTE 64
175 * Just to make the common cases easier to deal with
177 #define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
178 #define MAY_ANYREAD (MAY_READ | MAY_EXEC)
179 #define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
180 #define MAY_READWRITE (MAY_READ | MAY_WRITE)
181 #define MAY_NOT 0
184 * Number of access types used by Smack (rwxa)
186 #define SMK_NUM_ACCESS_TYPE 4
189 * Smack audit data; is empty if CONFIG_AUDIT not set
190 * to save some stack
192 struct smk_audit_info {
193 #ifdef CONFIG_AUDIT
194 struct common_audit_data a;
195 #endif
198 * These functions are in smack_lsm.c
200 struct inode_smack *new_inode_smack(char *);
203 * These functions are in smack_access.c
205 int smk_access_entry(char *, char *);
206 int smk_access(char *, char *, int, struct smk_audit_info *);
207 int smk_curacc(char *, u32, struct smk_audit_info *);
208 int smack_to_cipso(const char *, struct smack_cipso *);
209 void smack_from_cipso(u32, char *, char *);
210 char *smack_from_secid(const u32);
211 char *smk_import(const char *, int);
212 struct smack_known *smk_import_entry(const char *, int);
213 u32 smack_to_secid(const char *);
216 * Shared data.
218 extern int smack_cipso_direct;
219 extern char *smack_net_ambient;
220 extern char *smack_onlycap;
221 extern const char *smack_cipso_option;
223 extern struct smack_known smack_known_floor;
224 extern struct smack_known smack_known_hat;
225 extern struct smack_known smack_known_huh;
226 extern struct smack_known smack_known_invalid;
227 extern struct smack_known smack_known_star;
228 extern struct smack_known smack_known_web;
230 extern struct list_head smack_known_list;
231 extern struct list_head smack_rule_list;
232 extern struct list_head smk_netlbladdr_list;
234 extern struct security_operations smack_ops;
237 * Stricly for CIPSO level manipulation.
238 * Set the category bit number in a smack label sized buffer.
240 static inline void smack_catset_bit(int cat, char *catsetp)
242 if (cat > SMK_LABELLEN * 8)
243 return;
245 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
249 * Is the directory transmuting?
251 static inline int smk_inode_transmutable(const struct inode *isp)
253 struct inode_smack *sip = isp->i_security;
254 return (sip->smk_flags & SMK_INODE_TRANSMUTE) != 0;
258 * Present a pointer to the smack label in an inode blob.
260 static inline char *smk_of_inode(const struct inode *isp)
262 struct inode_smack *sip = isp->i_security;
263 return sip->smk_inode;
267 * Present a pointer to the smack label in an task blob.
269 static inline char *smk_of_task(const struct task_smack *tsp)
271 return tsp->smk_task;
275 * Present a pointer to the forked smack label in an task blob.
277 static inline char *smk_of_forked(const struct task_smack *tsp)
279 return tsp->smk_forked;
283 * Present a pointer to the smack label in the current task blob.
285 static inline char *smk_of_current(void)
287 return smk_of_task(current_security());
291 * logging functions
293 #define SMACK_AUDIT_DENIED 0x1
294 #define SMACK_AUDIT_ACCEPT 0x2
295 extern int log_policy;
297 void smack_log(char *subject_label, char *object_label,
298 int request,
299 int result, struct smk_audit_info *auditdata);
301 #ifdef CONFIG_AUDIT
304 * some inline functions to set up audit data
305 * they do nothing if CONFIG_AUDIT is not set
308 static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
309 char type)
311 memset(a, 0, sizeof(*a));
312 a->a.type = type;
313 a->a.smack_audit_data.function = func;
316 static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
317 struct task_struct *t)
319 a->a.u.tsk = t;
321 static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
322 struct dentry *d)
324 a->a.u.fs.path.dentry = d;
326 static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
327 struct vfsmount *m)
329 a->a.u.fs.path.mnt = m;
331 static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
332 struct inode *i)
334 a->a.u.fs.inode = i;
336 static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
337 struct path p)
339 a->a.u.fs.path = p;
341 static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
342 struct sock *sk)
344 a->a.u.net.sk = sk;
347 #else /* no AUDIT */
349 static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
350 char type)
353 static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
354 struct task_struct *t)
357 static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
358 struct dentry *d)
361 static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
362 struct vfsmount *m)
365 static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
366 struct inode *i)
369 static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
370 struct path p)
373 static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
374 struct sock *sk)
377 #endif
379 #endif /* _SECURITY_SMACK_H */