From: Oleg Nesterov <oleg@redhat.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
". James Morris" <jmorris@namei.org>,
linux-security-module@vger.kernel.org,
linux-kernel <linux-kernel@vger.kernel.org>,
David Howells <dhowells@redhat.com>
Subject: [PATCH 4/4] task_work: kill task_work->data
Date: Wed, 27 Jun 2012 20:38:28 +0200 [thread overview]
Message-ID: <20120627183828.GE23086@redhat.com> (raw)
In-Reply-To: <20120627183721.GA23086@redhat.com>
Kill task_work->data, this makes sizeof(task_work) == sizeof(rcu_head).
Turn cred->rcu into rcu_head/task_work union for keyctl_session_to_parent().
Suggested-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
include/linux/cred.h | 6 +++++-
include/linux/task_work.h | 4 +---
kernel/irq/manage.c | 2 +-
security/keys/keyctl.c | 31 +++++++++++--------------------
security/keys/process_keys.c | 3 +--
5 files changed, 19 insertions(+), 27 deletions(-)
diff --git a/include/linux/cred.h b/include/linux/cred.h
index ebbed2c..a24c353 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -18,6 +18,7 @@
#include <linux/selinux.h>
#include <linux/atomic.h>
#include <linux/uidgid.h>
+#include <linux/task_work.h>
struct user_struct;
struct cred;
@@ -149,7 +150,10 @@ struct cred {
struct user_struct *user; /* real user ID subscription */
struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
struct group_info *group_info; /* supplementary groups for euid/fsgid */
- struct rcu_head rcu; /* RCU deletion hook */
+ union {
+ struct rcu_head rcu; /* RCU deletion hook */
+ struct task_work twork; /* keyctl_session_to_parent() */
+ };
};
extern void __put_cred(struct cred *);
diff --git a/include/linux/task_work.h b/include/linux/task_work.h
index ef70b01..09e470d 100644
--- a/include/linux/task_work.h
+++ b/include/linux/task_work.h
@@ -8,14 +8,12 @@ typedef void (*task_work_func_t)(struct task_work *);
struct task_work {
struct task_work *next;
task_work_func_t func;
- void *data;
};
static inline void
-init_task_work(struct task_work *twork, task_work_func_t func, void *data)
+init_task_work(struct task_work *twork, task_work_func_t func)
{
twork->func = func;
- twork->data = data;
}
int task_work_add(struct task_struct *task, struct task_work *twork, bool);
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 8c54823..d1dd547 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -830,7 +830,7 @@ static int irq_thread(void *data)
sched_setscheduler(current, SCHED_FIFO, ¶m);
- init_task_work(&on_exit_work, irq_thread_dtor, NULL);
+ init_task_work(&on_exit_work, irq_thread_dtor);
task_work_add(current, &on_exit_work, false);
while (!irq_wait_for_interrupt(action)) {
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 0f5b3f0..f221cab 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -1456,8 +1456,8 @@ long keyctl_session_to_parent(void)
{
struct task_struct *me, *parent;
const struct cred *mycred, *pcred;
- struct task_work *newwork, *oldwork;
key_ref_t keyring_r;
+ struct task_work *oldwork;
struct cred *cred;
int ret;
@@ -1465,20 +1465,16 @@ long keyctl_session_to_parent(void)
if (IS_ERR(keyring_r))
return PTR_ERR(keyring_r);
- ret = -ENOMEM;
- newwork = kmalloc(sizeof(struct task_work), GFP_KERNEL);
- if (!newwork)
- goto error_keyring;
-
/* our parent is going to need a new cred struct, a new tgcred struct
* and new security data, so we allocate them here to prevent ENOMEM in
* our parent */
+ ret = -ENOMEM;
cred = cred_alloc_blank();
if (!cred)
- goto error_newwork;
+ goto error_keyring;
cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r);
- init_task_work(newwork, key_change_session_keyring, cred);
+ init_task_work(&cred->twork, key_change_session_keyring);
me = current;
rcu_read_lock();
@@ -1527,24 +1523,19 @@ long keyctl_session_to_parent(void)
/* the replacement session keyring is applied just prior to userspace
* restarting */
- ret = task_work_add(parent, newwork, true);
+ ret = task_work_add(parent, &cred->twork, true);
if (!ret)
- newwork = NULL;
+ cred = NULL;
unlock:
write_unlock_irq(&tasklist_lock);
rcu_read_unlock();
- if (oldwork) {
- put_cred(oldwork->data);
- kfree(oldwork);
- }
- if (newwork) {
- put_cred(newwork->data);
- kfree(newwork);
- }
+
+ if (oldwork)
+ put_cred(container_of(oldwork, struct cred, twork));
+ if (cred)
+ put_cred(cred);
return ret;
-error_newwork:
- kfree(newwork);
error_keyring:
key_ref_put(keyring_r);
return ret;
diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
index 4ad54ee..01303c2 100644
--- a/security/keys/process_keys.c
+++ b/security/keys/process_keys.c
@@ -837,9 +837,8 @@ error:
void key_change_session_keyring(struct task_work *twork)
{
const struct cred *old = current_cred();
- struct cred *new = twork->data;
+ struct cred *new = container_of(twork, struct cred, twork);
- kfree(twork);
if (unlikely(current->flags & PF_EXITING)) {
put_cred(new);
return;
--
1.5.5.1
next prev parent reply other threads:[~2012-06-27 18:40 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-22 12:44 deferring __fput() Mimi Zohar
2012-06-23 9:20 ` Al Viro
2012-06-23 19:45 ` Al Viro
2012-06-23 20:38 ` Oleg Nesterov
2012-06-23 21:01 ` Al Viro
2012-06-23 21:11 ` Al Viro
2012-06-24 4:16 ` Al Viro
2012-06-24 10:09 ` Al Viro
2012-06-24 16:54 ` Oleg Nesterov
2012-06-24 15:33 ` Oleg Nesterov
2012-06-25 6:03 ` Al Viro
2012-06-25 15:18 ` Oleg Nesterov
2012-06-27 18:37 ` [PATCH 0/4] Was: " Oleg Nesterov
2012-06-27 18:37 ` [PATCH 1/4] task_work: use the single-linked list to shrink sizeof(task_work) Oleg Nesterov
2012-06-27 18:37 ` [PATCH 2/4] task_work: don't rely on PF_EXITING Oleg Nesterov
2012-06-27 18:38 ` [PATCH 3/4] task_work: deal with task_work callbacks adding more work Oleg Nesterov
2012-06-27 18:38 ` Oleg Nesterov [this message]
2012-06-27 19:05 ` [PATCH 4/4] task_work: kill task_work->data Oleg Nesterov
2012-06-28 4:38 ` [PATCH 0/4] Was: deferring __fput() Al Viro
2012-06-28 16:22 ` Oleg Nesterov
2012-06-28 16:45 ` Oleg Nesterov
2012-06-30 6:24 ` Al Viro
2012-06-30 17:41 ` Oleg Nesterov
2012-06-29 5:30 ` Mimi Zohar
2012-06-29 8:33 ` Al Viro
2012-06-29 13:02 ` Mimi Zohar
2012-06-29 17:41 ` Al Viro
2012-06-29 21:38 ` Mimi Zohar
2012-06-29 23:56 ` Mimi Zohar
2012-06-30 5:02 ` Al Viro
2012-07-01 19:50 ` Mimi Zohar
2012-07-01 20:57 ` Al Viro
2012-07-02 1:46 ` Mimi Zohar
2012-07-02 3:43 ` Al Viro
2012-07-02 5:11 ` Al Viro
2012-07-02 11:49 ` Mimi Zohar
2012-07-02 12:02 ` Al Viro
2012-07-02 13:01 ` Mimi Zohar
2012-07-02 13:33 ` Al Viro
2012-07-02 14:50 ` Mimi Zohar
2012-08-21 13:05 ` [PATCH] task_work: add a scheduling point in task_work_run() Eric Dumazet
2012-08-21 20:37 ` Mimi Zohar
2012-08-21 21:32 ` Eric Dumazet
2012-08-22 3:13 ` Mimi Zohar
2012-08-22 5:27 ` Michael Wang
2012-08-22 5:38 ` Al Viro
2012-06-23 20:57 ` deferring __fput() Al Viro
2012-06-23 21:33 ` Al Viro
2012-06-24 15:20 ` Oleg Nesterov
2012-06-24 18:11 ` Oleg Nesterov
2012-06-25 12:03 ` Peter Zijlstra
2012-06-25 12:14 ` Al Viro
2012-06-25 13:19 ` Peter Zijlstra
2012-06-25 13:53 ` Al Viro
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=20120627183828.GE23086@redhat.com \
--to=oleg@redhat.com \
--cc=dhowells@redhat.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@ZenIV.linux.org.uk \
--cc=zohar@linux.vnet.ibm.com \
/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;
as well as URLs for NNTP newsgroup(s).