From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Kery Qi <qikeyu2017@gmail.com>
Cc: andersson@kernel.org, linux-remoteproc@vger.kernel.org
Subject: Re: [PATCH] remoteproc: virtio: fix uninitialized buffer use in rproc_virtio_get()
Date: Mon, 12 Jan 2026 11:40:17 -0700 [thread overview]
Message-ID: <aWVAEZ5ZWgRkOgtf@p14s> (raw)
In-Reply-To: <20260108192336.1826-1-qikeyu2017@gmail.com>
Good day Kery,
On Fri, Jan 09, 2026 at 03:23:36AM +0800, Kery Qi wrote:
> 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);
I think this should be done in the caller, not virtio_config_ops->get(). I am
willing to reconsider if you include this change in a patchset that changes all
the other virtio_config_ops->get() function.
Thanks,
Mathieu
> +
> + 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
>
>
prev parent reply other threads:[~2026-01-12 18:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 19:23 [PATCH] remoteproc: virtio: fix uninitialized buffer use in rproc_virtio_get() Kery Qi
2026-01-12 11:02 ` Zhongqiu Han
2026-01-12 18:40 ` Mathieu Poirier [this message]
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=aWVAEZ5ZWgRkOgtf@p14s \
--to=mathieu.poirier@linaro.org \
--cc=andersson@kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=qikeyu2017@gmail.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