From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796200393; b=m6CXRUqgzHlWFobo1Vz2BXKg+3tHuiWAmWCVl1lycpO1uXZU6TJCxRkSLwToiAMDtvyh QvvYq+JO/TVFYkC8yIHPteBbT5gF2RuEQyN+jPtEXQmWbDCi58z+PD1QgS56UkixD2aq2 GA/9yL/gboRfc3cb7b154RCyxza682jFJDS1iRQB9vxpBou77uBxU213OLQCmkzRmzWbB 19CvoZT5ih1WufT+vTJCa1fdGOB/zYtGTvTcqg9YfWVME818/YrKvDLsdzlS/fSUMaFhq On8xoYqJD1x/m0TuXHx1Yl/TZedQTrkXzuMChC+OPgcwT+RnKTzZfVNtt7skG4S9Y7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200393; h=DMARC-Filter:DKIM-Signature:X-MC-Rep:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received: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:In-Reply-To:X-Mimecast-Spam-Score:X-Mimecast-MFC-PROC-ID: X-Mimecast-Originator:Content-Type:Content-Disposition: Content-Transfer-Encoding; bh=/0AmPpbcyGn/O2z/7ud5OogBo2+s0BPVMn1lhg1sEbA=; b=B0axVtXdwmK00INqicSU2cC2OV+6NzFh2djxU3RijA30Nta7cqmd7U3z9ahRCjeFzbOB ZpTCHYLd8+eS6TY/o/j5ijFlwTEXfcZOIZxn/gNez3M4MIMTQYWQFCZAEds7qtkK7fHWW ZUW0nhvTDQObBEHeA5ZFyBpHkbEOijPHmEpZKnTJ3dPdnHofcHgCo8/BCzjkxJj8YO0rx pO+6qctBsIVuYXAoI98yqsFxAolKFWjKRdA8g9B8yKOriO90Lcdm19ePtA4JGLVZF+Mfq gbqcUyxBcj5ohcsi0unQpVhjAQz9Ffs7MXSZW+QicS5tyZ+uhYKH4Oc8HRG5Xf9kXmQ== 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=D2Roz2KU; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 CA988606A323 for ; Wed, 2 Dec 2026 08:33:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA988606A323 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=D2Roz2KU DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796200392; 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=D2Roz2KUhpBzyJlel+wEYEBee/0NvUSSqPi0KMOQWrhZnHbT1qWnKyxUpZCdFTm8YGqQy0 CicAVLKS6oezesrGPXiilMX1nUzS1fgQssRqgyC4idDaL5t6Kinv1wwhZOB9qsIbFay9Qu aGFskN2qsEcwRVKPia1qsd6FS1BdbIg= X-MC-Rep: binary re single Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-5RWdnTQ8NQ-Palz8OeK-OA-1; Wed, 2 Dec 2026 08:33:10 +0000 X-MC-Unique: 5RWdnTQ8NQ-Palz8OeK-OA-1 X-Mimecast-MFC-AGG-ID: 5RWdnTQ8NQ-Palz8OeK-OA_1796200389 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4a204ac318aso60647685e9.2 for ; Wed, 02 Dec 2026 00:33:10 -0800 (PST) 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=ij2LQziBsyu2UVsD5CfA2NhcTcIDbn90nLMh4IADXg/oPo/RJ3YYk/EoArNvEjGUIl aO3sE/DiDVbWjDg5qny9eEOAHdbwsLKvYDz9UUZJX6yWMGkxqhwip2/P3Z4wQjWGtT4b YVQw1Nf0+XJy9TnUe4mxkFFRHY7iZlamVR1qIEm6Q0ulw8AuMW8zZJXm/LUqKASIsPZ0 Mg1STa3XyUn9CfcxPh7BTqOoBSBbqH4GPkkDbjxwIyKFmaOHq6yIyUNNBb/EZ/6xGkFr Tknk++4vH4UPIgkJHpssSigu83SNHd4XsC3uRrN6GbU6/kQVViFLRnY8lB7S0m1Yf12y Ud3g== X-Forwarded-Encrypted: i=1; AL+hErEuVWxFrd3NKd8TX2x95Yt4v32dGMtKWOtQxJsiMtbOeglW2T8JKeYc7U+2qnCYgj5mYm+5AQZH2fbbODPe4A==@lists.linux.dev X-Gm-Message-State: APuU4Z9bnbL/smNktKWfA70Qu+EJDvtLwzh457okMc2nNn8OJ3CP85aX woO9dVE3KEMxduD2I6ERLweaohVQYyb6vGEWPY680qjZ6JIKYsSK/j2UAPg9LTIZOw9pDeBq/l/ JiacHt4mF4Y2irLUu6LGPV2fWmqbw40yktB3kAwUaIJlq25Cehzjt4sWBPUsKuWIz8Cjl X-Gm-Gg: AZFdTZd/ZGb5RURwG3A2Xh2IkXRlyW9SOSgHmYLisFnQt04kNIxM8Fck3I/ueCEcpCB Qcs9+RW/hDZEdJxK0aXPQMR3pV54r45T5dac+DXbR8H+cC2KDF2K73nV9yC7I+1wHrzcDnv/X4w LukwRVHNYh6IrEhzcumuJodB+fQ+zwr/2bGlwQNewMgGv1h79Yla0NciITlnl32qWHPrqEEhHWh IAwFOQLNX7cujchGnDa13S1sLKbxEcZtX5ZN5ZIIGtw6SdbIOe86IAYYwVvSUIw4YEsPow4NFW8 r2Ilk3e5V96EG6RqAD+p6uKQb+QO1+gvWM4ZEaO9sARGdjJ2ScYW+SR7yn/cQ0YC731Cdn7thKh yZfzm6u+WW3Y6HiYqx2HclLMFyUUA3CXScY77xDkIcA== X-Received: by 2002:a05:600c:a117:b0:4bb:a5e1:7497 with SMTP id 5b1f17b1804b1-4bba5e18d83mr361722605e9.32.1796200389085; 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: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5rxv2EwwFrqQpctPn3boXmvVOViWptV55d-EYkMTJ1o_1796200389 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 > >