diff mbox series

crypto: sun4i-ss: erase key after use

Message ID 20190915183536.3835-1-clabbe.montjoie@gmail.com (mailing list archive)
State New, archived
Headers show
Series crypto: sun4i-ss: erase key after use | expand

Commit Message

Corentin Labbe Sept. 15, 2019, 6:35 p.m. UTC
When a TFM is unregistered, the sun4i-ss driver does not clean the key used,
leaking it in memory.
This patch adds this absent key cleaning.

Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
Cc: <stable@vger.kernel.org> # 4.3+
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Eric Biggers Sept. 15, 2019, 8:16 p.m. UTC | #1
On Sun, Sep 15, 2019 at 08:35:36PM +0200, Corentin Labbe wrote:
> When a TFM is unregistered, the sun4i-ss driver does not clean the key used,
> leaking it in memory.
> This patch adds this absent key cleaning.
> 
> Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
> Cc: <stable@vger.kernel.org> # 4.3+
> Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
> ---
>  drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
> index fa4b1b47822e..60d99370a4ec 100644
> --- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
> +++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
> @@ -503,6 +503,8 @@ int sun4i_ss_cipher_init(struct crypto_tfm *tfm)
>  void sun4i_ss_cipher_exit(struct crypto_tfm *tfm)
>  {
>  	struct sun4i_tfm_ctx *op = crypto_tfm_ctx(tfm);
> +
> +	memzero_explicit(op->key, op->keylen);
>  	crypto_free_sync_skcipher(op->fallback_tfm);
>  }
>  
> -- 
> 2.21.0
> 

It's already zeroed by the kzfree() in crypto_destroy_tfm().

- Eric
Sasha Levin Sept. 16, 2019, 8:30 a.m. UTC | #2
Hi,

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag,
fixing commit: 6298e948215f crypto: sunxi-ss - Add Allwinner Security System crypto accelerator.

The bot has tested the following trees: v5.2.14, v4.19.72, v4.14.143, v4.9.192, v4.4.192.

v5.2.14: Build OK!
v4.19.72: Failed to apply! Possible dependencies:
    0ae1f46c55f8 ("crypto: sun4i-ss - fallback when length is not multiple of blocksize")

v4.14.143: Failed to apply! Possible dependencies:
    0ae1f46c55f8 ("crypto: sun4i-ss - fallback when length is not multiple of blocksize")
    249c8d98ea33 ("crypto: crypto4xx - move and refactor dynamic_contents helpers")
    2c95e6d97892 ("crypto: skcipher - remove useless setting of type flags")
    333eb3edda38 ("crypto: crypto4xx - fix type mismatch compiler error")
    40e3b847bff7 ("crypto: crypto4xx - replace crypto4xx_dev's scatter_buffer_size with constant")
    453e3090b9c3 ("crypto: crypto4xx - fix dynamic_sa_ctl's sa_contents declaration")
    4865b122d4af ("crypto: crypto4xx - use the correct LE32 format for IV and key defs")
    5c727f92ea5e ("crypto: crypto4xx - refactor crypto4xx_copy_pkt_to_dst()")
    81065f66dd99 ("crypto: crypto4xx - remove unused definitions and write-only variables")
    886c251fd4ca ("crypto: crypto4xx - remove extern statement before function declaration")
    8ef8d195430c ("crypto: crypto4xx - add backlog queue support")
    9e0a0b3a192a ("crypto: crypto4xx - pointer arithmetic overhaul")
    a0aae821ba3d ("crypto: crypto4xx - prepare for AEAD support")
    a8d79d7bfb14 ("crypto: crypto4xx - performance optimizations")
    cd4dcd6da7a2 ("crypto: crypto4xx - overhaul crypto4xx_build_pd()")
    ce05ffe10457 ("crypto: crypto4xx - convert to skcipher")
    f2a13e7cba9e ("crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads")

v4.9.192: Failed to apply! Possible dependencies:
    0ae1f46c55f8 ("crypto: sun4i-ss - fallback when length is not multiple of blocksize")
    249c8d98ea33 ("crypto: crypto4xx - move and refactor dynamic_contents helpers")
    2c95e6d97892 ("crypto: skcipher - remove useless setting of type flags")
    317cbacf720c ("crypto: sun4i-ss - move from ablkcipher to skcipher API")
    333eb3edda38 ("crypto: crypto4xx - fix type mismatch compiler error")
    40e3b847bff7 ("crypto: crypto4xx - replace crypto4xx_dev's scatter_buffer_size with constant")
    453e3090b9c3 ("crypto: crypto4xx - fix dynamic_sa_ctl's sa_contents declaration")
    4865b122d4af ("crypto: crypto4xx - use the correct LE32 format for IV and key defs")
    5c727f92ea5e ("crypto: crypto4xx - refactor crypto4xx_copy_pkt_to_dst()")
    81065f66dd99 ("crypto: crypto4xx - remove unused definitions and write-only variables")
    886c251fd4ca ("crypto: crypto4xx - remove extern statement before function declaration")
    8ef8d195430c ("crypto: crypto4xx - add backlog queue support")
    9e0a0b3a192a ("crypto: crypto4xx - pointer arithmetic overhaul")
    a0aae821ba3d ("crypto: crypto4xx - prepare for AEAD support")
    a595e60a70c0 ("crypto: sun4i-ss - remove conditional checks against 0")
    a8d79d7bfb14 ("crypto: crypto4xx - performance optimizations")
    cd4dcd6da7a2 ("crypto: crypto4xx - overhaul crypto4xx_build_pd()")
    ce05ffe10457 ("crypto: crypto4xx - convert to skcipher")
    f2a13e7cba9e ("crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads")

v4.4.192: Failed to apply! Possible dependencies:
    0ae1f46c55f8 ("crypto: sun4i-ss - fallback when length is not multiple of blocksize")
    249c8d98ea33 ("crypto: crypto4xx - move and refactor dynamic_contents helpers")
    2c95e6d97892 ("crypto: skcipher - remove useless setting of type flags")
    317cbacf720c ("crypto: sun4i-ss - move from ablkcipher to skcipher API")
    333eb3edda38 ("crypto: crypto4xx - fix type mismatch compiler error")
    40e3b847bff7 ("crypto: crypto4xx - replace crypto4xx_dev's scatter_buffer_size with constant")
    453e3090b9c3 ("crypto: crypto4xx - fix dynamic_sa_ctl's sa_contents declaration")
    477d9b2e591b ("crypto: sun4i-ss - unify update/final function")
    4865b122d4af ("crypto: crypto4xx - use the correct LE32 format for IV and key defs")
    5343e674f32f ("crypto4xx: integrate ppc4xx-rng into crypto4xx")
    81065f66dd99 ("crypto: crypto4xx - remove unused definitions and write-only variables")
    886c251fd4ca ("crypto: crypto4xx - remove extern statement before function declaration")
    9e0a0b3a192a ("crypto: crypto4xx - pointer arithmetic overhaul")
    a0aae821ba3d ("crypto: crypto4xx - prepare for AEAD support")
    a595e60a70c0 ("crypto: sun4i-ss - remove conditional checks against 0")
    a8d79d7bfb14 ("crypto: crypto4xx - performance optimizations")
    b6ff2fdd429c ("crypto: sun4i-ss - fix indentation of two crypto alg")
    bfb2892018ca ("crypto: sunxi - don't print confusing data")
    cd4dcd6da7a2 ("crypto: crypto4xx - overhaul crypto4xx_build_pd()")
    ce05ffe10457 ("crypto: crypto4xx - convert to skcipher")
    ea1a67414318 ("crypto: sun4i-ss - fix a few signed warning")
    f2a13e7cba9e ("crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads")


NOTE: The patch will not be queued to stable trees until it is upstream.

How should we proceed with this patch?

--
Thanks,
Sasha
diff mbox series

Patch

diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
index fa4b1b47822e..60d99370a4ec 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
@@ -503,6 +503,8 @@  int sun4i_ss_cipher_init(struct crypto_tfm *tfm)
 void sun4i_ss_cipher_exit(struct crypto_tfm *tfm)
 {
 	struct sun4i_tfm_ctx *op = crypto_tfm_ctx(tfm);
+
+	memzero_explicit(op->key, op->keylen);
 	crypto_free_sync_skcipher(op->fallback_tfm);
 }