UBUNTU: SAUCE: security: create task_free security callback
authorKees Cook <kees.cook@canonical.com>
Tue, 29 Jun 2010 05:34:04 +0000 (22:34 -0700)
committerLeann Ogasawara <leann.ogasawara@canonical.com>
Mon, 28 Mar 2011 13:48:53 +0000 (06:48 -0700)
The current LSM interface to cred_free is not sufficient for allowing
an LSM to track the life and death of a task.  This patch adds the
task_free hook so that an LSM can clean up resources on task death.

Signed-off-by: Kees Cook <kees.cook@canonical.com>
Signed-off-by: Leann Ogasawara <leann.ogasawara@canonical.com>

include/linux/security.h
kernel/fork.c
security/capability.c
security/security.c

index b2b7f97..78d64cc 100644 (file)
@@ -636,6 +636,9 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     manual page for definitions of the @clone_flags.
  *     @clone_flags contains the flags indicating what should be shared.
  *     Return 0 if permission is granted.
+ * @task_free:
+ *     @task task being freed
+ *     Handle release of task-related resources.
  * @cred_alloc_blank:
  *     @cred points to the credentials.
  *     @gfp indicates the atomicity of any memory allocations.
@@ -1490,6 +1493,7 @@ struct security_operations {
        int (*dentry_open) (struct file *file, const struct cred *cred);
 
        int (*task_create) (unsigned long clone_flags);
+       void (*task_free) (struct task_struct *task);
        int (*cred_alloc_blank) (struct cred *cred, gfp_t gfp);
        void (*cred_free) (struct cred *cred);
        int (*cred_prepare)(struct cred *new, const struct cred *old,
@@ -1744,6 +1748,7 @@ int security_file_send_sigiotask(struct task_struct *tsk,
 int security_file_receive(struct file *file);
 int security_dentry_open(struct file *file, const struct cred *cred);
 int security_task_create(unsigned long clone_flags);
+void security_task_free(struct task_struct *task);
 int security_cred_alloc_blank(struct cred *cred, gfp_t gfp);
 void security_cred_free(struct cred *cred);
 int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp);
@@ -2250,6 +2255,9 @@ static inline int security_task_create(unsigned long clone_flags)
        return 0;
 }
 
+static inline int security_task_free(struct task_struct *task)
+{ }
+
 static inline int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
 {
        return 0;
index 25e4291..c85d59e 100644 (file)
@@ -186,6 +186,7 @@ void __put_task_struct(struct task_struct *tsk)
        WARN_ON(atomic_read(&tsk->usage));
        WARN_ON(tsk == current);
 
+       security_task_free(tsk);
        exit_creds(tsk);
        delayacct_tsk_free(tsk);
        put_signal_struct(tsk->signal);
index 2a5df2b..fa4f3a6 100644 (file)
@@ -358,6 +358,9 @@ static int cap_task_create(unsigned long clone_flags)
        return 0;
 }
 
+static void cap_task_free(struct task_struct *task)
+{ }
+
 static int cap_cred_alloc_blank(struct cred *cred, gfp_t gfp)
 {
        return 0;
@@ -954,6 +957,7 @@ void __init security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, file_receive);
        set_to_cap_if_null(ops, dentry_open);
        set_to_cap_if_null(ops, task_create);
+       set_to_cap_if_null(ops, task_free);
        set_to_cap_if_null(ops, cred_alloc_blank);
        set_to_cap_if_null(ops, cred_free);
        set_to_cap_if_null(ops, cred_prepare);
index 7b7308a..d422c6b 100644 (file)
@@ -695,6 +695,11 @@ int security_task_create(unsigned long clone_flags)
        return security_ops->task_create(clone_flags);
 }
 
+void security_task_free(struct task_struct *task)
+{
+       security_ops->task_free(task);
+}
+
 int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
 {
        return security_ops->cred_alloc_blank(cred, gfp);