summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2011-02-07 13:36:16 +0000
committerGreg Kroah-Hartman <gregkh@suse.de>2011-03-21 12:45:06 -0700
commit8f2f330a85acad0e2eb6d8529ccde763ed49548a (patch)
tree16297488f8afa9d5f81f94a8e9050191ccfadd6d /kernel
parentfbca9e285c0131b2182c34aaf6836858483e5339 (diff)
CRED: Fix memory and refcount leaks upon security_prepare_creds() failure
commit fb2b2a1d37f80cc818fd4487b510f4e11816e5e1 upstream. In prepare_kernel_cred() since 2.6.29, put_cred(new) is called without assigning new->usage when security_prepare_creds() returned an error. As a result, memory for new and refcount for new->{user,group_info,tgcred} are leaked because put_cred(new) won't call __put_cred() unless old->usage == 1. Fix these leaks by assigning new->usage (and new->subscribers which was added in 2.6.32) before calling security_prepare_creds(). Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cred.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/kernel/cred.c b/kernel/cred.c
index f8b2c3c192ca..ddeba366eaff 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -721,6 +721,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
validate_creds(old);
*new = *old;
+ atomic_set(&new->usage, 1);
+ set_cred_subscribers(new, 0);
get_uid(new->user);
get_group_info(new->group_info);
@@ -738,8 +740,6 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
if (security_prepare_creds(new, old, GFP_KERNEL) < 0)
goto error;
- atomic_set(&new->usage, 1);
- set_cred_subscribers(new, 0);
put_cred(old);
validate_creds(new);
return new;