Skip to content

Commit

Permalink
CRED: Fix memory and refcount leaks upon security_prepare_creds() fai…
Browse files Browse the repository at this point in the history
…lure

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 <[email protected]>
Signed-off-by: David Howells <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Tetsuo Handa authored and torvalds committed Feb 7, 2011
1 parent 2edeaa3 commit fb2b2a1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/cred.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,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);

Expand All @@ -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);
put_cred(old);
validate_creds(new);
return new;
Expand Down

0 comments on commit fb2b2a1

Please sign in to comment.