From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: Frank.Li@kernel.org, dmaengine@vger.kernel.org, vkoul@kernel.org
Subject: Re: [PATCHv2] dmaengine: ste_dma40: turn d40_base phy_chans into a flexible array
Date: Wed, 27 May 2026 20:48:05 +0000 [thread overview]
Message-ID: <20260527204806.1DDBC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260527203126.7053-1-rosenp@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Defeating struct_size() saturation arithmetic with unchecked addition can lead to a heap buffer overflow.
--
commit e3bf7e1250eb198cd9bf4617a8f0c3d6cc4d796b
Author: Rosen Penev <rosenp@gmail.com>
dmaengine: ste_dma40: turn d40_base phy_chans into a flexible array
This commit converts the separately-offset phy_chans pointer to a C99 flexible
array member at the end of struct d40_base, switching the allocation to
struct_size(). The log_chans and memcpy_chans slots continue to live in the
same allocation immediately after phy_chans.
> diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
> index 9b803c0aec254..d3e3c4cd43f17 100644
> --- a/drivers/dma/ste_dma40.c
> +++ b/drivers/dma/ste_dma40.c
[ ... ]
> @@ -3197,10 +3198,9 @@ static int __init d40_hw_detect_init(struct platform_device *pdev,
> "hardware rev: %d with %d physical and %d logical channels\n",
> rev, num_phy_chans, num_log_chans);
>
> - base = devm_kzalloc(dev,
> - ALIGN(sizeof(struct d40_base), 4) +
> - (num_phy_chans + num_log_chans + num_memcpy_chans) *
> - sizeof(struct d40_chan), GFP_KERNEL);
> + alloc_size = struct_size(base, phy_chans, num_phy_chans);
> + alloc_size += sizeof(*base->log_chans) * (num_log_chans + num_memcpy_chans);
[Severity: High]
Can this unchecked addition defeat the saturation arithmetic of struct_size()
and lead to a heap buffer overflow?
If struct_size() detects an overflow and saturates to SIZE_MAX, this
unconditional addition will wrap alloc_size around to a small integer value.
As a result, devm_kzalloc() might succeed in allocating an undersized buffer,
causing an out-of-bounds write when the channels are later initialized or
accessed.
Since phy_chans, log_chans, and memcpy_chans all use the same type and are
allocated contiguously, should the counts be summed inside a single
struct_size() call like this:
alloc_size = struct_size(base, phy_chans,
num_phy_chans + num_log_chans + num_memcpy_chans);
Alternatively, the size_add() and size_mul() macros could be used to preserve
the saturation protection.
> + base = devm_kzalloc(dev, alloc_size, GFP_KERNEL);
>
> if (!base)
> return -ENOMEM;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260527203126.7053-1-rosenp@gmail.com?part=1
next prev parent reply other threads:[~2026-05-27 20:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 20:31 [PATCHv2] dmaengine: ste_dma40: turn d40_base phy_chans into a flexible array Rosen Penev
2026-05-27 20:48 ` sashiko-bot [this message]
2026-05-27 22:07 ` Rosen Penev
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=20260527204806.1DDBC1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=rosenp@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