Commit f8b34007 authored by Tom Lendacky's avatar Tom Lendacky Committed by Greg Kroah-Hartman

crypto: ccp - Don't assume export/import areas are aligned

commit b31dde2a upstream.

Use a local variable for the exported and imported state so that
alignment is not an issue. On export, set a local variable from the
request context and then memcpy the contents of the local variable to
the export memory area. On import, memcpy the import memory area into
a local variable and then use the local variable to set the request
context.
Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fafbde3a
...@@ -204,12 +204,15 @@ static int ccp_aes_cmac_digest(struct ahash_request *req) ...@@ -204,12 +204,15 @@ static int ccp_aes_cmac_digest(struct ahash_request *req)
static int ccp_aes_cmac_export(struct ahash_request *req, void *out) 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 *rctx = ahash_request_ctx(req);
struct ccp_aes_cmac_exp_ctx *state = out; struct ccp_aes_cmac_exp_ctx state;
state->null_msg = rctx->null_msg; state.null_msg = rctx->null_msg;
memcpy(state->iv, rctx->iv, sizeof(state->iv)); memcpy(state.iv, rctx->iv, sizeof(state.iv));
state->buf_count = rctx->buf_count; state.buf_count = rctx->buf_count;
memcpy(state->buf, rctx->buf, sizeof(state->buf)); memcpy(state.buf, rctx->buf, sizeof(state.buf));
/* 'out' may not be aligned so memcpy from local variable */
memcpy(out, &state, sizeof(state));
return 0; return 0;
} }
...@@ -217,12 +220,15 @@ static int ccp_aes_cmac_export(struct ahash_request *req, void *out) ...@@ -217,12 +220,15 @@ 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) static int ccp_aes_cmac_import(struct ahash_request *req, const void *in)
{ {
struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req); struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
const struct ccp_aes_cmac_exp_ctx *state = in; struct ccp_aes_cmac_exp_ctx state;
/* 'in' may not be aligned so memcpy to local variable */
memcpy(&state, in, sizeof(state));
rctx->null_msg = state->null_msg; rctx->null_msg = state.null_msg;
memcpy(rctx->iv, state->iv, sizeof(rctx->iv)); memcpy(rctx->iv, state.iv, sizeof(rctx->iv));
rctx->buf_count = state->buf_count; rctx->buf_count = state.buf_count;
memcpy(rctx->buf, state->buf, sizeof(rctx->buf)); memcpy(rctx->buf, state.buf, sizeof(rctx->buf));
return 0; return 0;
} }
......
...@@ -260,14 +260,17 @@ static int ccp_sha_digest(struct ahash_request *req) ...@@ -260,14 +260,17 @@ static int ccp_sha_digest(struct ahash_request *req)
static int ccp_sha_export(struct ahash_request *req, void *out) 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 *rctx = ahash_request_ctx(req);
struct ccp_sha_exp_ctx *state = out; struct ccp_sha_exp_ctx state;
state->type = rctx->type; state.type = rctx->type;
state->msg_bits = rctx->msg_bits; state.msg_bits = rctx->msg_bits;
state->first = rctx->first; state.first = rctx->first;
memcpy(state->ctx, rctx->ctx, sizeof(state->ctx)); memcpy(state.ctx, rctx->ctx, sizeof(state.ctx));
state->buf_count = rctx->buf_count; state.buf_count = rctx->buf_count;
memcpy(state->buf, rctx->buf, sizeof(state->buf)); memcpy(state.buf, rctx->buf, sizeof(state.buf));
/* 'out' may not be aligned so memcpy from local variable */
memcpy(out, &state, sizeof(state));
return 0; return 0;
} }
...@@ -275,14 +278,17 @@ static int ccp_sha_export(struct ahash_request *req, void *out) ...@@ -275,14 +278,17 @@ static int ccp_sha_export(struct ahash_request *req, void *out)
static int ccp_sha_import(struct ahash_request *req, const void *in) static int ccp_sha_import(struct ahash_request *req, const void *in)
{ {
struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req); struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
const struct ccp_sha_exp_ctx *state = in; struct ccp_sha_exp_ctx state;
rctx->type = state->type; /* 'in' may not be aligned so memcpy to local variable */
rctx->msg_bits = state->msg_bits; memcpy(&state, in, sizeof(state));
rctx->first = state->first;
memcpy(rctx->ctx, state->ctx, sizeof(rctx->ctx)); rctx->type = state.type;
rctx->buf_count = state->buf_count; rctx->msg_bits = state.msg_bits;
memcpy(rctx->buf, state->buf, sizeof(rctx->buf)); 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; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment