From: Tetsuo Handa Date: Mon, 7 Feb 2011 13:36:16 +0000 (+0000) Subject: CRED: Fix memory and refcount leaks upon security_prepare_creds() failure X-Git-Tag: v2.6.34.10~150 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=c14b55cd3067feb77ce8b745d49a043a45f50f44;p=karo-tx-linux.git 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 Signed-off-by: David Howells Signed-off-by: Linus Torvalds Signed-off-by: Paul Gortmaker --- diff --git a/kernel/cred.c b/kernel/cred.c index 9a85aeec4933..aa66d6f69f21 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -725,6 +725,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); @@ -742,8 +744,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;