linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/21] dmaengine: Annotate with __counted_by
@ 2023-08-17 23:58 Kees Cook
  2023-08-17 23:58 ` [PATCH 01/21] dmaengine: apple-admac: Annotate struct admac_data " Kees Cook
                   ` (22 more replies)
  0 siblings, 23 replies; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-kernel, dmaengine, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening

Hi,

This annotates several structures with the coming __counted_by attribute
for bounds checking of flexible arrays at run-time. For more details, see
commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro").

Thanks!

-Kees

Kees Cook (21):
  dmaengine: apple-admac: Annotate struct admac_data with __counted_by
  dmaengine: at_hdmac: Annotate struct at_desc with __counted_by
  dmaengine: axi-dmac: Annotate struct axi_dmac_desc with __counted_by
  dmaengine: fsl-edma: Annotate struct fsl_edma_desc with __counted_by
  dmaengine: hisilicon: Annotate struct hisi_dma_dev with __counted_by
  dmaengine: moxart-dma: Annotate struct moxart_desc with __counted_by
  dmaengine: qcom: bam_dma: Annotate struct bam_async_desc with
    __counted_by
  dmaengine: sa11x0: Annotate struct sa11x0_dma_desc with __counted_by
  dmaengine: sf-pdma: Annotate struct sf_pdma with __counted_by
  dmaengine: sprd: Annotate struct sprd_dma_dev with __counted_by
  dmaengine: st_fdma: Annotate struct st_fdma_desc with __counted_by
  dmaengine: stm32-dma: Annotate struct stm32_dma_desc with __counted_by
  dmaengine: stm32-mdma: Annotate struct stm32_mdma_desc with
    __counted_by
  dmaengine: stm32-mdma: Annotate struct stm32_mdma_device with
    __counted_by
  dmaengine: tegra: Annotate struct tegra_dma_desc with __counted_by
  dmaengine: tegra210-adma: Annotate struct tegra_adma with __counted_by
  dmaengine: ti: edma: Annotate struct edma_desc with __counted_by
  dmaengine: ti: omap-dma: Annotate struct omap_desc with __counted_by
  dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_desc with
    __counted_by
  dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_device with
    __counted_by
  dmaengine: usb-dmac: Annotate struct usb_dmac_desc with __counted_by

 drivers/dma/apple-admac.c      |  2 +-
 drivers/dma/at_hdmac.c         |  2 +-
 drivers/dma/dma-axi-dmac.c     |  5 ++---
 drivers/dma/fsl-edma-common.h  |  2 +-
 drivers/dma/hisi_dma.c         |  2 +-
 drivers/dma/moxart-dma.c       |  5 ++---
 drivers/dma/qcom/bam_dma.c     |  2 +-
 drivers/dma/sa11x0-dma.c       |  6 +++---
 drivers/dma/sf-pdma/sf-pdma.h  |  2 +-
 drivers/dma/sh/usb-dmac.c      |  2 +-
 drivers/dma/sprd-dma.c         |  2 +-
 drivers/dma/st_fdma.h          |  2 +-
 drivers/dma/stm32-dma.c        | 11 ++++-------
 drivers/dma/stm32-mdma.c       |  9 ++++-----
 drivers/dma/tegra186-gpc-dma.c |  2 +-
 drivers/dma/tegra210-adma.c    |  2 +-
 drivers/dma/ti/edma.c          |  2 +-
 drivers/dma/ti/omap-dma.c      |  5 ++---
 drivers/dma/uniphier-xdmac.c   |  8 ++++----
 19 files changed, 33 insertions(+), 40 deletions(-)

-- 
2.34.1


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

* [PATCH 01/21] dmaengine: apple-admac: Annotate struct admac_data with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:22   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 02/21] dmaengine: at_hdmac: Annotate struct at_desc " Kees Cook
                   ` (21 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Hector Martin, Sven Peter, Alyssa Rosenzweig, asahi,
	linux-arm-kernel, dmaengine, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-arm-msm, linux-stm32, linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct admac_data.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Hector Martin <marcan@marcan.st>
Cc: Sven Peter <sven@svenpeter.dev>
Cc: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Cc: asahi@lists.linux.dev
Cc: linux-arm-kernel@lists.infradead.org
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/apple-admac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c
index 3af795635c5c..ff46260b6ebc 100644
--- a/drivers/dma/apple-admac.c
+++ b/drivers/dma/apple-admac.c
@@ -128,7 +128,7 @@ struct admac_data {
 	int irq;
 	int irq_index;
 	int nchannels;
-	struct admac_chan channels[];
+	struct admac_chan channels[] __counted_by(nchannels);
 };
 
 struct admac_tx {
-- 
2.34.1


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

* [PATCH 02/21] dmaengine: at_hdmac: Annotate struct at_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
  2023-08-17 23:58 ` [PATCH 01/21] dmaengine: apple-admac: Annotate struct admac_data " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  2:14   ` Gustavo A. R. Silva
  2023-08-18  9:29   ` Tudor Ambarus
  2023-08-17 23:58 ` [PATCH 03/21] dmaengine: axi-dmac: Annotate struct axi_dmac_desc " Kees Cook
                   ` (20 subsequent siblings)
  22 siblings, 2 replies; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Ludovic Desroches, Tudor Ambarus, linux-arm-kernel,
	dmaengine, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-msm, linux-stm32, linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct at_desc.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
Cc: Tudor Ambarus <tudor.ambarus@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/at_hdmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index b2876f67471f..b66c7f416881 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -239,7 +239,7 @@ struct at_desc {
 	bool				memset_buffer;
 	dma_addr_t			memset_paddr;
 	int				*memset_vaddr;
-	struct atdma_sg			sg[];
+	struct atdma_sg			sg[] __counted_by(sglen);
 };
 
 /*--  Channels  --------------------------------------------------------*/
-- 
2.34.1


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

* [PATCH 03/21] dmaengine: axi-dmac: Annotate struct axi_dmac_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
  2023-08-17 23:58 ` [PATCH 01/21] dmaengine: apple-admac: Annotate struct admac_data " Kees Cook
  2023-08-17 23:58 ` [PATCH 02/21] dmaengine: at_hdmac: Annotate struct at_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  2:14   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 04/21] dmaengine: fsl-edma: Annotate struct fsl_edma_desc " Kees Cook
                   ` (19 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Lars-Peter Clausen, dmaengine, Hector Martin,
	Sven Peter, Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Zhou Wang, Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Green Wan, Orson Zhai, Baolin Wang, Chunyan Zhang,
	Patrice Chotard, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct axi_dmac_desc.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/dma-axi-dmac.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
index fc7cdad37161..b9f85cb20d3e 100644
--- a/drivers/dma/dma-axi-dmac.c
+++ b/drivers/dma/dma-axi-dmac.c
@@ -117,7 +117,7 @@ struct axi_dmac_desc {
 	unsigned int num_submitted;
 	unsigned int num_completed;
 	unsigned int num_sgs;
-	struct axi_dmac_sg sg[];
+	struct axi_dmac_sg sg[] __counted_by(num_sgs);
 };
 
 struct axi_dmac_chan {
@@ -484,12 +484,11 @@ static struct axi_dmac_desc *axi_dmac_alloc_desc(unsigned int num_sgs)
 	desc = kzalloc(struct_size(desc, sg, num_sgs), GFP_NOWAIT);
 	if (!desc)
 		return NULL;
+	desc->num_sgs = num_sgs;
 
 	for (i = 0; i < num_sgs; i++)
 		desc->sg[i].id = AXI_DMAC_SG_UNUSED;
 
-	desc->num_sgs = num_sgs;
-
 	return desc;
 }
 
-- 
2.34.1


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

* [PATCH 04/21] dmaengine: fsl-edma: Annotate struct fsl_edma_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (2 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 03/21] dmaengine: axi-dmac: Annotate struct axi_dmac_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:23   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 05/21] dmaengine: hisilicon: Annotate struct hisi_dma_dev " Kees Cook
                   ` (18 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, linux-arm-msm, linux-stm32, linux-tegra, llvm,
	linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct fsl_edma_desc.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/fsl-edma-common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/fsl-edma-common.h b/drivers/dma/fsl-edma-common.h
index 004ec4a6bc86..fdbc79787643 100644
--- a/drivers/dma/fsl-edma-common.h
+++ b/drivers/dma/fsl-edma-common.h
@@ -135,7 +135,7 @@ struct fsl_edma_desc {
 	bool				iscyclic;
 	enum dma_transfer_direction	dirn;
 	unsigned int			n_tcds;
-	struct fsl_edma_sw_tcd		tcd[];
+	struct fsl_edma_sw_tcd		tcd[] __counted_by(n_tcds);
 };
 
 enum edma_version {
-- 
2.34.1


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

* [PATCH 05/21] dmaengine: hisilicon: Annotate struct hisi_dma_dev with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (3 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 04/21] dmaengine: fsl-edma: Annotate struct fsl_edma_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:23   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 06/21] dmaengine: moxart-dma: Annotate struct moxart_desc " Kees Cook
                   ` (17 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Zhou Wang, Jie Hai, dmaengine, Hector Martin,
	Sven Peter, Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Green Wan, Orson Zhai, Baolin Wang, Chunyan Zhang,
	Patrice Chotard, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct hisi_dma_dev.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Zhou Wang <wangzhou1@hisilicon.com>
Cc: Jie Hai <haijie1@huawei.com>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/hisi_dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/hisi_dma.c b/drivers/dma/hisi_dma.c
index c1350a36fddd..4c47bff81064 100644
--- a/drivers/dma/hisi_dma.c
+++ b/drivers/dma/hisi_dma.c
@@ -163,7 +163,7 @@ struct hisi_dma_dev {
 	u32 chan_depth;
 	enum hisi_dma_reg_layout reg_layout;
 	void __iomem *queue_base; /* queue region start of register */
-	struct hisi_dma_chan chan[];
+	struct hisi_dma_chan chan[] __counted_by(chan_num);
 };
 
 #ifdef CONFIG_DEBUG_FS
-- 
2.34.1


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

* [PATCH 06/21] dmaengine: moxart-dma: Annotate struct moxart_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (4 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 05/21] dmaengine: hisilicon: Annotate struct hisi_dma_dev " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:23   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 07/21] dmaengine: qcom: bam_dma: Annotate struct bam_async_desc " Kees Cook
                   ` (16 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, linux-arm-msm, linux-stm32, linux-tegra, llvm,
	linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct moxart_desc.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/moxart-dma.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/moxart-dma.c b/drivers/dma/moxart-dma.c
index 7565ad98ba66..c1dd5716a46d 100644
--- a/drivers/dma/moxart-dma.c
+++ b/drivers/dma/moxart-dma.c
@@ -124,7 +124,7 @@ struct moxart_desc {
 	unsigned int			dma_cycles;
 	struct virt_dma_desc		vd;
 	uint8_t				es;
-	struct moxart_sg		sg[];
+	struct moxart_sg		sg[] __counted_by(sglen);
 };
 
 struct moxart_chan {
@@ -309,6 +309,7 @@ static struct dma_async_tx_descriptor *moxart_prep_slave_sg(
 	d = kzalloc(struct_size(d, sg, sg_len), GFP_ATOMIC);
 	if (!d)
 		return NULL;
+	d->sglen = sg_len;
 
 	d->dma_dir = dir;
 	d->dev_addr = dev_addr;
@@ -319,8 +320,6 @@ static struct dma_async_tx_descriptor *moxart_prep_slave_sg(
 		d->sg[i].len = sg_dma_len(sgent);
 	}
 
-	d->sglen = sg_len;
-
 	ch->error = 0;
 
 	return vchan_tx_prep(&ch->vc, &d->vd, tx_flags);
-- 
2.34.1


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

* [PATCH 07/21] dmaengine: qcom: bam_dma: Annotate struct bam_async_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (5 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 06/21] dmaengine: moxart-dma: Annotate struct moxart_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:24   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 08/21] dmaengine: sa11x0: Annotate struct sa11x0_dma_desc " Kees Cook
                   ` (15 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	linux-arm-msm, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, linux-stm32, linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct bam_async_desc.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Andy Gross <agross@kernel.org>
Cc: Bjorn Andersson <andersson@kernel.org>
Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
Cc: linux-arm-msm@vger.kernel.org
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/qcom/bam_dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
index 4c3eb972039d..65b89bb7a56b 100644
--- a/drivers/dma/qcom/bam_dma.c
+++ b/drivers/dma/qcom/bam_dma.c
@@ -74,7 +74,7 @@ struct bam_async_desc {
 	struct list_head desc_node;
 	enum dma_transfer_direction dir;
 	size_t length;
-	struct bam_desc_hw desc[];
+	struct bam_desc_hw desc[] __counted_by(num_desc);
 };
 
 enum bam_reg {
-- 
2.34.1


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

* [PATCH 08/21] dmaengine: sa11x0: Annotate struct sa11x0_dma_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (6 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 07/21] dmaengine: qcom: bam_dma: Annotate struct bam_async_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:24   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 09/21] dmaengine: sf-pdma: Annotate struct sf_pdma " Kees Cook
                   ` (14 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, linux-arm-msm, linux-stm32, linux-tegra, llvm,
	linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct sa11x0_dma_desc.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/sa11x0-dma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/sa11x0-dma.c b/drivers/dma/sa11x0-dma.c
index a29c13cae716..e5849622f198 100644
--- a/drivers/dma/sa11x0-dma.c
+++ b/drivers/dma/sa11x0-dma.c
@@ -78,7 +78,7 @@ struct sa11x0_dma_desc {
 	bool			cyclic;
 
 	unsigned		sglen;
-	struct sa11x0_dma_sg	sg[];
+	struct sa11x0_dma_sg	sg[] __counted_by(sglen);
 };
 
 struct sa11x0_dma_phy;
@@ -558,6 +558,7 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_slave_sg(
 		dev_dbg(chan->device->dev, "vchan %p: kzalloc failed\n", &c->vc);
 		return NULL;
 	}
+	txd->sglen = j;
 
 	j = 0;
 	for_each_sg(sg, sgent, sglen, i) {
@@ -593,7 +594,6 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_slave_sg(
 
 	txd->ddar = c->ddar;
 	txd->size = size;
-	txd->sglen = j;
 
 	dev_dbg(chan->device->dev, "vchan %p: txd %p: size %zu nr %u\n",
 		&c->vc, &txd->vd, txd->size, txd->sglen);
@@ -628,6 +628,7 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_dma_cyclic(
 		dev_dbg(chan->device->dev, "vchan %p: kzalloc failed\n", &c->vc);
 		return NULL;
 	}
+	txd->sglen = sglen;
 
 	for (i = k = 0; i < size / period; i++) {
 		size_t tlen, len = period;
@@ -653,7 +654,6 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_dma_cyclic(
 
 	txd->ddar = c->ddar;
 	txd->size = size;
-	txd->sglen = sglen;
 	txd->cyclic = 1;
 	txd->period = sgperiod;
 
-- 
2.34.1


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

* [PATCH 09/21] dmaengine: sf-pdma: Annotate struct sf_pdma with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (7 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 08/21] dmaengine: sa11x0: Annotate struct sa11x0_dma_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:24   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 10/21] dmaengine: sprd: Annotate struct sprd_dma_dev " Kees Cook
                   ` (13 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Green Wan, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Orson Zhai, Baolin Wang,
	Chunyan Zhang, Patrice Chotard, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct sf_pdma.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Green Wan <green.wan@sifive.com>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/sf-pdma/sf-pdma.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/sf-pdma/sf-pdma.h b/drivers/dma/sf-pdma/sf-pdma.h
index 5c398a83b491..d05772b5d8d3 100644
--- a/drivers/dma/sf-pdma/sf-pdma.h
+++ b/drivers/dma/sf-pdma/sf-pdma.h
@@ -113,7 +113,7 @@ struct sf_pdma {
 	void __iomem            *membase;
 	void __iomem            *mappedbase;
 	u32			n_chans;
-	struct sf_pdma_chan	chans[];
+	struct sf_pdma_chan	chans[] __counted_by(n_chans);
 };
 
 #endif /* _SF_PDMA_H */
-- 
2.34.1


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

* [PATCH 10/21] dmaengine: sprd: Annotate struct sprd_dma_dev with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (8 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 09/21] dmaengine: sf-pdma: Annotate struct sf_pdma " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:24   ` Gustavo A. R. Silva
  2023-08-18  7:18   ` Chunyan Zhang
  2023-08-17 23:58 ` [PATCH 11/21] dmaengine: st_fdma: Annotate struct st_fdma_desc " Kees Cook
                   ` (12 subsequent siblings)
  22 siblings, 2 replies; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Orson Zhai, Baolin Wang, Chunyan Zhang, dmaengine,
	Hector Martin, Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Tudor Ambarus, Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-kernel, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct sprd_dma_dev.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Orson Zhai <orsonzhai@gmail.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/sprd-dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c
index 168aa0bd73a0..07871dcc4593 100644
--- a/drivers/dma/sprd-dma.c
+++ b/drivers/dma/sprd-dma.c
@@ -212,7 +212,7 @@ struct sprd_dma_dev {
 	struct clk		*ashb_clk;
 	int			irq;
 	u32			total_chns;
-	struct sprd_dma_chn	channels[];
+	struct sprd_dma_chn	channels[] __counted_by(total_chns);
 };
 
 static void sprd_dma_free_desc(struct virt_dma_desc *vd);
-- 
2.34.1


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

* [PATCH 11/21] dmaengine: st_fdma: Annotate struct st_fdma_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (9 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 10/21] dmaengine: sprd: Annotate struct sprd_dma_dev " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:24   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 12/21] dmaengine: stm32-dma: Annotate struct stm32_dma_desc " Kees Cook
                   ` (11 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Patrice Chotard, linux-arm-kernel, dmaengine,
	Hector Martin, Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Tudor Ambarus, Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct st_fdma_desc.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/st_fdma.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/st_fdma.h b/drivers/dma/st_fdma.h
index fa15b97a3bab..f296412e96b6 100644
--- a/drivers/dma/st_fdma.h
+++ b/drivers/dma/st_fdma.h
@@ -97,7 +97,7 @@ struct st_fdma_desc {
 	struct st_fdma_chan *fchan;
 	bool iscyclic;
 	unsigned int n_nodes;
-	struct st_fdma_sw_node node[];
+	struct st_fdma_sw_node node[] __counted_by(n_nodes);
 };
 
 enum st_fdma_type {
-- 
2.34.1


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

* [PATCH 12/21] dmaengine: stm32-dma: Annotate struct stm32_dma_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (10 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 11/21] dmaengine: st_fdma: Annotate struct st_fdma_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:25   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 13/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_desc " Kees Cook
                   ` (10 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Maxime Coquelin, Alexandre Torgue, dmaengine,
	linux-stm32, linux-arm-kernel, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Laxman Dewangan,
	Jon Hunter, Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-msm, linux-tegra, llvm,
	linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct stm32_dma_desc.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: dmaengine@vger.kernel.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/stm32-dma.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 5c36811aa134..a732b3807b11 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -191,7 +191,7 @@ struct stm32_dma_desc {
 	struct virt_dma_desc vdesc;
 	bool cyclic;
 	u32 num_sgs;
-	struct stm32_dma_sg_req sg_req[];
+	struct stm32_dma_sg_req sg_req[] __counted_by(num_sgs);
 };
 
 /**
@@ -1105,6 +1105,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg(
 	desc = kzalloc(struct_size(desc, sg_req, sg_len), GFP_NOWAIT);
 	if (!desc)
 		return NULL;
+	desc->num_sgs = sg_len;
 
 	/* Set peripheral flow controller */
 	if (chan->dma_sconfig.device_fc)
@@ -1141,8 +1142,6 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg(
 			desc->sg_req[i].chan_reg.dma_sm1ar += sg_dma_len(sg);
 		desc->sg_req[i].chan_reg.dma_sndtr = nb_data_items;
 	}
-
-	desc->num_sgs = sg_len;
 	desc->cyclic = false;
 
 	return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
@@ -1216,6 +1215,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_cyclic(
 	desc = kzalloc(struct_size(desc, sg_req, num_periods), GFP_NOWAIT);
 	if (!desc)
 		return NULL;
+	desc->num_sgs = num_periods;
 
 	for (i = 0; i < num_periods; i++) {
 		desc->sg_req[i].len = period_len;
@@ -1232,8 +1232,6 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_cyclic(
 		if (!chan->trig_mdma)
 			buf_addr += period_len;
 	}
-
-	desc->num_sgs = num_periods;
 	desc->cyclic = true;
 
 	return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
@@ -1254,6 +1252,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
 	desc = kzalloc(struct_size(desc, sg_req, num_sgs), GFP_NOWAIT);
 	if (!desc)
 		return NULL;
+	desc->num_sgs = num_sgs;
 
 	threshold = chan->threshold;
 
@@ -1283,8 +1282,6 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
 		desc->sg_req[i].chan_reg.dma_sndtr = xfer_count;
 		desc->sg_req[i].len = xfer_count;
 	}
-
-	desc->num_sgs = num_sgs;
 	desc->cyclic = false;
 
 	return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
-- 
2.34.1


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

* [PATCH 13/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (11 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 12/21] dmaengine: stm32-dma: Annotate struct stm32_dma_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:25   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 14/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_device " Kees Cook
                   ` (9 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Maxime Coquelin, Alexandre Torgue, dmaengine,
	linux-stm32, linux-arm-kernel, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Laxman Dewangan,
	Jon Hunter, Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-msm, linux-tegra, llvm,
	linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct stm32_mdma_desc.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: dmaengine@vger.kernel.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/stm32-mdma.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 0de234022c6d..926d6ecf1274 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -224,7 +224,7 @@ struct stm32_mdma_desc {
 	u32 ccr;
 	bool cyclic;
 	u32 count;
-	struct stm32_mdma_desc_node node[];
+	struct stm32_mdma_desc_node node[] __counted_by(count);
 };
 
 struct stm32_mdma_dma_config {
@@ -321,6 +321,7 @@ static struct stm32_mdma_desc *stm32_mdma_alloc_desc(
 	desc = kzalloc(struct_size(desc, node, count), GFP_NOWAIT);
 	if (!desc)
 		return NULL;
+	desc->count = count;
 
 	for (i = 0; i < count; i++) {
 		desc->node[i].hwdesc =
@@ -330,8 +331,6 @@ static struct stm32_mdma_desc *stm32_mdma_alloc_desc(
 			goto err;
 	}
 
-	desc->count = count;
-
 	return desc;
 
 err:
-- 
2.34.1


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

* [PATCH 14/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_device with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (12 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 13/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  1:26   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 15/21] dmaengine: tegra: Annotate struct tegra_dma_desc " Kees Cook
                   ` (8 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Maxime Coquelin, Alexandre Torgue, dmaengine,
	linux-stm32, linux-arm-kernel, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Laxman Dewangan,
	Jon Hunter, Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-msm, linux-tegra, llvm,
	linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct stm32_mdma_device.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: dmaengine@vger.kernel.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/stm32-mdma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 926d6ecf1274..0c7d2295856e 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -256,7 +256,7 @@ struct stm32_mdma_device {
 	u32 nr_ahb_addr_masks;
 	u32 chan_reserved;
 	struct stm32_mdma_chan chan[STM32_MDMA_MAX_CHANNELS];
-	u32 ahb_addr_masks[];
+	u32 ahb_addr_masks[] __counted_by(nr_ahb_addr_masks);
 };
 
 static struct stm32_mdma_device *stm32_mdma_get_dev(
@@ -1611,13 +1611,13 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 			      GFP_KERNEL);
 	if (!dmadev)
 		return -ENOMEM;
+	dmadev->nr_ahb_addr_masks = count;
 
 	dmadev->nr_channels = nr_channels;
 	dmadev->nr_requests = nr_requests;
 	device_property_read_u32_array(&pdev->dev, "st,ahb-addr-masks",
 				       dmadev->ahb_addr_masks,
 				       count);
-	dmadev->nr_ahb_addr_masks = count;
 
 	dmadev->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(dmadev->base))
-- 
2.34.1


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

* [PATCH 15/21] dmaengine: tegra: Annotate struct tegra_dma_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (13 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 14/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_device " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  2:15   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 16/21] dmaengine: tegra210-adma: Annotate struct tegra_adma " Kees Cook
                   ` (7 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Laxman Dewangan, Jon Hunter, Thierry Reding, dmaengine,
	linux-tegra, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct tegra_dma_desc.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Laxman Dewangan <ldewangan@nvidia.com>
Cc: Jon Hunter <jonathanh@nvidia.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: dmaengine@vger.kernel.org
Cc: linux-tegra@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/tegra186-gpc-dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/tegra186-gpc-dma.c b/drivers/dma/tegra186-gpc-dma.c
index 33b101001100..5e3d5f5d1e20 100644
--- a/drivers/dma/tegra186-gpc-dma.c
+++ b/drivers/dma/tegra186-gpc-dma.c
@@ -221,7 +221,7 @@ struct tegra_dma_desc {
 	unsigned int sg_count;
 	struct virt_dma_desc vd;
 	struct tegra_dma_channel *tdc;
-	struct tegra_dma_sg_req sg_req[];
+	struct tegra_dma_sg_req sg_req[] __counted_by(sg_count);
 };
 
 /*
-- 
2.34.1


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

* [PATCH 16/21] dmaengine: tegra210-adma: Annotate struct tegra_adma with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (14 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 15/21] dmaengine: tegra: Annotate struct tegra_dma_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  2:15   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 17/21] dmaengine: ti: edma: Annotate struct edma_desc " Kees Cook
                   ` (6 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Laxman Dewangan, Jon Hunter, Thierry Reding, dmaengine,
	linux-tegra, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct tegra_adma.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Laxman Dewangan <ldewangan@nvidia.com>
Cc: Jon Hunter <jonathanh@nvidia.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: dmaengine@vger.kernel.org
Cc: linux-tegra@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/tegra210-adma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/tegra210-adma.c b/drivers/dma/tegra210-adma.c
index e557bada1510..cea33912a4c9 100644
--- a/drivers/dma/tegra210-adma.c
+++ b/drivers/dma/tegra210-adma.c
@@ -162,7 +162,7 @@ struct tegra_adma {
 	const struct tegra_adma_chip_data *cdata;
 
 	/* Last member of the structure */
-	struct tegra_adma_chan		channels[];
+	struct tegra_adma_chan		channels[] __counted_by(nr_channels);
 };
 
 static inline void tdma_write(struct tegra_adma *tdma, u32 reg, u32 val)
-- 
2.34.1


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

* [PATCH 17/21] dmaengine: ti: edma: Annotate struct edma_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (15 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 16/21] dmaengine: tegra210-adma: Annotate struct tegra_adma " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  2:15   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 18/21] dmaengine: ti: omap-dma: Annotate struct omap_desc " Kees Cook
                   ` (5 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Peter Ujfalusi, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct edma_desc.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/ti/edma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/ti/edma.c b/drivers/dma/ti/edma.c
index aa8e2e8ac260..9c2b2c4c3882 100644
--- a/drivers/dma/ti/edma.c
+++ b/drivers/dma/ti/edma.c
@@ -202,7 +202,7 @@ struct edma_desc {
 	u32				residue;
 	u32				residue_stat;
 
-	struct edma_pset		pset[];
+	struct edma_pset		pset[] __counted_by(pset_nr);
 };
 
 struct edma_cc;
-- 
2.34.1


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

* [PATCH 18/21] dmaengine: ti: omap-dma: Annotate struct omap_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (16 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 17/21] dmaengine: ti: edma: Annotate struct edma_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  2:15   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 19/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_desc " Kees Cook
                   ` (4 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Peter Ujfalusi, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct omap_desc.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/ti/omap-dma.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/ti/omap-dma.c b/drivers/dma/ti/omap-dma.c
index cf96cf915c0c..11ac3fc0a52a 100644
--- a/drivers/dma/ti/omap-dma.c
+++ b/drivers/dma/ti/omap-dma.c
@@ -124,7 +124,7 @@ struct omap_desc {
 	uint32_t csdp;		/* CSDP value */
 
 	unsigned sglen;
-	struct omap_sg sg[];
+	struct omap_sg sg[] __counted_by(sglen);
 };
 
 enum {
@@ -1005,6 +1005,7 @@ static struct dma_async_tx_descriptor *omap_dma_prep_slave_sg(
 	d = kzalloc(struct_size(d, sg, sglen), GFP_ATOMIC);
 	if (!d)
 		return NULL;
+	d->sglen = sglen;
 
 	d->dir = dir;
 	d->dev_addr = dev_addr;
@@ -1120,8 +1121,6 @@ static struct dma_async_tx_descriptor *omap_dma_prep_slave_sg(
 		}
 	}
 
-	d->sglen = sglen;
-
 	/* Release the dma_pool entries if one allocation failed */
 	if (ll_failed) {
 		for (i = 0; i < d->sglen; i++) {
-- 
2.34.1


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

* [PATCH 19/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (17 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 18/21] dmaengine: ti: omap-dma: Annotate struct omap_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  2:15   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 20/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_device " Kees Cook
                   ` (3 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Kunihiko Hayashi, Masami Hiramatsu, dmaengine,
	linux-arm-kernel, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct uniphier_xdmac_desc.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: dmaengine@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/uniphier-xdmac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/uniphier-xdmac.c b/drivers/dma/uniphier-xdmac.c
index 290836b7e1be..dd51522879a7 100644
--- a/drivers/dma/uniphier-xdmac.c
+++ b/drivers/dma/uniphier-xdmac.c
@@ -80,7 +80,7 @@ struct uniphier_xdmac_desc {
 	unsigned int nr_node;
 	unsigned int cur_node;
 	enum dma_transfer_direction dir;
-	struct uniphier_xdmac_desc_node nodes[];
+	struct uniphier_xdmac_desc_node nodes[] __counted_by(nr_node);
 };
 
 struct uniphier_xdmac_chan {
@@ -295,6 +295,7 @@ uniphier_xdmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
 	xd = kzalloc(struct_size(xd, nodes, nr), GFP_NOWAIT);
 	if (!xd)
 		return NULL;
+	xd->nr_node = nr;
 
 	for (i = 0; i < nr; i++) {
 		burst_size = min_t(size_t, len, XDMAC_MAX_WORD_SIZE);
@@ -309,7 +310,6 @@ uniphier_xdmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
 	}
 
 	xd->dir = DMA_MEM_TO_MEM;
-	xd->nr_node = nr;
 	xd->cur_node = 0;
 
 	return vchan_tx_prep(vc, &xd->vd, flags);
@@ -351,6 +351,7 @@ uniphier_xdmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 	xd = kzalloc(struct_size(xd, nodes, sg_len), GFP_NOWAIT);
 	if (!xd)
 		return NULL;
+	xd->nr_node = sg_len;
 
 	for_each_sg(sgl, sg, sg_len, i) {
 		xd->nodes[i].src = (direction == DMA_DEV_TO_MEM)
@@ -385,7 +386,6 @@ uniphier_xdmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 	}
 
 	xd->dir = direction;
-	xd->nr_node = sg_len;
 	xd->cur_node = 0;
 
 	return vchan_tx_prep(vc, &xd->vd, flags);
-- 
2.34.1


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

* [PATCH 20/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_device with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (18 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 19/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_desc " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  2:16   ` Gustavo A. R. Silva
  2023-08-17 23:58 ` [PATCH 21/21] dmaengine: usb-dmac: Annotate struct usb_dmac_desc " Kees Cook
                   ` (2 subsequent siblings)
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Kunihiko Hayashi, Masami Hiramatsu, dmaengine,
	linux-arm-kernel, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct uniphier_xdmac_device.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: dmaengine@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/uniphier-xdmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/uniphier-xdmac.c b/drivers/dma/uniphier-xdmac.c
index dd51522879a7..3a8ee2b173b5 100644
--- a/drivers/dma/uniphier-xdmac.c
+++ b/drivers/dma/uniphier-xdmac.c
@@ -97,7 +97,7 @@ struct uniphier_xdmac_device {
 	struct dma_device ddev;
 	void __iomem *reg_base;
 	int nr_chans;
-	struct uniphier_xdmac_chan channels[];
+	struct uniphier_xdmac_chan channels[] __counted_by(nr_chans);
 };
 
 static struct uniphier_xdmac_chan *
-- 
2.34.1


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

* [PATCH 21/21] dmaengine: usb-dmac: Annotate struct usb_dmac_desc with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (19 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 20/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_device " Kees Cook
@ 2023-08-17 23:58 ` Kees Cook
  2023-08-18  2:17   ` Gustavo A. R. Silva
  2023-09-15 20:08 ` [PATCH 00/21] dmaengine: Annotate " Kees Cook
  2023-09-28 11:56 ` Vinod Koul
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-08-17 23:58 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Kees Cook, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Tudor Ambarus, dmaengine, Hector Martin,
	Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, linux-arm-msm, linux-stm32, linux-tegra, llvm,
	linux-hardening

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct usb_dmac_desc.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Vinod Koul <vkoul@kernel.org>
Cc: Yu Kuai <yukuai3@huawei.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jordy Zomer <jordy@pwning.systems>
Cc: Jernej Skrabec <jernej.skrabec@gmail.com>
Cc: Tudor Ambarus <tudor.ambarus@linaro.org>
Cc: dmaengine@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/dma/sh/usb-dmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
index b14cf350b669..4cfcd23e3268 100644
--- a/drivers/dma/sh/usb-dmac.c
+++ b/drivers/dma/sh/usb-dmac.c
@@ -57,7 +57,7 @@ struct usb_dmac_desc {
 	u32 residue;
 	struct list_head node;
 	dma_cookie_t done_cookie;
-	struct usb_dmac_sg sg[];
+	struct usb_dmac_sg sg[] __counted_by(sg_allocated_len);
 };
 
 #define to_usb_dmac_desc(vd)	container_of(vd, struct usb_dmac_desc, vd)
-- 
2.34.1


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

* Re: [PATCH 01/21] dmaengine: apple-admac: Annotate struct admac_data with __counted_by
  2023-08-17 23:58 ` [PATCH 01/21] dmaengine: apple-admac: Annotate struct admac_data " Kees Cook
@ 2023-08-18  1:22   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:22 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, asahi,
	linux-arm-kernel, dmaengine, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-arm-msm, linux-stm32, linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct admac_data.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Hector Martin <marcan@marcan.st>
> Cc: Sven Peter <sven@svenpeter.dev>
> Cc: Alyssa Rosenzweig <alyssa@rosenzweig.io>
> Cc: asahi@lists.linux.dev
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/apple-admac.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c
> index 3af795635c5c..ff46260b6ebc 100644
> --- a/drivers/dma/apple-admac.c
> +++ b/drivers/dma/apple-admac.c
> @@ -128,7 +128,7 @@ struct admac_data {
>   	int irq;
>   	int irq_index;
>   	int nchannels;
> -	struct admac_chan channels[];
> +	struct admac_chan channels[] __counted_by(nchannels);
>   };
>   
>   struct admac_tx {

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

* Re: [PATCH 04/21] dmaengine: fsl-edma: Annotate struct fsl_edma_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 04/21] dmaengine: fsl-edma: Annotate struct fsl_edma_desc " Kees Cook
@ 2023-08-18  1:23   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:23 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: dmaengine, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-kernel, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct fsl_edma_desc.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/fsl-edma-common.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/fsl-edma-common.h b/drivers/dma/fsl-edma-common.h
> index 004ec4a6bc86..fdbc79787643 100644
> --- a/drivers/dma/fsl-edma-common.h
> +++ b/drivers/dma/fsl-edma-common.h
> @@ -135,7 +135,7 @@ struct fsl_edma_desc {
>   	bool				iscyclic;
>   	enum dma_transfer_direction	dirn;
>   	unsigned int			n_tcds;
> -	struct fsl_edma_sw_tcd		tcd[];
> +	struct fsl_edma_sw_tcd		tcd[] __counted_by(n_tcds);
>   };
>   
>   enum edma_version {

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

* Re: [PATCH 05/21] dmaengine: hisilicon: Annotate struct hisi_dma_dev with __counted_by
  2023-08-17 23:58 ` [PATCH 05/21] dmaengine: hisilicon: Annotate struct hisi_dma_dev " Kees Cook
@ 2023-08-18  1:23   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:23 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Zhou Wang, Jie Hai, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Green Wan, Orson Zhai, Baolin Wang, Chunyan Zhang,
	Patrice Chotard, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct hisi_dma_dev.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Jie Hai <haijie1@huawei.com>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/hisi_dma.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/hisi_dma.c b/drivers/dma/hisi_dma.c
> index c1350a36fddd..4c47bff81064 100644
> --- a/drivers/dma/hisi_dma.c
> +++ b/drivers/dma/hisi_dma.c
> @@ -163,7 +163,7 @@ struct hisi_dma_dev {
>   	u32 chan_depth;
>   	enum hisi_dma_reg_layout reg_layout;
>   	void __iomem *queue_base; /* queue region start of register */
> -	struct hisi_dma_chan chan[];
> +	struct hisi_dma_chan chan[] __counted_by(chan_num);
>   };
>   
>   #ifdef CONFIG_DEBUG_FS

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

* Re: [PATCH 06/21] dmaengine: moxart-dma: Annotate struct moxart_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 06/21] dmaengine: moxart-dma: Annotate struct moxart_desc " Kees Cook
@ 2023-08-18  1:23   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:23 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: dmaengine, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-kernel, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct moxart_desc.
> Additionally, since the element count member must be set before accessing
> the annotated flexible array member, move its initialization earlier.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/moxart-dma.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/moxart-dma.c b/drivers/dma/moxart-dma.c
> index 7565ad98ba66..c1dd5716a46d 100644
> --- a/drivers/dma/moxart-dma.c
> +++ b/drivers/dma/moxart-dma.c
> @@ -124,7 +124,7 @@ struct moxart_desc {
>   	unsigned int			dma_cycles;
>   	struct virt_dma_desc		vd;
>   	uint8_t				es;
> -	struct moxart_sg		sg[];
> +	struct moxart_sg		sg[] __counted_by(sglen);
>   };
>   
>   struct moxart_chan {
> @@ -309,6 +309,7 @@ static struct dma_async_tx_descriptor *moxart_prep_slave_sg(
>   	d = kzalloc(struct_size(d, sg, sg_len), GFP_ATOMIC);
>   	if (!d)
>   		return NULL;
> +	d->sglen = sg_len;
>   
>   	d->dma_dir = dir;
>   	d->dev_addr = dev_addr;
> @@ -319,8 +320,6 @@ static struct dma_async_tx_descriptor *moxart_prep_slave_sg(
>   		d->sg[i].len = sg_dma_len(sgent);
>   	}
>   
> -	d->sglen = sg_len;
> -
>   	ch->error = 0;
>   
>   	return vchan_tx_prep(&ch->vc, &d->vd, tx_flags);

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

* Re: [PATCH 07/21] dmaengine: qcom: bam_dma: Annotate struct bam_async_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 07/21] dmaengine: qcom: bam_dma: Annotate struct bam_async_desc " Kees Cook
@ 2023-08-18  1:24   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:24 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, linux-arm-msm,
	dmaengine, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Green Wan, Orson Zhai, Baolin Wang, Chunyan Zhang,
	Patrice Chotard, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-stm32,
	linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct bam_async_desc.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Andy Gross <agross@kernel.org>
> Cc: Bjorn Andersson <andersson@kernel.org>
> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/qcom/bam_dma.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
> index 4c3eb972039d..65b89bb7a56b 100644
> --- a/drivers/dma/qcom/bam_dma.c
> +++ b/drivers/dma/qcom/bam_dma.c
> @@ -74,7 +74,7 @@ struct bam_async_desc {
>   	struct list_head desc_node;
>   	enum dma_transfer_direction dir;
>   	size_t length;
> -	struct bam_desc_hw desc[];
> +	struct bam_desc_hw desc[] __counted_by(num_desc);
>   };
>   
>   enum bam_reg {

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

* Re: [PATCH 08/21] dmaengine: sa11x0: Annotate struct sa11x0_dma_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 08/21] dmaengine: sa11x0: Annotate struct sa11x0_dma_desc " Kees Cook
@ 2023-08-18  1:24   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:24 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: dmaengine, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-kernel, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct sa11x0_dma_desc.
> Additionally, since the element count member must be set before accessing
> the annotated flexible array member, move its initialization earlier.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/sa11x0-dma.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/sa11x0-dma.c b/drivers/dma/sa11x0-dma.c
> index a29c13cae716..e5849622f198 100644
> --- a/drivers/dma/sa11x0-dma.c
> +++ b/drivers/dma/sa11x0-dma.c
> @@ -78,7 +78,7 @@ struct sa11x0_dma_desc {
>   	bool			cyclic;
>   
>   	unsigned		sglen;
> -	struct sa11x0_dma_sg	sg[];
> +	struct sa11x0_dma_sg	sg[] __counted_by(sglen);
>   };
>   
>   struct sa11x0_dma_phy;
> @@ -558,6 +558,7 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_slave_sg(
>   		dev_dbg(chan->device->dev, "vchan %p: kzalloc failed\n", &c->vc);
>   		return NULL;
>   	}
> +	txd->sglen = j;
>   
>   	j = 0;
>   	for_each_sg(sg, sgent, sglen, i) {
> @@ -593,7 +594,6 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_slave_sg(
>   
>   	txd->ddar = c->ddar;
>   	txd->size = size;
> -	txd->sglen = j;
>   
>   	dev_dbg(chan->device->dev, "vchan %p: txd %p: size %zu nr %u\n",
>   		&c->vc, &txd->vd, txd->size, txd->sglen);
> @@ -628,6 +628,7 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_dma_cyclic(
>   		dev_dbg(chan->device->dev, "vchan %p: kzalloc failed\n", &c->vc);
>   		return NULL;
>   	}
> +	txd->sglen = sglen;
>   
>   	for (i = k = 0; i < size / period; i++) {
>   		size_t tlen, len = period;
> @@ -653,7 +654,6 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_dma_cyclic(
>   
>   	txd->ddar = c->ddar;
>   	txd->size = size;
> -	txd->sglen = sglen;
>   	txd->cyclic = 1;
>   	txd->period = sgperiod;
>   

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

* Re: [PATCH 09/21] dmaengine: sf-pdma: Annotate struct sf_pdma with __counted_by
  2023-08-17 23:58 ` [PATCH 09/21] dmaengine: sf-pdma: Annotate struct sf_pdma " Kees Cook
@ 2023-08-18  1:24   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:24 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Green Wan, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Orson Zhai, Baolin Wang,
	Chunyan Zhang, Patrice Chotard, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct sf_pdma.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Green Wan <green.wan@sifive.com>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/sf-pdma/sf-pdma.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/sf-pdma/sf-pdma.h b/drivers/dma/sf-pdma/sf-pdma.h
> index 5c398a83b491..d05772b5d8d3 100644
> --- a/drivers/dma/sf-pdma/sf-pdma.h
> +++ b/drivers/dma/sf-pdma/sf-pdma.h
> @@ -113,7 +113,7 @@ struct sf_pdma {
>   	void __iomem            *membase;
>   	void __iomem            *mappedbase;
>   	u32			n_chans;
> -	struct sf_pdma_chan	chans[];
> +	struct sf_pdma_chan	chans[] __counted_by(n_chans);
>   };
>   
>   #endif /* _SF_PDMA_H */

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

* Re: [PATCH 10/21] dmaengine: sprd: Annotate struct sprd_dma_dev with __counted_by
  2023-08-17 23:58 ` [PATCH 10/21] dmaengine: sprd: Annotate struct sprd_dma_dev " Kees Cook
@ 2023-08-18  1:24   ` Gustavo A. R. Silva
  2023-08-18  7:18   ` Chunyan Zhang
  1 sibling, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:24 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Orson Zhai, Baolin Wang, Chunyan Zhang, dmaengine, Hector Martin,
	Sven Peter, Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-kernel, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct sprd_dma_dev.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Orson Zhai <orsonzhai@gmail.com>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: Chunyan Zhang <zhang.lyra@gmail.com>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/sprd-dma.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c
> index 168aa0bd73a0..07871dcc4593 100644
> --- a/drivers/dma/sprd-dma.c
> +++ b/drivers/dma/sprd-dma.c
> @@ -212,7 +212,7 @@ struct sprd_dma_dev {
>   	struct clk		*ashb_clk;
>   	int			irq;
>   	u32			total_chns;
> -	struct sprd_dma_chn	channels[];
> +	struct sprd_dma_chn	channels[] __counted_by(total_chns);
>   };
>   
>   static void sprd_dma_free_desc(struct virt_dma_desc *vd);

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

* Re: [PATCH 11/21] dmaengine: st_fdma: Annotate struct st_fdma_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 11/21] dmaengine: st_fdma: Annotate struct st_fdma_desc " Kees Cook
@ 2023-08-18  1:24   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:24 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Patrice Chotard, linux-arm-kernel, dmaengine, Hector Martin,
	Sven Peter, Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct st_fdma_desc.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Patrice Chotard <patrice.chotard@foss.st.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/st_fdma.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/st_fdma.h b/drivers/dma/st_fdma.h
> index fa15b97a3bab..f296412e96b6 100644
> --- a/drivers/dma/st_fdma.h
> +++ b/drivers/dma/st_fdma.h
> @@ -97,7 +97,7 @@ struct st_fdma_desc {
>   	struct st_fdma_chan *fchan;
>   	bool iscyclic;
>   	unsigned int n_nodes;
> -	struct st_fdma_sw_node node[];
> +	struct st_fdma_sw_node node[] __counted_by(n_nodes);
>   };
>   
>   enum st_fdma_type {

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

* Re: [PATCH 12/21] dmaengine: stm32-dma: Annotate struct stm32_dma_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 12/21] dmaengine: stm32-dma: Annotate struct stm32_dma_desc " Kees Cook
@ 2023-08-18  1:25   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:25 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Maxime Coquelin, Alexandre Torgue, dmaengine, linux-stm32,
	linux-arm-kernel, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-msm, linux-tegra, llvm,
	linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct stm32_dma_desc.
> Additionally, since the element count member must be set before accessing
> the annotated flexible array member, move its initialization earlier.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
> Cc: dmaengine@vger.kernel.org
> Cc: linux-stm32@st-md-mailman.stormreply.com
> Cc: linux-arm-kernel@lists.infradead.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/stm32-dma.c | 11 ++++-------
>   1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
> index 5c36811aa134..a732b3807b11 100644
> --- a/drivers/dma/stm32-dma.c
> +++ b/drivers/dma/stm32-dma.c
> @@ -191,7 +191,7 @@ struct stm32_dma_desc {
>   	struct virt_dma_desc vdesc;
>   	bool cyclic;
>   	u32 num_sgs;
> -	struct stm32_dma_sg_req sg_req[];
> +	struct stm32_dma_sg_req sg_req[] __counted_by(num_sgs);
>   };
>   
>   /**
> @@ -1105,6 +1105,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg(
>   	desc = kzalloc(struct_size(desc, sg_req, sg_len), GFP_NOWAIT);
>   	if (!desc)
>   		return NULL;
> +	desc->num_sgs = sg_len;
>   
>   	/* Set peripheral flow controller */
>   	if (chan->dma_sconfig.device_fc)
> @@ -1141,8 +1142,6 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg(
>   			desc->sg_req[i].chan_reg.dma_sm1ar += sg_dma_len(sg);
>   		desc->sg_req[i].chan_reg.dma_sndtr = nb_data_items;
>   	}
> -
> -	desc->num_sgs = sg_len;
>   	desc->cyclic = false;
>   
>   	return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
> @@ -1216,6 +1215,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_cyclic(
>   	desc = kzalloc(struct_size(desc, sg_req, num_periods), GFP_NOWAIT);
>   	if (!desc)
>   		return NULL;
> +	desc->num_sgs = num_periods;
>   
>   	for (i = 0; i < num_periods; i++) {
>   		desc->sg_req[i].len = period_len;
> @@ -1232,8 +1232,6 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_cyclic(
>   		if (!chan->trig_mdma)
>   			buf_addr += period_len;
>   	}
> -
> -	desc->num_sgs = num_periods;
>   	desc->cyclic = true;
>   
>   	return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
> @@ -1254,6 +1252,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
>   	desc = kzalloc(struct_size(desc, sg_req, num_sgs), GFP_NOWAIT);
>   	if (!desc)
>   		return NULL;
> +	desc->num_sgs = num_sgs;
>   
>   	threshold = chan->threshold;
>   
> @@ -1283,8 +1282,6 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
>   		desc->sg_req[i].chan_reg.dma_sndtr = xfer_count;
>   		desc->sg_req[i].len = xfer_count;
>   	}
> -
> -	desc->num_sgs = num_sgs;
>   	desc->cyclic = false;
>   
>   	return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);

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

* Re: [PATCH 13/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 13/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_desc " Kees Cook
@ 2023-08-18  1:25   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:25 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Maxime Coquelin, Alexandre Torgue, dmaengine, linux-stm32,
	linux-arm-kernel, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-msm, linux-tegra, llvm,
	linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct stm32_mdma_desc.
> Additionally, since the element count member must be set before accessing
> the annotated flexible array member, move its initialization earlier.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
> Cc: dmaengine@vger.kernel.org
> Cc: linux-stm32@st-md-mailman.stormreply.com
> Cc: linux-arm-kernel@lists.infradead.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/stm32-mdma.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
> index 0de234022c6d..926d6ecf1274 100644
> --- a/drivers/dma/stm32-mdma.c
> +++ b/drivers/dma/stm32-mdma.c
> @@ -224,7 +224,7 @@ struct stm32_mdma_desc {
>   	u32 ccr;
>   	bool cyclic;
>   	u32 count;
> -	struct stm32_mdma_desc_node node[];
> +	struct stm32_mdma_desc_node node[] __counted_by(count);
>   };
>   
>   struct stm32_mdma_dma_config {
> @@ -321,6 +321,7 @@ static struct stm32_mdma_desc *stm32_mdma_alloc_desc(
>   	desc = kzalloc(struct_size(desc, node, count), GFP_NOWAIT);
>   	if (!desc)
>   		return NULL;
> +	desc->count = count;
>   
>   	for (i = 0; i < count; i++) {
>   		desc->node[i].hwdesc =
> @@ -330,8 +331,6 @@ static struct stm32_mdma_desc *stm32_mdma_alloc_desc(
>   			goto err;
>   	}
>   
> -	desc->count = count;
> -
>   	return desc;
>   
>   err:

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

* Re: [PATCH 14/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_device with __counted_by
  2023-08-17 23:58 ` [PATCH 14/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_device " Kees Cook
@ 2023-08-18  1:26   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  1:26 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Maxime Coquelin, Alexandre Torgue, dmaengine, linux-stm32,
	linux-arm-kernel, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-msm, linux-tegra, llvm,
	linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct stm32_mdma_device.
> Additionally, since the element count member must be set before accessing
> the annotated flexible array member, move its initialization earlier.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
> Cc: dmaengine@vger.kernel.org
> Cc: linux-stm32@st-md-mailman.stormreply.com
> Cc: linux-arm-kernel@lists.infradead.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/stm32-mdma.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
> index 926d6ecf1274..0c7d2295856e 100644
> --- a/drivers/dma/stm32-mdma.c
> +++ b/drivers/dma/stm32-mdma.c
> @@ -256,7 +256,7 @@ struct stm32_mdma_device {
>   	u32 nr_ahb_addr_masks;
>   	u32 chan_reserved;
>   	struct stm32_mdma_chan chan[STM32_MDMA_MAX_CHANNELS];
> -	u32 ahb_addr_masks[];
> +	u32 ahb_addr_masks[] __counted_by(nr_ahb_addr_masks);
>   };
>   
>   static struct stm32_mdma_device *stm32_mdma_get_dev(
> @@ -1611,13 +1611,13 @@ static int stm32_mdma_probe(struct platform_device *pdev)
>   			      GFP_KERNEL);
>   	if (!dmadev)
>   		return -ENOMEM;
> +	dmadev->nr_ahb_addr_masks = count;
>   
>   	dmadev->nr_channels = nr_channels;
>   	dmadev->nr_requests = nr_requests;
>   	device_property_read_u32_array(&pdev->dev, "st,ahb-addr-masks",
>   				       dmadev->ahb_addr_masks,
>   				       count);
> -	dmadev->nr_ahb_addr_masks = count;
>   
>   	dmadev->base = devm_platform_ioremap_resource(pdev, 0);
>   	if (IS_ERR(dmadev->base))

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

* Re: [PATCH 02/21] dmaengine: at_hdmac: Annotate struct at_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 02/21] dmaengine: at_hdmac: Annotate struct at_desc " Kees Cook
@ 2023-08-18  2:14   ` Gustavo A. R. Silva
  2023-08-18  9:29   ` Tudor Ambarus
  1 sibling, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  2:14 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Ludovic Desroches, Tudor Ambarus, linux-arm-kernel, dmaengine,
	Hector Martin, Sven Peter, Alyssa Rosenzweig, Lars-Peter Clausen,
	Zhou Wang, Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Green Wan, Orson Zhai, Baolin Wang, Chunyan Zhang,
	Patrice Chotard, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct at_desc.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
> Cc: Tudor Ambarus <tudor.ambarus@linaro.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/at_hdmac.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
> index b2876f67471f..b66c7f416881 100644
> --- a/drivers/dma/at_hdmac.c
> +++ b/drivers/dma/at_hdmac.c
> @@ -239,7 +239,7 @@ struct at_desc {
>   	bool				memset_buffer;
>   	dma_addr_t			memset_paddr;
>   	int				*memset_vaddr;
> -	struct atdma_sg			sg[];
> +	struct atdma_sg			sg[] __counted_by(sglen);
>   };
>   
>   /*--  Channels  --------------------------------------------------------*/

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

* Re: [PATCH 03/21] dmaengine: axi-dmac: Annotate struct axi_dmac_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 03/21] dmaengine: axi-dmac: Annotate struct axi_dmac_desc " Kees Cook
@ 2023-08-18  2:14   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  2:14 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Lars-Peter Clausen, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-kernel, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct axi_dmac_desc.
> Additionally, since the element count member must be set before accessing
> the annotated flexible array member, move its initialization earlier.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/dma-axi-dmac.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
> index fc7cdad37161..b9f85cb20d3e 100644
> --- a/drivers/dma/dma-axi-dmac.c
> +++ b/drivers/dma/dma-axi-dmac.c
> @@ -117,7 +117,7 @@ struct axi_dmac_desc {
>   	unsigned int num_submitted;
>   	unsigned int num_completed;
>   	unsigned int num_sgs;
> -	struct axi_dmac_sg sg[];
> +	struct axi_dmac_sg sg[] __counted_by(num_sgs);
>   };
>   
>   struct axi_dmac_chan {
> @@ -484,12 +484,11 @@ static struct axi_dmac_desc *axi_dmac_alloc_desc(unsigned int num_sgs)
>   	desc = kzalloc(struct_size(desc, sg, num_sgs), GFP_NOWAIT);
>   	if (!desc)
>   		return NULL;
> +	desc->num_sgs = num_sgs;
>   
>   	for (i = 0; i < num_sgs; i++)
>   		desc->sg[i].id = AXI_DMAC_SG_UNUSED;
>   
> -	desc->num_sgs = num_sgs;
> -
>   	return desc;
>   }
>   

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

* Re: [PATCH 15/21] dmaengine: tegra: Annotate struct tegra_dma_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 15/21] dmaengine: tegra: Annotate struct tegra_dma_desc " Kees Cook
@ 2023-08-18  2:15   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  2:15 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Laxman Dewangan, Jon Hunter, Thierry Reding, dmaengine,
	linux-tegra, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct tegra_dma_desc.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Laxman Dewangan <ldewangan@nvidia.com>
> Cc: Jon Hunter <jonathanh@nvidia.com>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Cc: dmaengine@vger.kernel.org
> Cc: linux-tegra@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/tegra186-gpc-dma.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/tegra186-gpc-dma.c b/drivers/dma/tegra186-gpc-dma.c
> index 33b101001100..5e3d5f5d1e20 100644
> --- a/drivers/dma/tegra186-gpc-dma.c
> +++ b/drivers/dma/tegra186-gpc-dma.c
> @@ -221,7 +221,7 @@ struct tegra_dma_desc {
>   	unsigned int sg_count;
>   	struct virt_dma_desc vd;
>   	struct tegra_dma_channel *tdc;
> -	struct tegra_dma_sg_req sg_req[];
> +	struct tegra_dma_sg_req sg_req[] __counted_by(sg_count);
>   };
>   
>   /*

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

* Re: [PATCH 16/21] dmaengine: tegra210-adma: Annotate struct tegra_adma with __counted_by
  2023-08-17 23:58 ` [PATCH 16/21] dmaengine: tegra210-adma: Annotate struct tegra_adma " Kees Cook
@ 2023-08-18  2:15   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  2:15 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Laxman Dewangan, Jon Hunter, Thierry Reding, dmaengine,
	linux-tegra, Hector Martin, Sven Peter, Alyssa Rosenzweig,
	Ludovic Desroches, Tudor Ambarus, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct tegra_adma.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Laxman Dewangan <ldewangan@nvidia.com>
> Cc: Jon Hunter <jonathanh@nvidia.com>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Cc: dmaengine@vger.kernel.org
> Cc: linux-tegra@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/tegra210-adma.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/tegra210-adma.c b/drivers/dma/tegra210-adma.c
> index e557bada1510..cea33912a4c9 100644
> --- a/drivers/dma/tegra210-adma.c
> +++ b/drivers/dma/tegra210-adma.c
> @@ -162,7 +162,7 @@ struct tegra_adma {
>   	const struct tegra_adma_chip_data *cdata;
>   
>   	/* Last member of the structure */
> -	struct tegra_adma_chan		channels[];
> +	struct tegra_adma_chan		channels[] __counted_by(nr_channels);
>   };
>   
>   static inline void tdma_write(struct tegra_adma *tdma, u32 reg, u32 val)

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

* Re: [PATCH 17/21] dmaengine: ti: edma: Annotate struct edma_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 17/21] dmaengine: ti: edma: Annotate struct edma_desc " Kees Cook
@ 2023-08-18  2:15   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  2:15 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Peter Ujfalusi, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct edma_desc.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/ti/edma.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/ti/edma.c b/drivers/dma/ti/edma.c
> index aa8e2e8ac260..9c2b2c4c3882 100644
> --- a/drivers/dma/ti/edma.c
> +++ b/drivers/dma/ti/edma.c
> @@ -202,7 +202,7 @@ struct edma_desc {
>   	u32				residue;
>   	u32				residue_stat;
>   
> -	struct edma_pset		pset[];
> +	struct edma_pset		pset[] __counted_by(pset_nr);
>   };
>   
>   struct edma_cc;

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

* Re: [PATCH 18/21] dmaengine: ti: omap-dma: Annotate struct omap_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 18/21] dmaengine: ti: omap-dma: Annotate struct omap_desc " Kees Cook
@ 2023-08-18  2:15   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  2:15 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Peter Ujfalusi, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman,
	Jordy Zomer, Jernej Skrabec, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-kernel, asahi, linux-arm-kernel, linux-arm-msm,
	linux-stm32, linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct omap_desc.
> Additionally, since the element count member must be set before accessing
> the annotated flexible array member, move its initialization earlier.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/ti/omap-dma.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/ti/omap-dma.c b/drivers/dma/ti/omap-dma.c
> index cf96cf915c0c..11ac3fc0a52a 100644
> --- a/drivers/dma/ti/omap-dma.c
> +++ b/drivers/dma/ti/omap-dma.c
> @@ -124,7 +124,7 @@ struct omap_desc {
>   	uint32_t csdp;		/* CSDP value */
>   
>   	unsigned sglen;
> -	struct omap_sg sg[];
> +	struct omap_sg sg[] __counted_by(sglen);
>   };
>   
>   enum {
> @@ -1005,6 +1005,7 @@ static struct dma_async_tx_descriptor *omap_dma_prep_slave_sg(
>   	d = kzalloc(struct_size(d, sg, sglen), GFP_ATOMIC);
>   	if (!d)
>   		return NULL;
> +	d->sglen = sglen;
>   
>   	d->dir = dir;
>   	d->dev_addr = dev_addr;
> @@ -1120,8 +1121,6 @@ static struct dma_async_tx_descriptor *omap_dma_prep_slave_sg(
>   		}
>   	}
>   
> -	d->sglen = sglen;
> -
>   	/* Release the dma_pool entries if one allocation failed */
>   	if (ll_failed) {
>   		for (i = 0; i < d->sglen; i++) {

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

* Re: [PATCH 19/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 19/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_desc " Kees Cook
@ 2023-08-18  2:15   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  2:15 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Kunihiko Hayashi, Masami Hiramatsu, dmaengine, linux-arm-kernel,
	Hector Martin, Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Tudor Ambarus, Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-msm, linux-stm32, linux-tegra,
	llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct uniphier_xdmac_desc.
> Additionally, since the element count member must be set before accessing
> the annotated flexible array member, move its initialization earlier.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: dmaengine@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/uniphier-xdmac.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/uniphier-xdmac.c b/drivers/dma/uniphier-xdmac.c
> index 290836b7e1be..dd51522879a7 100644
> --- a/drivers/dma/uniphier-xdmac.c
> +++ b/drivers/dma/uniphier-xdmac.c
> @@ -80,7 +80,7 @@ struct uniphier_xdmac_desc {
>   	unsigned int nr_node;
>   	unsigned int cur_node;
>   	enum dma_transfer_direction dir;
> -	struct uniphier_xdmac_desc_node nodes[];
> +	struct uniphier_xdmac_desc_node nodes[] __counted_by(nr_node);
>   };
>   
>   struct uniphier_xdmac_chan {
> @@ -295,6 +295,7 @@ uniphier_xdmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
>   	xd = kzalloc(struct_size(xd, nodes, nr), GFP_NOWAIT);
>   	if (!xd)
>   		return NULL;
> +	xd->nr_node = nr;
>   
>   	for (i = 0; i < nr; i++) {
>   		burst_size = min_t(size_t, len, XDMAC_MAX_WORD_SIZE);
> @@ -309,7 +310,6 @@ uniphier_xdmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
>   	}
>   
>   	xd->dir = DMA_MEM_TO_MEM;
> -	xd->nr_node = nr;
>   	xd->cur_node = 0;
>   
>   	return vchan_tx_prep(vc, &xd->vd, flags);
> @@ -351,6 +351,7 @@ uniphier_xdmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
>   	xd = kzalloc(struct_size(xd, nodes, sg_len), GFP_NOWAIT);
>   	if (!xd)
>   		return NULL;
> +	xd->nr_node = sg_len;
>   
>   	for_each_sg(sgl, sg, sg_len, i) {
>   		xd->nodes[i].src = (direction == DMA_DEV_TO_MEM)
> @@ -385,7 +386,6 @@ uniphier_xdmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
>   	}
>   
>   	xd->dir = direction;
> -	xd->nr_node = sg_len;
>   	xd->cur_node = 0;
>   
>   	return vchan_tx_prep(vc, &xd->vd, flags);

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

* Re: [PATCH 20/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_device with __counted_by
  2023-08-17 23:58 ` [PATCH 20/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_device " Kees Cook
@ 2023-08-18  2:16   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  2:16 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Kunihiko Hayashi, Masami Hiramatsu, dmaengine, linux-arm-kernel,
	Hector Martin, Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Tudor Ambarus, Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-msm, linux-stm32, linux-tegra,
	llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct uniphier_xdmac_device.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: dmaengine@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/uniphier-xdmac.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/uniphier-xdmac.c b/drivers/dma/uniphier-xdmac.c
> index dd51522879a7..3a8ee2b173b5 100644
> --- a/drivers/dma/uniphier-xdmac.c
> +++ b/drivers/dma/uniphier-xdmac.c
> @@ -97,7 +97,7 @@ struct uniphier_xdmac_device {
>   	struct dma_device ddev;
>   	void __iomem *reg_base;
>   	int nr_chans;
> -	struct uniphier_xdmac_chan channels[];
> +	struct uniphier_xdmac_chan channels[] __counted_by(nr_chans);
>   };
>   
>   static struct uniphier_xdmac_chan *

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

* Re: [PATCH 21/21] dmaengine: usb-dmac: Annotate struct usb_dmac_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 21/21] dmaengine: usb-dmac: Annotate struct usb_dmac_desc " Kees Cook
@ 2023-08-18  2:17   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 50+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-18  2:17 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Yu Kuai, Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Tudor Ambarus, dmaengine, Hector Martin, Sven Peter,
	Alyssa Rosenzweig, Ludovic Desroches, Lars-Peter Clausen,
	Zhou Wang, Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Green Wan, Orson Zhai, Baolin Wang, Chunyan Zhang,
	Patrice Chotard, Maxime Coquelin, Alexandre Torgue,
	Laxman Dewangan, Jon Hunter, Thierry Reding, Peter Ujfalusi,
	Kunihiko Hayashi, Masami Hiramatsu, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, linux-kernel, asahi, linux-arm-kernel,
	linux-arm-msm, linux-stm32, linux-tegra, llvm, linux-hardening



On 8/17/23 17:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct usb_dmac_desc.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Yu Kuai <yukuai3@huawei.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Jordy Zomer <jordy@pwning.systems>
> Cc: Jernej Skrabec <jernej.skrabec@gmail.com>
> Cc: Tudor Ambarus <tudor.ambarus@linaro.org>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/dma/sh/usb-dmac.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
> index b14cf350b669..4cfcd23e3268 100644
> --- a/drivers/dma/sh/usb-dmac.c
> +++ b/drivers/dma/sh/usb-dmac.c
> @@ -57,7 +57,7 @@ struct usb_dmac_desc {
>   	u32 residue;
>   	struct list_head node;
>   	dma_cookie_t done_cookie;
> -	struct usb_dmac_sg sg[];
> +	struct usb_dmac_sg sg[] __counted_by(sg_allocated_len);
>   };
>   
>   #define to_usb_dmac_desc(vd)	container_of(vd, struct usb_dmac_desc, vd)

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

* Re: [PATCH 10/21] dmaengine: sprd: Annotate struct sprd_dma_dev with __counted_by
  2023-08-17 23:58 ` [PATCH 10/21] dmaengine: sprd: Annotate struct sprd_dma_dev " Kees Cook
  2023-08-18  1:24   ` Gustavo A. R. Silva
@ 2023-08-18  7:18   ` Chunyan Zhang
  1 sibling, 0 replies; 50+ messages in thread
From: Chunyan Zhang @ 2023-08-18  7:18 UTC (permalink / raw)
  To: Kees Cook
  Cc: Vinod Koul, Orson Zhai, Baolin Wang, dmaengine, Hector Martin,
	Sven Peter, Alyssa Rosenzweig, Ludovic Desroches, Tudor Ambarus,
	Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-kernel, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening

On Fri, 18 Aug 2023 at 07:59, Kees Cook <keescook@chromium.org> wrote:
>
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct sprd_dma_dev.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Orson Zhai <orsonzhai@gmail.com>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: Chunyan Zhang <zhang.lyra@gmail.com>
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Chunyan Zhang <zhang.lyra@gmail.com>

Thanks,
Chunyan

> ---
>  drivers/dma/sprd-dma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c
> index 168aa0bd73a0..07871dcc4593 100644
> --- a/drivers/dma/sprd-dma.c
> +++ b/drivers/dma/sprd-dma.c
> @@ -212,7 +212,7 @@ struct sprd_dma_dev {
>         struct clk              *ashb_clk;
>         int                     irq;
>         u32                     total_chns;
> -       struct sprd_dma_chn     channels[];
> +       struct sprd_dma_chn     channels[] __counted_by(total_chns);
>  };
>
>  static void sprd_dma_free_desc(struct virt_dma_desc *vd);
> --
> 2.34.1
>

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

* Re: [PATCH 02/21] dmaengine: at_hdmac: Annotate struct at_desc with __counted_by
  2023-08-17 23:58 ` [PATCH 02/21] dmaengine: at_hdmac: Annotate struct at_desc " Kees Cook
  2023-08-18  2:14   ` Gustavo A. R. Silva
@ 2023-08-18  9:29   ` Tudor Ambarus
  1 sibling, 0 replies; 50+ messages in thread
From: Tudor Ambarus @ 2023-08-18  9:29 UTC (permalink / raw)
  To: Kees Cook, Vinod Koul
  Cc: Ludovic Desroches, linux-arm-kernel, dmaengine, Hector Martin,
	Sven Peter, Alyssa Rosenzweig, Lars-Peter Clausen, Zhou Wang,
	Jie Hai, Andy Gross, Bjorn Andersson, Konrad Dybcio, Green Wan,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue, Laxman Dewangan, Jon Hunter,
	Thierry Reding, Peter Ujfalusi, Kunihiko Hayashi,
	Masami Hiramatsu, Yu Kuai, Greg Kroah-Hartman, Jordy Zomer,
	Jernej Skrabec, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, asahi, linux-arm-msm, linux-stm32, linux-tegra,
	llvm, linux-hardening



On 8/18/23 00:58, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct at_desc.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
> Cc: Tudor Ambarus <tudor.ambarus@linaro.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: dmaengine@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org>
> ---
>  drivers/dma/at_hdmac.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
> index b2876f67471f..b66c7f416881 100644
> --- a/drivers/dma/at_hdmac.c
> +++ b/drivers/dma/at_hdmac.c
> @@ -239,7 +239,7 @@ struct at_desc {
>  	bool				memset_buffer;
>  	dma_addr_t			memset_paddr;
>  	int				*memset_vaddr;
> -	struct atdma_sg			sg[];
> +	struct atdma_sg			sg[] __counted_by(sglen);
>  };
>  
>  /*--  Channels  --------------------------------------------------------*/

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

* Re: [PATCH 00/21] dmaengine: Annotate with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (20 preceding siblings ...)
  2023-08-17 23:58 ` [PATCH 21/21] dmaengine: usb-dmac: Annotate struct usb_dmac_desc " Kees Cook
@ 2023-09-15 20:08 ` Kees Cook
  2023-09-22 17:16   ` Kees Cook
  2023-09-28 11:56 ` Vinod Koul
  22 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-09-15 20:08 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Tudor Ambarus, Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, dmaengine, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening

Hi,

Just a ping on the series... how do these look to you, Vinod?

If you want I can carry them in my tree. Please let me know.

Thanks!

-Kees

On Thu, Aug 17, 2023 at 04:58:37PM -0700, Kees Cook wrote:
> Hi,
> 
> This annotates several structures with the coming __counted_by attribute
> for bounds checking of flexible arrays at run-time. For more details, see
> commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro").
> 
> Thanks!
> 
> -Kees
> 
> Kees Cook (21):
>   dmaengine: apple-admac: Annotate struct admac_data with __counted_by
>   dmaengine: at_hdmac: Annotate struct at_desc with __counted_by
>   dmaengine: axi-dmac: Annotate struct axi_dmac_desc with __counted_by
>   dmaengine: fsl-edma: Annotate struct fsl_edma_desc with __counted_by
>   dmaengine: hisilicon: Annotate struct hisi_dma_dev with __counted_by
>   dmaengine: moxart-dma: Annotate struct moxart_desc with __counted_by
>   dmaengine: qcom: bam_dma: Annotate struct bam_async_desc with
>     __counted_by
>   dmaengine: sa11x0: Annotate struct sa11x0_dma_desc with __counted_by
>   dmaengine: sf-pdma: Annotate struct sf_pdma with __counted_by
>   dmaengine: sprd: Annotate struct sprd_dma_dev with __counted_by
>   dmaengine: st_fdma: Annotate struct st_fdma_desc with __counted_by
>   dmaengine: stm32-dma: Annotate struct stm32_dma_desc with __counted_by
>   dmaengine: stm32-mdma: Annotate struct stm32_mdma_desc with
>     __counted_by
>   dmaengine: stm32-mdma: Annotate struct stm32_mdma_device with
>     __counted_by
>   dmaengine: tegra: Annotate struct tegra_dma_desc with __counted_by
>   dmaengine: tegra210-adma: Annotate struct tegra_adma with __counted_by
>   dmaengine: ti: edma: Annotate struct edma_desc with __counted_by
>   dmaengine: ti: omap-dma: Annotate struct omap_desc with __counted_by
>   dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_desc with
>     __counted_by
>   dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_device with
>     __counted_by
>   dmaengine: usb-dmac: Annotate struct usb_dmac_desc with __counted_by
> 
>  drivers/dma/apple-admac.c      |  2 +-
>  drivers/dma/at_hdmac.c         |  2 +-
>  drivers/dma/dma-axi-dmac.c     |  5 ++---
>  drivers/dma/fsl-edma-common.h  |  2 +-
>  drivers/dma/hisi_dma.c         |  2 +-
>  drivers/dma/moxart-dma.c       |  5 ++---
>  drivers/dma/qcom/bam_dma.c     |  2 +-
>  drivers/dma/sa11x0-dma.c       |  6 +++---
>  drivers/dma/sf-pdma/sf-pdma.h  |  2 +-
>  drivers/dma/sh/usb-dmac.c      |  2 +-
>  drivers/dma/sprd-dma.c         |  2 +-
>  drivers/dma/st_fdma.h          |  2 +-
>  drivers/dma/stm32-dma.c        | 11 ++++-------
>  drivers/dma/stm32-mdma.c       |  9 ++++-----
>  drivers/dma/tegra186-gpc-dma.c |  2 +-
>  drivers/dma/tegra210-adma.c    |  2 +-
>  drivers/dma/ti/edma.c          |  2 +-
>  drivers/dma/ti/omap-dma.c      |  5 ++---
>  drivers/dma/uniphier-xdmac.c   |  8 ++++----
>  19 files changed, 33 insertions(+), 40 deletions(-)
> 
> -- 
> 2.34.1
> 

-- 
Kees Cook

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

* Re: [PATCH 00/21] dmaengine: Annotate with __counted_by
  2023-09-15 20:08 ` [PATCH 00/21] dmaengine: Annotate " Kees Cook
@ 2023-09-22 17:16   ` Kees Cook
  2023-09-28 11:11     ` Vinod Koul
  0 siblings, 1 reply; 50+ messages in thread
From: Kees Cook @ 2023-09-22 17:16 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Tudor Ambarus, Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, dmaengine, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening

On Fri, Sep 15, 2023 at 01:08:30PM -0700, Kees Cook wrote:
> Just a ping on the series... how do these look to you, Vinod?
> 
> If you want I can carry them in my tree. Please let me know.

I'm now carrying this in my for-next/hardening tree. Let me know if
you'd prefer I drop it.

Thanks!

-Kees

-- 
Kees Cook

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

* Re: [PATCH 00/21] dmaengine: Annotate with __counted_by
  2023-09-22 17:16   ` Kees Cook
@ 2023-09-28 11:11     ` Vinod Koul
  0 siblings, 0 replies; 50+ messages in thread
From: Vinod Koul @ 2023-09-28 11:11 UTC (permalink / raw)
  To: Kees Cook
  Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Tudor Ambarus, Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, dmaengine, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening

On 22-09-23, 10:16, Kees Cook wrote:
> On Fri, Sep 15, 2023 at 01:08:30PM -0700, Kees Cook wrote:
> > Just a ping on the series... how do these look to you, Vinod?
> > 
> > If you want I can carry them in my tree. Please let me know.
> 
> I'm now carrying this in my for-next/hardening tree. Let me know if
> you'd prefer I drop it.

Sorry was busy in travel etc, it should be in dmaengine/next tomorrow.
You can drop it

Thanks
-- 
~Vinod

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

* Re: [PATCH 00/21] dmaengine: Annotate with __counted_by
  2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
                   ` (21 preceding siblings ...)
  2023-09-15 20:08 ` [PATCH 00/21] dmaengine: Annotate " Kees Cook
@ 2023-09-28 11:56 ` Vinod Koul
  2023-09-28 23:42   ` Kees Cook
  22 siblings, 1 reply; 50+ messages in thread
From: Vinod Koul @ 2023-09-28 11:56 UTC (permalink / raw)
  To: Kees Cook
  Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Tudor Ambarus, Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, dmaengine, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening


On Thu, 17 Aug 2023 16:58:37 -0700, Kees Cook wrote:
> This annotates several structures with the coming __counted_by attribute
> for bounds checking of flexible arrays at run-time. For more details, see
> commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro").
> 
> Thanks!
> 
> -Kees
> 
> [...]

Applied, thanks!

[01/21] dmaengine: apple-admac: Annotate struct admac_data with __counted_by
        commit: 83c5d35bf9112577da097c1b4fbfedef93b951e6
[02/21] dmaengine: at_hdmac: Annotate struct at_desc with __counted_by
        commit: 81cd3cb3b3dd37df1fc45c5b6443a07bc2a7fee4
[03/21] dmaengine: axi-dmac: Annotate struct axi_dmac_desc with __counted_by
        commit: f1bc0d01cb349da43d55548b57c915ef8fe024c7
[04/21] dmaengine: fsl-edma: Annotate struct fsl_edma_desc with __counted_by
        (no commit info)
[05/21] dmaengine: hisilicon: Annotate struct hisi_dma_dev with __counted_by
        commit: 7d4b82185521538eab8b0532b9bd7b8c8ca3e63b
[06/21] dmaengine: moxart-dma: Annotate struct moxart_desc with __counted_by
        commit: fd1cb31a037bf8894a710392c2354281c5276d09
[07/21] dmaengine: qcom: bam_dma: Annotate struct bam_async_desc with __counted_by
        commit: b9fe0bd5903140cc3e1ae4e542ae7ff38c90d011
[08/21] dmaengine: sa11x0: Annotate struct sa11x0_dma_desc with __counted_by
        commit: 04b5433b8c0e1b014f081f4bf79767bbc207a7b0
[09/21] dmaengine: sf-pdma: Annotate struct sf_pdma with __counted_by
        commit: 1539a22e144106eefc0ef05e7b91f68ad20a71ad
[10/21] dmaengine: sprd: Annotate struct sprd_dma_dev with __counted_by
        commit: 8360c11aef5775745fc10438e24db95ab2329b1d
[11/21] dmaengine: st_fdma: Annotate struct st_fdma_desc with __counted_by
        commit: 8279f0b476f37c51de2ed8bd70d770b2893dd2fa
[12/21] dmaengine: stm32-dma: Annotate struct stm32_dma_desc with __counted_by
        commit: 195e46df2d996ff4bbf624891b1d3ae8ea9f315d
[13/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_desc with __counted_by
        commit: 035472170a2a21fc62d8258883a9f566943058b7
[14/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_device with __counted_by
        commit: 7ba0035dc02ce0c877004dc4052c6d5f873539db
[15/21] dmaengine: tegra: Annotate struct tegra_dma_desc with __counted_by
        commit: 32b5e2d7cd14c80de1fa1cdffcc6ec211b615d82
[16/21] dmaengine: tegra210-adma: Annotate struct tegra_adma with __counted_by
        commit: 15f2c636dde8c4370db87ceabce5cc8325460d77
[17/21] dmaengine: ti: edma: Annotate struct edma_desc with __counted_by
        commit: 5f240e0cdbcb0cc60d6a75ea7d492ce93b7fd52e
[18/21] dmaengine: ti: omap-dma: Annotate struct omap_desc with __counted_by
        commit: b85178611c1156deb3c09e7f8d8cdd662b8df99c
[19/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_desc with __counted_by
        commit: 5a67a8f93f02027e4ac8583715d2f4bd2de20e10
[20/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_device with __counted_by
        commit: 7935de861aed45f97a4262d9b215d9feb172516b
[21/21] dmaengine: usb-dmac: Annotate struct usb_dmac_desc with __counted_by
        commit: a04bbeaa37d8789de5592506fa776256e784b69c

Best regards,
-- 
~Vinod



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

* Re: [PATCH 00/21] dmaengine: Annotate with __counted_by
  2023-09-28 11:56 ` Vinod Koul
@ 2023-09-28 23:42   ` Kees Cook
  0 siblings, 0 replies; 50+ messages in thread
From: Kees Cook @ 2023-09-28 23:42 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, Ludovic Desroches,
	Tudor Ambarus, Lars-Peter Clausen, Zhou Wang, Jie Hai, Andy Gross,
	Bjorn Andersson, Konrad Dybcio, Green Wan, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Patrice Chotard, Maxime Coquelin,
	Alexandre Torgue, Laxman Dewangan, Jon Hunter, Thierry Reding,
	Peter Ujfalusi, Kunihiko Hayashi, Masami Hiramatsu, Yu Kuai,
	Greg Kroah-Hartman, Jordy Zomer, Jernej Skrabec,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, asahi,
	linux-arm-kernel, dmaengine, linux-arm-msm, linux-stm32,
	linux-tegra, llvm, linux-hardening

On Thu, Sep 28, 2023 at 05:26:08PM +0530, Vinod Koul wrote:
> 
> On Thu, 17 Aug 2023 16:58:37 -0700, Kees Cook wrote:
> > This annotates several structures with the coming __counted_by attribute
> > for bounds checking of flexible arrays at run-time. For more details, see
> > commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro").
> > 
> > Thanks!
> > 
> > -Kees
> > 
> > [...]
> 
> Applied, thanks!

Thanks! I've dropped them from my tree. :)

Also, I found 1 more, which I'll send separately.

-Kees

-- 
Kees Cook

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

end of thread, other threads:[~2023-09-28 23:42 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-17 23:58 [PATCH 00/21] dmaengine: Annotate with __counted_by Kees Cook
2023-08-17 23:58 ` [PATCH 01/21] dmaengine: apple-admac: Annotate struct admac_data " Kees Cook
2023-08-18  1:22   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 02/21] dmaengine: at_hdmac: Annotate struct at_desc " Kees Cook
2023-08-18  2:14   ` Gustavo A. R. Silva
2023-08-18  9:29   ` Tudor Ambarus
2023-08-17 23:58 ` [PATCH 03/21] dmaengine: axi-dmac: Annotate struct axi_dmac_desc " Kees Cook
2023-08-18  2:14   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 04/21] dmaengine: fsl-edma: Annotate struct fsl_edma_desc " Kees Cook
2023-08-18  1:23   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 05/21] dmaengine: hisilicon: Annotate struct hisi_dma_dev " Kees Cook
2023-08-18  1:23   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 06/21] dmaengine: moxart-dma: Annotate struct moxart_desc " Kees Cook
2023-08-18  1:23   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 07/21] dmaengine: qcom: bam_dma: Annotate struct bam_async_desc " Kees Cook
2023-08-18  1:24   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 08/21] dmaengine: sa11x0: Annotate struct sa11x0_dma_desc " Kees Cook
2023-08-18  1:24   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 09/21] dmaengine: sf-pdma: Annotate struct sf_pdma " Kees Cook
2023-08-18  1:24   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 10/21] dmaengine: sprd: Annotate struct sprd_dma_dev " Kees Cook
2023-08-18  1:24   ` Gustavo A. R. Silva
2023-08-18  7:18   ` Chunyan Zhang
2023-08-17 23:58 ` [PATCH 11/21] dmaengine: st_fdma: Annotate struct st_fdma_desc " Kees Cook
2023-08-18  1:24   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 12/21] dmaengine: stm32-dma: Annotate struct stm32_dma_desc " Kees Cook
2023-08-18  1:25   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 13/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_desc " Kees Cook
2023-08-18  1:25   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 14/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_device " Kees Cook
2023-08-18  1:26   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 15/21] dmaengine: tegra: Annotate struct tegra_dma_desc " Kees Cook
2023-08-18  2:15   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 16/21] dmaengine: tegra210-adma: Annotate struct tegra_adma " Kees Cook
2023-08-18  2:15   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 17/21] dmaengine: ti: edma: Annotate struct edma_desc " Kees Cook
2023-08-18  2:15   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 18/21] dmaengine: ti: omap-dma: Annotate struct omap_desc " Kees Cook
2023-08-18  2:15   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 19/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_desc " Kees Cook
2023-08-18  2:15   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 20/21] dmaengine: uniphier-xdmac: Annotate struct uniphier_xdmac_device " Kees Cook
2023-08-18  2:16   ` Gustavo A. R. Silva
2023-08-17 23:58 ` [PATCH 21/21] dmaengine: usb-dmac: Annotate struct usb_dmac_desc " Kees Cook
2023-08-18  2:17   ` Gustavo A. R. Silva
2023-09-15 20:08 ` [PATCH 00/21] dmaengine: Annotate " Kees Cook
2023-09-22 17:16   ` Kees Cook
2023-09-28 11:11     ` Vinod Koul
2023-09-28 11:56 ` Vinod Koul
2023-09-28 23:42   ` Kees Cook

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