Skip to contentSkip to conversation

kernel: selinux: policy selectable handling of unknown classes and perms

PATCH In review Eric Paris 6 participants 15 messages Aug 1, 2007 – Aug 21, 2007 SELinux security module

lore
Share & tools
lore

Eric Paris

author
#0 lore raw

PATCH 1/1 kernel: selinux: policy selectable handling of unknown classes and perms

Allow policy to select, in much the same way as it selects MLS support, how the kernel should handle access decisions which contain either unknown classes or unknown permissions in unknown classes. The three choices are (from a kernel perspective)

0 - Deny unknown security access. (default)
2 - reject loading policy if it does not contain all definitions 4 - allow unknown security access

---

Biggest change between this patch and the last on list is that I changed handle_unknown to not be needlessly bit shifted. I also dropped a check in context_struct_computeav which was redundant.

 security/selinux/ss/policydb.c |    8 +++++
 security/selinux/ss/policydb.h |   10 ++++++
 security/selinux/ss/services.c |   65 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 74 insertions(+), 9 deletions(-)
security/selinux/ss/policydb.c +8 -0
index f05f97a..588dcfd 100644
@@ -677,6 +677,8 @@ void policydb_destroy(struct policydb *p)
 	}
 	kfree(p->type_attr_map);
 
+	kfree(p->undefined_perms);
+
 	return;
 }
 
@@ -1530,6 +1532,12 @@ int policydb_read(struct policydb *p, void *fp)
 			goto bad;
 		}
 	}
+	p->handle_unknown = le32_to_cpu(buf[1]) & POLICYDB_CONFIG_UNKNOWN_MASK;
+
+	if (p->handle_unknown > ALLOW_UNKNOWN) {
+		printk(KERN_ERR "selinux: invalid options for handle_unknown\n");
+		goto bad;
+	}
 
 	info = policydb_lookup_compat(p->policyvers);
 	if (!info) {
security/selinux/ss/policydb.h +10 -0
index 8319d5f..f84e856 100644
@@ -242,6 +242,9 @@ struct policydb {
 	struct ebitmap *type_attr_map;
 
 	unsigned int policyvers;
+
+	int handle_unknown;
+	u32 *undefined_perms;
 };
 
 extern void policydb_destroy(struct policydb *p);
@@ -253,6 +256,13 @@ extern int policydb_read(struct policydb *p, void *fp);
 
 #define POLICYDB_CONFIG_MLS    1
 
+/* the config flags related to unknown classes/perms are bits 2 and 3 */
+#define DENY_UNKNOWN	0x00000000
+#define REJECT_UNKNOWN	0x00000002
+#define ALLOW_UNKNOWN	0x00000004
+
+#define POLICYDB_CONFIG_UNKNOWN_MASK 	(DENY_UNKNOWN | REJECT_UNKNOWN | ALLOW_UNKNOWN)
+
 #define OBJECT_R "object_r"
 #define OBJECT_R_VAL 1
 
security/selinux/ss/services.c +56 -9

123 lines not on this page · raw 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.

#1 lore raw
Quoted 8 lines · Eric Paris

Allow policy to select, in much the same way as it selects MLS support, how the kernel should handle access decisions which contain either unknown classes or unknown permissions in unknown classes. The three choices are (from a kernel perspective)

0 - Deny unknown security access. (default)
2 - reject loading policy if it does not contain all definitions 4 - allow unknown security access

If we leave the default as the current behavior (i.e. deny access if checking an unknown class or permission), then what exactly have we achieved with this patch? The next time we introduce a new permission check in the kernel, anyone who installs that kernel on an existing distribution release will still encounter breakage. It will only start providing benefit for newer distribution releases with policies built to have the non-default setting.

Other points to ponder:
- Would this have helped with the recent netlabel breakage? I don't think so, as that was introducing a further check for an existing class/perm in the unlabeled case, not a new class/perm.
- Does this help with letting us fix the ioctl hook? Problem there is again that we are more likely to start mapping ioctls to read/write or getattr/setattr instead of the generic "ioctl" fallback rather than introducing new perms.
- We still can't easily add new perms to common definitions (displaces class-specific ones).
- Does this help us with secmark at all, e.g. can we eliminate compat_net? Do we want to eliminate compat_net yet? Fedora still seems to have compat_net=1.
- We still can't purge obsolete classes/perms or reorganize the existing ones safely with this change.

So...is it worth it by itself?

Quoted 203 lines

---

Biggest change between this patch and the last on list is that I changed handle_unknown to not be needlessly bit shifted. I also dropped a check in context_struct_computeav which was redundant.

 security/selinux/ss/policydb.c |    8 +++++
 security/selinux/ss/policydb.h |   10 ++++++
 security/selinux/ss/services.c |   65 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 74 insertions(+), 9 deletions(-)
security/selinux/ss/policydb.c +8 -0
index f05f97a..588dcfd 100644
@@ -677,6 +677,8 @@ void policydb_destroy(struct policydb *p)
 	}
 	kfree(p->type_attr_map);
 
+	kfree(p->undefined_perms);
+
 	return;
 }
 
@@ -1530,6 +1532,12 @@ int policydb_read(struct policydb *p, void *fp)
 			goto bad;
 		}
 	}
+	p->handle_unknown = le32_to_cpu(buf[1]) & POLICYDB_CONFIG_UNKNOWN_MASK;
+
+	if (p->handle_unknown > ALLOW_UNKNOWN) {
+		printk(KERN_ERR "selinux: invalid options for handle_unknown\n");
+		goto bad;
+	}
 
 	info = policydb_lookup_compat(p->policyvers);
 	if (!info) {
security/selinux/ss/policydb.h +10 -0
index 8319d5f..f84e856 100644
@@ -242,6 +242,9 @@ struct policydb {
 	struct ebitmap *type_attr_map;
 
 	unsigned int policyvers;
+
+	int handle_unknown;
+	u32 *undefined_perms;
 };
 
 extern void policydb_destroy(struct policydb *p);
@@ -253,6 +256,13 @@ extern int policydb_read(struct policydb *p, void *fp);
 
 #define POLICYDB_CONFIG_MLS    1
 
+/* the config flags related to unknown classes/perms are bits 2 and 3 */
+#define DENY_UNKNOWN	0x00000000
+#define REJECT_UNKNOWN	0x00000002
+#define ALLOW_UNKNOWN	0x00000004
+
+#define POLICYDB_CONFIG_UNKNOWN_MASK 	(DENY_UNKNOWN | REJECT_UNKNOWN | ALLOW_UNKNOWN)
+
 #define OBJECT_R "object_r"
 #define OBJECT_R_VAL 1
 
security/selinux/ss/services.c +56 -9
index 0ae032f..d3f3a43 100644
@@ -292,6 +292,7 @@ static int context_struct_compute_av(struct context *scontext,
 	struct class_datum *tclass_datum;
 	struct ebitmap *sattr, *tattr;
 	struct ebitmap_node *snode, *tnode;
+	const struct selinux_class_perm *kdefs = &selinux_class_perm;
 	unsigned int i, j;
 
 	/*
@@ -305,13 +306,6 @@ static int context_struct_compute_av(struct context *scontext,
 		    tclass <= SECCLASS_NETLINK_DNRT_SOCKET)
 			tclass = SECCLASS_NETLINK_SOCKET;
 
-	if (!tclass || tclass > policydb.p_classes.nprim) {
-		printk(KERN_ERR "security_compute_av:  unrecognized class %d\n",
-		       tclass);
-		return -EINVAL;
-	}
-	tclass_datum = policydb.class_val_to_struct[tclass - 1];
-
 	/*
 	 * Initialize the access vectors to the default values.
 	 */
@@ -322,6 +316,36 @@ static int context_struct_compute_av(struct context *scontext,
 	avd->seqno = latest_granting;
 
 	/*
+	 * Check for all the invalid cases.
+	 * - tclass 0
+	 * - tclass > policy and > kernel
+	 * - tclass > policy but is a userspace class
+	 * - tclass > policy but we do not allow unknowns
+	 */
+	if (unlikely(!tclass))
+		goto inval_class;
+	if (unlikely(tclass > policydb.p_classes.nprim))
+		if (tclass > kdefs->cts_len || 
+		    !kdefs->class_to_string[tclass - 1] ||
+		    policydb.handle_unknown != ALLOW_UNKNOWN)
+			goto inval_class;
+
+	/* 
+	 * Kernel class and we ALLOW_UNKNOWN so pad the allow decision 
+	 * the pad will be all 1 for unknown classes.
+	 */
+	if (tclass <= kdefs->cts_len && (policydb.handle_unknown == ALLOW_UNKNOWN))
+		avd->allowed = policydb.undefined_perms[tclass - 1];
+
+	/*
+	 * Not in policy. Since decision is completed (all 1 or all 0) return.
+	 */
+	if (unlikely(tclass > policydb.p_classes.nprim))
+		return 0;
+
+	tclass_datum = policydb.class_val_to_struct[tclass - 1];
+
+	/*
 	 * If a specific type enforcement rule was defined for
 	 * this permission check, then use it.
 	 */
@@ -387,6 +411,10 @@ static int context_struct_compute_av(struct context *scontext,
 	}
 
 	return 0;
+
+inval_class:
+	printk(KERN_ERR "security_compute_av:  unrecognized class %d\n", tclass);
+	return -EINVAL;
 }
 
 static int security_validtrans_handle_fail(struct context *ocontext,
@@ -1054,6 +1082,13 @@ static int validate_classes(struct policydb *p)
 	const char *def_class, *def_perm, *pol_class;
 	struct symtab *perms;
 
+	if (p->handle_unknown == ALLOW_UNKNOWN) {
+		u32 num_classes = kdefs->cts_len;
+		p->undefined_perms = kcalloc(num_classes, sizeof(u32), GFP_KERNEL);
+		if (!p->undefined_perms)
+			return -ENOMEM;
+	}
+
 	for (i = 1; i < kdefs->cts_len; i++) {
 		def_class = kdefs->class_to_string[i];
 		if (!def_class)
@@ -1062,6 +1097,10 @@ static int validate_classes(struct policydb *p)
 			printk(KERN_INFO
 			       "security:  class %s not defined in policy\n",
 			       def_class);
+			if (p->handle_unknown == ALLOW_UNKNOWN)
+				p->undefined_perms[i-1] = ~0U;
+			if (p->handle_unknown == REJECT_UNKNOWN)
+				return -EINVAL;
 			continue;
 		}
 		pol_class = p->p_class_val_to_name[i-1];
@@ -1087,12 +1126,16 @@ static int validate_classes(struct policydb *p)
 			printk(KERN_INFO
 			       "security:  permission %s in class %s not defined in policy\n",
 			       def_perm, pol_class);
+			if (p->handle_unknown == ALLOW_UNKNOWN)
+				p->undefined_perms[class_val-1] |= perm_val;
+			else if (p->handle_unknown == REJECT_UNKNOWN)
+				return -EINVAL;
 			continue;
 		}
 		perdatum = hashtab_search(perms->table, def_perm);
 		if (perdatum == NULL) {
 			printk(KERN_ERR
-			       "security:  permission %s in class %s not found in policy\n",
+			       "security:  permission %s in class %s not found in policy, bad policy\n",
 			       def_perm, pol_class);
 			return -EINVAL;
 		}
@@ -1130,12 +1173,16 @@ static int validate_classes(struct policydb *p)
 				printk(KERN_INFO
 				       "security:  permission %s in class %s not defined in policy\n",
 				       def_perm, pol_class);
+				if (p->handle_unknown == ALLOW_UNKNOWN)
+					p->undefined_perms[class_val-1] |= (1 << j);
+				else if (p->handle_unknown == REJECT_UNKNOWN)
+					return -EINVAL;
 				continue;
 			}
 			perdatum = hashtab_search(perms->table, def_perm);
 			if (perdatum == NULL) {
 				printk(KERN_ERR
-				       "security:  permission %s in class %s not found in policy\n",
+				       "security:  permission %s in class %s not found in policy, bad policy\n",
 				       def_perm, pol_class);
 				return -EINVAL;
 			}
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 12 lines · Stephen Smalley
Quoted 9 lines · Eric Paris

Allow policy to select, in much the same way as it selects MLS support, how the kernel should handle access decisions which contain either unknown classes or unknown permissions in unknown classes. The three choices are (from a kernel perspective)

0 - Deny unknown security access. (default)
2 - reject loading policy if it does not contain all definitions 4 - allow unknown security access

Quoted 9 lines

If we leave the default as the current behavior (i.e. deny access if checking an unknown class or permission), then what exactly have we achieved with this patch? The next time we introduce a new permission check in the kernel, anyone who installs that kernel on an existing distribution release will still encounter breakage. It will only start providing benefit for newer distribution releases with policies built to have the non-default setting.

I don't think we should change the default behavior of the policy, this could have some very unintended consequences to people building policies for security oriented systems that may not be aware of the build infrastructure changes necessary to keep the old behavior.

Quoted 9 lines

Other points to ponder:
- Would this have helped with the recent netlabel breakage? I don't think so, as that was introducing a further check for an existing class/perm in the unlabeled case, not a new class/perm.
- Does this help with letting us fix the ioctl hook? Problem there is again that we are more likely to start mapping ioctls to read/write or getattr/setattr instead of the generic "ioctl" fallback rather than introducing new perms.

How many policies give ioctl without giving read/write or getattr/setattr? Is this really an issue?

Quoted 3 lines

- We still can't easily add new perms to common definitions (displaces class-specific ones).

I'm not sure we are going to be able to handle this one until we extend object class/perm discovery to the kernel object managers, its a completely different problem from what this is attempting to solve.

Quoted 6 lines

- Does this help us with secmark at all, e.g. can we eliminate compat_net? Do we want to eliminate compat_net yet? Fedora still seems to have compat_net=1.
- We still can't purge obsolete classes/perms or reorganize the existing ones safely with this change.

Ditto.

Quoted 2 lines

So...is it worth it by itself?

--
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 22 lines · Joshua Brindle
Quoted 12 lines · Stephen Smalley
Quoted 9 lines · Eric Paris

Allow policy to select, in much the same way as it selects MLS support, how the kernel should handle access decisions which contain either unknown classes or unknown permissions in unknown classes. The three choices are (from a kernel perspective)

0 - Deny unknown security access. (default)
2 - reject loading policy if it does not contain all definitions 4 - allow unknown security access

Quoted 9 lines

If we leave the default as the current behavior (i.e. deny access if checking an unknown class or permission), then what exactly have we achieved with this patch? The next time we introduce a new permission check in the kernel, anyone who installs that kernel on an existing distribution release will still encounter breakage. It will only start providing benefit for newer distribution releases with policies built to have the non-default setting.

Quoted 4 lines

I don't think we should change the default behavior of the policy, this could have some very unintended consequences to people building policies for security oriented systems that may not be aware of the build infrastructure changes necessary to keep the old behavior.

One would generally expect such people to be using policies that define all the classes and perms they care about, right? Even more so in the -mls world, since you need them defined in order to define MLS constraints on them.

That is certainly a more specialized and security-aware community than the typical user, so it is fair to impose stronger requirements on them to configure their systems correctly.

Versus a typical kernel developer or user who just wants to run the latest kernel on his existing distro, and not have everything break the next time we add a new permission check.

If we require new policy to be used in order to gain the benefit of the compatibility behavior, then we aren't actually providing compatibility. If we could require policy upgrades in the first place when using a newer kernel, then we wouldn't have the problem that motivated this patch.

So either this patch cannot achieve its ends (regardless of default) or the default is wrong.

Quoted 11 lines
Quoted 9 lines

Other points to ponder:
- Would this have helped with the recent netlabel breakage? I don't think so, as that was introducing a further check for an existing class/perm in the unlabeled case, not a new class/perm.
- Does this help with letting us fix the ioctl hook? Problem there is again that we are more likely to start mapping ioctls to read/write or getattr/setattr instead of the generic "ioctl" fallback rather than introducing new perms.

How many policies give ioctl without giving read/write or getattr/setattr? Is this really an issue?

Today we typically allow ioctl whenever we allow read or write. But remapping ioctl to read/write or getattr/setattr based on _IOC_DIR() may yield cases where we were only giving read perms (read + ioctl) but now we need read + write or read + setattr. I don't if it will be an issue in practice, but it is technically a compatibility issue if it can ever cause a denial that would have been allowed previously.

Quoted 6 lines
Quoted 3 lines

- We still can't easily add new perms to common definitions (displaces class-specific ones).

I'm not sure we are going to be able to handle this one until we extend object class/perm discovery to the kernel object managers, its a completely different problem from what this is attempting to solve.

Yep, just wondering if it would make more sense to tackle that one directly, at which point this one becomes moot, right? Because if the object manager discovers that the class/perm isn't defined by the policy, it can disable the calling of the check altogether (which would also be more efficient than having the security server handle it).

Quoted 10 lines
Quoted 6 lines

- Does this help us with secmark at all, e.g. can we eliminate compat_net? Do we want to eliminate compat_net yet? Fedora still seems to have compat_net=1.
- We still can't purge obsolete classes/perms or reorganize the existing ones safely with this change.

Ditto.

Quoted 2 lines

So...is it worth it by itself?

You didn't answer the question ;)

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.
#4 lore raw
Quoted 10 lines · Stephen Smalley
Quoted 3 lines · Joshua Brindle
Quoted 3 lines

So...is it worth it by itself?

You didn't answer the question ;)

Hrm..

I thought it was at least useful sometimes but actually objclass/perm discoverability that lets the object managers short circuit decisions when object classes aren't defined seems like it has alot more benefits. Really the object manager knows how to deal with a lack of policy knowledge about its object classes better than the security server does.

--
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
In reply to Stephen Smalley
Quoted 16 lines · Stephen Smalley
Quoted 1 line · Joshua Brindle

Stephen Smalley wrote:

One would generally expect such people to be using policies that define all the classes and perms they care about, right? Even more so in the -mls world, since you need them defined in order to define MLS constraints on them.

That is certainly a more specialized and security-aware community than the typical user, so it is fair to impose stronger requirements on them to configure their systems correctly.

Versus a typical kernel developer or user who just wants to run the latest kernel on his existing distro, and not have everything break the next time we add a new permission check.

Quoted 8 lines

If we require new policy to be used in order to gain the benefit of the compatibility behavior, then we aren't actually providing compatibility. If we could require policy upgrades in the first place when using a newer kernel, then we wouldn't have the problem that motivated this patch.

So either this patch cannot achieve its ends (regardless of default) or the default is wrong.

I will ask the question, is there any concern of people with strict security goals grabbing some new kernel with this new feature and shooting themselves in the foot? Are there adequate safeguards at such sites that they would not make this mistake? I'm considering it for RHEL5, will users of RHEL5 get themselves in trouble if we default to allow? Would all such interesting users either use the RHEL5 MLS policy which would I assume default to reject_unknown? Would they use custom policy and most likely default to something they don't want unknowingly?

I also see a big different between "update your policy once and I'll stop breaking your X/DCCP/whatever until policy fixes it" and "every time Eric does some work you need a new policy"

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Other points to ponder:
- Would this have helped with the recent netlabel breakage? I don't think so, as that was introducing a further check for an existing class/perm in the unlabeled case, not a new class/perm.

Maybe instead a versioning scheme? Every security check comes with a 'version.' Every time we add/change a security check we add one to the 'version' for that check. If the policy handed to the kernel has a 'version' less than the value we get from the security hook call coded
in kernel we can just allow it? Maybe that could be a solution to the
issue I am addressing now along with things like this netlabel change? It certainly would have to touch a whole lot of stuff and might be a pain to keep up with. Lets say I move a security hook around in a function, I need to decide if the version need to be bumped on that hook or not. Not impossible, but not pretty. Also probably means a policy version update, which in turn breaks the discussion which we have ongoing above....

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

- Does this help with letting us fix the ioctl hook? Problem there is again that we are more likely to start mapping ioctls to read/write or getattr/setattr instead of the generic "ioctl" fallback rather than introducing new perms.

How many policies give ioctl without giving read/write or getattr/setattr? Is this really an issue?

Quoted 6 lines

Today we typically allow ioctl whenever we allow read or write. But remapping ioctl to read/write or getattr/setattr based on _IOC_DIR() may yield cases where we were only giving read perms (read + ioctl) but now we need read + write or read + setattr. I don't if it will be an issue in practice, but it is technically a compatibility issue if it can ever cause a denial that would have been allowed previously.

versioning like I talk about isn't pretty, but it could solve the problem...

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- We still can't easily add new perms to common definitions (displaces class-specific ones).

next policy bump move (hey when I add my 'version' right?) class-specific perms starting at the last bit and working forward while make common perms start at the front and move back? Guess that's just a hack though and makes validating and stuff a whole lot harder since we couldn't go from 0 to nperms.

Quoted 10 lines
Quoted 4 lines
Quoted 1 line

I'm not sure we are going to be able to handle this one until we extend object class/perm discovery to the kernel object managers, its a completely different problem from what this is attempting to solve.

Yep, just wondering if it would make more sense to tackle that one directly, at which point this one becomes moot, right? Because if the object manager discovers that the class/perm isn't defined by the policy, it can disable the calling of the check altogether (which would also be more efficient than having the security server handle it).

/me is confuzzled who in the kernel do you want to discover that
something isn't defined and to just 'not call' ? How does this something know not to do the new netlabel check?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

- Does this help us with secmark at all, e.g. can we eliminate compat_net? Do we want to eliminate compat_net yet? Fedora still seems to have compat_net=1.

I want compat_net off. 99.9% of people pay a perf penalty on networking and don't use any of it. The only network hooks policy cares about are bind/connect which don't care.

No, as it stand it does not help with secmark, and I don't think it should. Look at it this way, if you change the label on a file the kernel shouldn't realize policy doesn't know you changed the label and handle it special. If you add iptables rules and change the label on a network object you need to update policy. We are going to need some sort of working together somewhere to get secmark rules used by default, but I don't think this is the place.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- We still can't purge obsolete classes/perms or reorganize the existing ones safely with this change.

nope, although when do start allowing this we are going to end up with some sort of kernel/userspace upgrade required at the same time, or at least I assume so.....

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Ditto.

Quoted 1 line

So...is it worth it by itself?

obviously I thought so, but my opinion doesn't count for much on this one, does it?

--
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 4 lines · Eric Paris

Maybe instead a versioning scheme? Every security check comes with a 'version.' Every time we add/change a security check we add one to the 'version' for that check. If the policy handed to the kernel has a 'version' less than the value we get from the security hook call coded

Quoted 8 lines

in kernel we can just allow it? Maybe that could be a solution to the
issue I am addressing now along with things like this netlabel change? It certainly would have to touch a whole lot of stuff and might be a pain to keep up with. Lets say I move a security hook around in a function, I need to decide if the version need to be bumped on that hook or not. Not impossible, but not pretty. Also probably means a policy version update, which in turn breaks the discussion which we have ongoing above....

While I'm not an expert on the policy aspects of this discussion and how the kernel and userspace objects managers interact I think at some point we are going to need something like what Eric proposes above. With the requirement that new kernels must not regress when using old policy we are going to run into issues as we move forward and add new permission checks. While I don't think we've seen it yet, it is reasonable to think that this problem will expand into userspace as we develop more and more userspace object managers such a X, CUPS, Postgres, etc.

I know the changes aren't likely to be pretty, I'm kinda cringing at the thought actually, but I think it's a necessary evil for the long term survivability of SELinux. At least that's what I took away from Eric and Stephen's comments on this thread and I tend to agree.

Signature · 7 lines
paul moore
linux security @ hp

--
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.
#7 lore raw
Quoted 16 lines · Paul Moore
Quoted 4 lines · Eric Paris

Maybe instead a versioning scheme? Every security check comes with a 'version.' Every time we add/change a security check we add one to the 'version' for that check. If the policy handed to the kernel has a 'version' less than the value we get from the security hook call coded

Quoted 9 lines

in kernel we can just allow it? Maybe that could be a solution to the
issue I am addressing now along with things like this netlabel change? It certainly would have to touch a whole lot of stuff and might be a pain to keep up with. Lets say I move a security hook around in a function, I need to decide if the version need to be bumped on that hook or not. Not impossible, but not pretty. Also probably means a policy version update, which in turn breaks the discussion which we have ongoing above....

Quoted 4 lines

While I'm not an expert on the policy aspects of this discussion and how the kernel and userspace objects managers interact I think at some point we are going to need something like what Eric proposes above. With the requirement that new kernels must not regress when using old policy we are going to run into issues as we move forward and add new permission checks. While I don't think we've seen it yet, it is reasonable to think that this problem will expand into userspace as we develop more and more userspace object managers such a X, CUPS, Postgres, etc.

I know the changes aren't likely to be pretty, I'm kinda cringing at the thought actually, but I think it's a necessary evil for the long term survivability of SELinux. At least that's what I took away from Eric and Stephen's comments on this thread and I tend to agree.

I'd have to give a pretty hard NAK (for what it would be worth) to the versioning system, it simply doesn't scale; in the past we've used policy versions to decide how some permission checks work (see fine grained netlink discussions) and it was fairly non-ideal. I have to go back to the 'the object manager should decide how to deal with unknown permissions' argument. The object manager knows how its objects are used, and how the security system affects those objects, it is in the best position to make those decisions, the security server can only make a rough estimation on what the object manager and user want to do, which may or may not be accurate.

Here is an example, granted kernexec uses the reboot capability but suppose we wanted to make it a separate permission, I'm fairly certain that we'd want to always deny it if the policy didn't know about it, whereas SE-X is completely unusable without policy and still has OS level policy determining who can talk to the X daemon itself, SE-X would have to make a determination of whether to run at all or run with course grained permissions, chances are most people would want the latter. This means we'd actually have environments where some object managers deny by default and others allow (or even short circuit access attempts altogether). This is ideal from a scalability and dynamic system perspective and seems by far to be the best solution.

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

#12 lore raw
In reply to Eric Paris
Quoted 26 lines · Eric Paris
Quoted 16 lines · Stephen Smalley
Quoted 1 line · Joshua Brindle

Stephen Smalley wrote:

One would generally expect such people to be using policies that define all the classes and perms they care about, right? Even more so in the -mls world, since you need them defined in order to define MLS constraints on them.

That is certainly a more specialized and security-aware community than the typical user, so it is fair to impose stronger requirements on them to configure their systems correctly.

Versus a typical kernel developer or user who just wants to run the latest kernel on his existing distro, and not have everything break the next time we add a new permission check.

Quoted 8 lines

If we require new policy to be used in order to gain the benefit of the compatibility behavior, then we aren't actually providing compatibility. If we could require policy upgrades in the first place when using a newer kernel, then we wouldn't have the problem that motivated this patch.

So either this patch cannot achieve its ends (regardless of default) or the default is wrong.

Quoted 8 lines

I will ask the question, is there any concern of people with strict security goals grabbing some new kernel with this new feature and shooting themselves in the foot? Are there adequate safeguards at such sites that they would not make this mistake? I'm considering it for RHEL5, will users of RHEL5 get themselves in trouble if we default to allow? Would all such interesting users either use the RHEL5 MLS policy which would I assume default to reject_unknown? Would they use custom policy and most likely default to something they don't want unknowingly?

How does this feature benefit a RHEL (or other enterprise distro) user, whose kernel and policy are vendor-supplied (else warranty and certification invalidated) and should be consistent already in their set of permissions?

The point is for a new permission check in mainline to not break Fedora (or other community distro).

Just updating to a new kernel introduces a risk that you've got an uncontrolled operation or code path altogether, as security hooks seem often to be an afterthought. Or if it is an already hooked operation/code path and you've added a new check to it as a refinement, then all you "lose" is that refinement, not any security properties you had in the prior kernel.

Don't get me wrong, I prefer the secure default - I just wondered whether it makes the patch fail to meet the original goal.

Quoted 3 lines

I also see a big different between "update your policy once and I'll stop breaking your X/DCCP/whatever until policy fixes it" and "every time Eric does some work you need a new policy"

Fair enough - it offers potential benefit once a policy with always_allow set gets sufficiently widely deployed. But if akpm is regression testing on a Fedora release that is no longer getting updates in a VM, policy update won't ever hit it and the new kernel will still break it.

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Other points to ponder:
- Would this have helped with the recent netlabel breakage? I don't think so, as that was introducing a further check for an existing class/perm in the unlabeled case, not a new class/perm.

Quoted 12 lines

Maybe instead a versioning scheme? Every security check comes with a 'version.' Every time we add/change a security check we add one to the 'version' for that check. If the policy handed to the kernel has a 'version' less than the value we get from the security hook call coded
in kernel we can just allow it? Maybe that could be a solution to the
issue I am addressing now along with things like this netlabel change? It certainly would have to touch a whole lot of stuff and might be a pain to keep up with. Lets say I move a security hook around in a function, I need to decide if the version need to be bumped on that hook or not. Not impossible, but not pretty. Also probably means a policy version update, which in turn breaks the discussion which we have ongoing above....

Possibly, and would be more useful for things like secmark where we are not just adding permission checks but instead replacing one set of legacy checks with a newer check. Likewise for the desired ioctl checking. Or alternatively, a per-check index with a bitmap in policy to select which ones are required by the policy.

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- We still can't easily add new perms to common definitions (displaces class-specific ones).

next policy bump move (hey when I add my 'version' right?) class-specific perms starting at the last bit and working forward while make common perms start at the front and move back? Guess that's just a hack though and makes validating and stuff a whole lot harder since we couldn't go from 0 to nperms.

Object class and permission discovery solves it more cleanly. We have it now for userspace, just need it in kernel.

Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Quoted 1 line

I'm not sure we are going to be able to handle this one until we extend object class/perm discovery to the kernel object managers, its a completely different problem from what this is attempting to solve.

Yep, just wondering if it would make more sense to tackle that one directly, at which point this one becomes moot, right? Because if the object manager discovers that the class/perm isn't defined by the policy, it can disable the calling of the check altogether (which would also be more efficient than having the security server handle it).

Quoted 3 lines

/me is confuzzled who in the kernel do you want to discover that
something isn't defined and to just 'not call' ? How does this something know not to do the new netlabel check?

The SELinux module and hook functions. It would do something equivalent to the mapping and discovery code in libselinux, except that upon discovering that a class or permission isn't defined in the policy, we want to mark the check as disabled rather than treat it as an error.

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

- Does this help us with secmark at all, e.g. can we eliminate compat_net? Do we want to eliminate compat_net yet? Fedora still seems to have compat_net=1.

I want compat_net off. 99.9% of people pay a perf penalty on networking and don't use any of it. The only network hooks policy cares about are bind/connect which don't care.

Quoted 7 lines

No, as it stand it does not help with secmark, and I don't think it should. Look at it this way, if you change the label on a file the kernel shouldn't realize policy doesn't know you changed the label and handle it special. If you add iptables rules and change the label on a network object you need to update policy. We are going to need some sort of working together somewhere to get secmark rules used by default, but I don't think this is the place.

By "help with secmark", I mean eliminate the need for compat_net=1 altogether. It makes it hard to know what the system is enforcing (can't tell from policy, have to go look at /selinux/compat_net)

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Ditto.

Quoted 1 line

So...is it worth it by itself?

obviously I thought so, but my opinion doesn't count for much on this one, does it?

And it may yet be. But better to find out now before it gets merged...

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.
#8 lore raw
In reply to Joshua Brindle
Quoted 32 lines · Joshua Brindle
Quoted 25 lines · Paul Moore
Quoted 4 lines · Eric Paris

Maybe instead a versioning scheme? Every security check comes with a 'version.' Every time we add/change a security check we add one to the 'version' for that check. If the policy handed to the kernel has a 'version' less than the value we get from the security hook call coded

Quoted 9 lines

in kernel we can just allow it? Maybe that could be a solution to the
issue I am addressing now along with things like this netlabel change? It certainly would have to touch a whole lot of stuff and might be a pain to keep up with. Lets say I move a security hook around in a function, I need to decide if the version need to be bumped on that hook or not. Not impossible, but not pretty. Also probably means a policy version update, which in turn breaks the discussion which we have ongoing above....

While I'm not an expert on the policy aspects of this discussion and how the kernel and userspace objects managers interact I think at some point we are going to need something like what Eric proposes above. With the requirement that new kernels must not regress when using old policy we are going to run into issues as we move forward and add new permission checks. While I don't think we've seen it yet, it is reasonable to think that this problem will expand into userspace as we develop more and more userspace object managers such a X, CUPS, Postgres, etc.

Quoted 5 lines

I know the changes aren't likely to be pretty, I'm kinda cringing at the thought actually, but I think it's a necessary evil for the long term survivability of SELinux. At least that's what I took away from Eric and Stephen's comments on this thread and I tend to agree.

Quoted 4 lines

I'd have to give a pretty hard NAK (for what it would be worth) to the versioning system, it simply doesn't scale; in the past we've used policy versions to decide how some permission checks work (see fine grained netlink discussions) and it was fairly non-ideal.

Well, that was "policy format version" vs. a separate version that identifies the set of security checks known to / expected by the policy. Or, as I said in my other email, a bitmap of check indices, where each check (not permission, but individual check) has its own unique index assigned when it is first introduced and never recycled.

Quoted 7 lines

I have to go
back to the 'the object manager should decide how to deal with unknown permissions' argument. The object manager knows how its objects are used, and how the security system affects those objects, it is in the best position to make those decisions, the security server can only make a rough estimation on what the object manager and user want to do, which may or may not be accurate.

It's actually a policy issue - what set of checks are required in order to meet a given policy.

Quoted 3 lines

Here is an example, granted kernexec uses the reboot capability but suppose we wanted to make it a separate permission, I'm fairly certain that we'd want to always deny it if the policy didn't know about it,

Actually, I'm sure Fedora would want to allow it by default if it wasn't yet defined.

Quoted 4 lines

whereas SE-X is completely unusable without policy and still has OS level policy determining who can talk to the X daemon itself, SE-X would have to make a determination of whether to run at all or run with course grained permissions, chances are most people would want the latter.

That's a policy issue ;)

Quoted 5 lines

This
means we'd actually have environments where some object managers deny by default and others allow (or even short circuit access attempts altogether). This is ideal from a scalability and dynamic system perspective and seems by far to be the best solution.

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.
#10 lore raw
In reply to Joshua Brindle
Quoted 16 lines · Joshua Brindle
Quoted 15 lines · Paul Moore
Quoted 13 lines · Eric Paris

Maybe instead a versioning scheme? Every security check comes with a 'version.' Every time we add/change a security check we add one to the 'version' for that check. If the policy handed to the kernel has a 'version' less than the value we get from the security hook call coded
in kernel we can just allow it? Maybe that could be a solution to the
issue I am addressing now along with things like this netlabel change? It certainly would have to touch a whole lot of stuff and might be a pain to keep up with. Lets say I move a security hook around in a function, I need to decide if the version need to be bumped on that hook or not. Not impossible, but not pretty. Also probably means a policy version update, which in turn breaks the discussion which we have ongoing above....

Quoted 6 lines
Quoted 4 lines

While I'm not an expert on the policy aspects of this discussion and how the kernel and userspace objects managers interact I think at some point we are going to need something like what Eric proposes above. With the requirement that new kernels must not regress when using old policy we are going to run into issues as we move forward and add new permission checks. While I don't think we've seen it yet, it is reasonable to think that this problem will expand into userspace as we develop more and more userspace object managers such a X, CUPS, Postgres, etc.

I know the changes aren't likely to be pretty, I'm kinda cringing at the thought actually, but I think it's a necessary evil for the long term survivability of SELinux. At least that's what I took away from Eric and Stephen's comments on this thread and I tend to agree.

I'd have to give a pretty hard NAK (for what it would be worth) to the versioning system, it simply doesn't scale; in the past we've used policy versions to decide how some permission checks work (see fine grained netlink discussions) and it was fairly non-ideal. I have to go back to the 'the object manager should decide how to deal with unknown permissions' argument. The object manager knows how its objects are used, and how the security system affects those objects, it is in the best position to make those decisions, the security server can only make a rough estimation on what the object manager and user want to do, which may or may not be accurate.

I would suggest exporting the allow/deny bit to userspace in the same manner as the enforcing mode. The userspace AVC could then honor the behavior unless the object manager overrides it (I've been meaning to allow the object manager to override the enforcing mode so you could for example have a permissive X server on an otherwise enforcing system).

The selinux_set_mapping() call could be modified to return details on which specific classes and permissions were unknown. Perhaps this could be done through a callback which would also be called on policy reload, given that class/perm values could appear or disappear at these times.

Quoted 9 lines

Here is an example, granted kernexec uses the reboot capability but suppose we wanted to make it a separate permission, I'm fairly certain that we'd want to always deny it if the policy didn't know about it, whereas SE-X is completely unusable without policy and still has OS level policy determining who can talk to the X daemon itself, SE-X would have to make a determination of whether to run at all or run with course grained permissions, chances are most people would want the latter. This means we'd actually have environments where some object managers deny by default and others allow (or even short circuit access attempts altogether). This is ideal from a scalability and dynamic system perspective and seems by far to be the best solution.

--
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 · 7 lines
Eamon Walsh <[email protected]>
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.
#9 lore raw
In reply to Stephen Smalley
Quoted 26 lines · Stephen Smalley
Quoted 24 lines · Joshua Brindle
Quoted 22 lines · Paul Moore
Quoted 4 lines · Eric Paris

Maybe instead a versioning scheme? Every security check comes with a 'version.' Every time we add/change a security check we add one to the 'version' for that check. If the policy handed to the kernel has a 'version' less than the value we get from the security hook call coded

Quoted 10 lines

in kernel we can just allow it? Maybe that could be a solution to the
issue I am addressing now along with things like this netlabel change? It certainly would have to touch a whole lot of stuff and might be a pain to keep up with. Lets say I move a security hook around in a function, I need to decide if the version need to be bumped on that hook or not. Not impossible, but not pretty. Also probably means a policy version update, which in turn breaks the discussion which we have ongoing above....

While I'm not an expert on the policy aspects of this discussion and how the kernel and userspace objects managers interact I think at some point we are going to need something like what Eric proposes above. With the requirement that new kernels must not regress when using old policy we are going to run into issues as we move forward and add new permission checks. While I don't think we've seen it yet, it is reasonable to think that this problem will expand into userspace as we develop more and more userspace object managers such a X, CUPS, Postgres, etc.

I know the changes aren't likely to be pretty, I'm kinda cringing at the thought actually, but I think it's a necessary evil for the long term survivability of SELinux. At least that's what I took away from Eric and Stephen's comments on this thread and I tend to agree.

Quoted 10 lines
Quoted 2 lines

I'd have to give a pretty hard NAK (for what it would be worth) to the versioning system, it simply doesn't scale; in the past we've used policy versions to decide how some permission checks work (see fine grained netlink discussions) and it was fairly non-ideal.

Well, that was "policy format version" vs. a separate version that identifies the set of security checks known to / expected by the policy. Or, as I said in my other email, a bitmap of check indices, where each check (not permission, but individual check) has its own unique index assigned when it is first introduced and never recycled.

I was just giving an example on my the policy versioning idea doesn't scale, I know it would be something separate from policy format version but that doesn't necessarily make it better.

Quoted 8 lines
Quoted 3 lines

I have to go
back to the 'the object manager should decide how to deal with unknown permissions' argument. The object manager knows how its objects are used, and how the security system affects those objects, it is in the best position to make those decisions, the security server can only make a rough estimation on what the object manager and user want to do, which may or may not be accurate.

It's actually a policy issue - what set of checks are required in order to meet a given policy.

Yes, I was agreeing with that before but when it comes down to it the object manager is always responsible for enforcing said policy, and it can always make the decision not to. If the object manager decides a lack of security policy means that something should be denied wouldn't it know better than a security server with no concept of the object classes?

Quoted 7 lines
Quoted 2 lines

Here is an example, granted kernexec uses the reboot capability but suppose we wanted to make it a separate permission, I'm fairly certain that we'd want to always deny it if the policy didn't know about it,

Actually, I'm sure Fedora would want to allow it by default if it wasn't yet defined.

I'd certainly hope not but that probably isn't the issue.

Quoted 6 lines
Quoted 2 lines

whereas SE-X is completely unusable without policy and still has OS level policy determining who can talk to the X daemon itself, SE-X would have to make a determination of whether to run at all or run with course grained permissions, chances are most people would want the latter.

That's a policy issue ;)

Its also an object manager issue, as explained above.

Quoted 5 lines
Quoted 3 lines

This
means we'd actually have environments where some object managers deny by default and others allow (or even short circuit access attempts altogether). This is ideal from a scalability and dynamic system perspective and seems by far to be the best solution.

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

#11 lore raw
In reply to Eamon Walsh
Quoted 17 lines · Eamon Walsh
Quoted 16 lines · Joshua Brindle
Quoted 15 lines · Paul Moore
Quoted 13 lines · Eric Paris

Maybe instead a versioning scheme? Every security check comes with a 'version.' Every time we add/change a security check we add one to the 'version' for that check. If the policy handed to the kernel has a 'version' less than the value we get from the security hook call coded
in kernel we can just allow it? Maybe that could be a solution to the
issue I am addressing now along with things like this netlabel change? It certainly would have to touch a whole lot of stuff and might be a pain to keep up with. Lets say I move a security hook around in a function, I need to decide if the version need to be bumped on that hook or not. Not impossible, but not pretty. Also probably means a policy version update, which in turn breaks the discussion which we have ongoing above....

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

While I'm not an expert on the policy aspects of this discussion and how the kernel and userspace objects managers interact I think at some point we are going to need something like what Eric proposes above. With the requirement that new kernels must not regress when using old policy we are going to run into issues as we move forward and add new permission checks. While I don't think we've seen it yet, it is reasonable to think that this problem will expand into userspace as we develop more and more userspace object managers such a X, CUPS, Postgres, etc.

I know the changes aren't likely to be pretty, I'm kinda cringing at the thought actually, but I think it's a necessary evil for the long term survivability of SELinux. At least that's what I took away from Eric and Stephen's comments on this thread and I tend to agree.

I'd have to give a pretty hard NAK (for what it would be worth) to the versioning system, it simply doesn't scale; in the past we've used policy versions to decide how some permission checks work (see fine grained netlink discussions) and it was fairly non-ideal. I have to go back to the 'the object manager should decide how to deal with unknown permissions' argument. The object manager knows how its objects are used, and how the security system affects those objects, it is in the best position to make those decisions, the security server can only make a rough estimation on what the object manager and user want to do, which may or may not be accurate.

I would suggest exporting the allow/deny bit to userspace in the same manner as the enforcing mode. The userspace AVC could then honor the behavior unless the object manager overrides it (I've been meaning to allow the object manager to override the enforcing mode so you could for example have a permissive X server on an otherwise enforcing system).

If we could get this per domain, this would be a huge step forward. Customers looking to ship policy worry about putting out a policy that could break apps, before it got enough testing. They want to put out apolicy for an application and run it for a few weeks on many different realworld environments and gather the avc's to make the poicy foolproof.

Quoted 14 lines

The selinux_set_mapping() call could be modified to return details on which specific classes and permissions were unknown. Perhaps this could be done through a callback which would also be called on policy reload, given that class/perm values could appear or disappear at these times.

Quoted 9 lines

Here is an example, granted kernexec uses the reboot capability but suppose we wanted to make it a separate permission, I'm fairly certain that we'd want to always deny it if the policy didn't know about it, whereas SE-X is completely unusable without policy and still has OS level policy determining who can talk to the X daemon itself, SE-X would have to make a determination of whether to run at all or run with course grained permissions, chances are most people would want the latter. This means we'd actually have environments where some object managers deny by default and others allow (or even short circuit access attempts altogether). This is ideal from a scalability and dynamic system perspective and seems by far to be the best solution.

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

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

#13 lore raw
In reply to Eric Paris
Quoted 10 lines · Eric Paris

Allow policy to select, in much the same way as it selects MLS support, how the kernel should handle access decisions which contain either unknown classes or unknown permissions in unknown classes. The three choices are (from a kernel perspective)

0 - Deny unknown security access. (default)
2 - reject loading policy if it does not contain all definitions 4 - allow unknown security access

Anyone else want to speak up for or against this patch?

Quoted 207 lines

---

Biggest change between this patch and the last on list is that I changed handle_unknown to not be needlessly bit shifted. I also dropped a check in context_struct_computeav which was redundant.

 security/selinux/ss/policydb.c |    8 +++++
 security/selinux/ss/policydb.h |   10 ++++++
 security/selinux/ss/services.c |   65 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 74 insertions(+), 9 deletions(-)
security/selinux/ss/policydb.c +8 -0
index f05f97a..588dcfd 100644
@@ -677,6 +677,8 @@ void policydb_destroy(struct policydb *p)
 	}
 	kfree(p->type_attr_map);
 
+	kfree(p->undefined_perms);
+
 	return;
 }
 
@@ -1530,6 +1532,12 @@ int policydb_read(struct policydb *p, void *fp)
 			goto bad;
 		}
 	}
+	p->handle_unknown = le32_to_cpu(buf[1]) & POLICYDB_CONFIG_UNKNOWN_MASK;
+
+	if (p->handle_unknown > ALLOW_UNKNOWN) {
+		printk(KERN_ERR "selinux: invalid options for handle_unknown\n");
+		goto bad;
+	}
 
 	info = policydb_lookup_compat(p->policyvers);
 	if (!info) {
security/selinux/ss/policydb.h +10 -0
index 8319d5f..f84e856 100644
@@ -242,6 +242,9 @@ struct policydb {
 	struct ebitmap *type_attr_map;
 
 	unsigned int policyvers;
+
+	int handle_unknown;
+	u32 *undefined_perms;
 };
 
 extern void policydb_destroy(struct policydb *p);
@@ -253,6 +256,13 @@ extern int policydb_read(struct policydb *p, void *fp);
 
 #define POLICYDB_CONFIG_MLS    1
 
+/* the config flags related to unknown classes/perms are bits 2 and 3 */
+#define DENY_UNKNOWN	0x00000000
+#define REJECT_UNKNOWN	0x00000002
+#define ALLOW_UNKNOWN	0x00000004
+
+#define POLICYDB_CONFIG_UNKNOWN_MASK 	(DENY_UNKNOWN | REJECT_UNKNOWN | ALLOW_UNKNOWN)
+
 #define OBJECT_R "object_r"
 #define OBJECT_R_VAL 1
 
security/selinux/ss/services.c +56 -10
index 0ae032f..d3f3a43 100644
@@ -292,6 +292,7 @@ static int context_struct_compute_av(struct context *scontext,
 	struct class_datum *tclass_datum;
 	struct ebitmap *sattr, *tattr;
 	struct ebitmap_node *snode, *tnode;
+	const struct selinux_class_perm *kdefs = &selinux_class_perm;
 	unsigned int i, j;
 
 	/*
@@ -305,13 +306,6 @@ static int context_struct_compute_av(struct context *scontext,
 		    tclass <= SECCLASS_NETLINK_DNRT_SOCKET)
 			tclass = SECCLASS_NETLINK_SOCKET;
 
-	if (!tclass || tclass > policydb.p_classes.nprim) {
-		printk(KERN_ERR "security_compute_av:  unrecognized class %d\n",
-		       tclass);
-		return -EINVAL;
-	}
-	tclass_datum = policydb.class_val_to_struct[tclass - 1];
-
 	/*
 	 * Initialize the access vectors to the default values.
 	 */
@@ -322,6 +316,36 @@ static int context_struct_compute_av(struct context *scontext,
 	avd->seqno = latest_granting;
 
 	/*
+	 * Check for all the invalid cases.
+	 * - tclass 0
+	 * - tclass > policy and > kernel
+	 * - tclass > policy but is a userspace class
+	 * - tclass > policy but we do not allow unknowns
+	 */
+	if (unlikely(!tclass))
+		goto inval_class;
+	if (unlikely(tclass > policydb.p_classes.nprim))
+		if (tclass > kdefs->cts_len || 
+		    !kdefs->class_to_string[tclass - 1] ||
+		    policydb.handle_unknown != ALLOW_UNKNOWN)
+			goto inval_class;
+
+	/* 
+	 * Kernel class and we ALLOW_UNKNOWN so pad the allow decision 
+	 * the pad will be all 1 for unknown classes.
+	 */
+	if (tclass <= kdefs->cts_len && (policydb.handle_unknown == ALLOW_UNKNOWN))
+		avd->allowed = policydb.undefined_perms[tclass - 1];
+
+	/*
+	 * Not in policy. Since decision is completed (all 1 or all 0) return.
+	 */
+	if (unlikely(tclass > policydb.p_classes.nprim))
+		return 0;
+
+	tclass_datum = policydb.class_val_to_struct[tclass - 1];
+
+	/*
 	 * If a specific type enforcement rule was defined for
 	 * this permission check, then use it.
 	 */
@@ -387,6 +411,10 @@ static int context_struct_compute_av(struct context *scontext,
 	}
 
 	return 0;
+
+inval_class:
+	printk(KERN_ERR "security_compute_av:  unrecognized class %d\n", tclass);
+	return -EINVAL;
 }
 
 static int security_validtrans_handle_fail(struct context *ocontext,
@@ -1054,6 +1082,13 @@ static int validate_classes(struct policydb *p)
 	const char *def_class, *def_perm, *pol_class;
 	struct symtab *perms;
 
+	if (p->handle_unknown == ALLOW_UNKNOWN) {
+		u32 num_classes = kdefs->cts_len;
+		p->undefined_perms = kcalloc(num_classes, sizeof(u32), GFP_KERNEL);
+		if (!p->undefined_perms)
+			return -ENOMEM;
+	}
+
 	for (i = 1; i < kdefs->cts_len; i++) {
 		def_class = kdefs->class_to_string[i];
 		if (!def_class)
@@ -1062,6 +1097,10 @@ static int validate_classes(struct policydb *p)
 			printk(KERN_INFO
 			       "security:  class %s not defined in policy\n",
 			       def_class);
+			if (p->handle_unknown == ALLOW_UNKNOWN)
+				p->undefined_perms[i-1] = ~0U;
+			if (p->handle_unknown == REJECT_UNKNOWN)
+				return -EINVAL;
 			continue;
 		}
 		pol_class = p->p_class_val_to_name[i-1];
@@ -1087,12 +1126,16 @@ static int validate_classes(struct policydb *p)
 			printk(KERN_INFO
 			       "security:  permission %s in class %s not defined in policy\n",
 			       def_perm, pol_class);
+			if (p->handle_unknown == ALLOW_UNKNOWN)
+				p->undefined_perms[class_val-1] |= perm_val;
+			else if (p->handle_unknown == REJECT_UNKNOWN)
+				return -EINVAL;
 			continue;
 		}
 		perdatum = hashtab_search(perms->table, def_perm);
 		if (perdatum == NULL) {
 			printk(KERN_ERR
-			       "security:  permission %s in class %s not found in policy\n",
+			       "security:  permission %s in class %s not found in policy, bad policy\n",
 			       def_perm, pol_class);
 			return -EINVAL;
 		}
@@ -1130,12 +1173,16 @@ static int validate_classes(struct policydb *p)
 				printk(KERN_INFO
 				       "security:  permission %s in class %s not defined in policy\n",
 				       def_perm, pol_class);
+				if (p->handle_unknown == ALLOW_UNKNOWN)
+					p->undefined_perms[class_val-1] |= (1 << j);
+				else if (p->handle_unknown == REJECT_UNKNOWN)
+					return -EINVAL;
 				continue;
 			}
 			perdatum = hashtab_search(perms->table, def_perm);
 			if (perdatum == NULL) {
 				printk(KERN_ERR
-				       "security:  permission %s in class %s not found in policy\n",
+				       "security:  permission %s in class %s not found in policy, bad policy\n",
 				       def_perm, pol_class);
 				return -EINVAL;
 			}
 
 
 
--

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.
#14 lore raw
In reply to Eric Paris
Quoted 10 lines · Eric Paris

Allow policy to select, in much the same way as it selects MLS support, how the kernel should handle access decisions which contain either unknown classes or unknown permissions in unknown classes. The three choices are (from a kernel perspective)

0 - Deny unknown security access. (default)
2 - reject loading policy if it does not contain all definitions 4 - allow unknown security access

It would be nice to have SELinux emit a KERN_INFO message about which behavior was selected when policy is loaded, so that you can easily tell.

Quoted 207 lines

---

Biggest change between this patch and the last on list is that I changed handle_unknown to not be needlessly bit shifted. I also dropped a check in context_struct_computeav which was redundant.

 security/selinux/ss/policydb.c |    8 +++++
 security/selinux/ss/policydb.h |   10 ++++++
 security/selinux/ss/services.c |   65 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 74 insertions(+), 9 deletions(-)
security/selinux/ss/policydb.c +8 -0
index f05f97a..588dcfd 100644
@@ -677,6 +677,8 @@ void policydb_destroy(struct policydb *p)
 	}
 	kfree(p->type_attr_map);
 
+	kfree(p->undefined_perms);
+
 	return;
 }
 
@@ -1530,6 +1532,12 @@ int policydb_read(struct policydb *p, void *fp)
 			goto bad;
 		}
 	}
+	p->handle_unknown = le32_to_cpu(buf[1]) & POLICYDB_CONFIG_UNKNOWN_MASK;
+
+	if (p->handle_unknown > ALLOW_UNKNOWN) {
+		printk(KERN_ERR "selinux: invalid options for handle_unknown\n");
+		goto bad;
+	}
 
 	info = policydb_lookup_compat(p->policyvers);
 	if (!info) {
security/selinux/ss/policydb.h +10 -0
index 8319d5f..f84e856 100644
@@ -242,6 +242,9 @@ struct policydb {
 	struct ebitmap *type_attr_map;
 
 	unsigned int policyvers;
+
+	int handle_unknown;
+	u32 *undefined_perms;
 };
 
 extern void policydb_destroy(struct policydb *p);
@@ -253,6 +256,13 @@ extern int policydb_read(struct policydb *p, void *fp);
 
 #define POLICYDB_CONFIG_MLS    1
 
+/* the config flags related to unknown classes/perms are bits 2 and 3 */
+#define DENY_UNKNOWN	0x00000000
+#define REJECT_UNKNOWN	0x00000002
+#define ALLOW_UNKNOWN	0x00000004
+
+#define POLICYDB_CONFIG_UNKNOWN_MASK 	(DENY_UNKNOWN | REJECT_UNKNOWN | ALLOW_UNKNOWN)
+
 #define OBJECT_R "object_r"
 #define OBJECT_R_VAL 1
 
security/selinux/ss/services.c +56 -10
index 0ae032f..d3f3a43 100644
@@ -292,6 +292,7 @@ static int context_struct_compute_av(struct context *scontext,
 	struct class_datum *tclass_datum;
 	struct ebitmap *sattr, *tattr;
 	struct ebitmap_node *snode, *tnode;
+	const struct selinux_class_perm *kdefs = &selinux_class_perm;
 	unsigned int i, j;
 
 	/*
@@ -305,13 +306,6 @@ static int context_struct_compute_av(struct context *scontext,
 		    tclass <= SECCLASS_NETLINK_DNRT_SOCKET)
 			tclass = SECCLASS_NETLINK_SOCKET;
 
-	if (!tclass || tclass > policydb.p_classes.nprim) {
-		printk(KERN_ERR "security_compute_av:  unrecognized class %d\n",
-		       tclass);
-		return -EINVAL;
-	}
-	tclass_datum = policydb.class_val_to_struct[tclass - 1];
-
 	/*
 	 * Initialize the access vectors to the default values.
 	 */
@@ -322,6 +316,36 @@ static int context_struct_compute_av(struct context *scontext,
 	avd->seqno = latest_granting;
 
 	/*
+	 * Check for all the invalid cases.
+	 * - tclass 0
+	 * - tclass > policy and > kernel
+	 * - tclass > policy but is a userspace class
+	 * - tclass > policy but we do not allow unknowns
+	 */
+	if (unlikely(!tclass))
+		goto inval_class;
+	if (unlikely(tclass > policydb.p_classes.nprim))
+		if (tclass > kdefs->cts_len || 
+		    !kdefs->class_to_string[tclass - 1] ||
+		    policydb.handle_unknown != ALLOW_UNKNOWN)
+			goto inval_class;
+
+	/* 
+	 * Kernel class and we ALLOW_UNKNOWN so pad the allow decision 
+	 * the pad will be all 1 for unknown classes.
+	 */
+	if (tclass <= kdefs->cts_len && (policydb.handle_unknown == ALLOW_UNKNOWN))
+		avd->allowed = policydb.undefined_perms[tclass - 1];
+
+	/*
+	 * Not in policy. Since decision is completed (all 1 or all 0) return.
+	 */
+	if (unlikely(tclass > policydb.p_classes.nprim))
+		return 0;
+
+	tclass_datum = policydb.class_val_to_struct[tclass - 1];
+
+	/*
 	 * If a specific type enforcement rule was defined for
 	 * this permission check, then use it.
 	 */
@@ -387,6 +411,10 @@ static int context_struct_compute_av(struct context *scontext,
 	}
 
 	return 0;
+
+inval_class:
+	printk(KERN_ERR "security_compute_av:  unrecognized class %d\n", tclass);
+	return -EINVAL;
 }
 
 static int security_validtrans_handle_fail(struct context *ocontext,
@@ -1054,6 +1082,13 @@ static int validate_classes(struct policydb *p)
 	const char *def_class, *def_perm, *pol_class;
 	struct symtab *perms;
 
+	if (p->handle_unknown == ALLOW_UNKNOWN) {
+		u32 num_classes = kdefs->cts_len;
+		p->undefined_perms = kcalloc(num_classes, sizeof(u32), GFP_KERNEL);
+		if (!p->undefined_perms)
+			return -ENOMEM;
+	}
+
 	for (i = 1; i < kdefs->cts_len; i++) {
 		def_class = kdefs->class_to_string[i];
 		if (!def_class)
@@ -1062,6 +1097,10 @@ static int validate_classes(struct policydb *p)
 			printk(KERN_INFO
 			       "security:  class %s not defined in policy\n",
 			       def_class);
+			if (p->handle_unknown == ALLOW_UNKNOWN)
+				p->undefined_perms[i-1] = ~0U;
+			if (p->handle_unknown == REJECT_UNKNOWN)
+				return -EINVAL;
 			continue;
 		}
 		pol_class = p->p_class_val_to_name[i-1];
@@ -1087,12 +1126,16 @@ static int validate_classes(struct policydb *p)
 			printk(KERN_INFO
 			       "security:  permission %s in class %s not defined in policy\n",
 			       def_perm, pol_class);
+			if (p->handle_unknown == ALLOW_UNKNOWN)
+				p->undefined_perms[class_val-1] |= perm_val;
+			else if (p->handle_unknown == REJECT_UNKNOWN)
+				return -EINVAL;
 			continue;
 		}
 		perdatum = hashtab_search(perms->table, def_perm);
 		if (perdatum == NULL) {
 			printk(KERN_ERR
-			       "security:  permission %s in class %s not found in policy\n",
+			       "security:  permission %s in class %s not found in policy, bad policy\n",
 			       def_perm, pol_class);
 			return -EINVAL;
 		}
@@ -1130,12 +1173,16 @@ static int validate_classes(struct policydb *p)
 				printk(KERN_INFO
 				       "security:  permission %s in class %s not defined in policy\n",
 				       def_perm, pol_class);
+				if (p->handle_unknown == ALLOW_UNKNOWN)
+					p->undefined_perms[class_val-1] |= (1 << j);
+				else if (p->handle_unknown == REJECT_UNKNOWN)
+					return -EINVAL;
 				continue;
 			}
 			perdatum = hashtab_search(perms->table, def_perm);
 			if (perdatum == NULL) {
 				printk(KERN_ERR
-				       "security:  permission %s in class %s not found in policy\n",
+				       "security:  permission %s in class %s not found in policy, bad policy\n",
 				       def_perm, pol_class);
 				return -EINVAL;
 			}
 
 
 
--

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.