sched: make early bootup sched_clock() use safer
[wrt350n-kernel.git] / security / smack / smack.h
bloba21a0e907ab34092017e6a67243a1ad93b3be171
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 <net/netlabel.h>
21 * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
22 * bigger than can be used, and 24 is the next lower multiple
23 * of 8, and there are too many issues if there isn't space set
24 * aside for the terminating null byte.
26 #define SMK_MAXLEN 23
27 #define SMK_LABELLEN (SMK_MAXLEN+1)
30 * How many kinds of access are there?
31 * Here's your answer.
33 #define SMK_ACCESSDASH '-'
34 #define SMK_ACCESSLOW "rwxa"
35 #define SMK_ACCESSKINDS (sizeof(SMK_ACCESSLOW) - 1)
37 struct superblock_smack {
38 char *smk_root;
39 char *smk_floor;
40 char *smk_hat;
41 char *smk_default;
42 int smk_initialized;
43 spinlock_t smk_sblock; /* for initialization */
46 struct socket_smack {
47 char *smk_out; /* outbound label */
48 char *smk_in; /* inbound label */
49 char smk_packet[SMK_LABELLEN]; /* TCP peer label */
53 * Inode smack data
55 struct inode_smack {
56 char *smk_inode; /* label of the fso */
57 struct mutex smk_lock; /* initialization lock */
58 int smk_flags; /* smack inode flags */
61 #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
64 * A label access rule.
66 struct smack_rule {
67 char *smk_subject;
68 char *smk_object;
69 int smk_access;
73 * An entry in the table of permitted label accesses.
75 struct smk_list_entry {
76 struct smk_list_entry *smk_next;
77 struct smack_rule smk_rule;
81 * An entry in the table mapping smack values to
82 * CIPSO level/category-set values.
84 struct smack_cipso {
85 int smk_level;
86 char smk_catset[SMK_LABELLEN];
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 smack_known *smk_next;
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
137 * smackfs macic number
139 #define SMACK_MAGIC 0x43415d53 /* "SMAC" */
142 * A limit on the number of entries in the lists
143 * makes some of the list administration easier.
145 #define SMACK_LIST_MAX 10000
148 * CIPSO defaults.
150 #define SMACK_CIPSO_DOI_DEFAULT 3 /* Historical */
151 #define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
152 #define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
153 #define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
154 #define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
157 * Just to make the common cases easier to deal with
159 #define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
160 #define MAY_ANYREAD (MAY_READ | MAY_EXEC)
161 #define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
162 #define MAY_READWRITE (MAY_READ | MAY_WRITE)
163 #define MAY_NOT 0
166 * These functions are in smack_lsm.c
168 struct inode_smack *new_inode_smack(char *);
171 * These functions are in smack_access.c
173 int smk_access(char *, char *, int);
174 int smk_curacc(char *, u32);
175 int smack_to_cipso(const char *, struct smack_cipso *);
176 void smack_from_cipso(u32, char *, char *);
177 char *smack_from_secid(const u32);
178 char *smk_import(const char *, int);
179 struct smack_known *smk_import_entry(const char *, int);
180 u32 smack_to_secid(const char *);
183 * Shared data.
185 extern int smack_cipso_direct;
186 extern int smack_net_nltype;
187 extern char *smack_net_ambient;
189 extern struct smack_known *smack_known;
190 extern struct smack_known smack_known_floor;
191 extern struct smack_known smack_known_hat;
192 extern struct smack_known smack_known_huh;
193 extern struct smack_known smack_known_invalid;
194 extern struct smack_known smack_known_star;
195 extern struct smack_known smack_known_unset;
197 extern struct smk_list_entry *smack_list;
200 * Stricly for CIPSO level manipulation.
201 * Set the category bit number in a smack label sized buffer.
203 static inline void smack_catset_bit(int cat, char *catsetp)
205 if (cat > SMK_LABELLEN * 8)
206 return;
208 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
212 * Present a pointer to the smack label in an inode blob.
214 static inline char *smk_of_inode(const struct inode *isp)
216 struct inode_smack *sip = isp->i_security;
217 return sip->smk_inode;
220 #endif /* _SECURITY_SMACK_H */