[PATCH 2/2] keys: added cleanup code for trusted and encrypted key types

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

 



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@xxxxxxxxx>
---
 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: smime.p7s
Description: S/MIME cryptographic signature


[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux