Skip to contentSkip to conversation

SELinux: introduce permissive types

PATCH Superseded Eric Paris 2 participants 7 messages Mar 10, 2008 – Mar 11, 2008 SELinux security module

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Eric Paris

author
#0 lore raw

PATCH 1/1 SELinux: introduce permissive types

Introduce the concept of a permissive type. A new ebitmap is introduced to the policy database which indicates if a given type has the permissive bit set or not. This bit is tested for the scontext of any denial. The bit is meaningless on types which only appear as the target of a decision and never the source. A domain running with a permissive type will be allowed to perform any action similarly to when the system is globally set permissive.

---

I 'solved' the issue where security_compute_av and the permissive sid checking are not atomic by checking that the seqno in the avd still matches the latest_granting. latest_granting is protected by POLICY_WRLOCK except when !ss_initialized so this should close any races. Also cleaned up some formatting and fixed Kconfig.

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |   11 +++++++----
 security/selinux/include/security.h |    5 ++++-
 security/selinux/ss/policydb.c      |   11 +++++++++++
 security/selinux/ss/policydb.h      |    2 ++
 security/selinux/ss/services.c      |   25 +++++++++++++++++++++++++
 6 files changed, 50 insertions(+), 6 deletions(-)
security/selinux/Kconfig +1 -1
index 2b517d6..a436d1c 100644
@@ -145,7 +145,7 @@ config SECURITY_SELINUX_POLICYDB_VERSION_MAX
 config SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 	int "NSA SELinux maximum supported policy format version value"
 	depends on SECURITY_SELINUX_POLICYDB_VERSION_MAX
-	range 15 22
+	range 15 23
 	default 19
 	help
 	  This option sets the value for the maximum policy format version
security/selinux/avc.c +7 -4
index 187964e..b13cbc6 100644
@@ -891,12 +891,15 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
 	if (!requested || denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if ((!selinux_enforcing) ||
+			 (unlikely(security_permissive_sid(ssid, p_ae->avd.seqno) &&
+				   requested && node)))
+			avc_update_node(AVC_CALLBACK_GRANT, requested, ssid,
+					tsid, tclass);
 		else
-			if (node)
-				avc_update_node(AVC_CALLBACK_GRANT,requested,
-						ssid,tsid,tclass);
+			rc = -EACCES;
 	}
 
 	rcu_read_unlock();
security/selinux/include/security.h +4 -1
index f7d2f03..f317a4e 100644
@@ -26,13 +26,14 @@
 #define POLICYDB_VERSION_AVTAB		20
 #define POLICYDB_VERSION_RANGETRANS	21
 #define POLICYDB_VERSION_POLCAP		22
+#define POLICYDB_VERSION_PERMISSIVE	23
 
 /* Range of policy versions we understand*/
 #define POLICYDB_VERSION_MIN   POLICYDB_VERSION_BASE
 #ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX
 #define POLICYDB_VERSION_MAX	CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 #else
-#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_POLCAP
+#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_PERMISSIVE
 #endif
 
 #define CONTEXT_MNT	0x01
@@ -67,6 +68,8 @@ struct av_decision {
 	u32 seqno;
 };
 
+int security_permissive_sid(u32 sid, u32 seqno);
+
 int security_compute_av(u32 ssid, u32 tsid,
 	u16 tclass, u32 requested,
 	struct av_decision *avd);
security/selinux/ss/policydb.c +11 -0
index bd7d6a0..84dbab9 100644
@@ -111,6 +111,11 @@ static struct policydb_compat_info policydb_compat[] = {
 		.version	= POLICYDB_VERSION_POLCAP,
 		.sym_num	= SYM_NUM,
 		.ocon_num	= OCON_NUM,
+	},
+	{
+		.version	= POLICYDB_VERSION_PERMISSIVE,
+		.sym_num	= SYM_NUM,
+		.ocon_num	= OCON_NUM,
 	}
 };
 
@@ -194,6 +199,7 @@ static int policydb_init(struct policydb *p)
 		goto out_free_symtab;
 
 	ebitmap_init(&p->policycaps);
+	ebitmap_init(&p->permissive_map);
 
 out:
 	return rc;
@@ -687,6 +693,7 @@ void policydb_destroy(struct policydb *p)
 	kfree(p->type_attr_map);
 	kfree(p->undefined_perms);
 	ebitmap_destroy(&p->policycaps);
+	ebitmap_destroy(&p->permissive_map);
 
 	return;
 }
@@ -1570,6 +1577,10 @@ int policydb_read(struct policydb *p, void *fp)
 	    ebitmap_read(&p->policycaps, fp) != 0)
 		goto bad;
 
+	if (p->policyvers >= POLICYDB_VERSION_PERMISSIVE &&
+	    ebitmap_read(&p->permissive_map, fp) != 0)
+		goto bad;
+
 	info = policydb_lookup_compat(p->policyvers);
 	if (!info) {
 		printk(KERN_ERR "security:  unable to find policy compat info "
security/selinux/ss/policydb.h +2 -0
index c4ce996..ba593a3 100644
@@ -243,6 +243,8 @@ struct policydb {
 
 	struct ebitmap policycaps;
 
+	struct ebitmap permissive_map;
+
 	unsigned int policyvers;
 
 	unsigned int reject_unknown : 1;
security/selinux/ss/services.c +25 -0
index f374186..b5eb9f5 100644
@@ -416,6 +416,31 @@ inval_class:
 	return -EINVAL;
 }
 
+/*
+ * Given a sid find if the type has the permissive flag set
+ */
+int security_permissive_sid(u32 sid, u32 seqno)
+{
+	struct context *context;
+	u32 type;
+	int rc;
+
+	POLICY_RDLOCK;
+
+	/* return 0 if policy changed since decision was made */
+	if (seqno != latest_granting)
+		return 0;
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	rc = ebitmap_get_bit(&policydb.permissive_map, type);
+	
+	POLICY_RDUNLOCK;
+	return rc;
+}
+
 static int security_validtrans_handle_fail(struct context *ocontext,
                                            struct context *ncontext,
                                            struct context *tcontext,

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#1 lore raw
Quoted 44 lines · Eric Paris

Introduce the concept of a permissive type. A new ebitmap is introduced to the policy database which indicates if a given type has the permissive bit set or not. This bit is tested for the scontext of any denial. The bit is meaningless on types which only appear as the target of a decision and never the source. A domain running with a permissive type will be allowed to perform any action similarly to when the system is globally set permissive.

---

I 'solved' the issue where security_compute_av and the permissive sid checking are not atomic by checking that the seqno in the avd still matches the latest_granting. latest_granting is protected by POLICY_WRLOCK except when !ss_initialized so this should close any races. Also cleaned up some formatting and fixed Kconfig.

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |   11 +++++++----
 security/selinux/include/security.h |    5 ++++-
 security/selinux/ss/policydb.c      |   11 +++++++++++
 security/selinux/ss/policydb.h      |    2 ++
 security/selinux/ss/services.c      |   25 +++++++++++++++++++++++++
 6 files changed, 50 insertions(+), 6 deletions(-)
security/selinux/Kconfig +1 -1
index 2b517d6..a436d1c 100644
@@ -145,7 +145,7 @@ config SECURITY_SELINUX_POLICYDB_VERSION_MAX
 config SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 	int "NSA SELinux maximum supported policy format version value"
 	depends on SECURITY_SELINUX_POLICYDB_VERSION_MAX
-	range 15 22
+	range 15 23
 	default 19
 	help
 	  This option sets the value for the maximum policy format version
security/selinux/avc.c +0 -0
index 187964e..b13cbc6 100644

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 896

Quoted 7 lines
security/selinux/avc.c +2 -1
@@ -891,12 +891,15 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
 	if (!requested || denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if ((!selinux_enforcing) ||

Extraneous parens?

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 898

Quoted 2 lines
security/selinux/avc.c +2 -0
+			 (unlikely(security_permissive_sid(ssid, p_ae->avd.seqno) &&
+				   requested && node)))

Do we really need the test of requested here?

Quoted 107 lines
security/selinux/avc.c +3 -3
+			avc_update_node(AVC_CALLBACK_GRANT, requested, ssid,
+					tsid, tclass);
 		else
-			if (node)
-				avc_update_node(AVC_CALLBACK_GRANT,requested,
-						ssid,tsid,tclass);
+			rc = -EACCES;
 	}
 
 	rcu_read_unlock();
security/selinux/include/security.h +4 -1
index f7d2f03..f317a4e 100644
@@ -26,13 +26,14 @@
 #define POLICYDB_VERSION_AVTAB		20
 #define POLICYDB_VERSION_RANGETRANS	21
 #define POLICYDB_VERSION_POLCAP		22
+#define POLICYDB_VERSION_PERMISSIVE	23
 
 /* Range of policy versions we understand*/
 #define POLICYDB_VERSION_MIN   POLICYDB_VERSION_BASE
 #ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX
 #define POLICYDB_VERSION_MAX	CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 #else
-#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_POLCAP
+#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_PERMISSIVE
 #endif
 
 #define CONTEXT_MNT	0x01
@@ -67,6 +68,8 @@ struct av_decision {
 	u32 seqno;
 };
 
+int security_permissive_sid(u32 sid, u32 seqno);
+
 int security_compute_av(u32 ssid, u32 tsid,
 	u16 tclass, u32 requested,
 	struct av_decision *avd);
security/selinux/ss/policydb.c +11 -0
index bd7d6a0..84dbab9 100644
@@ -111,6 +111,11 @@ static struct policydb_compat_info policydb_compat[] = {
 		.version	= POLICYDB_VERSION_POLCAP,
 		.sym_num	= SYM_NUM,
 		.ocon_num	= OCON_NUM,
+	},
+	{
+		.version	= POLICYDB_VERSION_PERMISSIVE,
+		.sym_num	= SYM_NUM,
+		.ocon_num	= OCON_NUM,
 	}
 };
 
@@ -194,6 +199,7 @@ static int policydb_init(struct policydb *p)
 		goto out_free_symtab;
 
 	ebitmap_init(&p->policycaps);
+	ebitmap_init(&p->permissive_map);
 
 out:
 	return rc;
@@ -687,6 +693,7 @@ void policydb_destroy(struct policydb *p)
 	kfree(p->type_attr_map);
 	kfree(p->undefined_perms);
 	ebitmap_destroy(&p->policycaps);
+	ebitmap_destroy(&p->permissive_map);
 
 	return;
 }
@@ -1570,6 +1577,10 @@ int policydb_read(struct policydb *p, void *fp)
 	    ebitmap_read(&p->policycaps, fp) != 0)
 		goto bad;
 
+	if (p->policyvers >= POLICYDB_VERSION_PERMISSIVE &&
+	    ebitmap_read(&p->permissive_map, fp) != 0)
+		goto bad;
+
 	info = policydb_lookup_compat(p->policyvers);
 	if (!info) {
 		printk(KERN_ERR "security:  unable to find policy compat info "
security/selinux/ss/policydb.h +2 -0
index c4ce996..ba593a3 100644
@@ -243,6 +243,8 @@ struct policydb {
 
 	struct ebitmap policycaps;
 
+	struct ebitmap permissive_map;
+
 	unsigned int policyvers;
 
 	unsigned int reject_unknown : 1;
security/selinux/ss/services.c +4 -0
index f374186..b5eb9f5 100644
@@ -416,6 +416,31 @@ inval_class:
 	return -EINVAL;
 }
 
+/*
+ * Given a sid find if the type has the permissive flag set
+ */
+int security_permissive_sid(u32 sid, u32 seqno)

security/selinux/ss/services.c inval_class: · line 432

Quoted 10 lines
security/selinux/ss/services.c +10 -0
+{
+	struct context *context;
+	u32 type;
+	int rc;
+
+	POLICY_RDLOCK;
+
+	/* return 0 if policy changed since decision was made */
+	if (seqno != latest_granting)
+		return 0;

Is this really needed? May cause false denials.

security/selinux/ss/services.c inval_class: · line 438

Quoted 6 lines
security/selinux/ss/services.c +6 -0
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	rc = ebitmap_get_bit(&policydb.permissive_map, type);

Typically we'd use (type - 1) above.

Quoted 15 lines
security/selinux/ss/services.c +5 -1
+	
+	POLICY_RDUNLOCK;
+	return rc;
+}
+
 static int security_validtrans_handle_fail(struct context *ocontext,
                                            struct context *ncontext,
                                            struct context *tcontext,
 
 
 
--

This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
Quoted 163 lines · Stephen Smalley
Quoted 44 lines · Eric Paris

Introduce the concept of a permissive type. A new ebitmap is introduced to the policy database which indicates if a given type has the permissive bit set or not. This bit is tested for the scontext of any denial. The bit is meaningless on types which only appear as the target of a decision and never the source. A domain running with a permissive type will be allowed to perform any action similarly to when the system is globally set permissive.

---

I 'solved' the issue where security_compute_av and the permissive sid checking are not atomic by checking that the seqno in the avd still matches the latest_granting. latest_granting is protected by POLICY_WRLOCK except when !ss_initialized so this should close any races. Also cleaned up some formatting and fixed Kconfig.

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |   11 +++++++----
 security/selinux/include/security.h |    5 ++++-
 security/selinux/ss/policydb.c      |   11 +++++++++++
 security/selinux/ss/policydb.h      |    2 ++
 security/selinux/ss/services.c      |   25 +++++++++++++++++++++++++
 6 files changed, 50 insertions(+), 6 deletions(-)
security/selinux/Kconfig +1 -1
index 2b517d6..a436d1c 100644
@@ -145,7 +145,7 @@ config SECURITY_SELINUX_POLICYDB_VERSION_MAX
 config SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 	int "NSA SELinux maximum supported policy format version value"
 	depends on SECURITY_SELINUX_POLICYDB_VERSION_MAX
-	range 15 22
+	range 15 23
 	default 19
 	help
 	  This option sets the value for the maximum policy format version
security/selinux/avc.c +0 -0
index 187964e..b13cbc6 100644

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 896

Quoted 7 lines
security/selinux/avc.c +2 -1
@@ -891,12 +891,15 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
 	if (!requested || denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if ((!selinux_enforcing) ||

Extraneous parens?

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 898

Quoted 2 lines
security/selinux/avc.c +2 -0
+			 (unlikely(security_permissive_sid(ssid, p_ae->avd.seqno) &&
+				   requested && node)))

Do we really need the test of requested here?

Quoted 103 lines
security/selinux/avc.c +3 -3
+			avc_update_node(AVC_CALLBACK_GRANT, requested, ssid,
+					tsid, tclass);
 		else
-			if (node)
-				avc_update_node(AVC_CALLBACK_GRANT,requested,
-						ssid,tsid,tclass);
+			rc = -EACCES;
 	}
 
 	rcu_read_unlock();
security/selinux/include/security.h +4 -1
index f7d2f03..f317a4e 100644
@@ -26,13 +26,14 @@
 #define POLICYDB_VERSION_AVTAB		20
 #define POLICYDB_VERSION_RANGETRANS	21
 #define POLICYDB_VERSION_POLCAP		22
+#define POLICYDB_VERSION_PERMISSIVE	23
 
 /* Range of policy versions we understand*/
 #define POLICYDB_VERSION_MIN   POLICYDB_VERSION_BASE
 #ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX
 #define POLICYDB_VERSION_MAX	CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 #else
-#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_POLCAP
+#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_PERMISSIVE
 #endif
 
 #define CONTEXT_MNT	0x01
@@ -67,6 +68,8 @@ struct av_decision {
 	u32 seqno;
 };
 
+int security_permissive_sid(u32 sid, u32 seqno);
+
 int security_compute_av(u32 ssid, u32 tsid,
 	u16 tclass, u32 requested,
 	struct av_decision *avd);
security/selinux/ss/policydb.c +11 -0
index bd7d6a0..84dbab9 100644
@@ -111,6 +111,11 @@ static struct policydb_compat_info policydb_compat[] = {
 		.version	= POLICYDB_VERSION_POLCAP,
 		.sym_num	= SYM_NUM,
 		.ocon_num	= OCON_NUM,
+	},
+	{
+		.version	= POLICYDB_VERSION_PERMISSIVE,
+		.sym_num	= SYM_NUM,
+		.ocon_num	= OCON_NUM,
 	}
 };
 
@@ -194,6 +199,7 @@ static int policydb_init(struct policydb *p)
 		goto out_free_symtab;
 
 	ebitmap_init(&p->policycaps);
+	ebitmap_init(&p->permissive_map);
 
 out:
 	return rc;
@@ -687,6 +693,7 @@ void policydb_destroy(struct policydb *p)
 	kfree(p->type_attr_map);
 	kfree(p->undefined_perms);
 	ebitmap_destroy(&p->policycaps);
+	ebitmap_destroy(&p->permissive_map);
 
 	return;
 }
@@ -1570,6 +1577,10 @@ int policydb_read(struct policydb *p, void *fp)
 	    ebitmap_read(&p->policycaps, fp) != 0)
 		goto bad;
 
+	if (p->policyvers >= POLICYDB_VERSION_PERMISSIVE &&
+	    ebitmap_read(&p->permissive_map, fp) != 0)
+		goto bad;
+
 	info = policydb_lookup_compat(p->policyvers);
 	if (!info) {
 		printk(KERN_ERR "security:  unable to find policy compat info "
security/selinux/ss/policydb.h +2 -0
index c4ce996..ba593a3 100644
@@ -243,6 +243,8 @@ struct policydb {
 
 	struct ebitmap policycaps;
 
+	struct ebitmap permissive_map;
+
 	unsigned int policyvers;
 
 	unsigned int reject_unknown : 1;
security/selinux/ss/services.c +0 -0
index f374186..b5eb9f5 100644
@@ -416,6 +416,31 @@ inval_class:
 	return -EINVAL;
 }
 
Quoted 16 lines
Quoted 4 lines
security/selinux/ss/services.c +4 -0
+/*
+ * Given a sid find if the type has the permissive flag set
+ */
+int security_permissive_sid(u32 sid, u32 seqno)

security/selinux/ss/services.c inval_class: · line 432

Quoted 10 lines
security/selinux/ss/services.c +10 -0
+{
+	struct context *context;
+	u32 type;
+	int rc;
+
+	POLICY_RDLOCK;
+
+	/* return 0 if policy changed since decision was made */
+	if (seqno != latest_granting)
+		return 0;

Is this really needed? May cause false denials.

If this is a concern, then I'd say go with what you suggested originally, i.e. do the ebitmap test in compute_av on the source type, and add a char flag field to struct av_decision to carry it back to the AVC. Then you can just test p_ae->avd.permissive in the AVC and everything is guaranteed to be atomic.

What I don't want is someone running a permissive domain, doing a policy reload, and seeing their permissive domain process fall over dead because the seqno changed even though it stayed permissive across the reload.

Quoted 25 lines

security/selinux/ss/services.c inval_class: · line 438

Quoted 7 lines
security/selinux/ss/services.c +6 -0
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	rc = ebitmap_get_bit(&policydb.permissive_map, type);

Typically we'd use (type - 1) above.

Quoted 15 lines
security/selinux/ss/services.c +5 -1
+	
+	POLICY_RDUNLOCK;
+	return rc;
+}
+
 static int security_validtrans_handle_fail(struct context *ocontext,
                                            struct context *ncontext,
                                            struct context *tcontext,
 
 
 
--

This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
author
#3 lore raw
In reply to Stephen Smalley
Quoted 47 lines · Stephen Smalley
Quoted 46 lines · Eric Paris

Introduce the concept of a permissive type. A new ebitmap is introduced to the policy database which indicates if a given type has the permissive bit set or not. This bit is tested for the scontext of any denial. The bit is meaningless on types which only appear as the target of a decision and never the source. A domain running with a permissive type will be allowed to perform any action similarly to when the system is globally set permissive.

---

I 'solved' the issue where security_compute_av and the permissive sid checking are not atomic by checking that the seqno in the avd still matches the latest_granting. latest_granting is protected by POLICY_WRLOCK except when !ss_initialized so this should close any races. Also cleaned up some formatting and fixed Kconfig.

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |   11 +++++++----
 security/selinux/include/security.h |    5 ++++-
 security/selinux/ss/policydb.c      |   11 +++++++++++
 security/selinux/ss/policydb.h      |    2 ++
 security/selinux/ss/services.c      |   25 +++++++++++++++++++++++++
 6 files changed, 50 insertions(+), 6 deletions(-)
security/selinux/Kconfig +1 -1
index 2b517d6..a436d1c 100644
@@ -145,7 +145,7 @@ config SECURITY_SELINUX_POLICYDB_VERSION_MAX
 config SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 	int "NSA SELinux maximum supported policy format version value"
 	depends on SECURITY_SELINUX_POLICYDB_VERSION_MAX
-	range 15 22
+	range 15 23
 	default 19
 	help
 	  This option sets the value for the maximum policy format version
security/selinux/avc.c +0 -0
index 187964e..b13cbc6 100644
@@ -891,12 +891,15 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
Quoted 7 lines

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 896

Quoted 5 lines
security/selinux/avc.c +2 -1
 	if (!requested || denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if ((!selinux_enforcing) ||

Extraneous parens?

yeah, I can't format code.

Quoted 5 lines

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 898

Quoted 3 lines
security/selinux/avc.c +2 -0
+			 (unlikely(security_permissive_sid(ssid, p_ae->avd.seqno) &&
+				   requested && node)))

Do we really need the test of requested here?

What is supposed to be the return code of !requested? I was surprised to find that !requested would typically get back -EACCES even though clearly nothing was denied. Not quite sure what !requested means in this context so I'm not sure what the correct handling of the permissive bit should be.

Quoted 8 lines
Quoted 8 lines
security/selinux/avc.c +8 -0
+/*
+ * Given a sid find if the type has the permissive flag set
+ */
+int security_permissive_sid(u32 sid, u32 seqno)
+{
+	struct context *context;
+	u32 type;
+	int rc;
Quoted 8 lines

security/selinux/avc.c

Quoted 6 lines
security/selinux/avc.c +6 -0
+
+	POLICY_RDLOCK;
+
+	/* return 0 if policy changed since decision was made */
+	if (seqno != latest_granting)
+		return 0;

Is this really needed? May cause false denials.

I decided to be less worried about false denials then false allows. Assume policy has type1_t not permissive and type1_t is number 100. It gets a denial and between the av_computer call and the permissive check someone loads new policy with some_other_type_t as number 100. If some_other_type_t is permissive I want to make sure that type1_t still gets its denial. Its not a particularly large window (reload between the compute and the permissive check) and I'm not sure if we would rather have accidental allows or accidental denials? I'll leave that up to the list.

Then again anyone using a permissive domain is probably the type of user who would prefer an accidental allow to an accidental denial....

Quoted 8 lines

security/selinux/avc.c

Quoted 6 lines
security/selinux/avc.c +6 -0
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	rc = ebitmap_get_bit(&policydb.permissive_map, type);

Typically we'd use (type - 1) above.

Yes, I actually left bit 0 open in case we ever wanted to put global permissive into the policy rather than through the selinuxfs interface. Using bit 0 to do this seemed like an easy and ideal solution. I wasn't going to bring that discussion up just yet to see if people liked the idea but here it is. Who would be interested in seeing global permissive inside policy rather than through selinuxfs?

-Eric

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
Quoted 56 lines · Eric Paris
Quoted 47 lines · Stephen Smalley
Quoted 46 lines · Eric Paris

Introduce the concept of a permissive type. A new ebitmap is introduced to the policy database which indicates if a given type has the permissive bit set or not. This bit is tested for the scontext of any denial. The bit is meaningless on types which only appear as the target of a decision and never the source. A domain running with a permissive type will be allowed to perform any action similarly to when the system is globally set permissive.

---

I 'solved' the issue where security_compute_av and the permissive sid checking are not atomic by checking that the seqno in the avd still matches the latest_granting. latest_granting is protected by POLICY_WRLOCK except when !ss_initialized so this should close any races. Also cleaned up some formatting and fixed Kconfig.

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |   11 +++++++----
 security/selinux/include/security.h |    5 ++++-
 security/selinux/ss/policydb.c      |   11 +++++++++++
 security/selinux/ss/policydb.h      |    2 ++
 security/selinux/ss/services.c      |   25 +++++++++++++++++++++++++
 6 files changed, 50 insertions(+), 6 deletions(-)
security/selinux/Kconfig +1 -1
index 2b517d6..a436d1c 100644
@@ -145,7 +145,7 @@ config SECURITY_SELINUX_POLICYDB_VERSION_MAX
 config SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 	int "NSA SELinux maximum supported policy format version value"
 	depends on SECURITY_SELINUX_POLICYDB_VERSION_MAX
-	range 15 22
+	range 15 23
 	default 19
 	help
 	  This option sets the value for the maximum policy format version
security/selinux/avc.c +0 -0
index 187964e..b13cbc6 100644
@@ -891,12 +891,15 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
Quoted 7 lines

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 896

Quoted 5 lines
security/selinux/avc.c +2 -1
 	if (!requested || denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if ((!selinux_enforcing) ||

Extraneous parens?

Quoted 5 lines

yeah, I can't format code.

Quoted 3 lines

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 898

Quoted 3 lines
security/selinux/avc.c +2 -0
+			 (unlikely(security_permissive_sid(ssid, p_ae->avd.seqno) &&
+				   requested && node)))

Ditto here.

Quoted 8 lines
Quoted 2 lines

Do we really need the test of requested here?

What is supposed to be the return code of !requested? I was surprised to find that !requested would typically get back -EACCES even though clearly nothing was denied. Not quite sure what !requested means in this context so I'm not sure what the correct handling of the permissive bit should be.

It's really a bug, but we were turning it into a null denial. Except avc_audit doesn't quite get it right, as we found in userspace (the avc: granted null bug, recently fixed in libselinux AVC but not in the kernel one).

I suppose we could just make it a BUG_ON(!requested) on entry.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
security/selinux/avc.c +8 -0
+/*
+ * Given a sid find if the type has the permissive flag set
+ */
+int security_permissive_sid(u32 sid, u32 seqno)
+{
+	struct context *context;
+	u32 type;
+	int rc;
Quoted 8 lines

security/selinux/avc.c

Quoted 6 lines
security/selinux/avc.c +6 -0
+
+	POLICY_RDLOCK;
+
+	/* return 0 if policy changed since decision was made */
+	if (seqno != latest_granting)
+		return 0;

Is this really needed? May cause false denials.

Quoted 1 line

I decided to be less worried about false denials then false allows.

Bad strategy for permissive domains, as it can cause breakage which is precisely the thing you are trying to prevent with permissive domains.

Quoted 5 lines

Assume policy has type1_t not permissive and type1_t is number 100. It gets a denial and between the av_computer call and the permissive check someone loads new policy with some_other_type_t as number 100. If some_other_type_t is permissive I want to make sure that type1_t still gets its denial.

Contexts in the sidtab get remapped across policy reload.

Quoted 4 lines

Its not a particularly large window (reload between
the compute and the permissive check) and I'm not sure if we would rather have accidental allows or accidental denials? I'll leave that up to the list.

I'd rather just have it correct - so the compute_av approach.

Quoted 12 lines

Then again anyone using a permissive domain is probably the type of user who would prefer an accidental allow to an accidental denial....

Quoted 8 lines

security/selinux/avc.c

Quoted 6 lines
security/selinux/avc.c +6 -0
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	rc = ebitmap_get_bit(&policydb.permissive_map, type);

Typically we'd use (type - 1) above.

Quoted 6 lines

Yes, I actually left bit 0 open in case we ever wanted to put global permissive into the policy rather than through the selinuxfs interface. Using bit 0 to do this seemed like an easy and ideal solution. I wasn't going to bring that discussion up just yet to see if people liked the idea but here it is. Who would be interested in seeing global permissive inside policy rather than through selinuxfs?

Hmmm...but selinuxfs would still be able to override the policy setting? And what about enforcing=0 on the command line - who wins at initial policy load? Seems confusing.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
author
#5 lore raw
Quoted 27 lines · Stephen Smalley
Quoted 26 lines · Eric Paris
Quoted 24 lines · Stephen Smalley
Quoted 14 lines · Eric Paris

Introduce the concept of a permissive type. A new ebitmap is introduced to the policy database which indicates if a given type has the permissive bit set or not. This bit is tested for the scontext of any denial. The bit is meaningless on types which only appear as the target of a decision and never the source. A domain running with a permissive type will be allowed to perform any action similarly to when the system is globally set permissive.

security/selinux/avc.c +0 -0
index 187964e..b13cbc6 100644

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 896

Quoted 7 lines
security/selinux/avc.c +2 -1
@@ -891,12 +891,15 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
 	if (!requested || denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if ((!selinux_enforcing) ||

Extraneous parens?

Quoted 7 lines
Quoted 5 lines

yeah, I can't format code.

Quoted 3 lines

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 898

Quoted 3 lines
security/selinux/avc.c +2 -0
+			 (unlikely(security_permissive_sid(ssid, p_ae->avd.seqno) &&
+				   requested && node)))

Ditto here.

No, I think those parens are correct....

Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

Do we really need the test of requested here?

What is supposed to be the return code of !requested? I was surprised to find that !requested would typically get back -EACCES even though clearly nothing was denied. Not quite sure what !requested means in this context so I'm not sure what the correct handling of the permissive bit should be.

Quoted 6 lines

It's really a bug, but we were turning it into a null denial. Except avc_audit doesn't quite get it right, as we found in userspace (the avc: granted null bug, recently fixed in libselinux AVC but not in the kernel one).

I suppose we could just make it a BUG_ON(!requested) on entry.

Ok then, how about I stop paying attention to !requested at all, I think that whole section gets a little easier....

if (unlikely(!requested)) {
	printk("null requested\n")
	WARN_ON(1);
	return -EACCES;
}

if (denied)
do cool stuff

Quoted 22 lines
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
security/selinux/avc.c +8 -0
+/*
+ * Given a sid find if the type has the permissive flag set
+ */
+int security_permissive_sid(u32 sid, u32 seqno)
+{
+	struct context *context;
+	u32 type;
+	int rc;
Quoted 8 lines

security/selinux/avc.c

Quoted 6 lines
security/selinux/avc.c +6 -0
+
+	POLICY_RDLOCK;
+
+	/* return 0 if policy changed since decision was made */
+	if (seqno != latest_granting)
+		return 0;

Is this really needed? May cause false denials.

Quoted 1 line

I decided to be less worried about false denials then false allows.

Bad strategy for permissive domains, as it can cause breakage which is precisely the thing you are trying to prevent with permissive domains.

Quoted 7 lines
Quoted 5 lines

Assume policy has type1_t not permissive and type1_t is number 100. It gets a denial and between the av_computer call and the permissive check someone loads new policy with some_other_type_t as number 100. If some_other_type_t is permissive I want to make sure that type1_t still gets its denial.

Contexts in the sidtab get remapped across policy reload.

I'll reread the remapping stuff to convince myself that all of this is going to work correctly. As is most likely you are right and just allowing the permissive bit even on policy reload is the right way to go.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

security/selinux/avc.c

Quoted 6 lines
security/selinux/avc.c +6 -0
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	rc = ebitmap_get_bit(&policydb.permissive_map, type);

Typically we'd use (type - 1) above.

Quoted 6 lines

Yes, I actually left bit 0 open in case we ever wanted to put global permissive into the policy rather than through the selinuxfs interface. Using bit 0 to do this seemed like an easy and ideal solution. I wasn't going to bring that discussion up just yet to see if people liked the idea but here it is. Who would be interested in seeing global permissive inside policy rather than through selinuxfs?

Quoted 3 lines

Hmmm...but selinuxfs would still be able to override the policy setting? And what about enforcing=0 on the command line - who wins at initial policy load? Seems confusing.

Still a bit of thought before it comes to pass. But there was a reason I left the 0 bit unused...

-Eric

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#6 lore raw
Quoted 55 lines · Eric Paris
Quoted 27 lines · Stephen Smalley
Quoted 26 lines · Eric Paris
Quoted 24 lines · Stephen Smalley
Quoted 14 lines · Eric Paris

Introduce the concept of a permissive type. A new ebitmap is introduced to the policy database which indicates if a given type has the permissive bit set or not. This bit is tested for the scontext of any denial. The bit is meaningless on types which only appear as the target of a decision and never the source. A domain running with a permissive type will be allowed to perform any action similarly to when the system is globally set permissive.

security/selinux/avc.c +0 -0
index 187964e..b13cbc6 100644

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 896

Quoted 7 lines
security/selinux/avc.c +2 -1
@@ -891,12 +891,15 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
 	if (!requested || denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if ((!selinux_enforcing) ||

Extraneous parens?

Quoted 7 lines
Quoted 5 lines

yeah, I can't format code.

Quoted 3 lines

security/selinux/avc.c int avc_has_perm_noaudit(u32 ssid, u32 tsid, · line 898

Quoted 3 lines
security/selinux/avc.c +2 -0
+			 (unlikely(security_permissive_sid(ssid, p_ae->avd.seqno) &&
+				   requested && node)))

Ditto here.

No, I think those parens are correct....

Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

Do we really need the test of requested here?

What is supposed to be the return code of !requested? I was surprised to find that !requested would typically get back -EACCES even though clearly nothing was denied. Not quite sure what !requested means in this context so I'm not sure what the correct handling of the permissive bit should be.

Quoted 6 lines

It's really a bug, but we were turning it into a null denial. Except avc_audit doesn't quite get it right, as we found in userspace (the avc: granted null bug, recently fixed in libselinux AVC but not in the kernel one).

I suppose we could just make it a BUG_ON(!requested) on entry.

Quoted 8 lines

Ok then, how about I stop paying attention to !requested at all, I think that whole section gets a little easier....

if (unlikely(!requested)) {
	printk("null requested\n")
	WARN_ON(1);
	return -EACCES;
}

I'd just make it a BUG_ON. But make that a separate patch. You can put it first in the series.

Quoted 63 lines

if (denied)
do cool stuff

Quoted 22 lines
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
security/selinux/avc.c +8 -0
+/*
+ * Given a sid find if the type has the permissive flag set
+ */
+int security_permissive_sid(u32 sid, u32 seqno)
+{
+	struct context *context;
+	u32 type;
+	int rc;
Quoted 8 lines

security/selinux/avc.c

Quoted 6 lines
security/selinux/avc.c +6 -0
+
+	POLICY_RDLOCK;
+
+	/* return 0 if policy changed since decision was made */
+	if (seqno != latest_granting)
+		return 0;

Is this really needed? May cause false denials.

Quoted 1 line

I decided to be less worried about false denials then false allows.

Bad strategy for permissive domains, as it can cause breakage which is precisely the thing you are trying to prevent with permissive domains.

Quoted 7 lines
Quoted 5 lines

Assume policy has type1_t not permissive and type1_t is number 100. It gets a denial and between the av_computer call and the permissive check someone loads new policy with some_other_type_t as number 100. If some_other_type_t is permissive I want to make sure that type1_t still gets its denial.

Contexts in the sidtab get remapped across policy reload.

I'll reread the remapping stuff to convince myself that all of this is going to work correctly. As is most likely you are right and just allowing the permissive bit even on policy reload is the right way to go.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

security/selinux/avc.c

Quoted 6 lines
security/selinux/avc.c +6 -0
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	rc = ebitmap_get_bit(&policydb.permissive_map, type);

Typically we'd use (type - 1) above.

Quoted 6 lines

Yes, I actually left bit 0 open in case we ever wanted to put global permissive into the policy rather than through the selinuxfs interface. Using bit 0 to do this seemed like an easy and ideal solution. I wasn't going to bring that discussion up just yet to see if people liked the idea but here it is. Who would be interested in seeing global permissive inside policy rather than through selinuxfs?

Quoted 3 lines

Hmmm...but selinuxfs would still be able to override the policy setting? And what about enforcing=0 on the command line - who wins at initial policy load? Seems confusing.

Still a bit of thought before it comes to pass. But there was a reason I left the 0 bit unused...

-Eric

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.