2019-07-02 17:33:31

by Cfir Cohen

[permalink] [raw]
Subject: [PATCH v2] crypto: ccp/gcm - use const time tag comparison.

Avoid leaking GCM tag through timing side channel.

Fixes: 36cf515b9bbe ("crypto: ccp - Enable support for AES GCM on v5 CCPs")
Cc: <[email protected]> # v4.12+
Signed-off-by: Cfir Cohen <[email protected]>
---
drivers/crypto/ccp/ccp-ops.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
index db8de89d990f..633670220f6c 100644
--- a/drivers/crypto/ccp/ccp-ops.c
+++ b/drivers/crypto/ccp/ccp-ops.c
@@ -840,7 +840,8 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
if (ret)
goto e_tag;

- ret = memcmp(tag.address, final_wa.address, AES_BLOCK_SIZE);
+ ret = crypto_memneq(tag.address, final_wa.address,
+ AES_BLOCK_SIZE) ? -EBADMSG : 0;
ccp_dm_free(&tag);
}

--
2.22.0.410.gd8fdbe21b5-goog


2019-07-02 17:47:31

by Gary R Hook

[permalink] [raw]
Subject: Re: [PATCH v2] crypto: ccp/gcm - use const time tag comparison.

On 7/2/19 12:32 PM, Cfir Cohen wrote:
> Avoid leaking GCM tag through timing side channel.
>
> Fixes: 36cf515b9bbe ("crypto: ccp - Enable support for AES GCM on v5 CCPs")
> Cc: <[email protected]> # v4.12+
> Signed-off-by: Cfir Cohen <[email protected]>

Acked-by: Gary R Hook <[email protected]>

> ---
> drivers/crypto/ccp/ccp-ops.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
> index db8de89d990f..633670220f6c 100644
> --- a/drivers/crypto/ccp/ccp-ops.c
> +++ b/drivers/crypto/ccp/ccp-ops.c
> @@ -840,7 +840,8 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
> if (ret)
> goto e_tag;
>
> - ret = memcmp(tag.address, final_wa.address, AES_BLOCK_SIZE);
> + ret = crypto_memneq(tag.address, final_wa.address,
> + AES_BLOCK_SIZE) ? -EBADMSG : 0;
> ccp_dm_free(&tag);
> }
>
>