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=1796200395; b=mEr/89Fj5KIEQ7b0E7zdj1KJ80RkU3ymAEFX24q215STIMPzGLSR4WavC/cWClzFwHp1 P2HK+SVoQG/faPmWKgUJAqMhhJbT4fiypQ18DOlH7pK69+JMzNj3HeGxeqaKpxSKs+CTI 3l+8CFB997+cMlzdA1PAzcbXSYm997hOcPh2AlFQqx285w/KdWS9li/JWu96USqrQxT8v XwchF5eIXkaUFxpgZKz8z9vzaJH713xr4sASHG1FUqSE+GWnOkIatH0eOUNEbkKvj7/y+ yHKuxvc4WWgOmVHSX+aZW/Rd+Sbqe0/AyDyBytCNyYrickV9JOngdTKb35UJrrqqfQw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200395; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=bT2mSPzl6SZi1QC+DLc3cuSe4WvWJU/xDuMAt41337l1TE3l7AWhepINHhKhmSpP6OON 3Nhx/w6cf7ercNybmTUsfrr6b5WVrBy2tQjV2zVfgWR9cJ9+xcppuK9SMfXXt1u4IGHw7 rZXaq5Evxyv4sjh9PCa5ZpmhHYGofQf/FTidG/MlriqMgtl2U7nKjHt88avwLqo4vZZAZ F3KjDaoihqDJ8u7N89g/RWyjbDMIKnay5UUgsFbKlmjBb4C8juwVjNa61wNuYp/4qP6hb bDYmovo2ZiXv64fdCV5+wmibYc+MSf1EMBY4OGWQT8N18JoQIRO/iuit4poHKG99QkQ== 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="HwQxU/Q5"; 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 4F9B9606A32C for ; Wed, 2 Dec 2026 08:33:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4F9B9606A32C 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=HwQxU/Q5; 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=1796200395; 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=HwQxU/Q54sHc471nt+Hp1rLkduB11bBxe5GCMqgG9ff2JCXIiueWuxRswYyWLYDa69I3KX ukXbewPOW8lMO/weUf5XWmR8Up/eueea07FHd0Xs9eK4j80PlbUU6CG5Tmiv4tB2EFIuTS cEHqTl9Rd0DIsmot+8T1mEe/+Tb5ewk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-206-s2-kex-zMiij5kNmMxRj2w-1; Wed, 2 Dec 2026 08:33:10 +0000 X-MC-Unique: s2-kex-zMiij5kNmMxRj2w-1 X-Mimecast-MFC-AGG-ID: s2-kex-zMiij5kNmMxRj2w_1796200389 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4a204ac318aso60647695e9.2 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=n5o5Ie87yroTnCUVprpK8wtSh8crZouMoWSrlBqR2uD5awymtuf5raIil8ylckMFig mF/ZUTXAJys6qKxeEhlEhe5/8L9bRURg5Oz0iKn6VMGUThyblz9ewoSEUWnK7vy5yB2i g8PtpLlCpWtSjQ4NjwQyQOqELLff7q399Ln+lydUw923gT8UIHK8zt0+7Na/HW/DoBZq K5BOBvzcUpUGFecgJFKL3m91nXcKdSd3jEktRlk7zagRzgsLkyVZVA1tggwqXC5VEFjt 2CVS7OHU9UqiJpwudpVDsQMN2npATIy3AgZsM+d4+7mWQk6je9jJ/NiZPn47SjkNB9kw cVpA== X-Gm-Message-State: APuU4Z/HTNi5QN0BjPECqZwmS+jjBpvQVqLPnAyMLnYJlKO/HQJq9UBO 3H5EW0k2ih9mVFQfOZAsZ/9PuDF3EWXZOx7p9ARG0/XI6uOHX/MaM2krE4e9ORzo6Cf8vuKmjWO x6rOFOekQoKDr72joLNrQGEltsqPImJtnfJ+o+hWDl/p0u/nlcoKbOtcUK9bRfjwf7Q== X-Gm-Gg: AZFdTZdCTzHICn3RlvDnVPMS/5kTud/YAccK5lexfa/RUz5jJwV+NSVWlGFMBXsY1Ez 9xbdw7mq9f+pVLpF/MRHIsnK710VSK+6yUwkGzkP5d599MmxmR28BeBh3m35s+U+CeDOJIIREQH m2GNZHu0tM/8Rl5W7WidrFI7i/5+7ZYGgyfmfXnCqcTqeduKUxBg4xRGUDGs76pH/lNMYiRl+wY UDqCef8zc/sbuQuWQleY4fMPf8ZbzeORKFHZLPZvKbJqsJe521hphEeU4PbL7aT1bglhLj7u4jZ 5GVH6bDZeRAKOczMM4ka9I5D1xstAqyGHahH3oSvt5ZjmRhkdBfLntXJ4cNxhqpfC2h30GjyLYA EszUuHcFvDiH8+IKDBLecrO8CavSnOoz/VvoKB7gEaw== X-Received: by 2002:a05:600c:a117:b0:4bb:a5e1:7497 with SMTP id 5b1f17b1804b1-4bba5e18d83mr361722715e9.32.1796200389134; 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: linux-kernel@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 > >