audit validatetrans denials
PATCH 1/1 audit validatetrans denials
Attached is a patch that adds the auditing of denials caused by the validatetrans rules in the policy. Look good?
Thanks,
Signature · 1 line
Darrel
security/selinux/ss/services.c +44 -0
@@ -38,6 +38,13 @@#include "services.h" #include "conditional.h" #include "mls.h" +#ifdef CONFIG_AUDIT +static const char *class_to_string[] = { +#define S_(s) s, +#include "class_to_string.h" +#undef S_ +}; +#endif extern void selnl_notify_policyload (u32 seqno);unsigned int policydb_loaded_version;
@@ -417,6 +424,43 @@ int security_validate_transition(u32 old out:POLICY_RDUNLOCK ; + +/* audit failures */ +if (rc) { +int err; +char *context; +u32 context_len; +struct audit_buffer *ab; + + ab =audit_log_start (current->audit_context); +if (!ab) +return rc;/* audit_panic has been called */ +audit_log_format (ab,"avc: denied validate_transition" ); + err =security_sid_to_context (oldsid, &context, &context_len); +if (err) +audit_log_format (ab," oldsid=%d" , oldsid); +else { +audit_log_format (ab," oldcontext=%s" , context); +kfree (context); + } + err =security_sid_to_context (newsid, &context, &context_len); +if (err) +audit_log_format (ab," newsid=%d" , newsid); +else { +audit_log_format (ab," newcontext=%s" , context); +kfree (context); + } + err =security_sid_to_context (tasksid, &context, &context_len); +if (err) +audit_log_format (ab," tasksid=%d" , tasksid); +else { +audit_log_format (ab," taskcontext=%s" , context); +kfree (context); + } +audit_log_format (ab," tclass=%s" , class_to_string[tclass]); +audit_log_end (ab); + } +return rc; }
Quoted 2 lines · Darrel Goeddel
Attached is a patch that adds the auditing of denials caused by the validatetrans rules in the policy. Look good?
Looks fine to me.
- James
Signature · 9 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.
Quoted 2 lines · Darrel Goeddel
Attached is a patch that adds the auditing of denials caused by the validatetrans rules in the policy. Look good?
I'd rather do this the same way as compute_sid_handle_invalid_context(), i.e. generate the context strings up front using context_struct_to_string() after looking up the SIDs, use policydb.p_class_val_to_name[tclass-1] to lookup the class name, and perform a single audit_log() call. Since you are already within the security server at this point, you don't have to do it in the same manner as the AVC. And you already log error messages on any invalid SIDs or classes (in which case you aren't going to be able to look them up anyway). So I think you just want to call a similar helper as compute_sid_handle_invalid_context() in the case where constraint_expr_eval() fails.
Signature · 8 lines
Stephen Smalley <[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.
Quoted 12 lines · Stephen Smalley
I'd rather do this the same way as
compute_sid_handle_invalid_context(), i.e. generate the context strings up front usingcontext_struct_to_string()after looking up the SIDs, use policydb.p_class_val_to_name[tclass-1] to lookup the class name, and perform a singleaudit_log()call. Since you are already within the security server at this point, you don't have to do it in the same manner as the AVC. And you already log error messages on any invalid SIDs or classes (in which case you aren't going to be able to look them up anyway). So I think you just want to call a similar helper ascompute_sid_handle_invalid_context()in the case whereconstraint_expr_eval()fails.
Yeah, I really could have made this nicer when I moved the functionality into security_validate_transition (I originally had it another function which was called after security_validate_transition)... How about the attached patch instead.
Signature · 1 line
Darrel
security/selinux/ss/services.c +31 -0
@@ -64,6 +64,10 @@ int ss_initialized = 0;*/ static u32 latest_granting =0 ; +/* Forward declarations. */ +int context_struct_to_string (struct context *context,char **scontext, +u32 *scontext_len); +/* * Return the boolean value of a constraint expression * when it is applied to the specified source and target
@@ -347,6 +351,31 @@ static int context_struct_compute_av(strreturn 0 ; } +static void security_validtrans_audit_fail (struct context *ocontext, +struct context *ncontext, +struct context *tcontext, +u16 tclass) +{ +char *o =NULL , *n =NULL , *t =NULL ; +u32 olen, nlen, tlen; + +if (context_struct_to_string (ocontext, &o, &olen) <0 ) + goto out; +if (context_struct_to_string (ncontext, &n, &nlen) <0 ) + goto out; +if (context_struct_to_string (tcontext, &t, &tlen) <0 ) + goto out; +audit_log (current->audit_context, +"security_validate_transition: denied for" +" oldcontext=%s newcontext=%s taskcontext=%s tclass=%s" , + o, n, t, policydb.p_class_val_to_name[tclass-1 ]); +out: +kfree (o); +kfree (n); +kfree (t); +return ; +} +int security_validate_transition (u32 oldsid,u32 newsid,u32 tasksid,u16 tclass) {
@@ -410,6 +439,8 @@ int security_validate_transition(u32 oldif (!constraint_expr_eval (ocontext, ncontext, tcontext, constraint->expr)) { rc = -EPERM ; +security_validtrans_audit_fail (ocontext, ncontext, + tcontext, tclass); goto out; } constraint = constraint->next;
Quoted 3 lines · Darrel Goeddel
Yeah, I really could have made this nicer when I moved the functionality into
security_validate_transition(I originally had it another function which was called aftersecurity_validate_transition)... How about the attached patch instead.
Looks good, thanks.
Signature · 8 lines
Stephen Smalley <[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.
Quoted 3 lines · Darrel Goeddel
Yeah, I really could have made this nicer when I moved the functionality into
security_validate_transition(I originally had it another function which was called aftersecurity_validate_transition)... How about the attached patch instead.
One other question: At present, you won't perform any such auditing when in permissive mode, as you bail out of security_validate_transition() immediately in that case. Do you want instead to handle this more like security_compute_sid(), i.e. always auditing the denial but only returning an error if enforcing? Otherwise, you won't even see such denials if you are doing any kind of policy development in permissive mode.
Signature · 8 lines
Stephen Smalley <[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.
Quoted 7 lines · Stephen Smalley
One other question: At present, you won't perform any such auditing
when in permissive mode, as you bail out ofsecurity_validate_transition()immediately in that case. Do you want
instead to handle this more likesecurity_compute_sid(), i.e. always
auditing the denial but only returning an error if enforcing? Otherwise, you won't even see such denials if you are doing any kind of policy development in permissive mode.
Good catch. Version 3 attached...
Signature · 1 line
Darrel
security/selinux/ss/services.c +35 -2
@@ -64,6 +64,10 @@ int ss_initialized = 0;*/ static u32 latest_granting =0 ; +/* Forward declarations. */ +int context_struct_to_string (struct context *context,char **scontext, +u32 *scontext_len); +/* * Return the boolean value of a constraint expression * when it is applied to the specified source and target
@@ -347,6 +351,34 @@ static int context_struct_compute_av(strreturn 0 ; } +static int security_validtrans_handle_fail (struct context *ocontext, +struct context *ncontext, +struct context *tcontext, +u16 tclass) +{ +char *o =NULL , *n =NULL , *t =NULL ; +u32 olen, nlen, tlen; + +if (context_struct_to_string (ocontext, &o, &olen) <0 ) + goto out; +if (context_struct_to_string (ncontext, &n, &nlen) <0 ) + goto out; +if (context_struct_to_string (tcontext, &t, &tlen) <0 ) + goto out; +audit_log (current->audit_context, +"security_validate_transition: denied for" +" oldcontext=%s newcontext=%s taskcontext=%s tclass=%s" , + o, n, t, policydb.p_class_val_to_name[tclass-1 ]); +out: +kfree (o); +kfree (n); +kfree (t); + +if (!selinux_enforcing) +return 0 ; +return -EPERM ; +} +int security_validate_transition (u32 oldsid,u32 newsid,u32 tasksid,u16 tclass) {
@@ -357,7 +389,7 @@ int security_validate_transition(u32 oldstruct constraint_node *constraint;int rc =0 ; -if (!ss_initialized || !selinux_enforcing) +if (!ss_initialized)return 0 ;POLICY_RDLOCK ;
@@ -409,7 +441,8 @@ int security_validate_transition(u32 oldwhile (constraint) {if (!constraint_expr_eval (ocontext, ncontext, tcontext, constraint->expr)) { - rc = -EPERM ; + rc =security_validtrans_handle_fail (ocontext, ncontext, + tcontext, tclass); goto out; } constraint = constraint->next;