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.
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.
27 #define SMK_LABELLEN (SMK_MAXLEN+1)
29 <<<<<<< HEAD
:security
/smack
/smack
.h
31 * How many kinds of access are there?
34 #define SMK_ACCESSDASH '-'
35 #define SMK_ACCESSLOW "rwxa"
36 #define SMK_ACCESSKINDS (sizeof(SMK_ACCESSLOW) - 1)
39 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:security
/smack
/smack
.h
40 struct superblock_smack
{
46 spinlock_t smk_sblock
; /* for initialization */
50 char *smk_out
; /* outbound label */
51 char *smk_in
; /* inbound label */
52 char smk_packet
[SMK_LABELLEN
]; /* TCP peer label */
59 char *smk_inode
; /* label of the fso */
60 struct mutex smk_lock
; /* initialization lock */
61 int smk_flags
; /* smack inode flags */
64 #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
67 * A label access rule.
76 * An entry in the table of permitted label accesses.
78 struct smk_list_entry
{
79 struct smk_list_entry
*smk_next
;
80 struct smack_rule smk_rule
;
84 * An entry in the table mapping smack values to
85 * CIPSO level/category-set values.
89 char smk_catset
[SMK_LABELLEN
];
93 * This is the repository for labels seen so that it is
94 * not necessary to keep allocating tiny chuncks of memory
95 * and so that they can be shared.
97 * Labels are never modified in place. Anytime a label
98 * is imported (e.g. xattrset on a file) the list is checked
99 * for it and it is added if it doesn't exist. The address
100 * is passed out in either case. Entries are added, but
103 * Since labels are hanging around anyway it doesn't
104 * hurt to maintain a secid for those awkward situations
105 * where kernel components that ought to use LSM independent
106 * interfaces don't. The secid should go away when all of
107 * these components have been repaired.
109 * If there is a cipso value associated with the label it
110 * gets stored here, too. This will most likely be rare as
111 * the cipso direct mapping in used internally.
114 struct smack_known
*smk_next
;
115 char smk_known
[SMK_LABELLEN
];
117 struct smack_cipso
*smk_cipso
;
118 spinlock_t smk_cipsolock
; /* for changing cipso map */
124 #define SMK_FSDEFAULT "smackfsdef="
125 #define SMK_FSFLOOR "smackfsfloor="
126 #define SMK_FSHAT "smackfshat="
127 #define SMK_FSROOT "smackfsroot="
132 #define XATTR_SMACK_SUFFIX "SMACK64"
133 #define XATTR_SMACK_IPIN "SMACK64IPIN"
134 #define XATTR_SMACK_IPOUT "SMACK64IPOUT"
135 #define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
136 #define XATTR_NAME_SMACKIPIN XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
137 #define XATTR_NAME_SMACKIPOUT XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
140 * smackfs macic number
142 #define SMACK_MAGIC 0x43415d53 /* "SMAC" */
145 * A limit on the number of entries in the lists
146 * makes some of the list administration easier.
148 #define SMACK_LIST_MAX 10000
153 #define SMACK_CIPSO_DOI_DEFAULT 3 /* Historical */
154 #define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
155 #define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
156 #define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
157 #define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
160 * Just to make the common cases easier to deal with
162 #define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
163 #define MAY_ANYREAD (MAY_READ | MAY_EXEC)
164 #define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
165 #define MAY_READWRITE (MAY_READ | MAY_WRITE)
169 * These functions are in smack_lsm.c
171 struct inode_smack
*new_inode_smack(char *);
174 * These functions are in smack_access.c
176 int smk_access(char *, char *, int);
177 int smk_curacc(char *, u32
);
178 int smack_to_cipso(const char *, struct smack_cipso
*);
179 void smack_from_cipso(u32
, char *, char *);
180 char *smack_from_secid(const u32
);
181 char *smk_import(const char *, int);
182 struct smack_known
*smk_import_entry(const char *, int);
183 u32
smack_to_secid(const char *);
188 extern int smack_cipso_direct
;
189 extern int smack_net_nltype
;
190 extern char *smack_net_ambient
;
192 extern struct smack_known
*smack_known
;
193 extern struct smack_known smack_known_floor
;
194 extern struct smack_known smack_known_hat
;
195 extern struct smack_known smack_known_huh
;
196 extern struct smack_known smack_known_invalid
;
197 extern struct smack_known smack_known_star
;
198 extern struct smack_known smack_known_unset
;
200 extern struct smk_list_entry
*smack_list
;
203 * Stricly for CIPSO level manipulation.
204 * Set the category bit number in a smack label sized buffer.
206 static inline void smack_catset_bit(int cat
, char *catsetp
)
208 if (cat
> SMK_LABELLEN
* 8)
211 catsetp
[(cat
- 1) / 8] |= 0x80 >> ((cat
- 1) % 8);
215 * Present a pointer to the smack label in an inode blob.
217 static inline char *smk_of_inode(const struct inode
*isp
)
219 struct inode_smack
*sip
= isp
->i_security
;
220 return sip
->smk_inode
;
223 #endif /* _SECURITY_SMACK_H */