]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/auditsc.c
h63xx: tsc2101 alsa sound support
[linux-2.6-omap-h63xx.git] / kernel / auditsc.c
index a73176eaa57ddee98372f83b6ed5f4da81d0c95e..d7e7e637b92abc2e100503c5f0c31891b166381f 100644 (file)
@@ -30,8 +30,8 @@
  */
 
 #include <linux/init.h>
-#include <asm/atomic.h>
 #include <asm/types.h>
+#include <asm/atomic.h>
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/mount.h>
@@ -190,9 +190,36 @@ struct audit_entry {
 
 extern int audit_pid;
 
+/* Copy rule from user-space to kernel-space.  Called from 
+ * audit_add_rule during AUDIT_ADD. */
+static inline int audit_copy_rule(struct audit_rule *d, struct audit_rule *s)
+{
+       int i;
+
+       if (s->action != AUDIT_NEVER
+           && s->action != AUDIT_POSSIBLE
+           && s->action != AUDIT_ALWAYS)
+               return -1;
+       if (s->field_count < 0 || s->field_count > AUDIT_MAX_FIELDS)
+               return -1;
+       if ((s->flags & ~AUDIT_FILTER_PREPEND) >= AUDIT_NR_FILTERS)
+               return -1;
+
+       d->flags        = s->flags;
+       d->action       = s->action;
+       d->field_count  = s->field_count;
+       for (i = 0; i < d->field_count; i++) {
+               d->fields[i] = s->fields[i];
+               d->values[i] = s->values[i];
+       }
+       for (i = 0; i < AUDIT_BITMASK_SIZE; i++) d->mask[i] = s->mask[i];
+       return 0;
+}
+
 /* Check to see if two rules are identical.  It is called from
+ * audit_add_rule during AUDIT_ADD and 
  * audit_del_rule during AUDIT_DEL. */
-static int audit_compare_rule(struct audit_rule *a, struct audit_rule *b)
+static inline int audit_compare_rule(struct audit_rule *a, struct audit_rule *b)
 {
        int i;
 
@@ -221,18 +248,37 @@ static int audit_compare_rule(struct audit_rule *a, struct audit_rule *b)
 /* Note that audit_add_rule and audit_del_rule are called via
  * audit_receive() in audit.c, and are protected by
  * audit_netlink_sem. */
-static inline void audit_add_rule(struct audit_entry *entry,
+static inline int audit_add_rule(struct audit_rule *rule,
                                  struct list_head *list)
 {
+       struct audit_entry  *entry;
+
+       /* Do not use the _rcu iterator here, since this is the only
+        * addition routine. */
+       list_for_each_entry(entry, list, list) {
+               if (!audit_compare_rule(rule, &entry->rule)) {
+                       return -EEXIST;
+               }
+       }
+
+       if (!(entry = kmalloc(sizeof(*entry), GFP_KERNEL)))
+               return -ENOMEM;
+       if (audit_copy_rule(&entry->rule, rule)) {
+               kfree(entry);
+               return -EINVAL;
+       }
+
        if (entry->rule.flags & AUDIT_FILTER_PREPEND) {
                entry->rule.flags &= ~AUDIT_FILTER_PREPEND;
                list_add_rcu(&entry->list, list);
        } else {
                list_add_tail_rcu(&entry->list, list);
        }
+
+       return 0;
 }
 
-static void audit_free_rule(struct rcu_head *head)
+static inline void audit_free_rule(struct rcu_head *head)
 {
        struct audit_entry *e = container_of(head, struct audit_entry, rcu);
        kfree(e);
@@ -258,32 +304,6 @@ static inline int audit_del_rule(struct audit_rule *rule,
        return -ENOENT;         /* No matching rule */
 }
 
-/* Copy rule from user-space to kernel-space.  Called during
- * AUDIT_ADD. */
-static int audit_copy_rule(struct audit_rule *d, struct audit_rule *s)
-{
-       int i;
-
-       if (s->action != AUDIT_NEVER
-           && s->action != AUDIT_POSSIBLE
-           && s->action != AUDIT_ALWAYS)
-               return -1;
-       if (s->field_count < 0 || s->field_count > AUDIT_MAX_FIELDS)
-               return -1;
-       if ((s->flags & ~AUDIT_FILTER_PREPEND) >= AUDIT_NR_FILTERS)
-               return -1;
-
-       d->flags        = s->flags;
-       d->action       = s->action;
-       d->field_count  = s->field_count;
-       for (i = 0; i < d->field_count; i++) {
-               d->fields[i] = s->fields[i];
-               d->values[i] = s->values[i];
-       }
-       for (i = 0; i < AUDIT_BITMASK_SIZE; i++) d->mask[i] = s->mask[i];
-       return 0;
-}
-
 static int audit_list_rules(void *_dest)
 {
        int pid, seq;
@@ -313,7 +333,6 @@ static int audit_list_rules(void *_dest)
 int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
                                                        uid_t loginuid)
 {
-       struct audit_entry *entry;
        struct task_struct *tsk;
        int *dest;
        int                err = 0;
@@ -340,16 +359,14 @@ int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
                }
                break;
        case AUDIT_ADD:
-               if (!(entry = kmalloc(sizeof(*entry), GFP_KERNEL)))
-                       return -ENOMEM;
-               if (audit_copy_rule(&entry->rule, data)) {
-                       kfree(entry);
+               listnr =((struct audit_rule *)data)->flags & ~AUDIT_FILTER_PREPEND;
+               if (listnr >= AUDIT_NR_FILTERS)
                        return -EINVAL;
-               }
-               listnr = entry->rule.flags & ~AUDIT_FILTER_PREPEND;
-               audit_add_rule(entry, &audit_filter_list[listnr]);
-               audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE, 
-                               "auid=%u added an audit rule\n", loginuid);
+
+               err = audit_add_rule(data, &audit_filter_list[listnr]);
+               if (!err)
+                       audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
+                                 "auid=%u added an audit rule\n", loginuid);
                break;
        case AUDIT_DEL:
                listnr =((struct audit_rule *)data)->flags & ~AUDIT_FILTER_PREPEND;
@@ -423,8 +440,12 @@ static int audit_filter_rules(struct task_struct *tsk,
                                result = (ctx->return_code == value);
                        break;
                case AUDIT_SUCCESS:
-                       if (ctx && ctx->return_valid)
-                               result = (ctx->return_valid == AUDITSC_SUCCESS);
+                       if (ctx && ctx->return_valid) {
+                               if (value)
+                                       result = (ctx->return_valid == AUDITSC_SUCCESS);
+                               else
+                                       result = (ctx->return_valid == AUDITSC_FAILURE);
+                       }
                        break;
                case AUDIT_DEVMAJOR:
                        if (ctx) {
@@ -513,20 +534,23 @@ static enum audit_state audit_filter_syscall(struct task_struct *tsk,
                                             struct list_head *list)
 {
        struct audit_entry *e;
-       enum audit_state   state;
-       int                word = AUDIT_WORD(ctx->major);
-       int                bit  = AUDIT_BIT(ctx->major);
+       enum audit_state state;
 
        if (audit_pid && tsk->tgid == audit_pid)
                return AUDIT_DISABLED;
 
        rcu_read_lock();
-       list_for_each_entry_rcu(e, list, list) {
-               if ((e->rule.mask[word] & bit) == bit
-                   && audit_filter_rules(tsk, &e->rule, ctx, &state)) {
-                       rcu_read_unlock();
-                       return state;
-               }
+       if (!list_empty(list)) {
+                   int word = AUDIT_WORD(ctx->major);
+                   int bit  = AUDIT_BIT(ctx->major);
+
+                   list_for_each_entry_rcu(e, list, list) {
+                           if ((e->rule.mask[word] & bit) == bit
+                               && audit_filter_rules(tsk, &e->rule, ctx, &state)) {
+                                   rcu_read_unlock();
+                                   return state;
+                           }
+                   }
        }
        rcu_read_unlock();
        return AUDIT_BUILD_CONTEXT;
@@ -779,7 +803,7 @@ static void audit_log_task_info(struct audit_buffer *ab)
        up_read(&mm->mmap_sem);
 }
 
-static void audit_log_exit(struct audit_context *context, unsigned int gfp_mask)
+static void audit_log_exit(struct audit_context *context, gfp_t gfp_mask)
 {
        int i;
        struct audit_buffer *ab;
@@ -817,7 +841,7 @@ static void audit_log_exit(struct audit_context *context, unsigned int gfp_mask)
 
        for (aux = context->aux; aux; aux = aux->next) {
 
-               ab = audit_log_start(context, GFP_KERNEL, aux->type);
+               ab = audit_log_start(context, gfp_mask, aux->type);
                if (!ab)
                        continue; /* audit_panic has been called */
 
@@ -854,14 +878,14 @@ static void audit_log_exit(struct audit_context *context, unsigned int gfp_mask)
        }
 
        if (context->pwd && context->pwdmnt) {
-               ab = audit_log_start(context, GFP_KERNEL, AUDIT_CWD);
+               ab = audit_log_start(context, gfp_mask, AUDIT_CWD);
                if (ab) {
                        audit_log_d_path(ab, "cwd=", context->pwd, context->pwdmnt);
                        audit_log_end(ab);
                }
        }
        for (i = 0; i < context->name_count; i++) {
-               ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH);
+               ab = audit_log_start(context, gfp_mask, AUDIT_PATH);
                if (!ab)
                        continue; /* audit_panic has been called */
 
@@ -1023,7 +1047,6 @@ void audit_syscall_exit(struct task_struct *tsk, int valid, long return_code)
        } else {
                audit_free_names(context);
                audit_free_aux(context);
-               audit_zero_context(context, context->state);
                tsk->audit_context = context;
        }
  out: