+ cred-fix-memory-and-refcount-leaks-upon-security_prepare_creds-failure.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     cred: fix memory and refcount leaks upon security_prepare_creds() failure
has been added to the -mm tree.  Its filename is
     cred-fix-memory-and-refcount-leaks-upon-security_prepare_creds-failure.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find
out what to do about this

The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/

------------------------------------------------------
Subject: cred: fix memory and refcount leaks upon security_prepare_creds() failure
From: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
Cc: James Morris <jmorris@xxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 kernel/cred.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN kernel/cred.c~cred-fix-memory-and-refcount-leaks-upon-security_prepare_creds-failure kernel/cred.c
--- a/kernel/cred.c~cred-fix-memory-and-refcount-leaks-upon-security_prepare_creds-failure
+++ a/kernel/cred.c
@@ -657,6 +657,8 @@ struct cred *prepare_kernel_cred(struct 
 	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);
 
@@ -674,8 +676,6 @@ struct cred *prepare_kernel_cred(struct 
 	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;
_

Patches currently in -mm which might be from penguin-kernel@xxxxxxxxxxxxxxxxxxx are

origin.patch
cred-fix-bug-upon-security_cred_alloc_blank-failure.patch
cred-fix-memory-and-refcount-leaks-upon-security_prepare_creds-failure.patch

--
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Kernel Newbies FAQ]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux