powerpc/mm/iommu: allow large IOMMU page size only for hugetlb backing
[linux-2.6-block.git] / kernel / auditsc.c
index b2d1f043f17fb93fd30b28065e89d1f7371828a6..6593a5207fb03f28a24bf1dfd6a52bcc77412024 100644 (file)
@@ -200,7 +200,6 @@ static int audit_match_filetype(struct audit_context *ctx, int val)
  * References in it _are_ dropped - at the same time we free/drop aux stuff.
  */
 
-#ifdef CONFIG_AUDIT_TREE
 static void audit_set_auditable(struct audit_context *ctx)
 {
        if (!ctx->prio) {
@@ -245,12 +244,10 @@ static int grow_tree_refs(struct audit_context *ctx)
        ctx->tree_count = 31;
        return 1;
 }
-#endif
 
 static void unroll_tree_refs(struct audit_context *ctx,
                      struct audit_tree_refs *p, int count)
 {
-#ifdef CONFIG_AUDIT_TREE
        struct audit_tree_refs *q;
        int n;
        if (!p) {
@@ -274,7 +271,6 @@ static void unroll_tree_refs(struct audit_context *ctx,
        }
        ctx->trees = p;
        ctx->tree_count = count;
-#endif
 }
 
 static void free_tree_refs(struct audit_context *ctx)
@@ -288,7 +284,6 @@ static void free_tree_refs(struct audit_context *ctx)
 
 static int match_tree_refs(struct audit_context *ctx, struct audit_tree *tree)
 {
-#ifdef CONFIG_AUDIT_TREE
        struct audit_tree_refs *p;
        int n;
        if (!tree)
@@ -305,7 +300,6 @@ static int match_tree_refs(struct audit_context *ctx, struct audit_tree *tree)
                        if (audit_tree_match(p->c[n], tree))
                                return 1;
        }
-#endif
        return 0;
 }
 
@@ -836,44 +830,6 @@ void audit_filter_inodes(struct task_struct *tsk, struct audit_context *ctx)
        rcu_read_unlock();
 }
 
-/* Transfer the audit context pointer to the caller, clearing it in the tsk's struct */
-static inline struct audit_context *audit_take_context(struct task_struct *tsk,
-                                                     int return_valid,
-                                                     long return_code)
-{
-       struct audit_context *context = tsk->audit_context;
-
-       if (!context)
-               return NULL;
-       context->return_valid = return_valid;
-
-       /*
-        * we need to fix up the return code in the audit logs if the actual
-        * return codes are later going to be fixed up by the arch specific
-        * signal handlers
-        *
-        * This is actually a test for:
-        * (rc == ERESTARTSYS ) || (rc == ERESTARTNOINTR) ||
-        * (rc == ERESTARTNOHAND) || (rc == ERESTART_RESTARTBLOCK)
-        *
-        * but is faster than a bunch of ||
-        */
-       if (unlikely(return_code <= -ERESTARTSYS) &&
-           (return_code >= -ERESTART_RESTARTBLOCK) &&
-           (return_code != -ENOIOCTLCMD))
-               context->return_code = -EINTR;
-       else
-               context->return_code  = return_code;
-
-       if (context->in_syscall && !context->dummy) {
-               audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_EXIT]);
-               audit_filter_inodes(tsk, context);
-       }
-
-       audit_set_context(tsk, NULL);
-       return context;
-}
-
 static inline void audit_proctitle_free(struct audit_context *context)
 {
        kfree(context->proctitle.value);
@@ -1107,7 +1063,7 @@ static void audit_log_execve_info(struct audit_context *context,
                }
 
                /* write as much as we can to the audit log */
-               if (len_buf > 0) {
+               if (len_buf >= 0) {
                        /* NOTE: some magic numbers here - basically if we
                         *       can't fit a reasonable amount of data into the
                         *       existing audit buffer, flush it and start with
@@ -1302,15 +1258,18 @@ static inline int audit_proctitle_rtrim(char *proctitle, int len)
        return len;
 }
 
-static void audit_log_proctitle(struct task_struct *tsk,
-                        struct audit_context *context)
+static void audit_log_proctitle(void)
 {
        int res;
        char *buf;
        char *msg = "(null)";
        int len = strlen(msg);
+       struct audit_context *context = audit_context();
        struct audit_buffer *ab;
 
+       if (!context || context->dummy)
+               return;
+
        ab = audit_log_start(context, GFP_KERNEL, AUDIT_PROCTITLE);
        if (!ab)
                return; /* audit_panic or being filtered */
@@ -1323,7 +1282,7 @@ static void audit_log_proctitle(struct task_struct *tsk,
                if (!buf)
                        goto out;
                /* Historically called this from procfs naming */
-               res = get_cmdline(tsk, buf, MAX_PROCTITLE_AUDIT_LEN);
+               res = get_cmdline(current, buf, MAX_PROCTITLE_AUDIT_LEN);
                if (res == 0) {
                        kfree(buf);
                        goto out;
@@ -1343,15 +1302,15 @@ out:
        audit_log_end(ab);
 }
 
-static void audit_log_exit(struct audit_context *context, struct task_struct *tsk)
+static void audit_log_exit(void)
 {
        int i, call_panic = 0;
+       struct audit_context *context = audit_context();
        struct audit_buffer *ab;
        struct audit_aux_data *aux;
        struct audit_names *n;
 
-       /* tsk == current */
-       context->personality = tsk->personality;
+       context->personality = current->personality;
 
        ab = audit_log_start(context, GFP_KERNEL, AUDIT_SYSCALL);
        if (!ab)
@@ -1373,7 +1332,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
                         context->argv[3],
                         context->name_count);
 
-       audit_log_task_info(ab, tsk);
+       audit_log_task_info(ab);
        audit_log_key(ab, context->filterkey);
        audit_log_end(ab);
 
@@ -1462,7 +1421,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
                audit_log_name(context, n, NULL, i++, &call_panic);
        }
 
-       audit_log_proctitle(tsk, context);
+       audit_log_proctitle();
 
        /* Send end of event record to help user space know we are finished */
        ab = audit_log_start(context, GFP_KERNEL, AUDIT_EOE);
@@ -1480,22 +1439,31 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
  */
 void __audit_free(struct task_struct *tsk)
 {
-       struct audit_context *context;
+       struct audit_context *context = tsk->audit_context;
 
-       context = audit_take_context(tsk, 0, 0);
        if (!context)
                return;
 
-       /* Check for system calls that do not go through the exit
-        * function (e.g., exit_group), then free context block.
-        * We use GFP_ATOMIC here because we might be doing this
-        * in the context of the idle thread */
-       /* that can happen only if we are called from do_exit() */
-       if (context->in_syscall && context->current_state == AUDIT_RECORD_CONTEXT)
-               audit_log_exit(context, tsk);
+       /* We are called either by do_exit() or the fork() error handling code;
+        * in the former case tsk == current and in the latter tsk is a
+        * random task_struct that doesn't doesn't have any meaningful data we
+        * need to log via audit_log_exit().
+        */
+       if (tsk == current && !context->dummy && context->in_syscall) {
+               context->return_valid = 0;
+               context->return_code = 0;
+
+               audit_filter_syscall(tsk, context,
+                                    &audit_filter_list[AUDIT_FILTER_EXIT]);
+               audit_filter_inodes(tsk, context);
+               if (context->current_state == AUDIT_RECORD_CONTEXT)
+                       audit_log_exit();
+       }
+
        if (!list_empty(&context->killed_trees))
                audit_kill_trees(&context->killed_trees);
 
+       audit_set_context(tsk, NULL);
        audit_free_context(context);
 }
 
@@ -1565,17 +1533,40 @@ void __audit_syscall_exit(int success, long return_code)
 {
        struct audit_context *context;
 
-       if (success)
-               success = AUDITSC_SUCCESS;
-       else
-               success = AUDITSC_FAILURE;
-
-       context = audit_take_context(current, success, return_code);
+       context = audit_context();
        if (!context)
                return;
 
-       if (context->in_syscall && context->current_state == AUDIT_RECORD_CONTEXT)
-               audit_log_exit(context, current);
+       if (!context->dummy && context->in_syscall) {
+               if (success)
+                       context->return_valid = AUDITSC_SUCCESS;
+               else
+                       context->return_valid = AUDITSC_FAILURE;
+
+               /*
+                * we need to fix up the return code in the audit logs if the
+                * actual return codes are later going to be fixed up by the
+                * arch specific signal handlers
+                *
+                * This is actually a test for:
+                * (rc == ERESTARTSYS ) || (rc == ERESTARTNOINTR) ||
+                * (rc == ERESTARTNOHAND) || (rc == ERESTART_RESTARTBLOCK)
+                *
+                * but is faster than a bunch of ||
+                */
+               if (unlikely(return_code <= -ERESTARTSYS) &&
+                   (return_code >= -ERESTART_RESTARTBLOCK) &&
+                   (return_code != -ENOIOCTLCMD))
+                       context->return_code = -EINTR;
+               else
+                       context->return_code  = return_code;
+
+               audit_filter_syscall(current, context,
+                                    &audit_filter_list[AUDIT_FILTER_EXIT]);
+               audit_filter_inodes(current, context);
+               if (context->current_state == AUDIT_RECORD_CONTEXT)
+                       audit_log_exit();
+       }
 
        context->in_syscall = 0;
        context->prio = context->state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0;
@@ -1597,12 +1588,10 @@ void __audit_syscall_exit(int success, long return_code)
                kfree(context->filterkey);
                context->filterkey = NULL;
        }
-       audit_set_context(current, context);
 }
 
 static inline void handle_one(const struct inode *inode)
 {
-#ifdef CONFIG_AUDIT_TREE
        struct audit_context *context;
        struct audit_tree_refs *p;
        struct audit_chunk *chunk;
@@ -1627,12 +1616,10 @@ static inline void handle_one(const struct inode *inode)
                return;
        }
        put_tree_ref(context, chunk);
-#endif
 }
 
 static void handle_path(const struct dentry *dentry)
 {
-#ifdef CONFIG_AUDIT_TREE
        struct audit_context *context;
        struct audit_tree_refs *p;
        const struct dentry *d, *parent;
@@ -1685,7 +1672,6 @@ retry:
                return;
        }
        rcu_read_unlock();
-#endif
 }
 
 static struct audit_names *audit_alloc_name(struct audit_context *context,
@@ -2035,7 +2021,7 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
        uid = from_kuid(&init_user_ns, task_uid(current));
        oldloginuid = from_kuid(&init_user_ns, koldloginuid);
        loginuid = from_kuid(&init_user_ns, kloginuid),
-       tty = audit_get_tty(current);
+       tty = audit_get_tty();
 
        audit_log_format(ab, "pid=%d uid=%u", task_tgid_nr(current), uid);
        audit_log_task_context(ab);
@@ -2056,7 +2042,6 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
  */
 int audit_set_loginuid(kuid_t loginuid)
 {
-       struct task_struct *task = current;
        unsigned int oldsessionid, sessionid = AUDIT_SID_UNSET;
        kuid_t oldloginuid;
        int rc;
@@ -2075,8 +2060,8 @@ int audit_set_loginuid(kuid_t loginuid)
                        sessionid = (unsigned int)atomic_inc_return(&session_id);
        }
 
-       task->sessionid = sessionid;
-       task->loginuid = loginuid;
+       current->sessionid = sessionid;
+       current->loginuid = loginuid;
 out:
        audit_log_set_loginuid(oldloginuid, loginuid, oldsessionid, sessionid, rc);
        return rc;
@@ -2513,10 +2498,9 @@ void audit_seccomp_actions_logged(const char *names, const char *old_names,
        if (unlikely(!ab))
                return;
 
-       audit_log_format(ab, "op=seccomp-logging");
-       audit_log_format(ab, " actions=%s", names);
-       audit_log_format(ab, " old-actions=%s", old_names);
-       audit_log_format(ab, " res=%d", res);
+       audit_log_format(ab,
+                        "op=seccomp-logging actions=%s old-actions=%s res=%d",
+                        names, old_names, res);
        audit_log_end(ab);
 }