All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sai Sree Kartheek Adivi" <s-adivi@ti.com>
Cc: Frank.Li@kernel.org, conor+dt@kernel.org, vkoul@kernel.org,
	dmaengine@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org
Subject: Re: [PATCH v7 05/19] dmaengine: ti: k3-udma: move descriptor management to k3-udma-common.c
Date: Fri, 24 Jul 2026 10:44:59 +0000	[thread overview]
Message-ID: <20260724104459.B25201F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724102115.2854-6-s-adivi@ti.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Low] Global namespace pollution due to missing `static` keyword on `metadata_ops`.

Pre-existing issues:
- [Critical] Signed 32-bit integer overflow during multi-TR DMA address calculation causes massive negative offset.
- [High] Buffer underallocation and out-of-bounds write due to swapped arguments in `cppi5_trdesc_calc_size`.
--

--- Patch [5]: [PATCH v7 05/19] dmaengine: ti: k3-udma: move descriptor management to k3-udma-common.c ---
commit bdc5f8902724dd8a4b2dc695e0b04524fbd51779
Author: Sai Sree Kartheek Adivi <s-adivi@ti.com>

dmaengine: ti: k3-udma: move descriptor management to k3-udma-common.c

Refactor the K3 UDMA driver by moving all DMA descriptor handling
functions from k3-udma.c to a new common library, k3-udma-common.c.
This prepares the driver for supporting new K3 UDMA v2 variant
(used in AM62L) that can reuse the same descriptor handling logic.

> diff --git a/drivers/dma/ti/k3-udma-common.c b/drivers/dma/ti/k3-udma-common.c
> new file mode 100644
> index 0000000000000..daf5f19dfb3ab
> --- /dev/null
> +++ b/drivers/dma/ti/k3-udma-common.c
> @@ -0,0 +1,1243 @@
[ ... ]
> +
> +const struct dma_descriptor_metadata_ops metadata_ops = {
> +	.attach = udma_attach_metadata,
> +	.get_ptr = udma_get_metadata_ptr,
> +	.set_len = udma_set_metadata_len,
> +};

[Severity: Low]
Does this struct need to be exported to the global namespace? The static
keyword seems to have been dropped during the code move. Leaving such a
generic name in the global namespace might cause linker collisions with other
subsystems.

> +
> +struct udma_desc *udma_udma_desc_from_paddr(struct udma_chan *uc,
[ ... ]
> +struct udma_desc *udma_alloc_tr_desc(struct udma_chan *uc,
> +				     size_t tr_size, int tr_count,
> +				     enum dma_transfer_direction dir)
> +{
[ ... ]
> +	/* Allocate memory for DMA ring descriptor */
> +	if (uc->use_dma_pool) {
> +		hwdesc->cppi5_desc_size = uc->config.hdesc_size;
> +		hwdesc->cppi5_desc_vaddr = dma_pool_zalloc(uc->hdesc_pool,
> +							   GFP_NOWAIT,
> +							   &hwdesc->cppi5_desc_paddr);
> +	} else {
> +		hwdesc->cppi5_desc_size = cppi5_trdesc_calc_size(tr_size,
> +								 tr_count);

[Severity: High]
This is a pre-existing issue, but does this call to cppi5_trdesc_calc_size()
pass the arguments in the correct order? The function expects tr_count first
and tr_size second.

Passing them in reverse order calculates a smaller size than needed when
the scatterlist has a large number of entries (e.g., tr_count > 64). As a
result, when the hardware writes the 4-byte responses, does it write past the
allocated buffer size and corrupt adjacent coherent DMA memory?

> +		hwdesc->cppi5_desc_size = ALIGN(hwdesc->cppi5_desc_size,
> +						uc->ud->desc_align);
> +		hwdesc->cppi5_desc_vaddr = dma_alloc_coherent(uc->ud->dev,
[ ... ]
> +struct udma_desc *
> +udma_prep_slave_sg_tr(struct udma_chan *uc, struct scatterlist *sgl,
> +		      unsigned int sglen, enum dma_transfer_direction dir,
> +		      unsigned long tx_flags, void *context)
> +{
[ ... ]
> +		if (num_tr == 2) {
> +			cppi5_tr_init(&tr_req[tr_idx].flags, CPPI5_TR_TYPE1,
> +				      false, false,
> +				      CPPI5_TR_EVENT_SIZE_COMPLETION, 0);
> +			cppi5_tr_csf_set(&tr_req[tr_idx].flags,
> +					 CPPI5_TR_CSF_SUPR_EVT);
> +
> +			tr_req[tr_idx].addr = sg_addr + tr0_cnt1 * tr0_cnt0;

[Severity: Critical]
This is a pre-existing issue, but can this address calculation overflow and
result in a massive negative offset?

When processing a DMA buffer larger than 2GB, the variables tr0_cnt0 and
tr0_cnt1 (both u16) can have a product that exceeds 2^31. Multiplying two u16
values in C promotes them to a signed 32-bit int, so the product can become
negative.

When this negative 32-bit int is added to sg_addr (a 64-bit dma_addr_t), it
is sign-extended to a massive 64-bit negative offset, calculating a backward
DMA address. Could this bypass memory isolation and corrupt arbitrary kernel
memory?

> +			tr_req[tr_idx].icnt0 = tr1_cnt0;
> +			tr_req[tr_idx].icnt1 = 1;
> +			tr_req[tr_idx].dim1 = tr1_cnt0;
> +			tr_idx++;
> +		}
> +
> +		d->residue += sg_dma_len(sgent);
> +	}
[ ... ]
> +struct udma_desc *
> +udma_prep_dma_cyclic_tr(struct udma_chan *uc, dma_addr_t buf_addr,
> +			size_t buf_len, size_t period_len,
> +			enum dma_transfer_direction dir, unsigned long flags)
> +{
[ ... ]
> +		if (num_tr == 2) {
> +			cppi5_tr_csf_set(&tr_req[tr_idx].flags,
> +					 CPPI5_TR_CSF_SUPR_EVT);
> +			tr_idx++;
> +
> +			cppi5_tr_init(&tr_req[tr_idx].flags, CPPI5_TR_TYPE1,
> +				      false, false,
> +				      CPPI5_TR_EVENT_SIZE_COMPLETION, 0);
> +
> +			tr_req[tr_idx].addr = period_addr + tr0_cnt1 * tr0_cnt0;

[Severity: Critical]
This is a pre-existing issue, but can this run into the same signed 32-bit
integer overflow regression during the cyclic descriptor preparation path?

> +			tr_req[tr_idx].icnt0 = tr1_cnt0;
> +			tr_req[tr_idx].icnt1 = 1;
> +			tr_req[tr_idx].dim1 = tr1_cnt0;
> +		}
[ ... ]
> +struct dma_async_tx_descriptor *
> +udma_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
> +		     size_t len, unsigned long tx_flags)
> +{
[ ... ]
> +	if (num_tr == 2) {
> +		cppi5_tr_init(&tr_req[1].flags, CPPI5_TR_TYPE15, false, true,
> +			      CPPI5_TR_EVENT_SIZE_COMPLETION, 0);
> +		cppi5_tr_csf_set(&tr_req[1].flags, csf);
> +
> +		tr_req[1].addr = src + tr0_cnt1 * tr0_cnt0;
> +		tr_req[1].icnt0 = tr1_cnt0;
> +		tr_req[1].icnt1 = 1;
> +		tr_req[1].icnt2 = 1;
> +		tr_req[1].icnt3 = 1;
> +
> +		tr_req[1].daddr = dest + tr0_cnt1 * tr0_cnt0;

[Severity: Critical]
This is a pre-existing issue, but does the same vulnerable 32-bit integer
promotion and overflow occur here when calculating both the source and
destination addresses for the second TR?

> +		tr_req[1].dicnt0 = tr1_cnt0;
> +		tr_req[1].dicnt1 = 1;
> +		tr_req[1].dicnt2 = 1;
> +		tr_req[1].dicnt3 = 1;
> +	}
> +
> +	cppi5_tr_csf_set(&tr_req[num_tr - 1].flags, csf | CPPI5_TR_CSF_EOP);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724102115.2854-1-s-adivi@ti.com?part=5

  reply	other threads:[~2026-07-24 10:45 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 10:20 [PATCH v7 00/19] dmaengine: ti: Add support for BCDMA v2 and PKTDMA v2 Sai Sree Kartheek Adivi
2026-07-24 10:20 ` [PATCH v7 01/19] dmaengine: ti: k3-udma: Fix sporadic crash on AM62x Sai Sree Kartheek Adivi
2026-07-24 10:41   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 02/19] dmaengine: ti: k3-udma: move macros to header file Sai Sree Kartheek Adivi
2026-07-24 10:20 ` [PATCH v7 03/19] dmaengine: ti: k3-udma: move structs and enums " Sai Sree Kartheek Adivi
2026-07-24 10:20 ` [PATCH v7 04/19] dmaengine: ti: k3-udma: move static inline helper functions " Sai Sree Kartheek Adivi
2026-07-24 10:20 ` [PATCH v7 05/19] dmaengine: ti: k3-udma: move descriptor management to k3-udma-common.c Sai Sree Kartheek Adivi
2026-07-24 10:44   ` sashiko-bot [this message]
2026-07-24 10:20 ` [PATCH v7 06/19] dmaengine: ti: k3-udma: move ring management functions " Sai Sree Kartheek Adivi
2026-07-24 10:33   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 07/19] dmaengine: ti: k3-udma: Add variant-specific function pointers to udma_dev Sai Sree Kartheek Adivi
2026-07-24 10:41   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 08/19] dmaengine: ti: k3-udma: move udma utility functions to k3-udma-common.c Sai Sree Kartheek Adivi
2026-07-24 10:42   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 09/19] dmaengine: ti: k3-udma: move resource management " Sai Sree Kartheek Adivi
2026-07-24 10:52   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 10/19] dmaengine: ti: k3-udma: refactor resource setup functions Sai Sree Kartheek Adivi
2026-07-24 10:42   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 11/19] dmaengine: ti: k3-udma: move inclusion of k3-udma-private.c to k3-udma-common.c Sai Sree Kartheek Adivi
2026-07-24 10:20 ` [PATCH v7 12/19] drivers: soc: ti: k3-ringacc: handle absence of tisci Sai Sree Kartheek Adivi
2026-07-24 10:53   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 13/19] dt-bindings: dma: ti: Add K3 BCDMA V2 Sai Sree Kartheek Adivi
2026-07-24 10:20 ` [PATCH v7 14/19] dt-bindings: dma: ti: Add K3 PKTDMA V2 Sai Sree Kartheek Adivi
2026-07-24 10:46   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 15/19] dmaengine: ti: k3-psil-am62l: Add AM62Lx PSIL and PDMA data Sai Sree Kartheek Adivi
2026-07-24 10:48   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 16/19] dmaengine: ti: k3-udma-v2: New driver for K3 BCDMA_V2 Sai Sree Kartheek Adivi
2026-07-24 11:05   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 17/19] dmaengine: ti: k3-udma-v2: Add support for PKTDMA V2 Sai Sree Kartheek Adivi
2026-07-24 10:58   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 18/19] dmaengine: ti: k3-udma-v2: Update glue layer to support " Sai Sree Kartheek Adivi
2026-07-24 10:58   ` sashiko-bot
2026-07-24 10:20 ` [PATCH v7 19/19] dmaengine: ti: k3-udma: Validate resource ID and fix logging in reservation Sai Sree Kartheek Adivi
2026-07-24 11:00   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724104459.B25201F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=s-adivi@ti.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.