Commit fb2b2a1d authored by Tetsuo Handa's avatar Tetsuo Handa Committed by Linus Torvalds
Browse files

CRED: Fix memory and refcount leaks upon security_prepare_creds() failure

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: default avatarTetsuo Handa <>
Signed-off-by: default avatarDavid Howells <>
Signed-off-by: default avatarLinus Torvalds <>
parent 2edeaa34
......@@ -657,6 +657,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
*new = *old;
atomic_set(&new->usage, 1);
set_cred_subscribers(new, 0);
......@@ -674,8 +676,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);
return new;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment