AT91: Added a generic way to setup AT91 serial ports in Kconfig
[linux-2.6/pdupreez.git] / security / smack / smack.h
blob4a4477f5afdcd3468074c72ea05aa5697dea4566
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 <net/netlabel.h>
22 * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
23 * bigger than can be used, and 24 is the next lower multiple
24 * of 8, and there are too many issues if there isn't space set
25 * aside for the terminating null byte.
27 #define SMK_MAXLEN 23
28 #define SMK_LABELLEN (SMK_MAXLEN+1)
30 struct superblock_smack {
31 char *smk_root;
32 char *smk_floor;
33 char *smk_hat;
34 char *smk_default;
35 int smk_initialized;
36 spinlock_t smk_sblock; /* for initialization */
39 struct socket_smack {
40 char *smk_out; /* outbound label */
41 char *smk_in; /* inbound label */
42 char smk_packet[SMK_LABELLEN]; /* TCP peer label */
46 * Inode smack data
48 struct inode_smack {
49 char *smk_inode; /* label of the fso */
50 struct mutex smk_lock; /* initialization lock */
51 int smk_flags; /* smack inode flags */
54 #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
57 * A label access rule.
59 struct smack_rule {
60 char *smk_subject;
61 char *smk_object;
62 int smk_access;
66 * An entry in the table of permitted label accesses.
68 struct smk_list_entry {
69 struct smk_list_entry *smk_next;
70 struct smack_rule smk_rule;
74 * An entry in the table mapping smack values to
75 * CIPSO level/category-set values.
77 struct smack_cipso {
78 int smk_level;
79 char smk_catset[SMK_LABELLEN];
83 * This is the repository for labels seen so that it is
84 * not necessary to keep allocating tiny chuncks of memory
85 * and so that they can be shared.
87 * Labels are never modified in place. Anytime a label
88 * is imported (e.g. xattrset on a file) the list is checked
89 * for it and it is added if it doesn't exist. The address
90 * is passed out in either case. Entries are added, but
91 * never deleted.
93 * Since labels are hanging around anyway it doesn't
94 * hurt to maintain a secid for those awkward situations
95 * where kernel components that ought to use LSM independent
96 * interfaces don't. The secid should go away when all of
97 * these components have been repaired.
99 * If there is a cipso value associated with the label it
100 * gets stored here, too. This will most likely be rare as
101 * the cipso direct mapping in used internally.
103 struct smack_known {
104 struct smack_known *smk_next;
105 char smk_known[SMK_LABELLEN];
106 u32 smk_secid;
107 struct smack_cipso *smk_cipso;
108 spinlock_t smk_cipsolock; /* for changing cipso map */
112 * Mount options
114 #define SMK_FSDEFAULT "smackfsdef="
115 #define SMK_FSFLOOR "smackfsfloor="
116 #define SMK_FSHAT "smackfshat="
117 #define SMK_FSROOT "smackfsroot="
120 * xattr names
122 #define XATTR_SMACK_SUFFIX "SMACK64"
123 #define XATTR_SMACK_IPIN "SMACK64IPIN"
124 #define XATTR_SMACK_IPOUT "SMACK64IPOUT"
125 #define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
126 #define XATTR_NAME_SMACKIPIN XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
127 #define XATTR_NAME_SMACKIPOUT XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
130 * smackfs macic number
132 #define SMACK_MAGIC 0x43415d53 /* "SMAC" */
135 * A limit on the number of entries in the lists
136 * makes some of the list administration easier.
138 #define SMACK_LIST_MAX 10000
141 * CIPSO defaults.
143 #define SMACK_CIPSO_DOI_DEFAULT 3 /* Historical */
144 #define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
145 #define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
146 #define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
147 #define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
150 * Just to make the common cases easier to deal with
152 #define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
153 #define MAY_ANYREAD (MAY_READ | MAY_EXEC)
154 #define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
155 #define MAY_READWRITE (MAY_READ | MAY_WRITE)
156 #define MAY_NOT 0
159 * These functions are in smack_lsm.c
161 struct inode_smack *new_inode_smack(char *);
164 * These functions are in smack_access.c
166 int smk_access(char *, char *, int);
167 int smk_curacc(char *, u32);
168 int smack_to_cipso(const char *, struct smack_cipso *);
169 void smack_from_cipso(u32, char *, char *);
170 char *smack_from_secid(const u32);
171 char *smk_import(const char *, int);
172 struct smack_known *smk_import_entry(const char *, int);
173 u32 smack_to_secid(const char *);
176 * Shared data.
178 extern int smack_cipso_direct;
179 extern int smack_net_nltype;
180 extern char *smack_net_ambient;
182 extern struct smack_known *smack_known;
183 extern struct smack_known smack_known_floor;
184 extern struct smack_known smack_known_hat;
185 extern struct smack_known smack_known_huh;
186 extern struct smack_known smack_known_invalid;
187 extern struct smack_known smack_known_star;
188 extern struct smack_known smack_known_unset;
190 extern struct smk_list_entry *smack_list;
191 extern struct security_operations smack_ops;
194 * Stricly for CIPSO level manipulation.
195 * Set the category bit number in a smack label sized buffer.
197 static inline void smack_catset_bit(int cat, char *catsetp)
199 if (cat > SMK_LABELLEN * 8)
200 return;
202 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
206 * Present a pointer to the smack label in an inode blob.
208 static inline char *smk_of_inode(const struct inode *isp)
210 struct inode_smack *sip = isp->i_security;
211 return sip->smk_inode;
214 #endif /* _SECURITY_SMACK_H */