From: Stephen Smalley This patch 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. --- 25-akpm/security/selinux/ss/services.c | 43 +++++++++++++++++---------------- security/selinux/ss/services.c.orig | 0 2 files changed, 23 insertions(+), 20 deletions(-) diff -puN security/selinux/ss/services.c~selinux-compute_sid-fixes security/selinux/ss/services.c --- 25/security/selinux/ss/services.c~selinux-compute_sid-fixes 2004-03-22 20:24:17.940768864 -0800 +++ 25-akpm/security/selinux/ss/services.c 2004-03-22 20:24:17.945768104 -0800 @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "flask.h" #include "avc.h" @@ -548,32 +549,34 @@ out: 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, diff -puN security/selinux/ss/services.c.orig~selinux-compute_sid-fixes security/selinux/ss/services.c.orig _