Commit eff30363 authored by David Howells's avatar David Howells Committed by James Morris

CRED: Fix double free in prepare_usermodehelper_creds() error handling

Patch 570b8fb5:

	Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
	Date:   Tue Mar 30 00:04:00 2010 +0100
	Subject: CRED: Fix memory leak in error handling

attempts to fix a memory leak in the error handling by making the offending
return statement into a jump down to the bottom of the function where a
kfree(tgcred) is inserted.

This is, however, incorrect, as it does a kfree() after doing put_cred() if
security_prepare_creds() fails.  That will result in a double free if 'error'
is jumped to as put_cred() will also attempt to free the new tgcred record by
virtue of it being pointed to by the new cred record.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent 05ce7bfe
...@@ -398,6 +398,8 @@ struct cred *prepare_usermodehelper_creds(void) ...@@ -398,6 +398,8 @@ struct cred *prepare_usermodehelper_creds(void)
error: error:
put_cred(new); put_cred(new);
return NULL;
free_tgcred: free_tgcred:
#ifdef CONFIG_KEYS #ifdef CONFIG_KEYS
kfree(tgcred); kfree(tgcred);
......
Markdown is supported
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