dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
PATCH 1/1 dmaengine: stm32-mdma: Use struct_size() helper in devm_kzalloc()
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.
--- drivers/dma/stm32-mdma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/stm32-mdma.c +2 -1
@@ -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 ;
Signature · 1 line
2.27.0
Quoted 6 lines · Gustavo A. R. Silva
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.
Looks right to me.
Signature · 1 line
Kees Cook
Quoted 6 lines · Gustavo A. R. Silva
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.
Quoted 19 lines
--- drivers/dma/stm32-mdma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/dma/stm32-mdma.c +2
-1@@ -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 ;
Quoted 3 lines · Gustavo A. R. Silva
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
Signature · 1 line
~Vinod