All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
@ 2021-09-29 22:29 ` Gustavo A. R. Silva
  0 siblings, 0 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2021-09-29 22:29 UTC (permalink / raw)
  To: Vinod Koul, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Gustavo A. R. Silva, linux-hardening

Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worse scenario, could lead to heap overflows.

Link: https://github.com/KSPP/linux/issues/160
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/dma/stm32-mdma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 18cbd1e43c2e..d30a4a28d3bf 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -1566,7 +1566,8 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 	if (count < 0)
 		count = 0;
 
-	dmadev = devm_kzalloc(&pdev->dev, sizeof(*dmadev) + sizeof(u32) * count,
+	dmadev = devm_kzalloc(&pdev->dev,
+			      struct_size(dmadev, ahb_addr_masks, count),
 			      GFP_KERNEL);
 	if (!dmadev)
 		return -ENOMEM;
-- 
2.27.0


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

* [PATCH][next] dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
@ 2021-09-29 22:29 ` Gustavo A. R. Silva
  0 siblings, 0 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2021-09-29 22:29 UTC (permalink / raw)
  To: Vinod Koul, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Gustavo A. R. Silva, linux-hardening

Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worse scenario, could lead to heap overflows.

Link: https://github.com/KSPP/linux/issues/160
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/dma/stm32-mdma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 18cbd1e43c2e..d30a4a28d3bf 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -1566,7 +1566,8 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 	if (count < 0)
 		count = 0;
 
-	dmadev = devm_kzalloc(&pdev->dev, sizeof(*dmadev) + sizeof(u32) * count,
+	dmadev = devm_kzalloc(&pdev->dev,
+			      struct_size(dmadev, ahb_addr_masks, count),
 			      GFP_KERNEL);
 	if (!dmadev)
 		return -ENOMEM;
-- 
2.27.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
  2021-09-29 22:29 ` Gustavo A. R. Silva
@ 2021-09-30 18:00   ` Kees Cook
  -1 siblings, 0 replies; 8+ messages in thread
From: Kees Cook @ 2021-09-30 18:00 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Vinod Koul, Maxime Coquelin, Alexandre Torgue, dmaengine,
	linux-stm32, linux-arm-kernel, linux-kernel, linux-hardening

On Wed, Sep 29, 2021 at 05:29:22PM -0500, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worse scenario, could lead to heap overflows.
> 
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Looks right to me.

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

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

* Re: [PATCH][next] dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
@ 2021-09-30 18:00   ` Kees Cook
  0 siblings, 0 replies; 8+ messages in thread
From: Kees Cook @ 2021-09-30 18:00 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Vinod Koul, Maxime Coquelin, Alexandre Torgue, dmaengine,
	linux-stm32, linux-arm-kernel, linux-kernel, linux-hardening

On Wed, Sep 29, 2021 at 05:29:22PM -0500, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worse scenario, could lead to heap overflows.
> 
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Looks right to me.

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
  2021-09-29 22:29 ` Gustavo A. R. Silva
@ 2021-10-01  7:14   ` Amelie DELAUNAY
  -1 siblings, 0 replies; 8+ messages in thread
From: Amelie DELAUNAY @ 2021-10-01  7:14 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Vinod Koul, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel, linux-hardening



On 9/30/21 12:29 AM, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worse scenario, could lead to heap overflows.
> 
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Amelie Delaunay <amelie.delaunay@foss.st.com>

> ---
>   drivers/dma/stm32-mdma.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
> index 18cbd1e43c2e..d30a4a28d3bf 100644
> --- a/drivers/dma/stm32-mdma.c
> +++ b/drivers/dma/stm32-mdma.c
> @@ -1566,7 +1566,8 @@ static int stm32_mdma_probe(struct platform_device *pdev)
>   	if (count < 0)
>   		count = 0;
>   
> -	dmadev = devm_kzalloc(&pdev->dev, sizeof(*dmadev) + sizeof(u32) * count,
> +	dmadev = devm_kzalloc(&pdev->dev,
> +			      struct_size(dmadev, ahb_addr_masks, count),
>   			      GFP_KERNEL);
>   	if (!dmadev)
>   		return -ENOMEM;
> 

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

* Re: [PATCH][next] dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
@ 2021-10-01  7:14   ` Amelie DELAUNAY
  0 siblings, 0 replies; 8+ messages in thread
From: Amelie DELAUNAY @ 2021-10-01  7:14 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Vinod Koul, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel, linux-hardening



On 9/30/21 12:29 AM, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worse scenario, could lead to heap overflows.
> 
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Amelie Delaunay <amelie.delaunay@foss.st.com>

> ---
>   drivers/dma/stm32-mdma.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
> index 18cbd1e43c2e..d30a4a28d3bf 100644
> --- a/drivers/dma/stm32-mdma.c
> +++ b/drivers/dma/stm32-mdma.c
> @@ -1566,7 +1566,8 @@ static int stm32_mdma_probe(struct platform_device *pdev)
>   	if (count < 0)
>   		count = 0;
>   
> -	dmadev = devm_kzalloc(&pdev->dev, sizeof(*dmadev) + sizeof(u32) * count,
> +	dmadev = devm_kzalloc(&pdev->dev,
> +			      struct_size(dmadev, ahb_addr_masks, count),
>   			      GFP_KERNEL);
>   	if (!dmadev)
>   		return -ENOMEM;
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
  2021-09-29 22:29 ` Gustavo A. R. Silva
@ 2021-10-01 11:57   ` Vinod Koul
  -1 siblings, 0 replies; 8+ messages in thread
From: Vinod Koul @ 2021-10-01 11:57 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Maxime Coquelin, Alexandre Torgue, dmaengine, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-hardening

On 29-09-21, 17:29, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worse scenario, could lead to heap overflows.

Applied, thanks

-- 
~Vinod

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

* Re: [PATCH][next] dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
@ 2021-10-01 11:57   ` Vinod Koul
  0 siblings, 0 replies; 8+ messages in thread
From: Vinod Koul @ 2021-10-01 11:57 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Maxime Coquelin, Alexandre Torgue, dmaengine, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-hardening

On 29-09-21, 17:29, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worse scenario, could lead to heap overflows.

Applied, thanks

-- 
~Vinod

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-10-01 12:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 22:29 [PATCH][next] dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc() Gustavo A. R. Silva
2021-09-29 22:29 ` Gustavo A. R. Silva
2021-09-30 18:00 ` Kees Cook
2021-09-30 18:00   ` Kees Cook
2021-10-01  7:14 ` Amelie DELAUNAY
2021-10-01  7:14   ` Amelie DELAUNAY
2021-10-01 11:57 ` Vinod Koul
2021-10-01 11:57   ` Vinod Koul

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.