security.h revision 089be43e403a78cd6889cde2fba164fefe9dfd89
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
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "flask.h"
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECSID_NULL			0x00000000 /* unspecified SID */
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECSID_WILD			0xffffffff /* wildcard SID */
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECCLASS_NULL			0x0000 /* no class */
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SELINUX_MAGIC 0xf97cff8c
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Identify specific policy version changes */
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_BASE		15
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_BOOL		16
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_IPV6		17
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_NLCLASS	18
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_VALIDATETRANS	19
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define POLICYDB_VERSION_MLS		19
26782ebb992ec20b5afdd5786ee8c2f1b58b631f24Stephen Smalley#define POLICYDB_VERSION_AVTAB		20
27f3f8771420737004da55159c2f2dc0b6f483a4efDarrel Goeddel#define POLICYDB_VERSION_RANGETRANS	21
283bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore#define POLICYDB_VERSION_POLCAP		22
2964dbf07474d011540ca479a2e87fe998f570d6e3Eric Paris#define POLICYDB_VERSION_PERMISSIVE	23
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
3664dbf07474d011540ca479a2e87fe998f570d6e3Eric Paris#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_PERMISSIVE
37016b9bdb81d9c9c7800e4e224ade38d8b37669d3Stephen Smalley#endif
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
39e0007529893c1c064be90bd21422ca0da4a0198eEric Paris#define CONTEXT_MNT	0x01
40e0007529893c1c064be90bd21422ca0da4a0198eEric Paris#define FSCONTEXT_MNT	0x02
41e0007529893c1c064be90bd21422ca0da4a0198eEric Paris#define ROOTCONTEXT_MNT	0x04
42e0007529893c1c064be90bd21422ca0da4a0198eEric Paris#define DEFCONTEXT_MNT	0x08
43e0007529893c1c064be90bd21422ca0da4a0198eEric Paris
44832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris#define CONTEXT_STR	"context="
45832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris#define FSCONTEXT_STR	"fscontext="
46832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris#define ROOTCONTEXT_STR	"rootcontext="
47832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris#define DEFCONTEXT_STR	"defcontext="
48832cbd9aa1293cba57d06571f5fc8f0917c672afEric Paris
495778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moorestruct netlbl_lsm_secattr;
50bb22f58087fdf8b617803c9b65bc86c6d26b5115James Morris
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int selinux_enabled;
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int selinux_mls_enabled;
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
543bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore/* Policy capabilities */
553bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Mooreenum {
563bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore	POLICYDB_CAPABILITY_NETPEER,
57b0c636b99997c8594da6a46e166ce4fcf6956fdaEric Paris	POLICYDB_CAPABILITY_OPENPERM,
583bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore	__POLICYDB_CAPABILITY_MAX
593bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore};
603bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
613bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore
623bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Mooreextern int selinux_policycap_netpeer;
63b0c636b99997c8594da6a46e166ce4fcf6956fdaEric Parisextern int selinux_policycap_openperm;
643bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore
65b19d8eae99dae42bb747954fdbb2cd456922eb5fEric Parisint security_load_policy(void *data, size_t len);
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
673bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Mooreint security_policycap_supported(unsigned int req_cap);
683bb56b25dbe0a4b44bd2ebceab6736d068e85068Paul Moore
69e47c8fc582a2c9f3cba059e543c4a056cd6bf8c4Christopher J. PeBenito#define SEL_VEC_MAX 32
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct av_decision {
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 allowed;
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 decided;
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 auditallow;
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 auditdeny;
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 seqno;
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7864dbf07474d011540ca479a2e87fe998f570d6e3Eric Parisint security_permissive_sid(u32 sid);
7964dbf07474d011540ca479a2e87fe998f570d6e3Eric Paris
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_compute_av(u32 ssid, u32 tsid,
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16 tclass, u32 requested,
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct av_decision *avd);
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_transition_sid(u32 ssid, u32 tsid,
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16 tclass, u32 *out_sid);
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_member_sid(u32 ssid, u32 tsid,
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16 tclass, u32 *out_sid);
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_change_sid(u32 ssid, u32 tsid,
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u16 tclass, u32 *out_sid);
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_sid_to_context(u32 sid, char **scontext,
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 *scontext_len);
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
9612b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalleyint security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len);
9712b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalley
988f0cfa52a1d4ffacd8e7de906d19662f5da58d58David Howellsint security_context_to_sid(const char *scontext, u32 scontext_len,
991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 *out_sid);
1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1017bf570dc8dcf76df2a9f583bef2da96d4289ed0dDavid Howellsint security_context_to_sid_default(const char *scontext, u32 scontext_len,
102869ab5147e1eead890245cfd4f652ba282b6ac26Stephen Smalley				    u32 *out_sid, u32 def_sid, gfp_t gfp_flags);
103f5c1d5b2aaf9a98f15a6dcdfbba1f494d0aaae52James Morris
10412b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalleyint security_context_to_sid_force(const char *scontext, u32 scontext_len,
10512b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalley				  u32 *sid);
10612b29f34558b9b45a2c6eabd4f3c6be939a3980fStephen Smalley
1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_get_user_sids(u32 callsid, char *username,
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			   u32 **sids, u32 *nel);
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1103e11217263d0521e212cb8a017fbc2a1514db78fPaul Mooreint security_port_sid(u8 protocol, u16 port, u32 *out_sid);
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
112e8bfdb9d0dfc1231a6a71e849dfbd4447acdfff6Paul Mooreint security_netif_sid(char *name, u32 *if_sid);
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_node_sid(u16 domain, void *addr, u32 addrlen,
1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 *out_sid);
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
118b19d8eae99dae42bb747954fdbb2cd456922eb5fEric Paris				 u16 tclass);
1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
12008554d6b33e60aa8ee40bbef94505941c0eefef2Venkat Yekkiralaint security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid);
12108554d6b33e60aa8ee40bbef94505941c0eefef2Venkat Yekkirala
122220deb966ea51e0dedb6a187c0763120809f3e64Paul Mooreint security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
123220deb966ea51e0dedb6a187c0763120809f3e64Paul Moore				 u32 xfrm_sid,
124220deb966ea51e0dedb6a187c0763120809f3e64Paul Moore				 u32 *peer_sid);
125220deb966ea51e0dedb6a187c0763120809f3e64Paul Moore
12655fcf09b3fe4325c9395ebbb0322a547a157ebc7Christopher J. PeBenitoint security_get_classes(char ***classes, int *nclasses);
12755fcf09b3fe4325c9395ebbb0322a547a157ebc7Christopher J. PeBenitoint security_get_permissions(char *class, char ***perms, int *nperms);
1283f12070e27b4a213d62607d2bff139793089a77dEric Parisint security_get_reject_unknown(void);
1293f12070e27b4a213d62607d2bff139793089a77dEric Parisint security_get_allow_unknown(void);
13055fcf09b3fe4325c9395ebbb0322a547a157ebc7Christopher J. PeBenito
1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_XATTR		1 /* use xattr */
1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_TRANS		2 /* use transition SIDs, e.g. devpts/tmpfs */
1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_TASK		3 /* use task SIDs, e.g. pipefs/sockfs */
1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_GENFS		4 /* use the genfs support */
1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_NONE		5 /* no labeling support */
1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SECURITY_FS_USE_MNTPOINT	6 /* use mountpoint labeling */
1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_fs_use(const char *fstype, unsigned int *behavior,
139089be43e403a78cd6889cde2fba164fefe9dfd89James Morris	u32 *sid);
1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint security_genfs_sid(const char *fstype, char *name, u16 sclass,
1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	u32 *sid);
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1445778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore#ifdef CONFIG_NETLABEL
1455778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Mooreint security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,
1465778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore				   u32 *sid);
1475778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore
1485778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Mooreint security_netlbl_sid_to_secattr(u32 sid,
1495778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore				   struct netlbl_lsm_secattr *secattr);
1505778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore#else
1515778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moorestatic inline int security_netlbl_secattr_to_sid(
1525778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore					    struct netlbl_lsm_secattr *secattr,
1535778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore					    u32 *sid)
1545778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore{
1555778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore	return -EIDRM;
1565778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore}
1575778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore
1585778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moorestatic inline int security_netlbl_sid_to_secattr(u32 sid,
1595778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore					   struct netlbl_lsm_secattr *secattr)
1605778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore{
1615778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore	return -ENOENT;
1625778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore}
1635778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore#endif /* CONFIG_NETLABEL */
1645778eabd9cdbf16ea3e40248c452b4fd25554d11Paul Moore
165f0ee2e467ffa68c3122128b704c1540ee294b748James Carterconst char *security_get_initial_sid_context(u32 sid);
166f0ee2e467ffa68c3122128b704c1540ee294b748James Carter
1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* _SELINUX_SECURITY_H_ */
1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
169