Skip to contentSkip to conversation

SELinux: introduce permissive types

PATCH In review Eric Paris 4 participants 7 messages Mar 11, 2008 – Mar 31, 2008 SELinux security module

lore
Share & tools
lore

Eric Paris

author
#0 lore raw

PATCH v4 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.

---

Should be applied after the BUG_ON(!requested) patch

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |    9 +++++----
 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, 48 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 +5 -4
index cb3f0ce..a4fc6e6 100644
@@ -893,12 +893,13 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
 	if (denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if (!selinux_enforcing || security_permissive_sid(ssid))
+			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..fde8690 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);
+
 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..4bfbca5 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)
+{
+	struct context *context;
+	u32 type;
+	int rc;
+
+	POLICY_RDLOCK;
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	/*
+	 * we are intentionally using type here, not type-1, the 0th bit may
+	 * someday indicate that we are globally setting permissive in policy.
+	 */
+	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 7 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.

So you are ok with the potential false denial scenario I outlined in the prior set of comments?

If so, then we likely need to document that proper usage is to mark a type permissive, determine the right set of allow rules, add those allow rules, and then remove the permissive designation only afterward as a separate policy transaction.

Quoted 178 lines

---

Should be applied after the BUG_ON(!requested) patch

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |    9 +++++----
 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, 48 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 +5 -4
index cb3f0ce..a4fc6e6 100644
@@ -893,12 +893,13 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
 	if (denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if (!selinux_enforcing || security_permissive_sid(ssid))
+			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..fde8690 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);
+
 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 -1
index f374186..4bfbca5 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)
+{
+	struct context *context;
+	u32 type;
+	int rc;
+
+	POLICY_RDLOCK;
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	/*
+	 * we are intentionally using type here, not type-1, the 0th bit may
+	 * someday indicate that we are globally setting permissive in policy.
+	 */
+	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.

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

I think we all agree that this patch is good as is and we should go ahead and apply for the next round.

Correct?

-Eric

Quoted 205 lines · Stephen Smalley
Quoted 7 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.

So you are ok with the potential false denial scenario I outlined in the
prior set of comments?

If so, then we likely need to document that proper usage is to mark a type permissive, determine the right set of allow rules, add those allow rules, and then remove the permissive designation only afterward as a separate policy transaction.

Quoted 175 lines

---

Should be applied after the BUG_ON(!requested) patch

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |    9 +++++----
 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, 48 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 +5 -4
index cb3f0ce..a4fc6e6 100644
@@ -893,12 +893,13 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
      denied = requested & ~(p_ae->avd.allowed);
 
      if (denied) {
-             if (selinux_enforcing || (flags & AVC_STRICT))
+             if (flags & AVC_STRICT)
                      rc = -EACCES;
+             else if (!selinux_enforcing || security_permissive_sid(ssid))
+                     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..fde8690 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);
+
 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 -1
index f374186..4bfbca5 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)
+{
+     struct context *context;
+     u32 type;
+     int rc;
+
+     POLICY_RDLOCK;
+
+     context = sidtab_search(&sidtab, sid);
+     BUG_ON(!context);
+
+     type = context->type;
+     /*
+      * we are intentionally using type here, not type-1, the 0th bit may
+      * someday indicate that we are globally setting permissive in policy.
+      */
+     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,
 
 
 
--
Quoted 3 lines

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.

--
Stephen Smalley
National Security Agency

Quoted 5 lines

--
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.

--
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.

#3 lore raw
Quoted 4 lines · Eric Paris

I think we all agree that this patch is good as is and we should go ahead and apply for the next round.

Correct?

Yes - for the kernel patch. As I recall, there were a few minor issues with the libsepol patch.

Quoted 214 lines

-Eric

Quoted 210 lines · Stephen Smalley
Quoted 7 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.

So you are ok with the potential false denial scenario I outlined in the
prior set of comments?

If so, then we likely need to document that proper usage is to mark a type permissive, determine the right set of allow rules, add those allow rules, and then remove the permissive designation only afterward as a separate policy transaction.

Quoted 175 lines

---

Should be applied after the BUG_ON(!requested) patch

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |    9 +++++----
 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, 48 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 +5 -4
index cb3f0ce..a4fc6e6 100644
@@ -893,12 +893,13 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
      denied = requested & ~(p_ae->avd.allowed);
 
      if (denied) {
-             if (selinux_enforcing || (flags & AVC_STRICT))
+             if (flags & AVC_STRICT)
                      rc = -EACCES;
+             else if (!selinux_enforcing || security_permissive_sid(ssid))
+                     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..fde8690 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);
+
 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 -1
index f374186..4bfbca5 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)
+{
+     struct context *context;
+     u32 type;
+     int rc;
+
+     POLICY_RDLOCK;
+
+     context = sidtab_search(&sidtab, sid);
+     BUG_ON(!context);
+
+     type = context->type;
+     /*
+      * we are intentionally using type here, not type-1, the 0th bit may
+      * someday indicate that we are globally setting permissive in policy.
+      */
+     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,
 
 
 
--
Quoted 3 lines

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.

--
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.

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
#4 lore raw
Quoted 10 lines · Stephen Smalley
Quoted 4 lines · Eric Paris

I think we all agree that this patch is good as is and we should go ahead and apply for the next round.

Correct?

Yes - for the kernel patch. As I recall, there were a few minor issues with the libsepol patch.

Quoted 2 lines

-Eric

Yup, starting to go through the other patches, I think we just needed comments on the bitfield usage, but I'm looking over it now.

-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.

Acked-by on v4 1/1
#5 lore raw
In reply to Eric Paris
Quoted 9 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.

Quoted 176 lines

---

Should be applied after the BUG_ON(!requested) patch

 security/selinux/Kconfig            |    2 +-
 security/selinux/avc.c              |    9 +++++----
 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, 48 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 +5 -4
index cb3f0ce..a4fc6e6 100644
@@ -893,12 +893,13 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
 	denied = requested & ~(p_ae->avd.allowed);
 
 	if (denied) {
-		if (selinux_enforcing || (flags & AVC_STRICT))
+		if (flags & AVC_STRICT)
 			rc = -EACCES;
+		else if (!selinux_enforcing || security_permissive_sid(ssid))
+			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..fde8690 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);
+
 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 -1
index f374186..4bfbca5 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)
+{
+	struct context *context;
+	u32 type;
+	int rc;
+
+	POLICY_RDLOCK;
+
+	context = sidtab_search(&sidtab, sid);
+	BUG_ON(!context);
+
+	type = context->type;
+	/*
+	 * we are intentionally using type here, not type-1, the 0th bit may
+	 * someday indicate that we are globally setting permissive in policy.
+	 */
+	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.

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.
#6 lore raw
Quoted 10 lines · Stephen Smalley
Quoted 8 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.

Quoted 4 lines
Quoted 1 line

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6.git#for-akpm

Signature · 7 lines
James Morris
<[email protected]>

--
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.