From: Dongli Zhang <dongli.zhang@oracle.com>
To: "Michael S. Tsirkin" <mst@redhat.com>, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org, "Seohyeon Maeng" <bioloidgp@gmail.com>,
minki@morningstarsec.dev, "YanXin Li" <fadouse@pm.me>,
"Jason Wang" <jasowangio@gmail.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
"Linfeng Sun" <linfeng.sun.dev@gmail.com>,
kvm@vger.kernel.org, virtualization@lists.linux.dev,
netdev@vger.kernel.org
Subject: Re: [PATCH] vhost: reject used ring batches larger than the ring
Date: Wed, 2 Dec 2026 09:58:12 -0800 [thread overview]
Message-ID: <70e8959e-6102-4ef9-98da-ce8fc84f6739@oracle.com> (raw)
In-Reply-To: <66327153423e98bd10778bac1f29c26ba633e02a.1796163071.git.mst@redhat.com>
On Tue, Dec 1, 2026 2:18:53PM -0800, Michael S. Tsirkin wrote:
> A compliant driver never has more than vq->num buffers in flight at
> once, so a batch accumulated before used->idx advances never exceeds
> vq->num.
>
> Reject used count > vq->num in
> vhost_add_used_n()/vhost_add_used_n_in_order().
Only regarding the out_out_order case, may I confirm if this patch is still
required as the below one is already available?
vhost: split out-of-order used ring batches at every wrap
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5570a998b884c988dbe105430d7e2d8e9411e37e
Thank you very much!
Dongli Zhang
>
> Cc: stable@vger.kernel.org
> Reported-by: Seohyeon Maeng <bioloidgp@gmail.com>
> Reported-by: minki@morningstarsec.dev
> Reported-by: YanXin Li <fadouse@pm.me>
> Fixes: e2b3b35eb989 ("vhost_net: batch used ring update in rx")
> Fixes: 4afb52c2af44 ("vhost_net: batch update used ring for datacopy TX")
> Fixes: bfcde6b64769 ("vhost: fix dirty logging for in-order used ring entries")
> Cc: Jason Wang <jasowangio@gmail.com>
> Cc: Eugenio Pérez <eperezma@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> drivers/vhost/vhost.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index d1831f4e09981..a00151932e4e5 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -3181,6 +3181,7 @@ static int vhost_add_used_n_in_order(struct vhost_virtqueue *vq,
> {
> vring_used_elem_t __user *used;
> u16 old, new = vq->last_used_idx;
> + unsigned int total = 0;
> int start, i;
>
> if (!nheads)
> @@ -3189,6 +3190,12 @@ static int vhost_add_used_n_in_order(struct vhost_virtqueue *vq,
> start = vq->last_used_idx & (vq->num - 1);
>
> for (i = 0; i < count; i++) {
> + total += nheads[i];
> + if (unlikely(total > vq->num)) {
> + vq_err(vq, "Added %u > %u used heads\n",
> + total, vq->num);
> + return -EINVAL;
> + }
> if (vhost_put_used(vq, &heads[i], start, 1)) {
> vq_err(vq, "Failed to write used");
> return -EFAULT;
> @@ -3245,6 +3252,11 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
> bool in_order = vhost_has_feature(vq, VIRTIO_F_IN_ORDER);
> int r;
>
> + if (unlikely(count > vq->num)) {
> + vq_err(vq, "Added %u > %u used entries\n", count, vq->num);
> + return -EINVAL;
> + }
> +
> if (!in_order || !nheads)
> r = vhost_add_used_n_ooo(vq, heads, count);
> else
prev parent reply other threads:[~2026-12-02 17:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 22:18 [PATCH] vhost: reject used ring batches larger than the ring Michael S. Tsirkin
2026-12-02 8:15 ` Eugenio Perez Martin
2026-12-02 8:33 ` Michael S. Tsirkin
2026-12-02 17:58 ` Dongli Zhang [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=70e8959e-6102-4ef9-98da-ce8fc84f6739@oracle.com \
--to=dongli.zhang@oracle.com \
--cc=bioloidgp@gmail.com \
--cc=davem@davemloft.net \
--cc=eperezma@redhat.com \
--cc=fadouse@pm.me \
--cc=jasowangio@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linfeng.sun.dev@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minki@morningstarsec.dev \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=virtualization@lists.linux.dev \
/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