netlabel: Cleanup the Smack/NetLabel code to fix incoming TCP connections
[deliverable/linux.git] / security / smack / smack.h
CommitLineData
e114e473
CS
1/*
2 * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
3 *
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.
7 *
8 * Author:
9 * Casey Schaufler <casey@schaufler-ca.com>
10 *
11 */
12
13#ifndef _SECURITY_SMACK_H
14#define _SECURITY_SMACK_H
15
16#include <linux/capability.h>
17#include <linux/spinlock.h>
076c54c5 18#include <linux/security.h>
6d3dc07c 19#include <linux/in.h>
e114e473 20#include <net/netlabel.h>
7198e2ee
EB
21#include <linux/list.h>
22#include <linux/rculist.h>
e114e473
CS
23
24/*
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.
29 */
30#define SMK_MAXLEN 23
31#define SMK_LABELLEN (SMK_MAXLEN+1)
32
e114e473
CS
33struct 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 */
40};
41
42struct socket_smack {
43 char *smk_out; /* outbound label */
44 char *smk_in; /* inbound label */
45 char smk_packet[SMK_LABELLEN]; /* TCP peer label */
46};
47
48/*
49 * Inode smack data
50 */
51struct inode_smack {
52 char *smk_inode; /* label of the fso */
53 struct mutex smk_lock; /* initialization lock */
54 int smk_flags; /* smack inode flags */
55};
56
57#define SMK_INODE_INSTANT 0x01 /* inode is instantiated */
58
59/*
60 * A label access rule.
61 */
62struct smack_rule {
7198e2ee
EB
63 struct list_head list;
64 char *smk_subject;
65 char *smk_object;
66 int smk_access;
e114e473
CS
67};
68
69/*
70 * An entry in the table mapping smack values to
71 * CIPSO level/category-set values.
72 */
73struct smack_cipso {
74 int smk_level;
75 char smk_catset[SMK_LABELLEN];
76};
77
6d3dc07c
CS
78/*
79 * An entry in the table identifying hosts.
80 */
81struct smk_netlbladdr {
7198e2ee 82 struct list_head list;
6d3dc07c
CS
83 struct sockaddr_in smk_host; /* network address */
84 struct in_addr smk_mask; /* network mask */
85 char *smk_label; /* label */
86};
87
e114e473
CS
88/*
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.
92 *
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.
98 *
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.
104 *
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.
108 */
109struct smack_known {
7198e2ee 110 struct list_head list;
e114e473
CS
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 */
115};
116
117/*
118 * Mount options
119 */
120#define SMK_FSDEFAULT "smackfsdef="
121#define SMK_FSFLOOR "smackfsfloor="
122#define SMK_FSHAT "smackfshat="
123#define SMK_FSROOT "smackfsroot="
124
125/*
126 * xattr names
127 */
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
134
135/*
6d3dc07c
CS
136 * How communications on this socket are treated.
137 * Usually it's determined by the underlying netlabel code
138 * but there are certain cases, including single label hosts
139 * and potentially single label interfaces for which the
140 * treatment can not be known in advance.
141 *
142 * The possibility of additional labeling schemes being
143 * introduced in the future exists as well.
144 */
145#define SMACK_UNLABELED_SOCKET 0
146#define SMACK_CIPSO_SOCKET 1
147
148/*
149 * smackfs magic number
e114e473
CS
150 * smackfs macic number
151 */
152#define SMACK_MAGIC 0x43415d53 /* "SMAC" */
153
154/*
155 * A limit on the number of entries in the lists
156 * makes some of the list administration easier.
157 */
158#define SMACK_LIST_MAX 10000
159
160/*
161 * CIPSO defaults.
162 */
163#define SMACK_CIPSO_DOI_DEFAULT 3 /* Historical */
6d3dc07c 164#define SMACK_CIPSO_DOI_INVALID -1 /* Not a DOI */
e114e473
CS
165#define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
166#define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
167#define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
168#define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
169
170/*
171 * Just to make the common cases easier to deal with
172 */
173#define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
174#define MAY_ANYREAD (MAY_READ | MAY_EXEC)
175#define MAY_ANYWRITE (MAY_WRITE | MAY_APPEND)
176#define MAY_READWRITE (MAY_READ | MAY_WRITE)
177#define MAY_NOT 0
178
179/*
180 * These functions are in smack_lsm.c
181 */
182struct inode_smack *new_inode_smack(char *);
183
184/*
185 * These functions are in smack_access.c
186 */
187int smk_access(char *, char *, int);
188int smk_curacc(char *, u32);
189int smack_to_cipso(const char *, struct smack_cipso *);
190void smack_from_cipso(u32, char *, char *);
191char *smack_from_secid(const u32);
192char *smk_import(const char *, int);
193struct smack_known *smk_import_entry(const char *, int);
194u32 smack_to_secid(const char *);
195
196/*
197 * Shared data.
198 */
199extern int smack_cipso_direct;
e114e473 200extern char *smack_net_ambient;
15446235 201extern char *smack_onlycap;
e114e473 202
e114e473
CS
203extern struct smack_known smack_known_floor;
204extern struct smack_known smack_known_hat;
205extern struct smack_known smack_known_huh;
206extern struct smack_known smack_known_invalid;
207extern struct smack_known smack_known_star;
6d3dc07c 208extern struct smack_known smack_known_web;
e114e473 209
7198e2ee
EB
210extern struct list_head smack_known_list;
211extern struct list_head smack_rule_list;
212extern struct list_head smk_netlbladdr_list;
213
076c54c5 214extern struct security_operations smack_ops;
e114e473
CS
215
216/*
217 * Stricly for CIPSO level manipulation.
218 * Set the category bit number in a smack label sized buffer.
219 */
220static inline void smack_catset_bit(int cat, char *catsetp)
221{
222 if (cat > SMK_LABELLEN * 8)
223 return;
224
225 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
226}
227
228/*
229 * Present a pointer to the smack label in an inode blob.
230 */
231static inline char *smk_of_inode(const struct inode *isp)
232{
233 struct inode_smack *sip = isp->i_security;
234 return sip->smk_inode;
235}
236
237#endif /* _SECURITY_SMACK_H */
This page took 0.138023 seconds and 5 git commands to generate.