audit: use inline function to set audit context
authorRichard Guy Briggs <rgb@redhat.com>
Sun, 13 May 2018 01:58:21 +0000 (21:58 -0400)
committerPaul Moore <paul@paul-moore.com>
Mon, 14 May 2018 21:45:21 +0000 (17:45 -0400)
Recognizing that the audit context is an internal audit value, use an
access function to set the audit context pointer for the task
rather than reaching directly into the task struct to set it.

Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
[PM: merge fuzz in audit.h]
Signed-off-by: Paul Moore <paul@paul-moore.com>
include/linux/audit.h
kernel/auditsc.c
kernel/fork.c

index 831a4684df409ac201fa765e23f7a200f2ac2c1a..69c78477590b089727d1e44f61230e1f4a79544b 100644 (file)
@@ -237,6 +237,11 @@ extern void audit_seccomp_actions_logged(const char *names,
                                         const char *old_names, int res);
 extern void __audit_ptrace(struct task_struct *t);
 
+static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
+{
+       task->audit_context = ctx;
+}
+
 static inline struct audit_context *audit_context(void)
 {
        return current->audit_context;
@@ -469,6 +474,8 @@ static inline bool audit_dummy_context(void)
 {
        return true;
 }
+static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
+{ }
 static inline struct audit_context *audit_context(void)
 {
        return NULL;
index fce4acba576df887974980d25b7fa8b6a1e340b6..cbab0da86d1542e3400a9ee001dbf0e5de6f019e 100644 (file)
@@ -865,7 +865,7 @@ static inline struct audit_context *audit_take_context(struct task_struct *tsk,
                audit_filter_inodes(tsk, context);
        }
 
-       tsk->audit_context = NULL;
+       audit_set_context(tsk, NULL);
        return context;
 }
 
@@ -952,7 +952,7 @@ int audit_alloc(struct task_struct *tsk)
        }
        context->filterkey = key;
 
-       tsk->audit_context  = context;
+       audit_set_context(tsk, context);
        set_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT);
        return 0;
 }
@@ -1554,7 +1554,6 @@ void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2,
  */
 void __audit_syscall_exit(int success, long return_code)
 {
-       struct task_struct *tsk = current;
        struct audit_context *context;
 
        if (success)
@@ -1589,7 +1588,7 @@ void __audit_syscall_exit(int success, long return_code)
                kfree(context->filterkey);
                context->filterkey = NULL;
        }
-       tsk->audit_context = context;
+       audit_set_context(current, context);
 }
 
 static inline void handle_one(const struct inode *inode)
index 242c8c93d285d08a50b484b8e5e78d43dce5bbd4..cd18448b025abdaa0c61162039fc238d25485c6e 100644 (file)
@@ -1713,7 +1713,7 @@ static __latent_entropy struct task_struct *copy_process(
        p->start_time = ktime_get_ns();
        p->real_start_time = ktime_get_boot_ns();
        p->io_context = NULL;
-       p->audit_context = NULL;
+       audit_set_context(p, NULL);
        cgroup_fork(p);
 #ifdef CONFIG_NUMA
        p->mempolicy = mpol_dup(p->mempolicy);