From 97e6d964f46e82aa570163f3f8e4cabc3b65efb1 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 13 Sep 2019 12:47:02 +0100 Subject: [PATCH] 5.2-stable patches added patches: vhost-block-speculation-of-translated-descriptors.patch vhost-make-sure-log_num-in_num.patch --- queue-5.2/series | 2 + ...peculation-of-translated-descriptors.patch | 46 ++++++++++++++++ .../vhost-make-sure-log_num-in_num.patch | 54 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 queue-5.2/vhost-block-speculation-of-translated-descriptors.patch create mode 100644 queue-5.2/vhost-make-sure-log_num-in_num.patch diff --git a/queue-5.2/series b/queue-5.2/series index e207eefa9b4..3ca110cdfc8 100644 --- a/queue-5.2/series +++ b/queue-5.2/series @@ -33,3 +33,5 @@ drm-i915-whitelist-ps_-depth-invocation-_count.patch drm-i915-add-whitelist-workarounds-for-icl.patch drm-i915-icl-whitelist-ps_-depth-invocation-_count.patch btrfs-fix-unwritten-extent-buffers-and-hangs-on-future-writeback-attempts.patch +vhost-block-speculation-of-translated-descriptors.patch +vhost-make-sure-log_num-in_num.patch diff --git a/queue-5.2/vhost-block-speculation-of-translated-descriptors.patch b/queue-5.2/vhost-block-speculation-of-translated-descriptors.patch new file mode 100644 index 00000000000..098ddca0c59 --- /dev/null +++ b/queue-5.2/vhost-block-speculation-of-translated-descriptors.patch @@ -0,0 +1,46 @@ +From a89db445fbd7f1f8457b03759aa7343fa530ef6b Mon Sep 17 00:00:00 2001 +From: "Michael S. Tsirkin" +Date: Sun, 8 Sep 2019 07:04:08 -0400 +Subject: vhost: block speculation of translated descriptors + +From: Michael S. Tsirkin + +commit a89db445fbd7f1f8457b03759aa7343fa530ef6b upstream. + +iovec addresses coming from vhost are assumed to be +pre-validated, but in fact can be speculated to a value +out of range. + +Userspace address are later validated with array_index_nospec so we can +be sure kernel info does not leak through these addresses, but vhost +must also not leak userspace info outside the allowed memory table to +guests. + +Following the defence in depth principle, make sure +the address is not validated out of node range. + +Signed-off-by: Michael S. Tsirkin +Cc: stable@vger.kernel.org +Acked-by: Jason Wang +Tested-by: Jason Wang +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/vhost/vhost.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +--- a/drivers/vhost/vhost.c ++++ b/drivers/vhost/vhost.c +@@ -1965,8 +1965,10 @@ static int translate_desc(struct vhost_v + _iov = iov + ret; + size = node->size - addr + node->start; + _iov->iov_len = min((u64)len - s, size); +- _iov->iov_base = (void __user *)(unsigned long) +- (node->userspace_addr + addr - node->start); ++ _iov->iov_base = (void __user *) ++ ((unsigned long)node->userspace_addr + ++ array_index_nospec((unsigned long)(addr - node->start), ++ node->size)); + s += size; + addr += size; + ++ret; diff --git a/queue-5.2/vhost-make-sure-log_num-in_num.patch b/queue-5.2/vhost-make-sure-log_num-in_num.patch new file mode 100644 index 00000000000..aaa4fc0d753 --- /dev/null +++ b/queue-5.2/vhost-make-sure-log_num-in_num.patch @@ -0,0 +1,54 @@ +From 060423bfdee3f8bc6e2c1bac97de24d5415e2bc4 Mon Sep 17 00:00:00 2001 +From: yongduan +Date: Wed, 11 Sep 2019 17:44:24 +0800 +Subject: vhost: make sure log_num < in_num + +From: yongduan + +commit 060423bfdee3f8bc6e2c1bac97de24d5415e2bc4 upstream. + +The code assumes log_num < in_num everywhere, and that is true as long as +in_num is incremented by descriptor iov count, and log_num by 1. However +this breaks if there's a zero sized descriptor. + +As a result, if a malicious guest creates a vring desc with desc.len = 0, +it may cause the host kernel to crash by overflowing the log array. This +bug can be triggered during the VM migration. + +There's no need to log when desc.len = 0, so just don't increment log_num +in this case. + +Fixes: 3a4d5c94e959 ("vhost_net: a kernel-level virtio server") +Cc: stable@vger.kernel.org +Reviewed-by: Lidong Chen +Signed-off-by: ruippan +Signed-off-by: yongduan +Acked-by: Michael S. Tsirkin +Reviewed-by: Tyler Hicks +Signed-off-by: Michael S. Tsirkin +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/vhost/vhost.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--- a/drivers/vhost/vhost.c ++++ b/drivers/vhost/vhost.c +@@ -2074,7 +2074,7 @@ static int get_indirect(struct vhost_vir + /* If this is an input descriptor, increment that count. */ + if (access == VHOST_ACCESS_WO) { + *in_num += ret; +- if (unlikely(log)) { ++ if (unlikely(log && ret)) { + log[*log_num].addr = vhost64_to_cpu(vq, desc.addr); + log[*log_num].len = vhost32_to_cpu(vq, desc.len); + ++*log_num; +@@ -2217,7 +2217,7 @@ int vhost_get_vq_desc(struct vhost_virtq + /* If this is an input descriptor, + * increment that count. */ + *in_num += ret; +- if (unlikely(log)) { ++ if (unlikely(log && ret)) { + log[*log_num].addr = vhost64_to_cpu(vq, desc.addr); + log[*log_num].len = vhost32_to_cpu(vq, desc.len); + ++*log_num; -- 2.47.3