linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: hisilicon: Wipe entire pool on error
@ 2023-01-06  4:19 Kees Cook
  2023-01-06 16:07 ` Nathan Chancellor
  2023-01-07  1:55 ` Weili Qian
  0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2023-01-06  4:19 UTC (permalink / raw)
  To: Weili Qian
  Cc: Kees Cook, Nathan Chancellor, Zhou Wang, Herbert Xu,
	David S. Miller, linux-crypto, Nick Desaulniers, Tom Rix,
	linux-kernel, llvm, linux-hardening

To work around a Clang __builtin_object_size bug that shows up under
CONFIG_FORTIFY_SOURCE and UBSAN_BOUNDS, move the per-loop-iteration
mem_block wipe into a single wipe of the entire pool structure after
the loop.

Reported-by: Nathan Chancellor <nathan@kernel.org>
Link: https://github.com/ClangBuiltLinux/linux/issues/1780
Cc: Weili Qian <qianweili@huawei.com>
Cc: Zhou Wang <wangzhou1@hisilicon.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: linux-crypto@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/crypto/hisilicon/sgl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
index 2b6f2281cfd6..0974b0041405 100644
--- a/drivers/crypto/hisilicon/sgl.c
+++ b/drivers/crypto/hisilicon/sgl.c
@@ -124,9 +124,8 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
 	for (j = 0; j < i; j++) {
 		dma_free_coherent(dev, block_size, block[j].sgl,
 				  block[j].sgl_dma);
-		memset(block + j, 0, sizeof(*block));
 	}
-	kfree(pool);
+	kfree_sensitive(pool);
 	return ERR_PTR(-ENOMEM);
 }
 EXPORT_SYMBOL_GPL(hisi_acc_create_sgl_pool);
-- 
2.34.1


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

* Re: [PATCH] crypto: hisilicon: Wipe entire pool on error
  2023-01-06  4:19 [PATCH] crypto: hisilicon: Wipe entire pool on error Kees Cook
@ 2023-01-06 16:07 ` Nathan Chancellor
  2023-01-07  1:55 ` Weili Qian
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2023-01-06 16:07 UTC (permalink / raw)
  To: Kees Cook
  Cc: Weili Qian, Zhou Wang, Herbert Xu, David S. Miller, linux-crypto,
	Nick Desaulniers, Tom Rix, linux-kernel, llvm, linux-hardening

On Thu, Jan 05, 2023 at 08:19:48PM -0800, Kees Cook wrote:
> To work around a Clang __builtin_object_size bug that shows up under
> CONFIG_FORTIFY_SOURCE and UBSAN_BOUNDS, move the per-loop-iteration
> mem_block wipe into a single wipe of the entire pool structure after
> the loop.
> 
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1780
> Cc: Weili Qian <qianweili@huawei.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: linux-crypto@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Thanks for the patch!

Tested-by: Nathan Chancellor <nathan@kernel.org> # build

> ---
>  drivers/crypto/hisilicon/sgl.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
> index 2b6f2281cfd6..0974b0041405 100644
> --- a/drivers/crypto/hisilicon/sgl.c
> +++ b/drivers/crypto/hisilicon/sgl.c
> @@ -124,9 +124,8 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
>  	for (j = 0; j < i; j++) {
>  		dma_free_coherent(dev, block_size, block[j].sgl,
>  				  block[j].sgl_dma);
> -		memset(block + j, 0, sizeof(*block));
>  	}
> -	kfree(pool);
> +	kfree_sensitive(pool);
>  	return ERR_PTR(-ENOMEM);
>  }
>  EXPORT_SYMBOL_GPL(hisi_acc_create_sgl_pool);
> -- 
> 2.34.1
> 

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

* Re: [PATCH] crypto: hisilicon: Wipe entire pool on error
  2023-01-06  4:19 [PATCH] crypto: hisilicon: Wipe entire pool on error Kees Cook
  2023-01-06 16:07 ` Nathan Chancellor
@ 2023-01-07  1:55 ` Weili Qian
  1 sibling, 0 replies; 3+ messages in thread
From: Weili Qian @ 2023-01-07  1:55 UTC (permalink / raw)
  To: Kees Cook
  Cc: Nathan Chancellor, Zhou Wang, Herbert Xu, David S. Miller,
	linux-crypto, Nick Desaulniers, Tom Rix, linux-kernel, llvm,
	linux-hardening


On 2023/1/6 12:19, Kees Cook wrote:
> To work around a Clang __builtin_object_size bug that shows up under
> CONFIG_FORTIFY_SOURCE and UBSAN_BOUNDS, move the per-loop-iteration
> mem_block wipe into a single wipe of the entire pool structure after
> the loop.
> 
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1780
> Cc: Weili Qian <qianweili@huawei.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: linux-crypto@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/crypto/hisilicon/sgl.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
> index 2b6f2281cfd6..0974b0041405 100644
> --- a/drivers/crypto/hisilicon/sgl.c
> +++ b/drivers/crypto/hisilicon/sgl.c
> @@ -124,9 +124,8 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
>  	for (j = 0; j < i; j++) {
>  		dma_free_coherent(dev, block_size, block[j].sgl,
>  				  block[j].sgl_dma);
> -		memset(block + j, 0, sizeof(*block));
>  	}
> -	kfree(pool);
> +	kfree_sensitive(pool);
>  	return ERR_PTR(-ENOMEM);
>  }
>  EXPORT_SYMBOL_GPL(hisi_acc_create_sgl_pool);
> 
Thanks for your patch.

There is no sensitive data in the pool, so memset zero can be deleted directly.

Thanks,
Weili

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

end of thread, other threads:[~2023-01-07  1:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06  4:19 [PATCH] crypto: hisilicon: Wipe entire pool on error Kees Cook
2023-01-06 16:07 ` Nathan Chancellor
2023-01-07  1:55 ` Weili Qian

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).