2023-01-06 04:22:30

by Kees Cook

[permalink] [raw]
Subject: [PATCH] crypto: hisilicon: Wipe entire pool on error

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 <[email protected]>
Link: https://github.com/ClangBuiltLinux/linux/issues/1780
Cc: Weili Qian <[email protected]>
Cc: Zhou Wang <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
---
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


2023-01-06 16:09:35

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] crypto: hisilicon: Wipe entire pool on error

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 <[email protected]>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1780
> Cc: Weili Qian <[email protected]>
> Cc: Zhou Wang <[email protected]>
> Cc: Herbert Xu <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>

Thanks for the patch!

Tested-by: Nathan Chancellor <[email protected]> # 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
>

2023-01-07 01:58:38

by Weili Qian

[permalink] [raw]
Subject: Re: [PATCH] crypto: hisilicon: Wipe entire pool on error


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 <[email protected]>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1780
> Cc: Weili Qian <[email protected]>
> Cc: Zhou Wang <[email protected]>
> Cc: Herbert Xu <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>
> ---
> 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