From f83e0199c80e108576a5f0c9e523fd338db35d58 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Mon, 5 Feb 2018 13:16:00 +0100 Subject: [PATCH] vhost: reject invalid log base mmap offset If the log base mmap_offset is larger than mmap_size then it points outside the mmap region. We must not write to memory outside the mmap region, so validate mmap_offset in vhost_user_set_log_base(). Signed-off-by: Stefan Hajnoczi Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index baf58dd3a8..1a67e2c288 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1006,6 +1006,15 @@ vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg) size = msg->payload.log.mmap_size; off = msg->payload.log.mmap_offset; + + /* Don't allow mmap_offset to point outside the mmap region */ + if (off > size) { + RTE_LOG(ERR, VHOST_CONFIG, + "log offset %#"PRIx64" exceeds log size %#"PRIx64"\n", + off, size); + return -1; + } + RTE_LOG(INFO, VHOST_CONFIG, "log mmap size: %"PRId64", offset: %"PRId64"\n", size, off); -- 2.20.1