dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vinayak Katoch" <vinayak.katoch@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org, robh@kernel.org,
	conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 2/4] misc: fastrpc: handle multi-cell reg in context bank probe
Date: Wed, 07 Oct 2026 11:50:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-162941@kernel.org> (raw)
In-Reply-To: <20261007-extended-mapping-v2-2-5dca3aa2c2d3@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] misc: fastrpc: out-of-bounds read due to index underflow bypassing bounds check
--

commit a9dd81ce5afe0b6b73eb7394627f61e8448d9435
Author: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>

misc: fastrpc: handle multi-cell reg in context bank probe

Platforms that use #address-cells = <2> on the fastrpc node encode the
context bank number in cell[1] of the reg property rather than cell[0].
Reading cell[0] on such platforms yields 0 for every context bank,
causing all sessions to share SID 0 and corrupting IOVA address
construction.

> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index b29c1fd00de28..5c7bb56cf46d0 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -2348,7 +2348,8 @@ static int fastrpc_cb_init(struct platform_device *pdev)
>  	if (!cctx)
>  		return -EINVAL;
>  
> -	if (of_property_read_u32(dev->of_node, "reg", &sid))
> +	if (of_property_read_u32_index(dev->of_node, "reg",
> +				       of_n_addr_cells(dev->of_node) - 1, &sid))

[Severity: High]
Can this code underflow the index if a malformed device tree explicitly sets
#address-cells = <0> on the parent node?

If of_n_addr_cells() evaluates to 0, the unchecked subtraction introduces an
underflow. Because the index argument to of_property_read_u32_index() is a
u32, this implicitly casts -1 to 0xFFFFFFFF.

This propagates down to bypass bounds checking in the property reader:

drivers/of/property.c:of_property_read_u32_index() {
    ...
	const u32 *val = of_find_property_value_of_size(np, propname,
					((index + 1) * sizeof(*out_value)),
					0,
					NULL);
    ...
}

The index + 1 expression wraps to 0 here, reducing the min size to 0 and
defeating the internal length check inside of_find_property_value_of_size().

This subsequently triggers an out-of-bounds read when extracting the value:

drivers/of/property.c:of_property_read_u32_index() {
    ...
	*out_value = be32_to_cpup(((__be32 *)val) + index);
    ...
}

This pointer arithmetic adds 0xFFFFFFFF to the base property address, resulting
in an immediate out-of-bounds memory dereference traversing approximately 17 GB
past the base pointer.

>  		dev_info(dev, "FastRPC Session ID not specified in DT\n");
>  
>  	spin_lock_irqsave(&cctx->lock, flags);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261007-extended-mapping-v2-0-5dca3aa2c2d3@oss.qualcomm.com?part=2

  reply	other threads:[~2026-10-07 11:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 11:37 [PATCH v2 0/4] misc: fastrpc: add extended IOVA mapping support Vinayak Katoch
2026-10-07 11:37 ` [PATCH v2 1/4] dt-bindings: misc: qcom,fastrpc: add iommu-ranges support for context bank Vinayak Katoch
2026-10-07 11:47   ` sashiko-bot
2026-10-09  9:56   ` [PATCH v2 1/4] dt-bindings: misc: qcom, fastrpc: " Krzysztof Kozlowski
2026-10-07 11:37 ` [PATCH v2 2/4] misc: fastrpc: handle multi-cell reg in context bank probe Vinayak Katoch
2026-10-07 11:50   ` sashiko-bot [this message]
2026-10-07 11:37 ` [PATCH v2 3/4] misc: fastrpc: add extended context bank support Vinayak Katoch
2026-10-07 11:52   ` sashiko-bot
2026-10-07 11:37 ` [PATCH v2 4/4] misc: fastrpc: add UAPI flags for extended IOVA mapping Vinayak Katoch
2026-10-07 11:49   ` 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=sashiko-outbox-162941@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vinayak.katoch@oss.qualcomm.com \
    /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