From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796200393; b=nufdbhb2S0TffAyv9vibMOPyY5+PCN+U1z326nSoMwerQ675HcMZPzGNc9P7+756V6ER 3kj83IHl1XBONGKPkQVjgf7DQst19lsySfEUH2AGPGcDYQ3qzhOXUEkRaWp3Ze1qC4UtF Vqr0iqc7uEoq81e3lAe9/AJH8oc2sQbswEG+skpi0mQ3IbQiyeuGfL8uppaJwuxWvar2a vACTjxA84dzPR2r+sQ8EE5dGRIbqSafvMC8zZVnJkLsWR69EdGKKjEb0J8AY8k5zTDJgz a/tUbtZX5BUi/AyFSj4PxByAsTTS098PNmcOlNNUXYvMubX9BC5Le11gAZK9ij4HYcA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200393; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=/0AmPpbcyGn/O2z/7ud5OogBo2+s0BPVMn1lhg1sEbA=; b=XON0O6NExMFFBGTLQEkiLsGMNyOxTUsWSL+0x0lnyxmwjkQvOyDGv6KmVmLVzmLL1Dky SZ7IRt5pZouzJP92nrGet+1uZcvo3RPOiiHZi1VZv4ns6Jlofx87HdCQnpmstef05kW3J rzFCzq0dDwtlRY7H9gyNCLHr1ZLpIVccBK5IQVABeUsIdZExVmZUm/8V64OmB0z/Rce3n uuSv1CAV7zl9pqUOoXP4klB2Te4Xa27eUgs9YRqE/0OdXFDB8uUppL4iBKe90BNr+Tr7b 6j3efb8GHoq9SC1dcEA2rsgtSeasBwCrprZmUirvioTP/0SXsSiKDkqOx7kKhXBOEag== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aNj0FP40; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=HPxylftG; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6451A606A330 for ; Wed, 2 Dec 2026 08:33:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6451A606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aNj0FP40; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=HPxylftG DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796200393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/0AmPpbcyGn/O2z/7ud5OogBo2+s0BPVMn1lhg1sEbA=; b=aNj0FP40lqnPdthmB1aXj95XEccfp2IjmAWoynnYwfzW8vKK3wOjb0XlCfDBr/qXK2WA82 u5/SlKSAvKv3UxnKew2FwodvhW+YYeKsXEsf+jwtfR1d7V5ZIADx3VFfAt0N8VAfJwlUNl f7u2F2gxn27JAc21vnBKNrkUGUxOuEE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-4mahQ9v_Pli2CiLpunLabw-1; Wed, 2 Dec 2026 08:33:10 +0000 X-MC-Unique: 4mahQ9v_Pli2CiLpunLabw-1 X-Mimecast-MFC-AGG-ID: 4mahQ9v_Pli2CiLpunLabw_1796200389 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-49953abe51fso90839505e9.1 for ; Wed, 02 Dec 2026 00:33:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796200389; x=1796805189; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=/0AmPpbcyGn/O2z/7ud5OogBo2+s0BPVMn1lhg1sEbA=; b=HPxylftGAlFzysIBy1S1J2zn0kFu8YqTLccTPVsE4KjerLcAVZl5QB56Xv3QGgH6mZ LIpxYnkseJ3bX4MBSxfaSEnbvfatui162PKhQuQWbclG+yJfh+Nq+zJMBVT1tvZ2BWcz YDe67pT73iRIz6N0C3KM6HLRqdpVK2alg3ymJl2oA5eBU9aR+w09LEREk+8P/jJdDxvX Fv8BBZw/bd50OkOyGibJPL8GLHWwH9klLiGvqb4Pvzi38gJsOdtzo9lLZLuUj7UCfyzi UExQVHg96K7GUNhiDqs7I9XYBlKbZM2SnZoqCn5+w5YU2JT3Mmj5gf0XSKGwBgng9+Gk NifA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796200389; x=1796805189; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=/0AmPpbcyGn/O2z/7ud5OogBo2+s0BPVMn1lhg1sEbA=; b=TGVjJdpoB2MVRaRUbU7miNPImZO+zwhInb/neoZin1OycLOUfG4VPSsR0vAIh4YnoN WL461xi2jNqqR6i+0KBPvfql2vyDC+Z9v6SPHhMjTIR1jrO3mEar0UZa/AigIqcX7Xd9 OLXXwM84xAZxEnxuhRJWjZDa6udNCruIvJd3YiFq9cGaaRhs6XxrqU3eZ1v+DpWvb2T/ gKP8QAfjvyh2c6PwnPC/xuaWVIHxJ44HMBTMwbbeGiSvl6jJ5QgSM7kdbOh/zcc3+C+M KMTfWq6DxNwvEYosfTukej6cCVB7/deMaOE+4DNpHk0jN6ESkOs7PHequDJIo9x7Q68P he/g== X-Forwarded-Encrypted: i=1; AL+hErERhFl39dt2ajri8Xiik+hGE8iNK39AMR1tplXH0GX0yb3WlAwZcF/ArJgzEk/qyLM8mB2cIjA=@vger.kernel.org X-Gm-Message-State: APuU4Z9j6Su30QZy4QOa2LRm1SdMb2rzCU4dao0zZVWvkNegAx2Zyqye iPBe2LQzicbvsCpUWFGsNn+vkkwTBsTlY9AUiL9MKijyey529Y8QKoYY7bIHIPfy0VzBZZn4hPu 552lMW59ikx420u5pbDGOkTWZlhHtbxtPs5qYIytTqLFKWM3TccWWzW1FCg== X-Gm-Gg: AZFdTZel78XBzHsLlj35t73Ca6IHdNJYCPBS1Uir7LddoDPzRqr0aXgppSek1H/MwqI xX191+4GfJvFx0I3NF2GXtgCk4cgEvBzgcTRMQ618tCCGBaYTiRNNL8G516H3Csk1H6ok6KtsCX n78pGP20J+MhOtgTbhjnHRanoBT08Ci9aO56AQV20h4Rv11eJon2x4ZtJe08dhEXl4n+0ocf52W BQjVUqXOcJWYaTer8q3PMiJTjjc06p2qvDSd5t+fGHJ2Mlv1vHOd2LUlkCy8QEtsAKsq26wd/W9 qXis6BsgRcc6p73cNra6jxxJ+TZjyOwyh5amfLQU1EdB8HxC9+PHWdLx+obJx17axm/LoQNc4QX cOv2zEOu1lm1fg63KDfBawBrI5fvd0SE5277TQn121Q== X-Received: by 2002:a05:600c:a117:b0:4bb:a5e1:7497 with SMTP id 5b1f17b1804b1-4bba5e18d83mr361722585e9.32.1796200389083; Wed, 02 Dec 2026 00:33:09 -0800 (PST) X-Received: by 2002:a05:600c:a117:b0:4bb:a5e1:7497 with SMTP id 5b1f17b1804b1-4bba5e18d83mr361722045e9.32.1796200388554; Wed, 02 Dec 2026 00:33:08 -0800 (PST) Received: from redhat.com ([2a0d:6fc0:153a:4c00:6468:7acf:febf:a046]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884a3a3dsm1069819475e9.10.2026.12.02.00.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 00:33:07 -0800 (PST) Date: Wed, 2 Dec 2026 03:33:05 -0500 From: "Michael S. Tsirkin" To: Eugenio Perez Martin Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Seohyeon Maeng , minki@morningstarsec.dev, YanXin Li , Jason Wang , "David S. Miller" , Linfeng Sun , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org Subject: Re: [PATCH] vhost: reject used ring batches larger than the ring Message-ID: <20261202033151-mutt-send-email-mst@kernel.org> References: <66327153423e98bd10778bac1f29c26ba633e02a.1796163071.git.mst@redhat.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Dec 02, 2026 at 09:15:43AM +0100, Eugenio Perez Martin wrote: > On Tue, Dec 1, 2026 at 11:19 PM 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(). > > > > Cc: stable@vger.kernel.org > > Reported-by: Seohyeon Maeng > > Reported-by: minki@morningstarsec.dev > > Reported-by: YanXin Li > > 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 > > Cc: Eugenio Pérez > > Signed-off-by: Michael S. Tsirkin > > --- > > 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; > > + } > > Putting the check here returns -EINVAL, but some buffers have > effectively been sent if the for loop ran any iterations. But the > caller cannot know how many buffers have been sent. Perhaps the check > should occur before the for loop, ensuring an all-or-nothing > operation? That's an extra loop, and the driver is out of spec. Not worth the perf cost I'd say? > The caller is already broken if it performs this operation so this is > a little nitpick, but recovery is easier that way. Recovery is mostly reset anyway. > > > 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 > > -- > > MST > >