mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kees Cook <kees.cook@canonical.com>
To: linux-security-module@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] security: create task_free security callback
Date: Tue, 29 Jun 2010 17:39:33 -0700	[thread overview]
Message-ID: <20100630003933.GF4837@outflux.net> (raw)
In-Reply-To: <20100630003844.GE4837@outflux.net>

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>
---
 include/linux/security.h |    8 ++++++++
 kernel/fork.c            |    1 +
 security/capability.c    |    4 ++++
 security/security.c      |    5 +++++
 4 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/include/linux/security.h b/include/linux/security.h
index 723a93d..8007495 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -637,6 +637,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.
@@ -1481,6 +1484,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,
@@ -1732,6 +1736,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);
@@ -2232,6 +2237,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;
diff --git a/kernel/fork.c b/kernel/fork.c
index b6cce14..7fbc5e3 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -183,6 +183,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);
diff --git a/security/capability.c b/security/capability.c
index 4aeb699..3649d4b 100644
--- a/security/capability.c
+++ b/security/capability.c
@@ -353,6 +353,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;
@@ -936,6 +939,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);
diff --git a/security/security.c b/security/security.c
index e8c87b8..103c35f 100644
--- a/security/security.c
+++ b/security/security.c
@@ -691,6 +691,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);
-- 
1.7.1


-- 
Kees Cook
Ubuntu Security Team

  reply	other threads:[~2010-06-30  0:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-30  0:38 [PATCH 0/2] Yama: add PTRACE exception tracking Kees Cook
2010-06-30  0:39 ` Kees Cook [this message]
2010-06-30  0:40 ` [PATCH 2/2] " Kees Cook
2010-06-30  1:09   ` Tetsuo Handa
2010-06-30  3:51     ` Kees Cook
2010-06-30  3:56   ` Serge E. Hallyn
2010-06-30  5:27     ` Kees Cook
2010-06-30 12:40       ` Serge E. Hallyn
2010-06-30 15:41   ` Eric Paris
2010-06-30 15:53     ` Kees Cook
2010-06-30 21:39       ` Tetsuo Handa
2010-06-30  7:31 ` [PATCH 0/2] " Christoph Hellwig
2010-06-30 15:45   ` Kees Cook
2010-07-01  1:39   ` James Morris
2010-07-01  4:44     ` Kees Cook
2010-07-01 13:20       ` Serge E. Hallyn
2010-07-01 15:22         ` Stephen Smalley
2010-07-01 17:16         ` Kees Cook
2010-07-01 19:41           ` Serge E. Hallyn
2010-07-01 19:57             ` Stephen Smalley
2011-11-30 23:01 [PATCH v7 0/2] security: Yama LSM Kees Cook
2011-11-30 23:01 ` [PATCH 1/2] security: create task_free security callback Kees Cook
2011-12-16  6:33 [PATCH v8 0/2] security: Yama LSM Kees Cook
2011-12-16  6:33 ` [PATCH 1/2] security: create task_free security callback Kees Cook
2011-12-19 22:17 [PATCH v9 0/2] security: Yama LSM Kees Cook
2011-12-19 22:17 ` [PATCH 1/2] security: create task_free security callback Kees Cook
2011-12-21 20:17 [PATCH v10 0/2] security: Yama LSM Kees Cook
2011-12-21 20:17 ` [PATCH 1/2] security: create task_free security callback Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100630003933.GF4837@outflux.net \
    --to=kees.cook@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome