[dpdk-dev] net/virtio: fix of untrusted scalar value

Message ID 20170920091917.3929-1-danielx.t.mrzyglod@intel.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Daniel Mrzyglod Sept. 20, 2017, 9:19 a.m. UTC
  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.

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

Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
 drivers/net/virtio/virtio_user/vhost_user.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Daniel Mrzyglod Sept. 20, 2017, 9:31 a.m. UTC | #1
This patch is for Coverity issue: 139601

Does it need v2 for updating Message Body ?
  
Jianfeng Tan Sept. 20, 2017, 9:38 a.m. UTC | #2
Hi,

> -----Original Message-----
> From: Mrzyglod, DanielX T
> Sent: Wednesday, September 20, 2017 5:19 PM
> To: yliu@fridaylinux.org
> Cc: dev@dpdk.org; Mrzyglod, DanielX T; Tan, Jianfeng
> Subject: [PATCH] net/virtio: fix of untrusted scalar value
> 
> 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.

Please add below line.
Coverity issue: 139601

> 
> Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")
> Cc: jianfeng.tan@intel.com
> 
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>

Acked-by: Jianfeng Tan <jianfeng.tan@intel.com>

Thanks,
Jianfeng
  

Patch

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) {