From: "Pandey, Radhey Shyam" <radheys@amd.com>
To: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>,
linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org
Cc: git@amd.com, shubhrajyoti.datta@gmail.com,
Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>,
Borislav Petkov <bp@alien8.de>, Tony Luck <tony.luck@intel.com>,
Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
Subject: Re: [PATCH v3 1/7] EDAC/versalnet: Add bounds validation in rpmsg_cb()
Date: Mon, 30 Nov 2026 11:35:15 +0530 [thread overview]
Message-ID: <277d4a54-4686-4076-9183-682b1553d40e@amd.com> (raw)
In-Reply-To: <20261127163853.3563991-2-shubhrajyoti.datta@amd.com>
On 11/27/2026 9:59 PM, Shubhrajyoti Datta wrote:
> The firmware-supplied offset and length values from the RPMsg payload
> are used without validation to index mc_priv->regs[] (REG_MAX entries).
> A malformed or buggy firmware message could access past the end of the
> array, corrupting adjacent structure members or kernel memory.
>
> Add bounds checks for the offset and length before accessing the array.
>
> rpmsg_cb() supports messages split across two RPMsg callbacks. If
> validation fails for either part of a split message, discard the entire
> message.
>
> Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR controller")
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
Copied from internal sashiko run. Seems valid, please review/fix.
The new check bounds length only against REG_MAX, but nothing compares
length against the len argument of rpmsg_cb(). Can this read past the
end of the received RPMsg buffer?
rpmsg_cb() reads result[ERROR_LEVEL], result[ERROR_ID],
result[TOTAL_ERR_LENGTH], result[MSG_ERR_OFFSET] and
result[MSG_ERR_LENGTH] without checking that len covers the header.
Should the patch also check that len is at least the header size, and
that (ERROR_DATA + length) * 4 <= len?
Is the offset != mc_priv->part_len condition safe for messages that are
dropped or interrupted? part_len persists across callbacks, so an
interrupted split sequence leaves it non-zero.
> ---
>
> Changes in v3:
> If it is a split message tben discard both the messages
>
> Changes in v2:
> Sashiko comment
> "This is a pre-existing issue, but are offset and length validated before
> being used as indices?"
>
> drivers/edac/versalnet_edac.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
> index 2019a0f102c6..405d994303c7 100644
> --- a/drivers/edac/versalnet_edac.c
> +++ b/drivers/edac/versalnet_edac.c
> @@ -607,6 +607,22 @@ static int rpmsg_cb(struct rpmsg_device *rpdev, void *data,
> length = result[MSG_ERR_LENGTH];
> offset = result[MSG_ERR_OFFSET];
>
> + /*
> + * For a message that is part of a split sequence, offset must
> + * continue exactly where the previously accumulated data
> + * (mc_priv->part_len) left off; otherwise either a fragment was
> + * dropped or this is an unrelated/replayed message. Reject it and
> + * reset part_len so a bad fragment cannot desync, or be used to
> + * smuggle data into, subsequent split messages.
Trim this explanation. Few checks are self explanatory.
> + */
> + if (length > REG_MAX || offset > REG_MAX - length ||
> + result[TOTAL_ERR_LENGTH] > REG_MAX || offset != mc_priv->part_len) {
> + dev_warn_ratelimited(&rpdev->dev,
> + "Rejecting the faulty message\n");
> + mc_priv->part_len = 0;
> + 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
next prev parent reply other threads:[~2026-11-30 6:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 16:29 [PATCH v3 0/7] EDAC/versalnet: Fix error handling, teardown, and robustness Shubhrajyoti Datta
2026-11-27 16:29 ` [PATCH v3 1/7] EDAC/versalnet: Add bounds validation in rpmsg_cb() Shubhrajyoti Datta
2026-11-30 6:05 ` Pandey, Radhey Shyam [this message]
2026-11-27 16:29 ` [PATCH v3 2/7] EDAC/versalnet: Make dwidth per-controller Shubhrajyoti Datta
2026-11-30 6:14 ` Pandey, Radhey Shyam
2026-11-27 16:29 ` [PATCH v3 3/7] EDAC/versalnet: Wait for RPMsg endpoint initialization Shubhrajyoti Datta
2026-11-27 16:51 ` Shubhrajyoti Datta
2026-11-27 16:29 ` [PATCH v3 4/7] EDAC/versalnet: Guard against NULL drvdata in rpmsg_cb() Shubhrajyoti Datta
2026-11-27 16:29 ` [PATCH v3 5/7] EDAC/versalnet: Make get_ddr_config() return errors Shubhrajyoti Datta
2026-11-27 16:29 ` [PATCH v3 6/7] EDAC/versalnet: fix the remove controller crash Shubhrajyoti Datta
2026-11-27 16:29 ` [PATCH v3 7/7] EDAC/versalnet: Move platform_set_drvdata() to mc_probe() Shubhrajyoti Datta
2026-11-30 6:49 ` [PATCH v3 0/7] EDAC/versalnet: Fix error handling, teardown, and robustness Pandey, Radhey Shyam
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=277d4a54-4686-4076-9183-682b1553d40e@amd.com \
--to=radheys@amd.com \
--cc=bp@alien8.de \
--cc=git@amd.com \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=radhey.shyam.pandey@amd.com \
--cc=sai.krishna.potthuri@amd.com \
--cc=shubhrajyoti.datta@amd.com \
--cc=shubhrajyoti.datta@gmail.com \
--cc=tony.luck@intel.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