2004-03-22 21:11:08

by Stephen Smalley

[permalink] [raw]
Subject: [PATCH][SELINUX] Audit compute_sid errors

This patch against 2.6.5-rc2-mm1 changes an error message printk'd by
security_compute_sid to use the audit framework instead. These errors
reflect situations where a security transition would normally occur due
to policy, but the resulting security context is not valid. The patch
also changes the code to always call the audit framework rather than
only doing so when permissive as this was causing problems with testing
policy, and does some code cleanup. Please apply.

--- linux-2.6.5-rc2-mm1/security/selinux/ss/services.c.orig 2004-03-22 10:52:25.000000000 -0500
+++ linux-2.6.5-rc2-mm1/security/selinux/ss/services.c 2004-03-22 15:34:31.897927706 -0500
@@ -26,6 +26,7 @@
#include <linux/errno.h>
#include <linux/in.h>
#include <linux/sched.h>
+#include <linux/audit.h>
#include <asm/semaphore.h>
#include "flask.h"
#include "avc.h"
@@ -548,32 +549,34 @@
return rc;
}

-static inline int compute_sid_handle_invalid_context(
+static int compute_sid_handle_invalid_context(
struct context *scontext,
struct context *tcontext,
u16 tclass,
struct context *newcontext)
{
- int rc = 0;
-
- if (selinux_enforcing) {
- rc = -EACCES;
- } else {
- char *s, *t, *n;
- u32 slen, tlen, nlen;
+ char *s = NULL, *t = NULL, *n = NULL;
+ u32 slen, tlen, nlen;

- context_struct_to_string(scontext, &s, &slen);
- context_struct_to_string(tcontext, &t, &tlen);
- context_struct_to_string(newcontext, &n, &nlen);
- printk(KERN_ERR "security_compute_sid: invalid context %s", n);
- printk(" for scontext=%s", s);
- printk(" tcontext=%s", t);
- printk(" tclass=%s\n", policydb.p_class_val_to_name[tclass-1]);
- kfree(s);
- kfree(t);
- kfree(n);
- }
- return rc;
+ if (context_struct_to_string(scontext, &s, &slen) < 0)
+ goto out;
+ if (context_struct_to_string(tcontext, &t, &tlen) < 0)
+ goto out;
+ if (context_struct_to_string(newcontext, &n, &nlen) < 0)
+ goto out;
+ audit_log(current->audit_context,
+ "security_compute_sid: invalid context %s"
+ " for scontext=%s"
+ " tcontext=%s"
+ " tclass=%s",
+ n, s, t, policydb.p_class_val_to_name[tclass-1]);
+out:
+ kfree(s);
+ kfree(t);
+ kfree(n);
+ if (!selinux_enforcing)
+ return 0;
+ return -EACCES;
}

static int security_compute_sid(u32 ssid,

--
Stephen Smalley <[email protected]>
National Security Agency


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part