Skip to contentSkip to conversation

crypto: zeroization of buffers

PATCH In review Stephan Mueller 3 participants 5 messages Nov 11, 2014 – Nov 12, 2014 Crypto API

lore
Share & tools
lore
#0 lore raw

cover crypto: zeroization of buffers

Hi Herbert,

as discussed, these patches use the memzero_explicit function that is yet to be integrated into the cryptodev-2.6 tree.

Stephan Mueller (2):
crypto: AF_ALG - zeroize message digest buffer
crypto: AF_ALG - zeroize IV buffer

 crypto/algif_hash.c     | 2 ++
 crypto/algif_skcipher.c | 1 +
 2 files changed, 3 insertions(+)
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/2 crypto: AF_ALG - zeroize message digest buffer

Zeroize the buffer holding the message digest calculated for the consumer before the buffer is released by the hash AF_ALG interface handler.

---
 crypto/algif_hash.c | 2 ++
 1 file changed, 2 insertions(+)
crypto/algif_hash.c +2 -0
index 8502462..f75db4c 100644
@@ -258,6 +258,8 @@ static void hash_sock_destruct(struct sock *sk)
 	struct alg_sock *ask = alg_sk(sk);
 	struct hash_ctx *ctx = ask->private;
 
+	memzero_explicit(ctx->result,
+		     crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req)));
 	sock_kfree_s(sk, ctx->result,
 		     crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req)));
 	sock_kfree_s(sk, ctx, ctx->len);
Signature · 1 line
2.1.0
#2 lore raw

Re: [PATCH 1/2] crypto: AF_ALG - zeroize message digest buffer

Hi Stephan,

Quoted 14 lines · Stephan Mueller

Zeroize the buffer holding the message digest calculated for the consumer before the buffer is released by the hash AF_ALG interface handler.

---
  crypto/algif_hash.c | 2 ++
  1 file changed, 2 insertions(+)
crypto/algif_hash.c +0 -0
index 8502462..f75db4c 100644

crypto/algif_hash.c static void hash_sock_destruct(struct sock *sk) · line 263

Quoted 6 lines
crypto/algif_hash.c +2 -0
@@ -258,6 +258,8 @@ static void hash_sock_destruct(struct sock *sk)
  	struct alg_sock *ask = alg_sk(sk);
  	struct hash_ctx *ctx = ask->private;
 
+	memzero_explicit(ctx->result,
+		     crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req)));
  	sock_kfree_s(sk, ctx->result,

Perhaps something like this (alternatively kzfree() would work, too) ...

static void __sock_kfree_s(struct sock *sk, void *mem, int size,
bool clear_mem)

{
	if (WARN_ON_ONCE(!mem))
		return;
	if (clear_mem)
		memzero_explicit(mem, size);
	kfree(mem);
	atomic_sub(size, &sk->sk_omem_alloc);
}

void sock_kfree_s(struct sock *sk, void *mem, int size)

{
	__sock_kfree_s(sk, mem, size, false);
}

EXPORT_SYMBOL(sock_kfree_s);

void sock_kzfree_s(struct sock *sk, void *mem, int size)

{
	__sock_kfree_s(sk, mem, size, true);
}

EXPORT_SYMBOL(sock_kzfree_s);

... so you could then just use it as drop-in in various places:

sock_kzfree_s(sk, ctx->result, ...);

crypto/algif_hash.c static void hash_sock_destruct(struct sock *sk) · line 265

Quoted 3 lines
crypto/algif_hash.c +0 -0
  		     crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req)));
  	sock_kfree_s(sk, ctx, ctx->len);

Thanks,
Daniel

#3 lore raw

PATCH 2/2 crypto: AF_ALG - zeroize IV buffer

In reply to Stephan Mueller

Zeroize the buffer holding the IV used for the completed cipher operation before the buffer is released by the skcipher AF_ALG interface handler.

---
 crypto/algif_skcipher.c | 1 +
 1 file changed, 1 insertion(+)
crypto/algif_skcipher.c +1 -0
index 83187f4..85e3bdb 100644
@@ -566,6 +566,7 @@ static void skcipher_sock_destruct(struct sock *sk)
 	struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(&ctx->req);
 
 	skcipher_free_sgl(sk);
+	memzero_explicit(ctx->iv, crypto_ablkcipher_ivsize(tfm));
 	sock_kfree_s(sk, ctx->iv, crypto_ablkcipher_ivsize(tfm));
 	sock_kfree_s(sk, ctx, ctx->len);
 	af_alg_release_parent(sk);
Signature · 1 line
2.1.0
maintainer
#4 lore raw
In reply to Stephan Mueller
Quoted 5 lines · Stephan Mueller

Hi Herbert,

as discussed, these patches use the memzero_explicit function that is yet to be integrated into the cryptodev-2.6 tree.

Quoted 7 lines

Stephan Mueller (2):
crypto: AF_ALG - zeroize message digest buffer
crypto: AF_ALG - zeroize IV buffer

 crypto/algif_hash.c     | 2 ++
 crypto/algif_skcipher.c | 1 +
 2 files changed, 3 insertions(+)

All applied.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt