Merge branch 'mini2440-dev-extras' into mini2440-dev
[linux-2.6/mini2440.git] / security / smack / smack.h
blobc6e9acae72e4b74b9e75f037845e54b61fce6163
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 struct mutex smk_lock; /* initialization lock */
55 int smk_flags; /* smack inode flags */
58 #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
61 * A label access rule.
63 struct smack_rule {
64 struct list_head list;
65 char *smk_subject;
66 char *smk_object;
67 int smk_access;
71 * An entry in the table mapping smack values to
72 * CIPSO level/category-set values.
74 struct smack_cipso {
75 int smk_level;
76 char smk_catset[SMK_LABELLEN];
80 * An entry in the table identifying hosts.
82 struct smk_netlbladdr {
83 struct list_head list;
84 struct sockaddr_in smk_host; /* network address */
85 struct in_addr smk_mask; /* network mask */
86 char *smk_label; /* label */
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.
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.
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.
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.
110 struct smack_known {
111 struct list_head list;
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 */
119 * Mount options
121 #define SMK_FSDEFAULT "smackfsdef="
122 #define SMK_FSFLOOR "smackfsfloor="
123 #define SMK_FSHAT "smackfshat="
124 #define SMK_FSROOT "smackfsroot="
127 * xattr names
129 #define XATTR_SMACK_SUFFIX "SMACK64"
130 #define XATTR_SMACK_IPIN "SMACK64IPIN"
131 #define XATTR_SMACK_IPOUT "SMACK64IPOUT"
132 #define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
133 #define XATTR_NAME_SMACKIPIN XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
134 #define XATTR_NAME_SMACKIPOUT XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
136 #define SMACK_CIPSO_OPTION "-CIPSO"
139 * How communications on this socket are treated.
140 * Usually it's determined by the underlying netlabel code
141 * but there are certain cases, including single label hosts
142 * and potentially single label interfaces for which the
143 * treatment can not be known in advance.
145 * The possibility of additional labeling schemes being
146 * introduced in the future exists as well.
148 #define SMACK_UNLABELED_SOCKET 0
149 #define SMACK_CIPSO_SOCKET 1
152 * smackfs magic number
153 * smackfs macic number
155 #define SMACK_MAGIC 0x43415d53 /* "SMAC" */
158 * A limit on the number of entries in the lists
159 * makes some of the list administration easier.
161 #define SMACK_LIST_MAX 10000
164 * CIPSO defaults.
166 #define SMACK_CIPSO_DOI_DEFAULT 3 /* Historical */
167 #define SMACK_CIPSO_DOI_INVALID -1 /* Not a DOI */
168 #define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
169 #define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
170 #define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
171 #define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
174 * Just to make the common cases easier to deal with
176 #define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
177 #define MAY_ANYREAD (MAY_READ | MAY_EXEC)
178 #define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
179 #define MAY_READWRITE (MAY_READ | MAY_WRITE)
180 #define MAY_NOT 0
183 * Number of access types used by Smack (rwxa)
185 #define SMK_NUM_ACCESS_TYPE 4
188 * Smack audit data; is empty if CONFIG_AUDIT not set
189 * to save some stack
191 struct smk_audit_info {
192 #ifdef CONFIG_AUDIT
193 struct common_audit_data a;
194 #endif
197 * These functions are in smack_lsm.c
199 struct inode_smack *new_inode_smack(char *);
202 * These functions are in smack_access.c
204 int smk_access(char *, char *, int, struct smk_audit_info *);
205 int smk_curacc(char *, u32, struct smk_audit_info *);
206 int smack_to_cipso(const char *, struct smack_cipso *);
207 void smack_from_cipso(u32, char *, char *);
208 char *smack_from_secid(const u32);
209 char *smk_import(const char *, int);
210 struct smack_known *smk_import_entry(const char *, int);
211 u32 smack_to_secid(const char *);
214 * Shared data.
216 extern int smack_cipso_direct;
217 extern char *smack_net_ambient;
218 extern char *smack_onlycap;
219 extern const char *smack_cipso_option;
221 extern struct smack_known smack_known_floor;
222 extern struct smack_known smack_known_hat;
223 extern struct smack_known smack_known_huh;
224 extern struct smack_known smack_known_invalid;
225 extern struct smack_known smack_known_star;
226 extern struct smack_known smack_known_web;
228 extern struct list_head smack_known_list;
229 extern struct list_head smack_rule_list;
230 extern struct list_head smk_netlbladdr_list;
232 extern struct security_operations smack_ops;
235 * Stricly for CIPSO level manipulation.
236 * Set the category bit number in a smack label sized buffer.
238 static inline void smack_catset_bit(int cat, char *catsetp)
240 if (cat > SMK_LABELLEN * 8)
241 return;
243 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
247 * Present a pointer to the smack label in an inode blob.
249 static inline char *smk_of_inode(const struct inode *isp)
251 struct inode_smack *sip = isp->i_security;
252 return sip->smk_inode;
256 * logging functions
258 #define SMACK_AUDIT_DENIED 0x1
259 #define SMACK_AUDIT_ACCEPT 0x2
260 extern int log_policy;
262 void smack_log(char *subject_label, char *object_label,
263 int request,
264 int result, struct smk_audit_info *auditdata);
266 #ifdef CONFIG_AUDIT
269 * some inline functions to set up audit data
270 * they do nothing if CONFIG_AUDIT is not set
273 static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
274 char type)
276 memset(a, 0, sizeof(*a));
277 a->a.type = type;
278 a->a.smack_audit_data.function = func;
281 static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
282 struct task_struct *t)
284 a->a.u.tsk = t;
286 static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
287 struct dentry *d)
289 a->a.u.fs.path.dentry = d;
291 static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
292 struct vfsmount *m)
294 a->a.u.fs.path.mnt = m;
296 static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
297 struct inode *i)
299 a->a.u.fs.inode = i;
301 static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
302 struct path p)
304 a->a.u.fs.path = p;
306 static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
307 struct sock *sk)
309 a->a.u.net.sk = sk;
312 #else /* no AUDIT */
314 static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
315 char type)
318 static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
319 struct task_struct *t)
322 static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
323 struct dentry *d)
326 static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
327 struct vfsmount *m)
330 static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
331 struct inode *i)
334 static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
335 struct path p)
338 static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
339 struct sock *sk)
342 #endif
344 #endif /* _SECURITY_SMACK_H */