From: Kery Qi <qikeyu2017@gmail.com>
To: andersson@kernel.org
Cc: linux-remoteproc@vger.kernel.org, Kery Qi <qikeyu2017@gmail.com>
Subject: [PATCH] remoteproc: virtio: fix uninitialized buffer use in rproc_virtio_get()
Date: Fri, 9 Jan 2026 03:23:36 +0800 [thread overview]
Message-ID: <20260108192336.1826-1-qikeyu2017@gmail.com> (raw)
rproc_virtio_get() returns early on out-of-bounds access without touching
the caller-provided buffer. Callers of virtio config accessors commonly
pass stack storage and do not get an error code back, so stale/uninit
bytes may be consumed as device configuration, leading to unpredictable
behavior and potentially leaking stack data if later exposed.
Always clear the destination buffer, reject offsets past config_len, and
clamp the read length to the available config bytes before copying.
Fixes: 92b38f851470 ("remoteproc: support virtio config space.")
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
drivers/remoteproc/remoteproc_virtio.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index c5d46a878149..8fa8c8a86b4b 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -298,10 +298,13 @@ static void rproc_virtio_get(struct virtio_device *vdev, unsigned int offset,
rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
cfg = &rsc->vring[rsc->num_of_vrings];
- if (offset + len > rsc->config_len || offset + len < len) {
- dev_err(&vdev->dev, "rproc_virtio_get: access out of bounds\n");
+ memset(buf, 0, len);
+
+ if (offset > rsc->config_len)
return;
- }
+
+ if (len > rsc->config_len - offset)
+ len = rsc->config_len - offset;
memcpy(buf, cfg + offset, len);
}
--
2.34.1
next reply other threads:[~2026-01-08 19:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 19:23 Kery Qi [this message]
2026-01-12 11:02 ` [PATCH] remoteproc: virtio: fix uninitialized buffer use in rproc_virtio_get() Zhongqiu Han
2026-01-12 18:40 ` Mathieu Poirier
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=20260108192336.1826-1-qikeyu2017@gmail.com \
--to=qikeyu2017@gmail.com \
--cc=andersson@kernel.org \
--cc=linux-remoteproc@vger.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