From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Lianjie Wang <karin0.zst@gmail.com>
Cc: Bjorn Andersson <andersson@kernel.org>,
Tanmay Shah <tanmay.shah@amd.com>,
Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>,
linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rpmsg: virtio: bound the buffer sizes read from config space
Date: Mon, 2 Nov 2026 11:42:56 -0600 [thread overview]
Message-ID: <aujLoEtfDfXfh2t9@p14s> (raw)
In-Reply-To: <20261022194129.2233880-1-karin0.zst@gmail.com>
On Fri, Oct 23, 2026 at 04:41:29AM +0900, Lianjie Wang wrote:
> With VIRTIO_RPMSG_F_BUFSZ, rpmsg_virtio_get_buf_size() reads the rx and
> tx buffer sizes from the config space as u32 values and checks only that
> each can hold the message header. The probe multiplies them by the
> buffer counts in unsigned int arithmetic to size the buffer area. An rx
> buffer size of 0x1000000 with 256 rx buffers wraps the rx part to zero,
> so the allocation covers only the tx buffers, and the driver posts the
> rx buffers at offsets up to 4 GiB past its start for the device to
> write.
>
> Reject a buffer larger than the header plus U16_MAX, since the 16-bit
> msg->len cannot describe a longer payload. With at most 256 buffers in
> each direction, this bound also keeps the size of the buffer area from
> wrapping.
>
> This patch is assisted by Claude Opus 5.5.
>
> Fixes: ca96ea25e51a ("rpmsg: virtio_rpmsg_bus: Get buffer size from config space")
> Signed-off-by: Lianjie Wang <karin0.zst@gmail.com>
> ---
> The patch is tested against a virtio-rpmsg device added to QEMU. With
> buffer sizes in config space that wrap the size of the buffer area, the
> unpatched driver probes and warns in rpmsg_sg_init() while posting
> buffers past its allocation. With the patch, the probe fails with "bad
> vdev config".
>
> drivers/rpmsg/virtio_rpmsg_bus.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
Applied.
Thanks,
Mathieu
> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
> index 23ff6c8b7a20b..de4af75ee1620 100644
> --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> @@ -91,6 +91,7 @@ struct rpmsg_hdr {
> u8 data[];
> } __packed;
>
> +#define MAX_RPMSG_BUF_SIZE (sizeof(struct rpmsg_hdr) + U16_MAX)
>
> /**
> * struct virtio_rpmsg_channel - rpmsg channel descriptor
> @@ -851,9 +852,14 @@ static int rpmsg_virtio_get_buf_size(struct virtproc_info *vrp)
> virtio_cread(vdev, struct virtio_rpmsg_config,
> rxbuf_size, &vrp->tx_buf_size);
>
> - /* The buffers must hold at least the rpmsg header */
> + /*
> + * The buffers must hold at least the rpmsg header, and at most
> + * the header and the largest payload its 16-bit len describes.
> + */
> if (vrp->rx_buf_size < sizeof(struct rpmsg_hdr) ||
> - vrp->tx_buf_size < sizeof(struct rpmsg_hdr)) {
> + vrp->tx_buf_size < sizeof(struct rpmsg_hdr) ||
> + vrp->rx_buf_size > MAX_RPMSG_BUF_SIZE ||
> + vrp->tx_buf_size > MAX_RPMSG_BUF_SIZE) {
> dev_err(&vdev->dev,
> "bad vdev config: rx buf sz = %u, tx buf sz = %u\n",
> vrp->rx_buf_size, vrp->tx_buf_size);
>
> base-commit: bd1ecbb61afefc6a8b876ccbc31e9228b44e9eab
> --
> 2.56.0
>
prev parent reply other threads:[~2026-11-02 17:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 19:41 Lianjie Wang
2026-10-26 16:59 ` Mathieu Poirier
2026-11-02 17:42 ` 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=aujLoEtfDfXfh2t9@p14s \
--to=mathieu.poirier@linaro.org \
--cc=andersson@kernel.org \
--cc=arnaud.pouliquen@foss.st.com \
--cc=karin0.zst@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=tanmay.shah@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
all inboxes | Powered by JetHome®