From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <danielx.t.mrzyglod@intel.com>
Received: from mga01.intel.com (mga01.intel.com [192.55.52.88])
 by dpdk.org (Postfix) with ESMTP id 5DA502935;
 Wed, 20 Sep 2017 15:28:18 +0200 (CEST)
Received: from orsmga002.jf.intel.com ([10.7.209.21])
 by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 20 Sep 2017 06:28:17 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.42,421,1500966000"; d="scan'208";a="137499228"
Received: from unknown (HELO Sent) ([10.103.102.81])
 by orsmga002.jf.intel.com with SMTP; 20 Sep 2017 06:28:13 -0700
Received: by Sent (sSMTP sendmail emulation); Wed, 20 Sep 2017 15:25:59 +0200
From: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
To: yliu@fridaylinux.org
Cc: dev@dpdk.org, Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>,
 jianfeng.tan@intel.com, stable@stable@dpdk.org
Date: Wed, 20 Sep 2017 15:25:56 +0200
Message-Id: <20170920132556.5310-1-danielx.t.mrzyglod@intel.com>
X-Mailer: git-send-email 2.13.5
In-Reply-To: <20170920091917.3929-1-danielx.t.mrzyglod@intel.com>
References: <20170920091917.3929-1-danielx.t.mrzyglod@intel.com>
Subject: [dpdk-dev] [PATCH v2] net/virtio: fix of untrusted scalar value
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 20 Sep 2017 13:28:19 -0000

The unscrutinized value may be incorrectly assumed to be within a certain
range by later operations.

In vhost_user_read: An unscrutinized value from an untrusted source used
in a trusted context - the value of sz_payload may be harmfull and we need
limit them to the max value of payload.

Coverity issue: 139601

Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")
Cc: jianfeng.tan@intel.com
Cc: stable@stable@dpdk.org

Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
v2:
* Add Cc for stable in gitlog massage
* Add Coverity line
* v1 was acked by Acked-by: Jianfeng Tan <jianfeng.tan@intel.com>

 drivers/net/virtio/virtio_user/vhost_user.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c
index 4ad7b21..b490336 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -130,6 +130,10 @@ vhost_user_read(int fd, struct vhost_user_msg *msg)
 	}
 
 	sz_payload = msg->size;
+
+	if (sz_payload > sizeof(msg->payload))
+		goto fail;
+
 	if (sz_payload) {
 		ret = recv(fd, (void *)((char *)msg + sz_hdr), sz_payload, 0);
 		if (ret < sz_payload) {
-- 
2.7.4