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=XGO3zrzkmXYdMOMuc7YNFazB4SsoIwdtgW0F3P4teE5CsgTqxC3yru6aysKJ/mOkTWxS Qe/Zv24Ed1oMHk1X1Y1IiKLX6ns7YP+q7jon++lsjgbGcHjwx7Q8l38WJBTY+IBUaftAW Uz87eDsRe9nWRG8IWUqeBftHSqaD28t43ZlOuLotcGIx7UrJrGMk5SVV/7VrRZn1TvH+g UG++ttEKmyHgqvcBylfzkfYfYaIgwnAFZ9viIE+ENcx3f495IDGceuYp3qbyCQVU70A/J +TuvwQgq6xkQZFj97tt8WVlmBJMzd1imhMAOq3MNwB4ZsW8FBbrYGTZBGh62aLGNYlA== 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=QLGHyQiWuPnWOhB8pyVWF7AokNWSdCy3ltI06neWqMerwaRJa0wD3ud3+P026PlMZQaY winzm3WFjO2iZDu9j2m74OPQDWL8A5BfPJQq+MnXNSeA8U9w/CR+6XHwD0h4ukImdDwNF /k/ma4iALbLPQeRDqo+yhTItM/zGGaqZmrZ6Rx+uXGz4cEBeePUAdkkgLlKxEIp/4ZQv5 v5q1dsIkPBVYZdeXm0ukzTj8oQktnugc2Lvnnrw8g3PHueMtprMyvyfU5BqvtchBdfkw5 bi5cLLz/f5WRbZAOvg2N3EAMQn30vhyKVqYsRTE3l3OLj7h9LtAOyVnzWGQk0zA3Zog== 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 4BC13606A32F for ; Wed, 2 Dec 2026 08:33:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4BC13606A32F 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-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-88-NBX6kIw1PS2qO-L9PwFZEw-1; Wed, 2 Dec 2026 08:33:10 +0000 X-MC-Unique: NBX6kIw1PS2qO-L9PwFZEw-1 X-Mimecast-MFC-AGG-ID: NBX6kIw1PS2qO-L9PwFZEw_1796200389 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-49953abe51fso90839485e9.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=rc45X8QPCv6nHtd4iA4B3x6ZkgcpVWfrFRfqsbVZfTMh7by4EQ5qmEmTi7Etd805nL ouaqVYd/MGcIQhTXsuwLFNSuvieoi0djCl96f1+k/c9TbLD6d1kKVyh8w/XJTpDGU7nC +PqxjQ6IrXcuSp7pzV69+s7RNdFyUT4oArMdwyAKOPXbMpysJaj0JKMzfySxdtaMUcCh hqmxSC5hKRG7r5QwdRNHVmFHO/sqXCjO5Xqi+RnrXq3i9j4vCqjJv24pHFsuW8PDmqCV H9JkgZwfnyv+E6lXllaXrEqvnHOzAA3MBHnTClmbk/2571p8nQ/S7++KL6U1HO2O/puE sefg== X-Forwarded-Encrypted: i=1; AL+hErG9OLESUCuOu5TeL8Ge8HFZwR+uG+OTPME5uVTGJAPIU5E/taE6wFRSWi4xjP+7ywUigP4=@vger.kernel.org X-Gm-Message-State: APuU4Z+2IsXT0DUx36X9ld8BGZj0CpefAl6geTQ04JYpnFRttC2bjPnH AEdUE4YGwnhLepMmzhkq2a82kctJdTKmZbG8lF14hS6qA0LOZppQ6eI7cQcxMI1UW39OgMKS8lX 06jEtXixuiyPOTlovkSRAPVdgMuFA4pbS+5Qf8FI9OwJOsBhjCjdF0w== X-Gm-Gg: AZFdTZeMs7VfKeZVchnaYnulJ2EGNGv+gxNuOrEdfULrNF+BiD5hypLG0twqOhdRhUx db4m5ouJHpkHyp0DwM1VGqXjHphjRHq9mVkjk/hACngLbfi0UdiuFs9IgmRjydR93MWm0kyWipG hqntQT/toZsxn74d1ZHkRHNKPFZwGa35o14NT9Uz8dZirJehC5oxMFGRR5xMUNA3KVp8tOXdbPn hITYAfjZZb8OFyo8/VbGZYnJAZZaQMiPoCB3B87Bn9O11398ZuQ5o/LkvlN4SW+4S8wF/nMmHPA Aksu9ygh4zWPNcOY6hXN4x1mKdLD3HR5/nTXD3hkPRgQ4qjclQow89WwMU5aWU9MB/4IXXbdY8i CfOlW/wgigYQpc2AlovhsVbiqyRifR2vp8l13v6SZ5A== X-Received: by 2002:a05:600c:a117:b0:4bb:a5e1:7497 with SMTP id 5b1f17b1804b1-4bba5e18d83mr361722565e9.32.1796200389079; 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: kvm@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 > >