[PATCH 15/20] selinux: change handling of invalid classes (Was: Re: 2.6.26-rc5-mm1 selinux whine)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: James Morris
Date: Monday, July 7, 2008 - 9:42 am

From: Stephen Smalley <sds@tycho.nsa.gov>

On Mon, 2008-06-09 at 01:24 -0700, Andrew Morton wrote:

Change handling of invalid classes by SELinux, reporting class values
unknown to the kernel as errors (w/ ratelimit applied) and handling
class values unknown to policy as normal denials.

Signed-off-by:  Stephen Smalley <sds@tycho.nsa.gov>
Acked-by: Eric Paris <eparis@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
---
 security/selinux/ss/services.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 543fd0f..04c0b70 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -407,9 +407,19 @@ static int context_struct_compute_av(struct context *scontext,
 	return 0;
 
 inval_class:
-	printk(KERN_ERR "SELinux: %s:  unrecognized class %d\n", __func__,
-		tclass);
-	return -EINVAL;
+	if (!tclass || tclass > kdefs->cts_len ||
+	    !kdefs->class_to_string[tclass]) {
+		if (printk_ratelimit())
+			printk(KERN_ERR "SELinux: %s:  unrecognized class %d\n",
+			       __func__, tclass);
+		return -EINVAL;
+	}
+
+	/*
+	 * Known to the kernel, but not to the policy.
+	 * Handle as a denial (allowed is 0).
+	 */
+	return 0;
 }
 
 /*
-- 
1.5.5.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
SELinux patches for 2.6.26, James Morris, (Mon Jul 7, 9:42 am)
[PATCH 08/20] selinux: simplify ioctl checking, James Morris, (Mon Jul 7, 9:42 am)
[PATCH 10/20] SELinux: open code policy_rwlock, James Morris, (Mon Jul 7, 9:42 am)
[PATCH 11/20] SELinux: open code load_mutex, James Morris, (Mon Jul 7, 9:42 am)
[PATCH 12/20] SELinux: open code sidtab lock, James Morris, (Mon Jul 7, 9:42 am)
[PATCH 15/20] selinux: change handling of invalid classes ..., James Morris, (Mon Jul 7, 9:42 am)
Re: SELinux patches for 2.6.26, Theodore Tso, (Mon Jul 7, 11:23 am)
Re: SELinux patches for 2.6.26, James Morris, (Mon Jul 7, 3:49 pm)