From: sashiko-bot@kernel.org
To: "Sergey Matsievskiy" <matsievskiysv@gmail.com>,
dmaengine@vger.kernel.org
Cc: vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH] dmaengine: axi-dmac: fix incorrect segment size calculation
Date: Thu, 05 Nov 2026 13:26:06 +0000 [thread overview]
Message-ID: <sashiko-outbox-199139@kernel.org> (raw)
In-Reply-To: <20261105131547.305510-1-matsievskiysv@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] dmaengine: axi-dmac: 32-bit overflow in axi_dmac_prep_slave_sg()
--
commit 6fad587f5aff185e8ba37fde1bcd2a484b6fa19d
Author: Sergey Matsievskiy <matsievskiysv@gmail.com>
dmaengine: axi-dmac: fix incorrect segment size calculation
This commit switches segment count calculations in axi-dmac from DIV_ROUND_UP
to DIV_ROUND_UP_ULL to avoid 32-bit unsigned integer overflow when
chan->max_length is 0xffffffff.
> diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
> index d47ff27e1408f..bfa83ccfd7dc0 100644
> --- a/drivers/dma/dma-axi-dmac.c
> +++ b/drivers/dma/dma-axi-dmac.c
> @@ -706,7 +706,7 @@ static struct axi_dmac_sg *axi_dmac_fill_linear_sg(struct axi_dmac_chan *chan,
> unsigned int len;
>
> /* Split into multiple equally sized segments if necessary */
> - num_segments = DIV_ROUND_UP(period_len, chan->max_length);
> + num_segments = DIV_ROUND_UP_ULL(period_len, chan->max_length);
[Severity: High]
Can axi_dmac_prep_slave_sg() under-allocate desc->sg[] and write out of
bounds on 32-bit architectures when chan->max_length is 0xffffffff?
While axi_dmac_fill_linear_sg(), axi_dmac_prep_peripheral_dma_vec(), and
axi_dmac_prep_dma_cyclic() now use DIV_ROUND_UP_ULL(), axi_dmac_prep_slave_sg()
still calculates num_sgs via sg_nents_for_dma() before calling
axi_dmac_alloc_desc() and axi_dmac_fill_linear_sg():
drivers/dma/dma-axi-dmac.c:axi_dmac_prep_slave_sg() {
...
num_sgs = sg_nents_for_dma(sgl, sg_len, chan->max_length);
desc = axi_dmac_alloc_desc(chan, num_sgs);
if (!desc)
return NULL;
dsg = desc->sg;
for_each_sg(sgl, sg, sg_len, i) {
...
dsg = axi_dmac_fill_linear_sg(chan, direction, sg_dma_address(sg), 1,
sg_dma_len(sg), dsg);
}
...
}
In lib/scatterlist.c, sg_nents_for_dma() uses DIV_ROUND_UP() with unsigned
int sg_dma_len(sg) and size_t len:
lib/scatterlist.c:sg_nents_for_dma() {
...
for_each_sg(sgl, sg, sglen, i)
nents += DIV_ROUND_UP(sg_dma_len(sg), len);
return nents;
}
On 32-bit architectures where size_t is 32 bits wide, passing len = 0xffffffff
causes DIV_ROUND_UP(sg_dma_len(sg), len) to overflow 32-bit arithmetic and
evaluate to 0 for any scatterlist entry with length >= 2.
When that happens, axi_dmac_alloc_desc(chan, num_sgs) either dereferences
desc->sg[num_sgs - 1].hw out of bounds when num_sgs is 0:
drivers/dma/dma-axi-dmac.c:axi_dmac_alloc_desc() {
...
/* The last hardware descriptor will trigger an interrupt */
desc->sg[num_sgs - 1].hw->flags = AXI_DMAC_HW_FLAG_LAST | AXI_DMAC_HW_FLAG_IRQ;
...
}
or allocates fewer sg entries than needed while the updated
axi_dmac_fill_linear_sg() computes num_segments = 1 via DIV_ROUND_UP_ULL()
and advances dsg past the end of desc->sg[].
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261105131547.305510-1-matsievskiysv@gmail.com?part=1
next prev parent reply other threads:[~2026-11-05 13:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 13:15 [PATCH] dmaengine: axi-dmac: fix incorrect segment size calculation Sergey Matsievskiy
2026-11-05 13:26 ` sashiko-bot [this message]
2026-11-05 13:55 ` Sergey Matsievskiy
2026-11-05 17:16 ` Frank Li
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=sashiko-outbox-199139@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=matsievskiysv@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox