security.h revision 0719aaf5ead7555b7b7a4a080ebf2826a871384e
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Security server interface.
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef _SELINUX_SECURITY_H_
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _SELINUX_SECURITY_H_
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1175834fc3b6fcff00327f5d2a18760c1e8e0179c5Eric Paris#include <linux/magic.h>
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "flask.h"
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECSID_NULL			0x00000000 /* unspecified SID */
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECSID_WILD			0xffffffff /* wildcard SID */
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECCLASS_NULL			0x0000 /* no class */
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Identify specific policy version changes */
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_BASE		15
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_BOOL		16
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_IPV6		17
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_NLCLASS	18
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_VALIDATETRANS	19
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_MLS		19
25782ebb992ec20b5afdd5786ee8c2f1b58b631f24Stephen Smalley#define POLICYDB_VERSION_AVTAB		20
26f3f8771420737004da55159c2f2dc0b6f483a4efDarrel Goeddel#define POLICYDB_VERSION_RANGETRANS	21
273bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore#define POLICYDB_VERSION_POLCAP		22
2864dbf07474d011540ca479a2e87fe998f570d6e3Eric Paris#define POLICYDB_VERSION_PERMISSIVE	23
29d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei#define POLICYDB_VERSION_BOUNDARY	24
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Range of policy versions we understand*/
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_MIN   POLICYDB_VERSION_BASE
33016b9bdb81d9c9c7800e4e224ade38d8b37669d3Stephen Smalley#ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX
34016b9bdb81d9c9c7800e4e224ade38d8b37669d3Stephen Smalley#define POLICYDB_VERSION_MAX	CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
35016b9bdb81d9c9c7800e4e224ade38d8b37669d3Stephen Smalley#else
36d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_BOUNDARY
37016b9bdb81d9c9c7800e4e224ade38d8b37669d3Stephen Smalley#endif
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
390d90a7ec48c704025307b129413bc62451b20ab3David P. Quigley/* Mask for just the mount related flags */
400d90a7ec48c704025307b129413bc62451b20ab3David P. Quigley#define SE_MNTMASK	0x0f
410d90a7ec48c704025307b129413bc62451b20ab3David P. Quigley/* Super block security struct flags for mount options */
42e0007529893c1c064be90bd21422ca0da4a0198eEric Paris#define CONTEXT_MNT	0x01
43e0007529893c1c064be90bd21422ca0da4a0198eEric Paris#define FSCONTEXT_MNT	0x02
44e0007529893c1c064be90bd21422ca0da4a0198eEric Paris#define ROOTCONTEXT_MNT	0x04
45e0007529893c1c064be90bd21422ca0da4a0198eEric Paris#define DEFCONTEXT_MNT	0x08
460d90a7ec48c704025307b129413bc62451b20ab3David P. Quigley/* Non-mount related flags */
470d90a7ec48c704025307b129413bc62451b20ab3David P. Quigley#define SE_SBINITIALIZED	0x10
480d90a7ec48c704025307b129413bc62451b20ab3David P. Quigley#define SE_SBPROC		0x20
4911689d47f0957121920c9ec646eb5d838755853aDavid P. Quigley#define SE_SBLABELSUPP	0x40
50e0007529893c1c064be90bd21422ca0da4a0198eEric Paris
51832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris#define CONTEXT_STR	"context="
52832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris#define FSCONTEXT_STR	"fscontext="
53832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris#define ROOTCONTEXT_STR	"rootcontext="
54832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris#define DEFCONTEXT_STR	"defcontext="
5511689d47f0957121920c9ec646eb5d838755853aDavid P. Quigley#define LABELSUPP_STR "seclabel"
56832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris
575778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moorestruct netlbl_lsm_secattr;
58bb22f58087fdf8b617803c9b65bc86c6d26b5115James Morris
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int selinux_enabled;
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
613bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore/* Policy capabilities */
623bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Mooreenum {
633bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore	POLICYDB_CAPABILITY_NETPEER,
64b0c636b99997c8594da6a46e166ce4fcf6956fdaEric Paris	POLICYDB_CAPABILITY_OPENPERM,
653bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore	__POLICYDB_CAPABILITY_MAX
663bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore};
673bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
683bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore
693bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Mooreextern int selinux_policycap_netpeer;
70b0c636b99997c8594da6a46e166ce4fcf6956fdaEric Parisextern int selinux_policycap_openperm;
713bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore
72d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei/*
73d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei * type_datum properties
74d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei * available at the kernel policy version >= POLICYDB_VERSION_BOUNDARY
75d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei */
76d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei#define TYPEDATUM_PROPERTY_PRIMARY	0x0001
77d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei#define TYPEDATUM_PROPERTY_ATTRIBUTE	0x0002
78d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei
79d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei/* limitation of boundary depth  */
80d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei#define POLICYDB_BOUNDS_MAXDEPTH	4
81d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei
820719aaf5ead7555b7b7a4a080ebf2826a871384eGuido Trentalanciaint security_mls_enabled(void);
830719aaf5ead7555b7b7a4a080ebf2826a871384eGuido Trentalancia
84b19d8eae99dae42bb747954fdbb2cd456922eb5fEric Parisint security_load_policy(void *data, size_t len);
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
863bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Mooreint security_policycap_supported(unsigned int req_cap);
873bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore
88e47c8fc582a2c9f3cba059e543c4a056cd6bf8c4Christopher J. PeBenito#define SEL_VEC_MAX 32
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct av_decision {
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 allowed;
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 auditallow;
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 auditdeny;
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 seqno;
948a6f83afd0c5355db6d11394a798e94950306239KaiGai Kohei	u32 flags;
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
978a6f83afd0c5355db6d11394a798e94950306239KaiGai Kohei/* definitions of av_decision.flags */
988a6f83afd0c5355db6d11394a798e94950306239KaiGai Kohei#define AVD_FLAGS_PERMISSIVE	0x0001
9964dbf07474d011540ca479a2e87fe998f570d6e3Eric Paris
10019439d05b88dafc4e55d9ffce84ccc27cf8b2bccStephen Smalleyvoid security_compute_av(u32 ssid, u32 tsid,
10119439d05b88dafc4e55d9ffce84ccc27cf8b2bccStephen Smalley			 u16 tclass, struct av_decision *avd);
102c6d3aaa4e35c71a32a86ececacd4eea7ecfc316cStephen Smalley
10319439d05b88dafc4e55d9ffce84ccc27cf8b2bccStephen Smalleyvoid security_compute_av_user(u32 ssid, u32 tsid,
10419439d05b88dafc4e55d9ffce84ccc27cf8b2bccStephen Smalley			     u16 tclass, struct av_decision *avd);
1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_transition_sid(u32 ssid, u32 tsid,
107c6d3aaa4e35c71a32a86ececacd4eea7ecfc316cStephen Smalley			    u16 tclass, u32 *out_sid);
108c6d3aaa4e35c71a32a86ececacd4eea7ecfc316cStephen Smalley
109c6d3aaa4e35c71a32a86ececacd4eea7ecfc316cStephen Smalleyint security_transition_sid_user(u32 ssid, u32 tsid,
110c6d3aaa4e35c71a32a86ececacd4eea7ecfc316cStephen Smalley				 u16 tclass, u32 *out_sid);
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_member_sid(u32 ssid, u32 tsid,
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16 tclass, u32 *out_sid);
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_change_sid(u32 ssid, u32 tsid,
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16 tclass, u32 *out_sid);
1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_sid_to_context(u32 sid, char **scontext,
1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 *scontext_len);
1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
12112b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalleyint security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len);
12212b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalley
1238f0cfa52a1d4ffacd8e7de906d19662f5da58d58David Howellsint security_context_to_sid(const char *scontext, u32 scontext_len,
1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 *out_sid);
1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1267bf570dc8dcf76df2a9f583bef2da96d4289ed0dDavid Howellsint security_context_to_sid_default(const char *scontext, u32 scontext_len,
127869ab5147e1eead890245cfd4f652ba282b6ac26Stephen Smalley				    u32 *out_sid, u32 def_sid, gfp_t gfp_flags);
128f5c1d5b2aaf9a98f15a6dcdfbba1f494d0aaae52James Morris
12912b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalleyint security_context_to_sid_force(const char *scontext, u32 scontext_len,
13012b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalley				  u32 *sid);
13112b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalley
1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_get_user_sids(u32 callsid, char *username,
1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			   u32 **sids, u32 *nel);
1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1353e11217263d0521e212cb8a017fbc2a1514db78fPaul Mooreint security_port_sid(u8 protocol, u16 port, u32 *out_sid);
1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
137e8bfdb9d0dfc1231a6a71e849dfbd4447acdfff6Paul Mooreint security_netif_sid(char *name, u32 *if_sid);
1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_node_sid(u16 domain, void *addr, u32 addrlen,
1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 *out_sid);
1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
143b19d8eae99dae42bb747954fdbb2cd456922eb5fEric Paris				 u16 tclass);
1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
145d9250dea3f89fe808a525f08888016b495240ed4KaiGai Koheiint security_bounded_transition(u32 oldsid, u32 newsid);
146d9250dea3f89fe808a525f08888016b495240ed4KaiGai Kohei
14708554d6b33e60aa8ee40bbef94505941c0eefef2Venkat Yekkiralaint security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid);
14808554d6b33e60aa8ee40bbef94505941c0eefef2Venkat Yekkirala
149220deb966ea51e0dedb6a187c0763120809f3e64Paul Mooreint security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
150220deb966ea51e0dedb6a187c0763120809f3e64Paul Moore				 u32 xfrm_sid,
151220deb966ea51e0dedb6a187c0763120809f3e64Paul Moore				 u32 *peer_sid);
152220deb966ea51e0dedb6a187c0763120809f3e64Paul Moore
15355fcf09b3fe4325c9395ebbb0322a547a157ebc7Christopher J. PeBenitoint security_get_classes(char ***classes, int *nclasses);
15455fcf09b3fe4325c9395ebbb0322a547a157ebc7Christopher J. PeBenitoint security_get_permissions(char *class, char ***perms, int *nperms);
1553f12070e27b4a213d62607d2bff139793089a77dEric Parisint security_get_reject_unknown(void);
1563f12070e27b4a213d62607d2bff139793089a77dEric Parisint security_get_allow_unknown(void);
15755fcf09b3fe4325c9395ebbb0322a547a157ebc7Christopher J. PeBenito
1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_XATTR		1 /* use xattr */
1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_TRANS		2 /* use transition SIDs, e.g. devpts/tmpfs */
1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_TASK		3 /* use task SIDs, e.g. pipefs/sockfs */
1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_GENFS		4 /* use the genfs support */
1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_NONE		5 /* no labeling support */
1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_MNTPOINT	6 /* use mountpoint labeling */
1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_fs_use(const char *fstype, unsigned int *behavior,
166089be43e403a78cd6889cde2fba164fefe9dfd89James Morris	u32 *sid);
1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_genfs_sid(const char *fstype, char *name, u16 sclass,
1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 *sid);
1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1715778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore#ifdef CONFIG_NETLABEL
1725778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Mooreint security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,
1735778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore				   u32 *sid);
1745778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore
1755778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Mooreint security_netlbl_sid_to_secattr(u32 sid,
1765778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore				   struct netlbl_lsm_secattr *secattr);
1775778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore#else
1785778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moorestatic inline int security_netlbl_secattr_to_sid(
1795778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore					    struct netlbl_lsm_secattr *secattr,
1805778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore					    u32 *sid)
1815778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore{
1825778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore	return -EIDRM;
1835778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore}
1845778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore
1855778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moorestatic inline int security_netlbl_sid_to_secattr(u32 sid,
1865778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore					   struct netlbl_lsm_secattr *secattr)
1875778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore{
1885778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore	return -ENOENT;
1895778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore}
1905778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore#endif /* CONFIG_NETLABEL */
1915778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore
192f0ee2e467ffa68c3122128b704c1540ee294b748James Carterconst char *security_get_initial_sid_context(u32 sid);
193f0ee2e467ffa68c3122128b704c1540ee294b748James Carter
1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* _SELINUX_SECURITY_H_ */
1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
196