From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B698AA04B6 for ; Tue, 12 Nov 2019 16:19:10 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6DDB2B62; Tue, 12 Nov 2019 16:19:10 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id CE792B62 for ; Tue, 12 Nov 2019 16:19:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573571948; 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=hhS052sxe+Wv8LKF+dnGtKJNk19yjUYvyeJe6AAp+Ig=; b=Hugj+ipnHytiReYjI+oP848+1fephfm0T6p4ShSvzuGygrzVR+oHcsTAS9D223RG6WZ+DY PDc2N+Jy/QmCDP7DLXLydqnKrVyGLhJ/slTif/7P3Jj77CR5JAik+SXUFlTSqyJ5vnIzJZ XqLIEgv7ytwHTl9umCkt9bht6CqG1aU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-295-s3Yd1GrNPHGpxWg8a-faWQ-1; Tue, 12 Nov 2019 10:19:06 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E306D8D9A32; Tue, 12 Nov 2019 15:19:05 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-39.ams2.redhat.com [10.36.112.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E10ABEA73; Tue, 12 Nov 2019 15:18:56 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, stable@dpdk.org Cc: Stefan Hajnoczi , Maxime Coquelin Date: Tue, 12 Nov 2019 16:18:49 +0100 Message-Id: <20191112151852.27341-1-maxime.coquelin@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: s3Yd1GrNPHGpxWg8a-faWQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] [v16.11 PATCH v2 1/4] vhost: validate virtqueue size X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 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 Sender: "stable" From: Stefan Hajnoczi [ backported from upstream commit eb7c574b21cc92792ea5a1f219ddf6dd3cf3b1e1 = ] Check the virtqueue size constraints so that invalid values don't cause bugs later on in the code. For example, sometimes the virtqueue size is stored as unsigned int and sometimes as uint16_t, so bad things happen if it is ever larger than 65535. Signed-off-by: Stefan Hajnoczi Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 618d413fe1..8a01c295e7 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -189,6 +189,17 @@ vhost_user_set_vring_num(struct virtio_net *dev, =20 =09vq->size =3D state->num; =20 +=09/* VIRTIO 1.0, 2.4 Virtqueues says: +=09 * +=09 * Queue Size value is always a power of 2. The maximum Queue Size +=09 * value is 32768. +=09 */ +=09if ((vq->size & (vq->size - 1)) || vq->size > 32768) { +=09=09RTE_LOG(ERR, VHOST_CONFIG, +=09=09=09"invalid virtqueue size %u\n", vq->size); +=09=09return -1; +=09} + =09if (dev->dequeue_zero_copy) { =09=09vq->nr_zmbuf =3D 0; =09=09vq->last_zmbuf_idx =3D 0; --=20 2.21.0