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=1kaJj26NmTIrU+UMgUVI67mLoMLnBT3np2O7mbL0RZZpZhPps2VtIsxvccebmLMHf1zl FcNmMGH6uDrwRGVxt6CMu3ZVZCKWaiL8jOA2Xj9fMKeUG9j+GBT425C5DqsYO1FnAYf8t Nt+H+vG/5l7eqCVGB8MNc+s1gQpv3tB7Zc3v5bar0kSf3wlF61kbwfeKnFIOFO8/ZUGEZ B3TOBvgZVarARqFblqa8CE6FiBn42jyujHu3L2gVbHpj44DijGiA801U+y+7H8fGvM3Jo K9a6iuItSLrhZg5SYSRRPX7PmfPwT7tEAvtI8PFUqMxpyMl9smFHmhgD/LnVpnZeR0w== 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-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=ak5f6S7/6+b1IhhWk6FvfzHeJYT40SGCRlCwA4Qp5kxmnRbwRgpPdyus6ErdGQ3Pxo6h duxHZThP7+pSH3zNf+TFQxZMDKi7sWqEEAA7uow3YYenp2mSr7WqA86Ht9YHwr3Mue+NN cNFGpzfAN6KTUP4Bw1I0/5nMueo4TPKhLjGqs9Sf2+XB4k8yki0ugBzgtWlcxJnoIsU4F fOQ7rPBHdSEmHKlZW6s0PM3UvzAatjRvPAQ5vEimO4aO0XuXqd1ptAMkIl2+KosCImi2I btjGcD2ePGrJr7+g/NcWF/lL8JyCYVNhGOsMkVaQKoo8Q5Byt2SdPITES6rVTJj/G4A== 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 49BE3606A68B for ; Wed, 2 Dec 2026 08:33:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 49BE3606A68B 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-tJgAq1diOMWlvHlUUMsKQA-1; Wed, 2 Dec 2026 08:33:10 +0000 X-MC-Unique: tJgAq1diOMWlvHlUUMsKQA-1 X-Mimecast-MFC-AGG-ID: tJgAq1diOMWlvHlUUMsKQA_1796200389 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4b9fde3044dso93671815e9.0 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=kc+zohGFP/GI/jsTLNLoS395uhtqcVpS59mXrSoAX97VhXgD/NL1N8bdmjMeUiEosQ FZiLs0MtL8eydYDfPtsYPevy+CSYMjnTPHi1b8PkYDihHu+oOcad5jpLuNZlMIpVcOq6 YSqnTlQDkuq9V4pvkxaMLl3Fpe/y04bO8Np6+aV1NrRKdR+rXa2xUmG4Yk6lsBWl9k9r h3VNEFUQ6a8Xxdm//ZqJbVgwSK5PQ+xSVtYLwBnrhTFH6T6NUuDE693D7oedtGwoql4D 5d2u6asW4S+P2hN1vomOjcpsNw926sVyvfI+5wt6bmBZIQl4DkcbpYp/JcbDeJYYAl1e zNVg== X-Forwarded-Encrypted: i=1; AL+hErGa7Zc130mAt0VONbcQqIPsrScsofLAfPhgKKRxG3ODQFC4gCGx/r5vSh+1viqhonfvm+y6yE4=@vger.kernel.org X-Gm-Message-State: APuU4Z+Q1r+RW5MFaMPSrJvpds+gjnJ6xxqQv5r62X51ousvmiAV86Ds e8eyPUnqEPpZiBUFyejYZpAeHynq4zOGCfzdHgOTZYXurb1lMf8ws70LHrX1XT8E982EVy15vVj GcNNA0bcKivEmEOjdWm+AMRFrmzNNnoLnMQSjlU6LxNeJI6jzVSHbdMrySAtObwEovQ== X-Gm-Gg: AZFdTZdqwjFb/whpD7+D9UfTFsnIl5HjGJCF6g8hR2OZciut6JoTku4rljTMScoeKDY Gxghzr9rErmiZ9Db+fg7Fal9SJtZ6ZKdCo50lwLLsj4hMXWdmIAoDWTGWdR+RRC+XlwtdS4+781 Xh7IGLnxaHEaWBoNvt4hNw0/BHdYhJquQRTi3n+6xANP3PcK37d4pZPlXFN7lEN5pV73tg3IeQe ccugmLRZzWke0HfEOGjPhnyqLZR7BHOc5zN1wSCtw14CHsXpBpi0EThQ35IFFJO6WS9Y0RrsjG3 41gw3eK0lVyR4xz7BfZ1GZRsKbmTrV8ZihYOUDQAHJ7Zx4Ft5lM1oJ6FlqiIWb1onToYuaEzBB6 hEzelqotXpjP889NH37VdMMhJPFPp6Ch6GS1b9OfIlQ== X-Received: by 2002:a05:600c:a117:b0:4bb:a5e1:7497 with SMTP id 5b1f17b1804b1-4bba5e18d83mr361722535e9.32.1796200389072; 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: stable@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 > >