thinkpad-acpi: silence bogus warning when ACPI video is disabled
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / security / smack / smack.h
blob42ef313f98560451b2b45d563d1f5e26e23ca795
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>
25 * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
26 * bigger than can be used, and 24 is the next lower multiple
27 * of 8, and there are too many issues if there isn't space set
28 * aside for the terminating null byte.
30 #define SMK_MAXLEN 23
31 #define SMK_LABELLEN (SMK_MAXLEN+1)
33 struct superblock_smack {
34 char *smk_root;
35 char *smk_floor;
36 char *smk_hat;
37 char *smk_default;
38 int smk_initialized;
39 spinlock_t smk_sblock; /* for initialization */
42 struct socket_smack {
43 char *smk_out; /* outbound label */
44 char *smk_in; /* inbound label */
45 char smk_packet[SMK_LABELLEN]; /* TCP peer label */
49 * Inode smack data
51 struct inode_smack {
52 char *smk_inode; /* label of the fso */
53 struct mutex smk_lock; /* initialization lock */
54 int smk_flags; /* smack inode flags */
57 #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
60 * A label access rule.
62 struct smack_rule {
63 struct list_head list;
64 char *smk_subject;
65 char *smk_object;
66 int smk_access;
70 * An entry in the table mapping smack values to
71 * CIPSO level/category-set values.
73 struct smack_cipso {
74 int smk_level;
75 char smk_catset[SMK_LABELLEN];
79 * An entry in the table identifying hosts.
81 struct smk_netlbladdr {
82 struct list_head list;
83 struct sockaddr_in smk_host; /* network address */
84 struct in_addr smk_mask; /* network mask */
85 char *smk_label; /* label */
89 * This is the repository for labels seen so that it is
90 * not necessary to keep allocating tiny chuncks of memory
91 * and so that they can be shared.
93 * Labels are never modified in place. Anytime a label
94 * is imported (e.g. xattrset on a file) the list is checked
95 * for it and it is added if it doesn't exist. The address
96 * is passed out in either case. Entries are added, but
97 * never deleted.
99 * Since labels are hanging around anyway it doesn't
100 * hurt to maintain a secid for those awkward situations
101 * where kernel components that ought to use LSM independent
102 * interfaces don't. The secid should go away when all of
103 * these components have been repaired.
105 * If there is a cipso value associated with the label it
106 * gets stored here, too. This will most likely be rare as
107 * the cipso direct mapping in used internally.
109 struct smack_known {
110 struct list_head list;
111 char smk_known[SMK_LABELLEN];
112 u32 smk_secid;
113 struct smack_cipso *smk_cipso;
114 spinlock_t smk_cipsolock; /* for changing cipso map */
118 * Mount options
120 #define SMK_FSDEFAULT "smackfsdef="
121 #define SMK_FSFLOOR "smackfsfloor="
122 #define SMK_FSHAT "smackfshat="
123 #define SMK_FSROOT "smackfsroot="
126 * xattr names
128 #define XATTR_SMACK_SUFFIX "SMACK64"
129 #define XATTR_SMACK_IPIN "SMACK64IPIN"
130 #define XATTR_SMACK_IPOUT "SMACK64IPOUT"
131 #define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
132 #define XATTR_NAME_SMACKIPIN XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
133 #define XATTR_NAME_SMACKIPOUT XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
135 #define SMACK_CIPSO_OPTION "-CIPSO"
138 * How communications on this socket are treated.
139 * Usually it's determined by the underlying netlabel code
140 * but there are certain cases, including single label hosts
141 * and potentially single label interfaces for which the
142 * treatment can not be known in advance.
144 * The possibility of additional labeling schemes being
145 * introduced in the future exists as well.
147 #define SMACK_UNLABELED_SOCKET 0
148 #define SMACK_CIPSO_SOCKET 1
151 * smackfs magic number
152 * smackfs macic number
154 #define SMACK_MAGIC 0x43415d53 /* "SMAC" */
157 * A limit on the number of entries in the lists
158 * makes some of the list administration easier.
160 #define SMACK_LIST_MAX 10000
163 * CIPSO defaults.
165 #define SMACK_CIPSO_DOI_DEFAULT 3 /* Historical */
166 #define SMACK_CIPSO_DOI_INVALID -1 /* Not a DOI */
167 #define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
168 #define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
169 #define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
170 #define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
173 * Just to make the common cases easier to deal with
175 #define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
176 #define MAY_ANYREAD (MAY_READ | MAY_EXEC)
177 #define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
178 #define MAY_READWRITE (MAY_READ | MAY_WRITE)
179 #define MAY_NOT 0
182 * These functions are in smack_lsm.c
184 struct inode_smack *new_inode_smack(char *);
187 * These functions are in smack_access.c
189 int smk_access(char *, char *, int);
190 int smk_curacc(char *, u32);
191 int smack_to_cipso(const char *, struct smack_cipso *);
192 void smack_from_cipso(u32, char *, char *);
193 char *smack_from_secid(const u32);
194 char *smk_import(const char *, int);
195 struct smack_known *smk_import_entry(const char *, int);
196 u32 smack_to_secid(const char *);
199 * Shared data.
201 extern int smack_cipso_direct;
202 extern char *smack_net_ambient;
203 extern char *smack_onlycap;
204 extern const char *smack_cipso_option;
206 extern struct smack_known smack_known_floor;
207 extern struct smack_known smack_known_hat;
208 extern struct smack_known smack_known_huh;
209 extern struct smack_known smack_known_invalid;
210 extern struct smack_known smack_known_star;
211 extern struct smack_known smack_known_web;
213 extern struct list_head smack_known_list;
214 extern struct list_head smack_rule_list;
215 extern struct list_head smk_netlbladdr_list;
217 extern struct security_operations smack_ops;
220 * Stricly for CIPSO level manipulation.
221 * Set the category bit number in a smack label sized buffer.
223 static inline void smack_catset_bit(int cat, char *catsetp)
225 if (cat > SMK_LABELLEN * 8)
226 return;
228 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
232 * Present a pointer to the smack label in an inode blob.
234 static inline char *smk_of_inode(const struct inode *isp)
236 struct inode_smack *sip = isp->i_security;
237 return sip->smk_inode;
240 #endif /* _SECURITY_SMACK_H */