stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] crypto: ccp - Limit the amount of information exported
@ 2016-01-29 18:45 Tom Lendacky
  2016-02-01 14:34 ` Herbert Xu
  2016-02-01 14:35 ` Herbert Xu
  0 siblings, 2 replies; 4+ messages in thread
From: Tom Lendacky @ 2016-01-29 18:45 UTC (permalink / raw)
  To: linux-crypto; +Cc: Herbert Xu, stable, David Miller

Since the exported information can be exposed to user-space, instead of
exporting the entire request context only export the minimum information
needed.

Cc: <stable@vger.kernel.org> # 3.14.x-
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 drivers/crypto/ccp/ccp-crypto-aes-cmac.c |   16 +++++++++++-----
 drivers/crypto/ccp/ccp-crypto-sha.c      |   20 +++++++++++++++-----
 drivers/crypto/ccp/ccp-crypto.h          |   22 ++++++++++++++++++++++
 3 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
index 00207cf..6a2d836 100644
--- a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
+++ b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
@@ -223,9 +223,12 @@ static int ccp_aes_cmac_digest(struct ahash_request *req)
 static int ccp_aes_cmac_export(struct ahash_request *req, void *out)
 {
 	struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
-	struct ccp_aes_cmac_req_ctx *state = out;
+	struct ccp_aes_cmac_exp_ctx *state = out;
 
-	*state = *rctx;
+	state->null_msg = rctx->null_msg;
+	memcpy(state->iv, rctx->iv, sizeof(state->iv));
+	state->buf_count = rctx->buf_count;
+	memcpy(state->buf, rctx->buf, sizeof(state->buf));
 
 	return 0;
 }
@@ -233,9 +236,12 @@ static int ccp_aes_cmac_export(struct ahash_request *req, void *out)
 static int ccp_aes_cmac_import(struct ahash_request *req, const void *in)
 {
 	struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
-	const struct ccp_aes_cmac_req_ctx *state = in;
+	const struct ccp_aes_cmac_exp_ctx *state = in;
 
-	*rctx = *state;
+	rctx->null_msg = state->null_msg;
+	memcpy(rctx->iv, state->iv, sizeof(rctx->iv));
+	rctx->buf_count = state->buf_count;
+	memcpy(rctx->buf, state->buf, sizeof(rctx->buf));
 
 	return 0;
 }
@@ -378,7 +384,7 @@ int ccp_register_aes_cmac_algs(struct list_head *head)
 
 	halg = &alg->halg;
 	halg->digestsize = AES_BLOCK_SIZE;
-	halg->statesize = sizeof(struct ccp_aes_cmac_req_ctx);
+	halg->statesize = sizeof(struct ccp_aes_cmac_exp_ctx);
 
 	base = &halg->base;
 	snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "cmac(aes)");
diff --git a/drivers/crypto/ccp/ccp-crypto-sha.c b/drivers/crypto/ccp/ccp-crypto-sha.c
index 3aae58d..a67128a 100644
--- a/drivers/crypto/ccp/ccp-crypto-sha.c
+++ b/drivers/crypto/ccp/ccp-crypto-sha.c
@@ -210,9 +210,14 @@ static int ccp_sha_digest(struct ahash_request *req)
 static int ccp_sha_export(struct ahash_request *req, void *out)
 {
 	struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
-	struct ccp_sha_req_ctx *state = out;
+	struct ccp_sha_exp_ctx *state = out;
 
-	*state = *rctx;
+	state->type = rctx->type;
+	state->msg_bits = rctx->msg_bits;
+	state->first = rctx->first;
+	memcpy(state->ctx, rctx->ctx, sizeof(state->ctx));
+	state->buf_count = rctx->buf_count;
+	memcpy(state->buf, rctx->buf, sizeof(state->buf));
 
 	return 0;
 }
@@ -220,9 +225,14 @@ static int ccp_sha_export(struct ahash_request *req, void *out)
 static int ccp_sha_import(struct ahash_request *req, const void *in)
 {
 	struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
-	const struct ccp_sha_req_ctx *state = in;
+	const struct ccp_sha_exp_ctx *state = in;
 
-	*rctx = *state;
+	rctx->type = state->type;
+	rctx->msg_bits = state->msg_bits;
+	rctx->first = state->first;
+	memcpy(rctx->ctx, state->ctx, sizeof(rctx->ctx));
+	rctx->buf_count = state->buf_count;
+	memcpy(rctx->buf, state->buf, sizeof(rctx->buf));
 
 	return 0;
 }
@@ -428,7 +438,7 @@ static int ccp_register_sha_alg(struct list_head *head,
 
 	halg = &alg->halg;
 	halg->digestsize = def->digest_size;
-	halg->statesize = sizeof(struct ccp_sha_req_ctx);
+	halg->statesize = sizeof(struct ccp_sha_exp_ctx);
 
 	base = &halg->base;
 	snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name);
diff --git a/drivers/crypto/ccp/ccp-crypto.h b/drivers/crypto/ccp/ccp-crypto.h
index 76a96f0..a326ec2 100644
--- a/drivers/crypto/ccp/ccp-crypto.h
+++ b/drivers/crypto/ccp/ccp-crypto.h
@@ -129,6 +129,15 @@ struct ccp_aes_cmac_req_ctx {
 	struct ccp_cmd cmd;
 };
 
+struct ccp_aes_cmac_exp_ctx {
+	unsigned int null_msg;
+
+	u8 iv[AES_BLOCK_SIZE];
+
+	unsigned int buf_count;
+	u8 buf[AES_BLOCK_SIZE];
+};
+
 /***** SHA related defines *****/
 #define MAX_SHA_CONTEXT_SIZE	SHA256_DIGEST_SIZE
 #define MAX_SHA_BLOCK_SIZE	SHA256_BLOCK_SIZE
@@ -171,6 +180,19 @@ struct ccp_sha_req_ctx {
 	struct ccp_cmd cmd;
 };
 
+struct ccp_sha_exp_ctx {
+	enum ccp_sha_type type;
+
+	u64 msg_bits;
+
+	unsigned int first;
+
+	u8 ctx[MAX_SHA_CONTEXT_SIZE];
+
+	unsigned int buf_count;
+	u8 buf[MAX_SHA_BLOCK_SIZE];
+};
+
 /***** Common Context Structure *****/
 struct ccp_ctx {
 	int (*complete)(struct crypto_async_request *req, int ret);


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

* Re: [PATCH v1] crypto: ccp - Limit the amount of information exported
  2016-01-29 18:45 [PATCH v1] crypto: ccp - Limit the amount of information exported Tom Lendacky
@ 2016-02-01 14:34 ` Herbert Xu
  2016-02-01 14:35 ` Herbert Xu
  1 sibling, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2016-02-01 14:34 UTC (permalink / raw)
  To: Tom Lendacky; +Cc: linux-crypto, stable, David Miller

On Fri, Jan 29, 2016 at 12:45:14PM -0600, Tom Lendacky wrote:
> Since the exported information can be exposed to user-space, instead of
> exporting the entire request context only export the minimum information
> needed.
> 
> Cc: <stable@vger.kernel.org> # 3.14.x-
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>

Applied.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH v1] crypto: ccp - Limit the amount of information exported
  2016-01-29 18:45 [PATCH v1] crypto: ccp - Limit the amount of information exported Tom Lendacky
  2016-02-01 14:34 ` Herbert Xu
@ 2016-02-01 14:35 ` Herbert Xu
  2016-02-01 22:18   ` Tom Lendacky
  1 sibling, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2016-02-01 14:35 UTC (permalink / raw)
  To: Tom Lendacky; +Cc: linux-crypto, stable, David Miller

On Fri, Jan 29, 2016 at 12:45:14PM -0600, Tom Lendacky wrote:
> Since the exported information can be exposed to user-space, instead of
> exporting the entire request context only export the minimum information
> needed.
> 
> Cc: <stable@vger.kernel.org> # 3.14.x-
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
>  drivers/crypto/ccp/ccp-crypto-aes-cmac.c |   16 +++++++++++-----
>  drivers/crypto/ccp/ccp-crypto-sha.c      |   20 +++++++++++++++-----
>  drivers/crypto/ccp/ccp-crypto.h          |   22 ++++++++++++++++++++++
>  3 files changed, 48 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
> index 00207cf..6a2d836 100644
> --- a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
> +++ b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
> @@ -223,9 +223,12 @@ static int ccp_aes_cmac_digest(struct ahash_request *req)
>  static int ccp_aes_cmac_export(struct ahash_request *req, void *out)
>  {
>  	struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
> -	struct ccp_aes_cmac_req_ctx *state = out;
> +	struct ccp_aes_cmac_exp_ctx *state = out;
>  
> -	*state = *rctx;
> +	state->null_msg = rctx->null_msg;
> +	memcpy(state->iv, rctx->iv, sizeof(state->iv));
> +	state->buf_count = rctx->buf_count;
> +	memcpy(state->buf, rctx->buf, sizeof(state->buf));
>  
>  	return 0;
>  }

BTW this code needs to be fixed to not assume that in/out are
aligned.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH v1] crypto: ccp - Limit the amount of information exported
  2016-02-01 14:35 ` Herbert Xu
@ 2016-02-01 22:18   ` Tom Lendacky
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Lendacky @ 2016-02-01 22:18 UTC (permalink / raw)
  To: Herbert Xu; +Cc: linux-crypto, stable, David Miller

On 02/01/2016 08:35 AM, Herbert Xu wrote:
> On Fri, Jan 29, 2016 at 12:45:14PM -0600, Tom Lendacky wrote:
>> Since the exported information can be exposed to user-space, instead of
>> exporting the entire request context only export the minimum information
>> needed.
>>
>> Cc: <stable@vger.kernel.org> # 3.14.x-
>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
>> ---
>>  drivers/crypto/ccp/ccp-crypto-aes-cmac.c |   16 +++++++++++-----
>>  drivers/crypto/ccp/ccp-crypto-sha.c      |   20 +++++++++++++++-----
>>  drivers/crypto/ccp/ccp-crypto.h          |   22 ++++++++++++++++++++++
>>  3 files changed, 48 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
>> index 00207cf..6a2d836 100644
>> --- a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
>> +++ b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
>> @@ -223,9 +223,12 @@ static int ccp_aes_cmac_digest(struct ahash_request *req)
>>  static int ccp_aes_cmac_export(struct ahash_request *req, void *out)
>>  {
>>  	struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
>> -	struct ccp_aes_cmac_req_ctx *state = out;
>> +	struct ccp_aes_cmac_exp_ctx *state = out;
>>  
>> -	*state = *rctx;
>> +	state->null_msg = rctx->null_msg;
>> +	memcpy(state->iv, rctx->iv, sizeof(state->iv));
>> +	state->buf_count = rctx->buf_count;
>> +	memcpy(state->buf, rctx->buf, sizeof(state->buf));
>>  
>>  	return 0;
>>  }
> 
> BTW this code needs to be fixed to not assume that in/out are
> aligned.
> 

Ugh, yeah I missed that.  I'll follow up with (yet) another patch
to be alignment safe.

Thanks,
Tom

> Cheers,
> 

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

end of thread, other threads:[~2016-02-01 23:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-29 18:45 [PATCH v1] crypto: ccp - Limit the amount of information exported Tom Lendacky
2016-02-01 14:34 ` Herbert Xu
2016-02-01 14:35 ` Herbert Xu
2016-02-01 22:18   ` Tom Lendacky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).