From nobody Thu Sep 24 15:11:03 2026 Received: from out28-149.mail.aliyun.com (out28-149.mail.aliyun.com [115.124.28.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6E87544D5F; Tue, 22 Sep 2026 12:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790080211; cv=none; b=IKwB74nNetTS11soJlPzqTTX4l775y4hsWrMUxVt9qrSWyqXwmaevGhfPYGLnJxj/qFkQkUjxLPbMbKfOFnvBifKW53S+xbh8gr89whGmpITLTbOEWeL//b2HJ0X9DJFMJvFbEDmg/uEQA0lf3v8cJVG/bEDNGHXO4lStlyThbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790080211; c=relaxed/simple; bh=5Dk7dds7UmISQ/2v9i4UVig/uA0/ad+4B2F0rHm/DOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VfrVzo0KheL8sYjmC4TynTV3taadGoxem3mK/oR6spcBP2zqnJRB/0zxZvhS+najGynY/L73Hfqp8WwA6nSXjpphIy2qc5sp+kFTjwgPzrSq3nVuK8TlI60lv9y9XlzK0QpDWfcb6TUtHmpBp2InD9pVUi/L0Fw2naDBHHfhzHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com; spf=pass smtp.mailfrom=xiaopeng.com; dkim=pass (1024-bit key) header.d=xiaopeng.com header.i=@xiaopeng.com header.b=g5W/ZvS/; arc=none smtp.client-ip=115.124.28.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xiaopeng.com header.i=@xiaopeng.com header.b="g5W/ZvS/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1790080198; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=oQB+xtAD5KZGAfEEgSaFnU89mf3ldcR0f6mL0uIVlAI=; b=g5W/ZvS/1grC1SCeP/flknu2aYqKlWHRIPcqz+VZfUwxmU5TQAz4ga1Yq0GTUntamr5Rdx/Z4YuwCGJ3cJaFRRsZkFfRf8rLh1GDA0q4PhP4vmfK01ZCDso5url4CgQg1Sl9zKSwMVMM7niZV6m49MIMvNgMsjak8jfzWrOTAwc= X-Alimail-AntiSpam: AC=CONTINUE;BC=0.0922767|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_enroll_verification|0.00425737-0.000751315-0.994991;FP=7925488823215324254|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033032053168;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=10;RT=10;SR=0;TI=SMTPD_---.jK24y74_1790080197; Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.jK24y74_1790080197 cluster:ay29) by smtp.aliyun-inc.com; Tue, 22 Sep 2026 20:29:58 +0800 From: Fang Xieyan To: "Michael S . Tsirkin" , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= Cc: Xie Yongji , Xuan Zhuo , stable@vger.kernel.org, virtualization@lists.linux.dev, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] vringh: bound top-level re-entry into indirect tables Date: Tue, 22 Sep 2026 20:29:54 +0800 Message-ID: <20260922122955.69433-2-fangxy@xiaopeng.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260922122955.69433-1-fangxy@xiaopeng.com> References: <20260922122955.69433-1-fangxy@xiaopeng.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In __vringh_iov(), the F_INDIRECT branch descends into the indirect table and continues before the descriptor accounting runs. A top-level indirect descriptor is therefore never charged to count. If such a descriptor sets NEXT to point back at itself, returning from the indirect table resumes at the same top-level descriptor, which is again not counted, so the walk never makes forward progress. Because count stays flat and indirect_count is reset to 0 on every return to the top-level table, neither bound in the loop check trips. A guest can spin the vringh worker at 100% CPU inside __vringh_iov(), an uninterruptible host DoS. Move the descriptor accounting above the indirect switch so that a top-level indirect descriptor is charged one top-level traversal step before the walk descends into its table, bringing this re-entry under the existing vrh->vring.num bound. Each top-level descriptor is still charged at most one step and indirect_count still bounds a single table, so legitimate chains (including the multiple-indirect case in tools/virtio/vringh_test.c) stay within vring.num, while a cyclic indirect descriptor is now rejected with -ELOOP. Fixes: dbd29e075228 ("vringh: Fix loop descriptors check in the indirect ca= ses") Cc: Xie Yongji Cc: stable@vger.kernel.org Assisted-by: Hawkeye:GLM-5.3-flash Assisted-by: Qoder:Qwen3.8-Max Signed-off-by: Fang Xieyan --- drivers/vhost/vringh.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index 9066f9f..f672e11 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -333,6 +333,17 @@ __vringh_iov(struct vringh *vrh, u16 i, if (unlikely(err)) goto fail; =20 + if (up_next =3D=3D -1) + count++; + else + indirect_count++; + + if (count > vrh->vring.num || indirect_count > desc_max) { + vringh_bad("Descriptor loop in %p", descs); + err =3D -ELOOP; + goto fail; + } + if (unlikely(desc.flags & cpu_to_vringh16(vrh, VRING_DESC_F_INDIRECT))) { u64 a =3D vringh64_to_cpu(vrh, desc.addr); @@ -358,17 +369,6 @@ __vringh_iov(struct vringh *vrh, u16 i, continue; } =20 - if (up_next =3D=3D -1) - count++; - else - indirect_count++; - - if (count > vrh->vring.num || indirect_count > desc_max) { - vringh_bad("Descriptor loop in %p", descs); - err =3D -ELOOP; - goto fail; - } - if (desc.flags & cpu_to_vringh16(vrh, VRING_DESC_F_WRITE)) iov =3D wiov; else { --=20 2.50.1 From nobody Thu Sep 24 15:11:03 2026 Received: from out28-220.mail.aliyun.com (out28-220.mail.aliyun.com [115.124.28.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66DE7542ED5; Tue, 22 Sep 2026 12:30:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790080206; cv=none; b=ZOc3PVlSXhViWK+qQOTLKbQwAZCsiBts1QTIl0B41LbPlyi4m8+8bdMFXIoP9z2scsrYt6F9GWZ/F+COEI14n/T838j7uHyVFlwQWP5DG6MtAlfVfTB4etWnX9/fz6nJlJwTEzzwTW23ecJWyt3AzLSzxfpFKdzO4bX1spbpIsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790080206; c=relaxed/simple; bh=kvjYLm/dk+4s+Mv6NTFfsPwA0UEVspm+3CjszQbYoBs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YD0PuAexFloy8xTDOsu3zfaHdsI8utzz1oHENgJoXC/i0AGJRL0S38iFIbDuyYBmrXXhQFYhq3PKbGfYfpg2X4QzgWAuYgsfUK+7/jji+FM+SwrKT+64gUNLwud1fvTh7v1lsDzR+qsX7MWRu3vpkmkjT6TRGFw1S4ktN9aNdMk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com; spf=pass smtp.mailfrom=xiaopeng.com; dkim=pass (1024-bit key) header.d=xiaopeng.com header.i=@xiaopeng.com header.b=VRFqtcBy; arc=none smtp.client-ip=115.124.28.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xiaopeng.com header.i=@xiaopeng.com header.b="VRFqtcBy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1790080199; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=oMlXdrGUkDd2x+R+qGZUFmpS/mij8+4hCn9f+C8UqJ0=; b=VRFqtcBy/udJEN0XiTMvup82I1/j8Z+mJk2KwdnGAAuHgfqzbqYTpXMmulJQ9aqaX1H5RplAYbSUeYKa6tsBlassdAr1M0uugDQFKFVc+xXqMZwXUIZEMu3uwih5CW/CUakyrNLvRSJsIoei0r3/PaHOy0rnEgzTpCmnqSTVa60= X-Alimail-AntiSpam: AC=CONTINUE;BC=0.04471682|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_alarm|0.0180885-0.000132619-0.981779;FP=12497215314873208052|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033068005250;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=10;RT=10;SR=0;TI=SMTPD_---.jK24y7w_1790080198; Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.jK24y7w_1790080198 cluster:ay29) by smtp.aliyun-inc.com; Tue, 22 Sep 2026 20:29:59 +0800 From: Fang Xieyan To: "Michael S . Tsirkin" , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= Cc: Xie Yongji , Xuan Zhuo , stable@vger.kernel.org, virtualization@lists.linux.dev, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] vringh: add regression test for cyclic indirect descriptor Date: Tue, 22 Sep 2026 20:29:55 +0800 Message-ID: <20260922122955.69433-3-fangxy@xiaopeng.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260922122955.69433-1-fangxy@xiaopeng.com> References: <20260922122955.69433-1-fangxy@xiaopeng.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a case to tools/virtio/vringh_test.c that builds a top-level indirect descriptor whose NEXT points back at itself and checks that vringh_getdesc_user() rejects it with -ELOOP. Without the preceding fix, the walk re-enters the same top-level descriptor without making forward progress: count stays flat, so the traversal limit is never reached and -ELOOP is never returned. With the fix, the top-level count advances on each re-entry and vringh_getdesc_user() returns -ELOOP once the traversal limit is reached. Use index 1 rather than 0 for the self-cycle, since returning from an indirect table is only performed for a positive up_next value. A self-cycle at index 0 would instead terminate the walk and would not reproduce the bug. Assisted-by: Hawkeye:GLM-5.3-flash Assisted-by: Qoder:Qwen3.8-Max Signed-off-by: Fang Xieyan --- tools/virtio/vringh_test.c | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/virtio/vringh_test.c b/tools/virtio/vringh_test.c index 84961b9..2a5d7f7 100644 --- a/tools/virtio/vringh_test.c +++ b/tools/virtio/vringh_test.c @@ -458,6 +458,8 @@ int main(int argc, char *argv[]) int err; unsigned i; void *ret; + struct vring_desc *ind; + char *data; bool (*getrange)(struct vringh *vrh, u64 addr, struct vringh_range *r); bool fast_vringh =3D false, parallel =3D false; =20 @@ -755,6 +757,45 @@ int main(int argc, char *argv[]) vringh_iov_cleanup(&riov); } =20 + /* + * Regression test: a top-level indirect descriptor whose NEXT + * points back to itself must be rejected with -ELOOP instead of + * looping forever. Use index 1 rather than 0 so that returning + * from the indirect table re-enters the same top-level descriptor. + */ + ind =3D __user_addr_max - USER_MEM/2; + data =3D __user_addr_max - USER_MEM/4; + + /* Fresh ring and host state; resets last_avail_idx to 0. */ + vring_init(&vrh.vring, RINGSIZE, __user_addr_min, ALIGN); + vringh_init_user(&vrh, vdev.features, RINGSIZE, true, + vrh.vring.desc, vrh.vring.avail, vrh.vring.used); + + /* Single-entry indirect table pointing at valid data. */ + ind[0].addr =3D (unsigned long)data; + ind[0].len =3D 1; + ind[0].flags =3D 0; + + /* Top-level desc[1]: INDIRECT, and NEXT loops back to itself. */ + vrh.vring.desc[1].addr =3D (unsigned long)ind; + vrh.vring.desc[1].len =3D sizeof(*ind); + vrh.vring.desc[1].flags =3D VRING_DESC_F_INDIRECT | VRING_DESC_F_NEXT; + vrh.vring.desc[1].next =3D 1; + + /* Publish head 1 on the avail ring. */ + vrh.vring.avail->ring[0] =3D 1; + vrh.vring.avail->idx =3D 1; + + vringh_iov_init(&riov, host_riov, ARRAY_SIZE(host_riov)); + vringh_iov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov)); + + err =3D vringh_getdesc_user(&vrh, &riov, &wiov, getrange, &head); + if (err !=3D -ELOOP) + errx(1, "self-referential indirect: %i not -ELOOP", err); + + vringh_iov_cleanup(&riov); + vringh_iov_cleanup(&wiov); + /* Don't leak memory... */ vring_del_virtqueue(vq); free(__user_addr_min); --=20 2.50.1