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 BF7FFA04FA; Wed, 5 Feb 2020 16:05:54 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0AA531C232; Wed, 5 Feb 2020 16:05:54 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 495F71C1FD for ; Wed, 5 Feb 2020 16:05:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580915151; 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; bh=tR3y+OTRf/PgrQ5zuS6d1uHBs/0xKH8O3yTjrRmEcBs=; b=A8sZd8417xpee1d/0W1iy8crc3OXGCJdIIHd41h22Pf1kTOqejRsoa8jUyBZRzITU4ZDhd BKhmq+vcV9aZT5suFj0rjJN0Kny2bvwts7OhSnsc/eQcotrNVkJjMrLLiv/rN1oby3uYFW ZhEu0LaKfeuiy54DHnRrUiF6xFIMlzY= 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-354-YR-JKmu9N-uDBj-N-Jtf7w-1; Wed, 05 Feb 2020 10:05:45 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA0AC18C8C1E; Wed, 5 Feb 2020 15:05:42 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-40.ams2.redhat.com [10.36.112.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9299326E4B; Wed, 5 Feb 2020 15:05:34 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: stable@dpdk.org, Maxime Coquelin , Ilja Van Sprundel Date: Wed, 5 Feb 2020 16:05:29 +0100 Message-Id: <20200205150529.794623-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: YR-JKmu9N-uDBj-N-Jtf7w-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-dev] [PATCH v2] vhost: check vhost message header size read X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds a check to ensure the read size of the Vhost-user message header is not smaller than the expected size. In case of unexpected read size, report an error and close file descriptors passed with the message, if any. Fixes: 8f972312b8f4 ("vhost: support vhost-user") Cc: stable@dpdk.org Reported-by: Ilja Van Sprundel Signed-off-by: Maxime Coquelin --- v2: close message FDs on error (Tiwei) lib/librte_vhost/vhost_user.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 9f14ea6676..91482ccd67 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -2456,8 +2456,13 @@ read_vhost_message(int sockfd, struct VhostUserMsg *= msg) =20 =09ret =3D read_fd_message(sockfd, (char *)msg, VHOST_USER_HDR_SIZE, =09=09msg->fds, VHOST_MEMORY_MAX_NREGIONS, &msg->fd_num); -=09if (ret <=3D 0) +=09if (ret <=3D 0) { =09=09return ret; +=09} else if (ret !=3D VHOST_USER_HDR_SIZE) { +=09=09VHOST_LOG_CONFIG(ERR, "Unexpected header size read\n"); +=09=09close_msg_fds(msg); +=09=09return -1; +=09} =20 =09if (msg->size) { =09=09if (msg->size > sizeof(msg->payload)) { --=20 2.24.1