DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: vkoul@kernel.org, dmaengine@vger.kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH] bestcomm/gen_bd: fix out-of-bounds access in PSC parameter lookup
Date: Sat, 30 May 2026 03:12:59 +0000	[thread overview]
Message-ID: <20260530031259.A630B1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260530030152.49759-1-rosenp@gmail.com>

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

Pre-existing issues:
- [Critical] Unchecked array access in `mpc512x_psc_alloc_clock` and related clock functions where `psc_num` derived from device tree is used to index arrays, causing out-of-bounds reads and writes.
--

commit 7a3c433b5cd814a1fd0d2b57113cd41cb03279a5
Author: Rosen Penev <rosenp@gmail.com>

bestcomm/gen_bd: fix out-of-bounds access in PSC parameter lookup

This commit fixes an out-of-bounds access issue in bcom_psc_gen_bd_rx_init()
and bcom_psc_gen_bd_tx_init() by properly using ARRAY_SIZE() for bounds
checking on psc_num. It also removes an unused forward declaration in
bcom_psc_gen_bd_tx_init().

> diff --git a/drivers/dma/bestcomm/gen_bd.c b/drivers/dma/bestcomm/gen_bd.c
> index 8a24a5cbc2633..75d1a6f543df9 100644
> --- a/drivers/dma/bestcomm/gen_bd.c
> +++ b/drivers/dma/bestcomm/gen_bd.c
> @@ -315,7 +315,7 @@ static struct bcom_psc_params {
>  struct bcom_task * bcom_psc_gen_bd_rx_init(unsigned psc_num, int queue_len,
>  					   phys_addr_t fifo, int maxbufsize)
>  {
> -	if (psc_num >= MPC52xx_PSC_MAXNUM)
> +	if (psc_num >= ARRAY_SIZE(bcom_psc_params))

[Severity: Critical]
This is a pre-existing issue, but while looking at this fix for the psc_num
bounds checking, I noticed a similar unchecked array access regression vector
using psc_num in drivers/tty/serial/mpc52xx_uart.c.

In mpc512x_psc_alloc_clock(), psc_num is calculated directly from
port->mapbase:

drivers/tty/serial/mpc52xx_uart.c:mpc512x_psc_alloc_clock() {
	...
	psc_num = (port->mapbase & 0xf00) >> 8;
	...
	psc_mclk_clk[psc_num] = clk;
	...
}

Because port->mapbase comes from the device tree via
of_address_to_resource(), a malformed device tree could supply an address
like 0x11F00, allowing psc_num to evaluate up to 15.

Since psc_mclk_clk and psc_ipg_clk are arrays sized to MPC52xx_PSC_MAXNUM
(which is 12 when CONFIG_PPC_MPC512x is defined), wouldn't this allow an
out-of-bounds write of a pointer to the BSS section?

The exact same unchecked psc_num calculation also appears in
mpc512x_psc_relse_clock() and mpc512x_psc_endis_clock(), leading to similar
out-of-bounds reads and writes.

>  		return NULL;
>  
>  	return bcom_gen_bd_rx_init(queue_len, fifo,
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260530030152.49759-1-rosenp@gmail.com?part=1

  reply	other threads:[~2026-05-30  3:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-30  3:01 [PATCH] bestcomm/gen_bd: fix out-of-bounds access in PSC parameter lookup Rosen Penev
2026-05-30  3:12 ` sashiko-bot [this message]
2026-05-30  4:18   ` 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=20260530031259.A630B1F00893@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