Skip to content

Commit fb2b2a1

Browse files
Tetsuo Handatorvalds
authored andcommitted
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: 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>
1 parent 2edeaa3 commit fb2b2a1

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎kernel/cred.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
657657
validate_creds(old);
658658

659659
*new = *old;
660+
atomic_set(&new->usage, 1);
661+
set_cred_subscribers(new, 0);
660662
get_uid(new->user);
661663
get_group_info(new->group_info);
662664

@@ -674,8 +676,6 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
674676
if (security_prepare_creds(new, old, GFP_KERNEL) < 0)
675677
goto error;
676678

677-
atomic_set(&new->usage, 1);
678-
set_cred_subscribers(new, 0);
679679
put_cred(old);
680680
validate_creds(new);
681681
return new;

0 commit comments

Comments
 (0)