Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shubhrajyoti Datta" <shubhrajyoti.datta@amd.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 04/12] EDAC/versalnet: Add bounds validation in rpmsg_cb()
Date: Wed, 18 Nov 2026 14:33:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-221219@kernel.org> (raw)
In-Reply-To: <20261118142213.100581-5-shubhrajyoti.datta@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] EDAC/versalnet: stale part_len on split-message failure in
  rpmsg_cb()
--

commit a43cb655a4c7983a62adb71672a8f139d96e6c3c
Author: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>

EDAC/versalnet: Add bounds validation in rpmsg_cb()

This commit adds bounds checks on the RPMsg payload's offset, length, and
total error length before indexing mc_priv->regs[] in rpmsg_cb().

> diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
> index 2d1417135e42a..0364648d91a1e 100644
> --- a/drivers/edac/versalnet_edac.c
> +++ b/drivers/edac/versalnet_edac.c
> @@ -607,6 +607,13 @@ static int rpmsg_cb(struct rpmsg_device *rpdev, void *data,
>  	length = result[MSG_ERR_LENGTH];
>  	offset = result[MSG_ERR_OFFSET];
>  
> +	if (length > REG_MAX || offset > REG_MAX - length ||
> +	    result[TOTAL_ERR_LENGTH] > REG_MAX) {
> +		dev_warn_ratelimited(&rpdev->dev,
> +				     "Rejecting the faulty message\n");
> +		return -EINVAL;
> +	}
> +
>  	/*
>  	 * The data can come in two stretches. Construct the regs from two
>  	 * messages. The offset indicates the offset from which the data is to

[Severity: Medium]
Does rejecting one part of a split message leave mc_priv->part_len out of
sync instead of discarding the entire message?

When the first part of a split message succeeds, rpmsg_cb() stores its
length in mc_priv->part_len and returns 0:

drivers/edac/versalnet_edac.c:rpmsg_cb() {
	...
	if (result[TOTAL_ERR_LENGTH] > length) {
		if (!mc_priv->part_len)
			mc_priv->part_len = length;
		else
			mc_priv->part_len += length;

		if (mc_priv->part_len < result[TOTAL_ERR_LENGTH])
			return 0;
		mc_priv->part_len = 0;
	}
	...
}

If the second part then fails the bounds check and returns -EINVAL,
mc_priv->part_len is not reset to 0.  When the first part of the next
valid split message arrives, its length is added to the stale
mc_priv->part_len, causing rpmsg_cb() to report an error prematurely from
incomplete and stale data in mc_priv->regs[] and leaving mc_priv->part_len
desynchronized for subsequent split messages.

Conversely, if the first part of a split message is rejected (leaving
mc_priv->part_len at 0) and the second part arrives with a valid non-zero
offset, rpmsg_cb() does not check that offset matches mc_priv->part_len
and accepts the orphaned second fragment.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118142213.100581-1-shubhrajyoti.datta@amd.com?part=4

  reply	other threads:[~2026-11-18 14:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 14:20 [PATCH v2 00/12] EDAC/versalnet: Fix error handling, teardown, and robustness Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 01/12] EDAC/versalnet: Fix device_register() error handling in init_one_mc() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 02/12] EDAC/versalnet: Use designated initializer for rpmsg_channel_info Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 03/12] EDAC/versalnet: Fix use-after-free in remove_one_mc() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 04/12] EDAC/versalnet: Add bounds validation in rpmsg_cb() Shubhrajyoti Datta
2026-11-18 14:33   ` sashiko-bot [this message]
2026-11-18 14:20 ` [PATCH v2 05/12] EDAC/versalnet: Make dwidth per-controller Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 06/12] EDAC/versalnet: Wait for RPMsg endpoint initialization Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 07/12] EDAC/versalnet: Initialize MCDI before RPMsg registration Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 08/12] EDAC/versalnet: Guard against NULL drvdata in rpmsg_cb() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 09/12] EDAC/versalnet: Move platform_set_drvdata() to mc_probe() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 10/12] dt-bindings: memory: xlnx,versal-net-ddrmc5: Add amd,num-ctrl property Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 11/12] EDAC/versalnet: use device tree property for number of controllers Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 12/12] EDAC/versalnet: Make get_ddr_config() return errors Shubhrajyoti Datta

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-221219@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shubhrajyoti.datta@amd.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