Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@polito.it>
To: Mimi Zohar <zohar@linux.vnet.ibm.com>,
	keyrings@linux-nfs.org, linux-crypto@vger.kernel.org,
	David Howells <dhowells@redhat.com>,
	David Safford <safford@watson.ibm.com>,
	Rajiv Andrade
Subject: [PATCH 2/2] keys: added cleanup code for trusted and encrypted key types
Date: Thu, 7 Oct 2010 14:30:45 +0200	[thread overview]
Message-ID: <201010071430.46281.roberto.sassu@polito.it> (raw)

[-- 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 --]

             reply	other threads:[~2010-10-07 12:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-07 12:30 Roberto Sassu [this message]
2010-10-07 21:05 ` [PATCH 2/2] keys: added cleanup code for trusted and encrypted key types Mimi Zohar
2010-10-07 21:38   ` James Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201010071430.46281.roberto.sassu@polito.it \
    --to=roberto.sassu@polito.it \
    --cc=dhowells@redhat.com \
    --cc=keyrings@linux-nfs.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=safford@watson.ibm.com \
    --cc=zohar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox