linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: hisilicon - Cap block size at 2^31
@ 2020-06-04  7:37 Herbert Xu
  2020-06-04 13:54 ` Zhou Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Herbert Xu @ 2020-06-04  7:37 UTC (permalink / raw)
  To: Linux Crypto Mailing List, Zhou Wang, Shukun Tan

The function hisi_acc_create_sg_pool may allocate a block of
memory of size PAGE_SIZE * 2^(MAX_ORDER - 1).  This value may
exceed 2^31 on ia64, which would overflow the u32.

This patch caps it at 2^31.

Reported-by: kernel test robot <lkp@intel.com>
Fixes: d8ac7b85236b ("crypto: hisilicon - fix large sgl memory...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
index 0e8c7e324fb4..725a739800b0 100644
--- a/drivers/crypto/hisilicon/sgl.c
+++ b/drivers/crypto/hisilicon/sgl.c
@@ -66,7 +66,8 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
 
 	sgl_size = sizeof(struct acc_hw_sge) * sge_nr +
 		   sizeof(struct hisi_acc_hw_sgl);
-	block_size = PAGE_SIZE * (1 << (MAX_ORDER - 1));
+	block_size = 1 << (PAGE_SHIFT + MAX_ORDER <= 32 ?
+			   PAGE_SHIFT + MAX_ORDER - 1 : 31);
 	sgl_num_per_block = block_size / sgl_size;
 	block_num = count / sgl_num_per_block;
 	remain_sgl = count % sgl_num_per_block;
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH] crypto: hisilicon - Cap block size at 2^31
  2020-06-04  7:37 [PATCH] crypto: hisilicon - Cap block size at 2^31 Herbert Xu
@ 2020-06-04 13:54 ` Zhou Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Zhou Wang @ 2020-06-04 13:54 UTC (permalink / raw)
  To: Herbert Xu, Linux Crypto Mailing List, Shukun Tan

On 2020/6/4 15:37, Herbert Xu wrote:
> The function hisi_acc_create_sg_pool may allocate a block of
> memory of size PAGE_SIZE * 2^(MAX_ORDER - 1).  This value may
> exceed 2^31 on ia64, which would overflow the u32.
> 
> This patch caps it at 2^31.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Fixes: d8ac7b85236b ("crypto: hisilicon - fix large sgl memory...")
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Fine to me, Thanks!

> 
> diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
> index 0e8c7e324fb4..725a739800b0 100644
> --- a/drivers/crypto/hisilicon/sgl.c
> +++ b/drivers/crypto/hisilicon/sgl.c
> @@ -66,7 +66,8 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
>  
>  	sgl_size = sizeof(struct acc_hw_sge) * sge_nr +
>  		   sizeof(struct hisi_acc_hw_sgl);
> -	block_size = PAGE_SIZE * (1 << (MAX_ORDER - 1));
> +	block_size = 1 << (PAGE_SHIFT + MAX_ORDER <= 32 ?
> +			   PAGE_SHIFT + MAX_ORDER - 1 : 31);
>  	sgl_num_per_block = block_size / sgl_size;
>  	block_num = count / sgl_num_per_block;
>  	remain_sgl = count % sgl_num_per_block;
> 

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

end of thread, other threads:[~2020-06-04 13:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-04  7:37 [PATCH] crypto: hisilicon - Cap block size at 2^31 Herbert Xu
2020-06-04 13:54 ` Zhou Wang

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