selinux: call WARN_ONCE() instead of calling audit_log_start()
authorRichard Guy Briggs <rgb@redhat.com>
Thu, 21 Nov 2013 18:31:40 +0000 (13:31 -0500)
committerEric Paris <eparis@redhat.com>
Tue, 14 Jan 2014 03:32:00 +0000 (22:32 -0500)
Two of the conditions in selinux_audit_rule_match() should never happen and
the third indicates a race that should be retried.  Remove the calls to
audit_log() (which call audit_log_start()) and deal with the errors in the
caller, logging only once if the condition is met.  Calling audit_log_start()
in this location makes buffer allocation and locking more complicated in the
calling tree (audit_filter_user()).

Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
security/selinux/ss/services.c

index b4feecc3fe0110d10bbdc183c369a03ab8495a6c..f4dda05d7db0b96da73ddb9a6257d278cef03c8f 100644 (file)
@@ -2938,25 +2938,21 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
        struct selinux_audit_rule *rule = vrule;
        int match = 0;
 
-       if (!rule) {
-               audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR,
-                         "selinux_audit_rule_match: missing rule\n");
+       if (unlikely(!rule)) {
+               WARN_ONCE(1, "selinux_audit_rule_match: missing rule\n");
                return -ENOENT;
        }
 
        read_lock(&policy_rwlock);
 
        if (rule->au_seqno < latest_granting) {
-               audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR,
-                         "selinux_audit_rule_match: stale rule\n");
                match = -ESTALE;
                goto out;
        }
 
        ctxt = sidtab_search(&sidtab, sid);
-       if (!ctxt) {
-               audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR,
-                         "selinux_audit_rule_match: unrecognized SID %d\n",
+       if (unlikely(!ctxt)) {
+               WARN_ONCE(1, "selinux_audit_rule_match: unrecognized SID %d\n",
                          sid);
                match = -ENOENT;
                goto out;