All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] cred: fix memory leak
@ 2010-01-06 17:01 Jiri Slaby
  2010-01-06 17:06 ` David Howells
  2010-01-06 17:25 ` Serge E. Hallyn
  0 siblings, 2 replies; 4+ messages in thread
From: Jiri Slaby @ 2010-01-06 17:01 UTC (permalink / raw)
  To: jmorris
  Cc: linux-security-module, linux-kernel, jirislaby, David Howells,
	Serge Hallyn

Stanse found a memory leak in prepare_exec_creds. tgcred is not
freed/assigned on all paths. Fix that.

I.e. unifdef tgcred and add kfree(tgcred); as it is initialized to
NULL already.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: David Howells <dhowells@redhat.com>
Cc: James Morris <jmorris@namei.org>
Cc: Serge Hallyn <serue@us.ibm.com>
---
 kernel/cred.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/cred.c b/kernel/cred.c
index dd76cfe..0e10f73 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -351,9 +351,7 @@ struct cred *prepare_exec_creds(void)
  */
 struct cred *prepare_usermodehelper_creds(void)
 {
-#ifdef CONFIG_KEYS
 	struct thread_group_cred *tgcred = NULL;
-#endif
 	struct cred *new;
 
 #ifdef CONFIG_KEYS
@@ -363,8 +361,10 @@ struct cred *prepare_usermodehelper_creds(void)
 #endif
 
 	new = kmem_cache_alloc(cred_jar, GFP_ATOMIC);
-	if (!new)
+	if (!new) {
+		kfree(tgcred);
 		return NULL;
+	}
 
 	kdebug("prepare_usermodehelper_creds() alloc %p", new);
 
-- 
1.6.5.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] cred: fix memory leak
  2010-01-06 17:01 [PATCH 1/1] cred: fix memory leak Jiri Slaby
@ 2010-01-06 17:06 ` David Howells
  2010-01-06 17:25 ` Serge E. Hallyn
  1 sibling, 0 replies; 4+ messages in thread
From: David Howells @ 2010-01-06 17:06 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: dhowells, jmorris, linux-security-module, linux-kernel, jirislaby,
	Serge Hallyn

Jiri Slaby <jslaby@suse.cz> wrote:

> Stanse found a memory leak in prepare_exec_creds. tgcred is not
> freed/assigned on all paths. Fix that.
> 
> I.e. unifdef tgcred and add kfree(tgcred); as it is initialized to
> NULL already.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: David Howells <dhowells@redhat.com>
> Cc: James Morris <jmorris@namei.org>
> Cc: Serge Hallyn <serue@us.ibm.com>

Acked-by: David Howells <dhowells@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] cred: fix memory leak
  2010-01-06 17:01 [PATCH 1/1] cred: fix memory leak Jiri Slaby
  2010-01-06 17:06 ` David Howells
@ 2010-01-06 17:25 ` Serge E. Hallyn
  2010-01-06 17:31   ` Jiri Slaby
  1 sibling, 1 reply; 4+ messages in thread
From: Serge E. Hallyn @ 2010-01-06 17:25 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: jmorris, linux-security-module, linux-kernel, jirislaby,
	David Howells

Quoting Jiri Slaby (jslaby@suse.cz):
> Stanse found a memory leak in prepare_exec_creds. tgcred is not
> freed/assigned on all paths. Fix that.
> 
> I.e. unifdef tgcred and add kfree(tgcred); as it is initialized to
> NULL already.

Does this compile with CONFIG_KEYS=n, , though?  I don't see a dummy
define for struct thread_group_cred in cred.h.  Should this patch add
one?

> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: David Howells <dhowells@redhat.com>
> Cc: James Morris <jmorris@namei.org>
> Cc: Serge Hallyn <serue@us.ibm.com>
> ---
>  kernel/cred.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/cred.c b/kernel/cred.c
> index dd76cfe..0e10f73 100644
> --- a/kernel/cred.c
> +++ b/kernel/cred.c
> @@ -351,9 +351,7 @@ struct cred *prepare_exec_creds(void)
>   */
>  struct cred *prepare_usermodehelper_creds(void)
>  {
> -#ifdef CONFIG_KEYS
>  	struct thread_group_cred *tgcred = NULL;
> -#endif
>  	struct cred *new;
> 
>  #ifdef CONFIG_KEYS
> @@ -363,8 +361,10 @@ struct cred *prepare_usermodehelper_creds(void)
>  #endif
> 
>  	new = kmem_cache_alloc(cred_jar, GFP_ATOMIC);
> -	if (!new)
> +	if (!new) {
> +		kfree(tgcred);
>  		return NULL;
> +	}
> 
>  	kdebug("prepare_usermodehelper_creds() alloc %p", new);
> 
> -- 
> 1.6.5.7

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] cred: fix memory leak
  2010-01-06 17:25 ` Serge E. Hallyn
@ 2010-01-06 17:31   ` Jiri Slaby
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2010-01-06 17:31 UTC (permalink / raw)
  To: Serge E. Hallyn
  Cc: Jiri Slaby, jmorris, linux-security-module, linux-kernel,
	David Howells

On 01/06/2010 06:25 PM, Serge E. Hallyn wrote:
> Quoting Jiri Slaby (jslaby@suse.cz):
>> Stanse found a memory leak in prepare_exec_creds. tgcred is not
>> freed/assigned on all paths. Fix that.
>>
>> I.e. unifdef tgcred and add kfree(tgcred); as it is initialized to
>> NULL already.
> 
> Does this compile with CONFIG_KEYS=n, , though? 

Yes and I guess it's due to no dereference of the pointer.

> Should this patch add one?

Hmm, I don't think so. The patch is ugly in the light of not having the
struct defined. I should come up with something where the CONFIG_KEYS is
left there.

thanks,
-- 
js

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-01-06 17:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-06 17:01 [PATCH 1/1] cred: fix memory leak Jiri Slaby
2010-01-06 17:06 ` David Howells
2010-01-06 17:25 ` Serge E. Hallyn
2010-01-06 17:31   ` Jiri Slaby

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.