From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A2B10471B7 for ; Thu, 8 Jan 2026 15:52:41 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 467264027A; Thu, 8 Jan 2026 15:52:41 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id C04014027A for ; Thu, 8 Jan 2026 15:52:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767883959; 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: in-reply-to:in-reply-to:references:references; bh=Zm+sIX9km2brizKKQlaYdKBFxechPFjo1zTVRb+8CbU=; b=CS2O7cQzjHvELlvmJ3PmU1o35dGigerBbpQSj8hrk6Qvb88Er5/sLFekmvbIaqquRBq/oj zRmq2diq0GFPa3jHdy8aUFjBNH86FXO+TxUHsCNwJK1DsQjULHGxVzV/4dV66/mClA2E8T YNYF44VYsoR8cOIMaBqF1tMap8GZ7iM= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-rtLwZLpIPGmFp68tQ1jdlA-1; Thu, 08 Jan 2026 09:52:38 -0500 X-MC-Unique: rtLwZLpIPGmFp68tQ1jdlA-1 X-Mimecast-MFC-AGG-ID: rtLwZLpIPGmFp68tQ1jdlA_1767883957 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-38300efef65so1174851fa.1 for ; Thu, 08 Jan 2026 06:52:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767883956; x=1768488756; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Zm+sIX9km2brizKKQlaYdKBFxechPFjo1zTVRb+8CbU=; b=Q7LLAmKfQ3zlZQwswrQd5yL8pZ8F28byvHLfDN+y4cyZl4XlAj9VGbHv4aywKKzuk9 o5f/5A+V2g+nYra+Klf6BAsMO8JorCSHkEpxTiSsX8SNcDiWmDPnXB1bmqV2W/B/WE/w 1LkGXqr3n+qLy8FnP1gacZdeCf3/xEP3tA/E48gIiZ30EOSxCr3UdcJOD49tXE0BCwzA mIvtC5C0x4F7WL9VfWidvKOfCGSt75GhcREw+T7smm6ZIA9CCArAKu+nx+aqOKabVDD3 CFyd3hJHcLuBmie15JE1whxka16QOYCQd4op3YUpMnsDE/RRRDBED+yeaq2I8MEZOWU1 pd3g== X-Forwarded-Encrypted: i=1; AJvYcCWZG4KO944YNQ6wrDOPDcyEDqdw5YnaTegeVXHBrRcwDVFnnILvk+iVPOg3oIHTSgmmiaXi5Dw=@dpdk.org X-Gm-Message-State: AOJu0YyOMj/bN3OkiFEXQdYGUQckjMIPGA+wxq3JS/bSj4+DRWDqsCHv raDsyK77ysWlHaj3kIqIuweJhbyjC0uy2rYQOmYhpayCaBnZ+tOyqAfB00vEOGYht9kzQm1UT1M FmXMy3hUG5uNymBT9C+x7btjaTskoaVdr7EM4LRlCKx8dvDjtq57rXZqAZq8fszjTTBnzxZuv+O FyWgTTfVl+4tSaxMmvP1NVyAU= X-Gm-Gg: AY/fxX4glje1Aw+otHE9s/ryuTP5ZSwFl3zt4YosTJjvCGSBP0sYZ1N0D1hRfr4AIxj 9Q9gHMeak4jezPGiqb768/kAGsApO/z81vBmM3L97tryglY10Ky1OnWvVzuOJLD4NZugBi73vEN b0ASvn75TJydJJDmkNMjGdcNgOfzWL2J2VgnCVtH492v2PHWxxKVlg1ZoDb6nXm8Sis0EI X-Received: by 2002:a05:651c:198e:b0:383:1565:629b with SMTP id 38308e7fff4ca-383156567eamr4573371fa.1.1767883956467; Thu, 08 Jan 2026 06:52:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTeJvFZENQGwz5zJFK+WJsIf12ZFhoTuJbxy8pStReBIxWQXoj1Gff6sW5z7AaChanMWfywaQV6lLMQXGhcD8= X-Received: by 2002:a05:651c:198e:b0:383:1565:629b with SMTP id 38308e7fff4ca-383156567eamr4573201fa.1.1767883955975; Thu, 08 Jan 2026 06:52:35 -0800 (PST) MIME-Version: 1.0 References: <20260108134951.3857110-1-maxime.coquelin@redhat.com> <20260108134951.3857110-3-maxime.coquelin@redhat.com> In-Reply-To: <20260108134951.3857110-3-maxime.coquelin@redhat.com> From: David Marchand Date: Thu, 8 Jan 2026 15:52:24 +0100 X-Gm-Features: AQt7F2rFi-E4nx0uHreUJkvrsBR1L0VL4L80UmAgdfHUYEnjDn1YRwPQStmb93I Message-ID: Subject: Re: [PATCH 2/3] vhost: fix descriptor chain bounds check in control queue To: Maxime Coquelin Cc: dev@dpdk.org, chenbox@nvidia.com, stable@dpdk.org X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: mCMVnZOl0UUjs647K1Qndp4aqQwzf22BKAftnMmkj6w_1767883957 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On Thu, 8 Jan 2026 at 14:50, Maxime Coquelin wrote: > > The virtio_net_ctrl_pop() function traverses descriptor chains from > guest-controlled memory without validating that the descriptor index > stays within bounds and without a counter to prevent infinite loops > from circular chains. > > A malicious guest could craft descriptors with a next field pointing > out of bounds causing memory corruption, or create circular descriptor > chains causing an infinite loop and denial of service. > > Add bounds checking and a loop counter to both descriptor chain > traversal loops, similar to the existing protection in virtio_net.c > fill_vec_buf_split(). Too bad we have two separate implementations.. > > Fixes: 474f4d7840ad ("vhost: add control virtqueue") > Cc: stable@dpdk.org > > Signed-off-by: Maxime Coquelin > --- > lib/vhost/virtio_net_ctrl.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/lib/vhost/virtio_net_ctrl.c b/lib/vhost/virtio_net_ctrl.c > index 603a8db728..8149885384 100644 > --- a/lib/vhost/virtio_net_ctrl.c > +++ b/lib/vhost/virtio_net_ctrl.c > @@ -28,7 +28,7 @@ virtio_net_ctrl_pop(struct virtio_net *dev, struct vhost_virtqueue *cvq, > struct virtio_net_ctrl_elem *ctrl_elem) > __rte_requires_shared_capability(&cvq->iotlb_lock) > { > - uint16_t avail_idx, desc_idx, n_descs = 0; > + uint16_t avail_idx, desc_idx, n_descs = 0, nr_descs, cnt = 0; > uint64_t desc_len, desc_addr, desc_iova, data_len = 0; > uint8_t *ctrl_req; > struct vring_desc *descs; > @@ -59,12 +59,19 @@ virtio_net_ctrl_pop(struct virtio_net *dev, struct vhost_virtqueue *cvq, > goto err; > } > > + nr_descs = desc_len / sizeof(struct vring_desc); > desc_idx = 0; > } else { > descs = cvq->desc; > + nr_descs = cvq->size; > } > > while (1) { > + if (unlikely(desc_idx >= nr_descs || ++cnt > nr_descs)) { I don't like pre increment. Can we use post increment and stay aligned with known to work fill_vec_buf_split? > + VHOST_CONFIG_LOG(dev->ifname, ERR, "Invalid ctrl descriptor chain"); > + goto err; > + } > + > desc_len = descs[desc_idx].len; > desc_iova = descs[desc_idx].addr; > > @@ -142,12 +149,23 @@ virtio_net_ctrl_pop(struct virtio_net *dev, struct vhost_virtqueue *cvq, > goto free_err; > } > > + nr_descs = desc_len / sizeof(struct vring_desc); > desc_idx = 0; > } else { > descs = cvq->desc; > + nr_descs = cvq->size; > } > > - while (!(descs[desc_idx].flags & VRING_DESC_F_WRITE)) { > + cnt = 0; > + while (1) { > + if (unlikely(desc_idx >= nr_descs || ++cnt > nr_descs)) { Idem. > + VHOST_CONFIG_LOG(dev->ifname, ERR, "Invalid ctrl descriptor chain"); > + goto free_err; > + } > + > + if (descs[desc_idx].flags & VRING_DESC_F_WRITE) > + break; > + > desc_len = descs[desc_idx].len; > desc_iova = descs[desc_idx].addr; > I wonder if we are missing some call to vhost_alloc_copy_ind_table() as well. -- David Marchand