From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381408; b=b+pOEWUsEzMLmIwOzT8qHbHVONI0rT/EWvXdaMWM931ayHXaeZvJHdKfAVhL7lTYnPkV LcbRZmCnLQRS0CjNSWE2XnfsyUCL6BtuoMveXV1PoYd1kdbZvTaoN/Zl6bkMfzk5FY0tc zySZoL/Tov3Y9e9Rdiwmd3pufp8MS5P9R7tQRwLhrIlEubzHNXLm59fJXA4D2BSCRa6Zz SxXhLTgS8pdItvDTRu2/36OifeNXIz4rS6+ACvRLLc4WHmHNEnJ3Mocv+1Ql4L8uTPfTr 3xPqsg15gdAoT9pXDTzP4thKYWTnEAoUFgQFGDWR7drqysAAu85k2+KTQirv+Om2yTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381408; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=LiViuYWhjZKT2uKSGmfplFIK9ECaWZK8tpXS/AoTQEI=; b=SgVCniLCMHdlV+8oYAOuVG7IJuWIpXOaJ3TU2P5Tec/33+X1Q7SUbgCXVgoK6nLX2KPe /P07VezbGNaTcXNJFsg9aV9NkpBlAyZWtem/TEZJk2rR1nRvVIsR8hMF6eblanjYjSWgD i8kSVJ62bKDS7zkQmKzlx5v12+fkSBK17XDWWoM3gfCgsFS5jDuchuIs5ZXmjlQJC/RLf aO9J7EnULkCmkfrPN2Tm4q7gCECfjGSbOsTTDXuHQhME1sD1BndLfvNohlLcIh9/iSAvw 4ABI4pcYaC0aNa6CdGnsUCj9Ne1NElHhiv6lrM31YIQx6DpQagTnNm/fJSXOhlvY2Aw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yLJ4DxfM; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5A59606A330; Fri, 4 Dec 2026 10:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yLJ4DxfM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C7B91F00A02; Fri, 4 Dec 2026 10:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381408; bh=LiViuYWhjZKT2uKSGmfplFIK9ECaWZK8tpXS/AoTQEI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yLJ4DxfM01+USknsBvVU0peNuTjaFbvcc6VfliJp3v66CRJeWreg/5T5uk0qeTh1Q d4sA+E2tGBI90hfJOIiHw1/Pujmv/d3TbFbxaQic9qHzKayqz888SdRdKQC+0aTXKy 8lJxJUxj1+kZzFogUvYso2HKMNCj75Jio+MTHrxI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Seohyeon Maeng , minki@morningstarsec.dev, YanXin Li , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S. Tsirkin" Subject: [PATCH 7.3 690/742] vhost: reject used ring batches larger than the ring Date: Fri, 4 Dec 2026 19:09:14 +0900 Message-ID: <20261204100653.380849432@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael S. Tsirkin commit 700737df3b825a1b9d0724acfc62b177f1e723df upstream. 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 Message-ID: <66327153423e98bd10778bac1f29c26ba633e02a.1796163071.git.mst@redhat.com> Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/vhost.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -3158,6 +3158,7 @@ static int vhost_add_used_n_in_order(str { vring_used_elem_t __user *used; u16 old, new = vq->last_used_idx; + unsigned int total = 0; int start, i; if (!nheads) @@ -3166,6 +3167,12 @@ static int vhost_add_used_n_in_order(str 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; + } if (vhost_put_used(vq, &heads[i], start, 1)) { vq_err(vq, "Failed to write used"); return -EFAULT; @@ -3222,6 +3229,11 @@ int vhost_add_used_n(struct vhost_virtqu 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