public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Trusted and Encrypted Keys: fix up TSS_rawhmac() so we always kfree() and remember to call va_end()
@ 2011-01-13 20:07 Jesper Juhl
  2011-01-14 13:28 ` David Safford
  2011-01-14 13:31 ` [PATCH] Trusted and Encrypted Keys: fix up TSS_rawhmac() so we always kfree() and remember to call va_end() David Howells
  0 siblings, 2 replies; 25+ messages in thread
From: Jesper Juhl @ 2011-01-13 20:07 UTC (permalink / raw)
  To: David Howells
  Cc: David Safford, James Morris, keyrings, linux-security-module,
	linux-kernel

In security/keys/trusted_defined.c::TSS_rawhmac() we may leak the storage 
allocated to 'sdesc' if
  data = va_arg(argp, unsigned char *);
results in a NULL 'data' and we then leave the function by returning 
-EINVAL. We also neglect calling va_end(argp) in that case and furthermore 
we neglect va_end(argp) if
  ret = crypto_shash_update(&sdesc->shash, data, dlen);
results in ret being negative and we then jump to the 'out' label.

I believe this patch takes care of these issues. Please review and 
consider for inclusion.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 trusted_defined.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

  compile tested only.

diff --git a/security/keys/trusted_defined.c b/security/keys/trusted_defined.c
index 975e9f2..0ec7ab8 100644
--- a/security/keys/trusted_defined.c
+++ b/security/keys/trusted_defined.c
@@ -101,16 +101,18 @@ static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
 		if (dlen == 0)
 			break;
 		data = va_arg(argp, unsigned char *);
-		if (data == NULL)
-			return -EINVAL;
+		if (data == NULL) {
+			ret = -EINVAL;
+			goto out;
+		}
 		ret = crypto_shash_update(&sdesc->shash, data, dlen);
 		if (ret < 0)
 			goto out;
 	}
-	va_end(argp);
 	if (!ret)
 		ret = crypto_shash_final(&sdesc->shash, digest);
 out:
+	va_end(argp);
 	kfree(sdesc);
 	return ret;
 }



-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.


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

end of thread, other threads:[~2011-01-18 22:55 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-13 20:07 [PATCH] Trusted and Encrypted Keys: fix up TSS_rawhmac() so we always kfree() and remember to call va_end() Jesper Juhl
2011-01-14 13:28 ` David Safford
2011-01-14 13:45   ` [PATCH] Trusted and Encrypted Keys: fix up TSS_rawhmac() so wealways " Tetsuo Handa
2011-01-14 14:07     ` Tetsuo Handa
2011-01-15  0:58       ` Tetsuo Handa
2011-01-16 14:04       ` Jesper Juhl
2011-01-17  0:39         ` [PATCH 1/3] trusted-keys: another free memory bugfix Tetsuo Handa
2011-01-17  0:41           ` [PATCH 2/3] trusted-keys: check for NULL before using it Tetsuo Handa
2011-01-17  0:44             ` [PATCH 3/3] trusted-keys: avoid scattring va_end() Tetsuo Handa
2011-01-17  9:39               ` David Howells
2011-01-17 18:36               ` Jesper Juhl
2011-01-17 21:06               ` Mimi Zohar
2011-01-18  1:39                 ` [PATCH 3/3] trusted-keys: small cleanup Tetsuo Handa
2011-01-18  9:26                   ` Mimi Zohar
2011-01-18 11:03                     ` Tetsuo Handa
2011-01-18 11:28                       ` Mimi Zohar
2011-01-18 11:42                         ` Mimi Zohar
2011-01-17  9:34             ` [PATCH 2/3] trusted-keys: check for NULL before using it David Howells
2011-01-17 18:35             ` Jesper Juhl
2011-01-17 21:02             ` Mimi Zohar
2011-01-17  9:33           ` [PATCH 1/3] trusted-keys: another free memory bugfix David Howells
2011-01-17 18:34           ` Jesper Juhl
2011-01-17 21:01           ` Mimi Zohar
2011-01-18 22:55           ` James Morris
2011-01-14 13:31 ` [PATCH] Trusted and Encrypted Keys: fix up TSS_rawhmac() so we always kfree() and remember to call va_end() David Howells

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