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 <linux/security.h>
20 #include <net/netlabel.h>
23 * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
24 * bigger than can be used, and 24 is the next lower multiple
25 * of 8, and there are too many issues if there isn't space set
26 * aside for the terminating null byte.
29 #define SMK_LABELLEN (SMK_MAXLEN+1)
31 struct superblock_smack
{
37 spinlock_t smk_sblock
; /* for initialization */
41 char *smk_out
; /* outbound label */
42 char *smk_in
; /* inbound label */
43 char smk_packet
[SMK_LABELLEN
]; /* TCP peer label */
50 char *smk_inode
; /* label of the fso */
51 struct mutex smk_lock
; /* initialization lock */
52 int smk_flags
; /* smack inode flags */
55 #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
58 * A label access rule.
67 * An entry in the table of permitted label accesses.
69 struct smk_list_entry
{
70 struct smk_list_entry
*smk_next
;
71 struct smack_rule smk_rule
;
75 * An entry in the table mapping smack values to
76 * CIPSO level/category-set values.
80 char smk_catset
[SMK_LABELLEN
];
84 * An entry in the table identifying hosts.
86 struct smk_netlbladdr
{
87 struct smk_netlbladdr
*smk_next
;
88 struct sockaddr_in smk_host
; /* network address */
89 struct in_addr smk_mask
; /* network mask */
90 char *smk_label
; /* label */
94 * This is the repository for labels seen so that it is
95 * not necessary to keep allocating tiny chuncks of memory
96 * and so that they can be shared.
98 * Labels are never modified in place. Anytime a label
99 * is imported (e.g. xattrset on a file) the list is checked
100 * for it and it is added if it doesn't exist. The address
101 * is passed out in either case. Entries are added, but
104 * Since labels are hanging around anyway it doesn't
105 * hurt to maintain a secid for those awkward situations
106 * where kernel components that ought to use LSM independent
107 * interfaces don't. The secid should go away when all of
108 * these components have been repaired.
110 * If there is a cipso value associated with the label it
111 * gets stored here, too. This will most likely be rare as
112 * the cipso direct mapping in used internally.
115 struct smack_known
*smk_next
;
116 char smk_known
[SMK_LABELLEN
];
118 struct smack_cipso
*smk_cipso
;
119 spinlock_t smk_cipsolock
; /* for changing cipso map */
125 #define SMK_FSDEFAULT "smackfsdef="
126 #define SMK_FSFLOOR "smackfsfloor="
127 #define SMK_FSHAT "smackfshat="
128 #define SMK_FSROOT "smackfsroot="
133 #define XATTR_SMACK_SUFFIX "SMACK64"
134 #define XATTR_SMACK_IPIN "SMACK64IPIN"
135 #define XATTR_SMACK_IPOUT "SMACK64IPOUT"
136 #define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
137 #define XATTR_NAME_SMACKIPIN XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
138 #define XATTR_NAME_SMACKIPOUT XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
141 * How communications on this socket are treated.
142 * Usually it's determined by the underlying netlabel code
143 * but there are certain cases, including single label hosts
144 * and potentially single label interfaces for which the
145 * treatment can not be known in advance.
147 * The possibility of additional labeling schemes being
148 * introduced in the future exists as well.
150 #define SMACK_UNLABELED_SOCKET 0
151 #define SMACK_CIPSO_SOCKET 1
154 * smackfs magic number
155 * smackfs macic number
157 #define SMACK_MAGIC 0x43415d53 /* "SMAC" */
160 * A limit on the number of entries in the lists
161 * makes some of the list administration easier.
163 #define SMACK_LIST_MAX 10000
168 #define SMACK_CIPSO_DOI_DEFAULT 3 /* Historical */
169 #define SMACK_CIPSO_DOI_INVALID -1 /* Not a DOI */
170 #define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
171 #define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
172 #define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
173 #define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
176 * Just to make the common cases easier to deal with
178 #define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
179 #define MAY_ANYREAD (MAY_READ | MAY_EXEC)
180 #define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
181 #define MAY_READWRITE (MAY_READ | MAY_WRITE)
185 * These functions are in smack_lsm.c
187 struct inode_smack
*new_inode_smack(char *);
190 * These functions are in smack_access.c
192 int smk_access(char *, char *, int);
193 int smk_curacc(char *, u32
);
194 int smack_to_cipso(const char *, struct smack_cipso
*);
195 void smack_from_cipso(u32
, char *, char *);
196 char *smack_from_secid(const u32
);
197 char *smk_import(const char *, int);
198 struct smack_known
*smk_import_entry(const char *, int);
199 u32
smack_to_secid(const char *);
204 extern int smack_cipso_direct
;
205 extern char *smack_net_ambient
;
206 extern char *smack_onlycap
;
208 extern struct smack_known
*smack_known
;
209 extern struct smack_known smack_known_floor
;
210 extern struct smack_known smack_known_hat
;
211 extern struct smack_known smack_known_huh
;
212 extern struct smack_known smack_known_invalid
;
213 extern struct smack_known smack_known_star
;
214 extern struct smack_known smack_known_web
;
216 extern struct smk_list_entry
*smack_list
;
217 extern struct smk_netlbladdr
*smack_netlbladdrs
;
218 extern struct security_operations smack_ops
;
221 * Stricly for CIPSO level manipulation.
222 * Set the category bit number in a smack label sized buffer.
224 static inline void smack_catset_bit(int cat
, char *catsetp
)
226 if (cat
> SMK_LABELLEN
* 8)
229 catsetp
[(cat
- 1) / 8] |= 0x80 >> ((cat
- 1) % 8);
233 * Present a pointer to the smack label in an inode blob.
235 static inline char *smk_of_inode(const struct inode
*isp
)
237 struct inode_smack
*sip
= isp
->i_security
;
238 return sip
->smk_inode
;
241 #endif /* _SECURITY_SMACK_H */