Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH 2/2] keys: added cleanup code for trusted and encrypted key types
@ 2010-10-07 12:30 Roberto Sassu
  2010-10-07 21:05 ` Mimi Zohar
  0 siblings, 1 reply; 3+ messages in thread
From: Roberto Sassu @ 2010-10-07 12:30 UTC (permalink / raw)
  To: Mimi Zohar, keyrings, linux-crypto, David Howells, David Safford,
	Rajiv 

[-- Attachment #1: Type: text/plain, Size: 1396 bytes --]

This patch frees the payload at the end of the instantiate
method of both trusted and encrypted key types if an error occurs.

Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
---
 security/keys/encrypted_defined.c |    6 ++++++
 security/keys/trusted_defined.c   |    4 ++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/security/keys/encrypted_defined.c b/security/keys/encrypted_defined.c
index 54c0f0f..8426e66 100644
--- a/security/keys/encrypted_defined.c
+++ b/security/keys/encrypted_defined.c
@@ -624,7 +624,13 @@ static int encrypted_instantiate(struct key *key, const void *data,
 	}
 	ret = encrypted_init(epayload, master_desc, decrypted_datalen,
 			     hex_encoded_iv, hex_encoded_data);
+	if (ret)
+		goto out_free_epayload;
+
 	rcu_assign_pointer(key->payload.data, epayload);
+out_free_epayload:
+	if (ret)
+		kfree(epayload);
 out:
 	kfree(datablob);
 	return ret > 0 ? -EINVAL : ret;
diff --git a/security/keys/trusted_defined.c b/security/keys/trusted_defined.c
index aedad16..ab7c7f9 100644
--- a/security/keys/trusted_defined.c
+++ b/security/keys/trusted_defined.c
@@ -848,6 +848,10 @@ static int trusted_instantiate(struct key *key, const void *data,
 out:
 	if (!ret)
 		rcu_assign_pointer(key->payload.data, p);
+	else {
+		if (p)
+			kfree(p);
+	}
 	kfree(datablob);
 	return ret;
 }
-- 
1.7.2.3


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 4707 bytes --]

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

* Re: [PATCH 2/2] keys: added cleanup code for trusted and encrypted key types
  2010-10-07 12:30 [PATCH 2/2] keys: added cleanup code for trusted and encrypted key types Roberto Sassu
@ 2010-10-07 21:05 ` Mimi Zohar
  2010-10-07 21:38   ` James Morris
  0 siblings, 1 reply; 3+ messages in thread
From: Mimi Zohar @ 2010-10-07 21:05 UTC (permalink / raw)
  To: Roberto Sassu
  Cc: keyrings, linux-crypto, David Howells, David Safford,
	Rajiv Andrade, linux-security-module

Thanks for catching this! This patch applies cleanly to the
trusted/encrypted patch set posted today.

thanks,

Acked-by: Mimi Zohar <zohar@us.ibm.com>

On Thu, 2010-10-07 at 14:30 +0200, Roberto Sassu wrote:
> This patch frees the payload at the end of the instantiate
> method of both trusted and encrypted key types if an error occurs.
> 
> Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
> ---
>  security/keys/encrypted_defined.c |    6 ++++++
>  security/keys/trusted_defined.c   |    4 ++++
>  2 files changed, 10 insertions(+), 0 deletions(-)
> 
> diff --git a/security/keys/encrypted_defined.c b/security/keys/encrypted_defined.c
> index 54c0f0f..8426e66 100644
> --- a/security/keys/encrypted_defined.c
> +++ b/security/keys/encrypted_defined.c
> @@ -624,7 +624,13 @@ static int encrypted_instantiate(struct key *key, const void *data,
>  	}
>  	ret = encrypted_init(epayload, master_desc, decrypted_datalen,
>  			     hex_encoded_iv, hex_encoded_data);
> +	if (ret)
> +		goto out_free_epayload;
> +
>  	rcu_assign_pointer(key->payload.data, epayload);
> +out_free_epayload:
> +	if (ret)
> +		kfree(epayload);
>  out:
>  	kfree(datablob);
>  	return ret > 0 ? -EINVAL : ret;
> diff --git a/security/keys/trusted_defined.c b/security/keys/trusted_defined.c
> index aedad16..ab7c7f9 100644
> --- a/security/keys/trusted_defined.c
> +++ b/security/keys/trusted_defined.c
> @@ -848,6 +848,10 @@ static int trusted_instantiate(struct key *key, const void *data,
>  out:
>  	if (!ret)
>  		rcu_assign_pointer(key->payload.data, p);
> +	else {
> +		if (p)
> +			kfree(p);
> +	}
>  	kfree(datablob);
>  	return ret;
>  }

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

* Re: [PATCH 2/2] keys: added cleanup code for trusted and encrypted key types
  2010-10-07 21:05 ` Mimi Zohar
@ 2010-10-07 21:38   ` James Morris
  0 siblings, 0 replies; 3+ messages in thread
From: James Morris @ 2010-10-07 21:38 UTC (permalink / raw)
  To: Mimi Zohar
  Cc: Roberto Sassu, keyrings, linux-crypto, David Howells,
	David Safford, Rajiv Andrade, linux-security-module

On Thu, 7 Oct 2010, Mimi Zohar wrote:

> Thanks for catching this! This patch applies cleanly to the
> trusted/encrypted patch set posted today.
> 
> thanks,
> 
> Acked-by: Mimi Zohar <zohar@us.ibm.com>

It's probably best if you incorporate these fixes into your patches, so we 
don't commit known-broken code into the tree.

-- 
James Morris
<jmorris@namei.org>

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

end of thread, other threads:[~2010-10-07 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-07 12:30 [PATCH 2/2] keys: added cleanup code for trusted and encrypted key types Roberto Sassu
2010-10-07 21:05 ` Mimi Zohar
2010-10-07 21:38   ` James Morris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox