[PATCH v2 04/12] EDAC/versalnet: Add bounds validation in rpmsg_cb()

From: Shubhrajyoti Datta

Date: Wed Nov 18 2026 - 09:23:55 EST


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@xxxxxxx>
---

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 | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
index 2d1417135e42..0364648d91a1 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
--
2.44.4