Skip to contentSkip to conversation

vhost: block speculation of translated descriptors

PATCH In review Michael S. Tsirkin 3 participants 16 messages Sep 11, 2019

Subsystems (5)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH v2 1/1 vhost: block speculation of translated descriptors

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.

---

changes from v1: fix build on 32 bit

 drivers/vhost/vhost.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +4 -2
index 5dc174ac8cac..34ea219936e3 100644
@@ -2071,8 +2071,10 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
 		_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;
Signature · 1 line
MST
#1 lore raw
Quoted 9 lines · Michael S. Tsirkin

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.

Quoted 6 lines

Following the defence in depth principle, make sure the address is not validated out of node range.

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

Quoted 26 lines

---

changes from v1: fix build on 32 bit

 drivers/vhost/vhost.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +4 -2
index 5dc174ac8cac..34ea219936e3 100644
@@ -2071,8 +2071,10 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
 		_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;
Signature · 1 line
MST
Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#2 lore raw
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

That one doesn't seem to be tagged for stable. Was it queued there in practice?

Quoted 30 lines
Quoted 26 lines

---

changes from v1: fix build on 32 bit

 drivers/vhost/vhost.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +4 -2
index 5dc174ac8cac..34ea219936e3 100644
@@ -2071,8 +2071,10 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
 		_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;
Signature · 1 line
MST
Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#3 lore raw
In reply to Michal Hocko
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

That one doesn't seem to be tagged for stable. Was it queued there in practice?

Quoted 30 lines
Quoted 26 lines

---

changes from v1: fix build on 32 bit

 drivers/vhost/vhost.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +4 -2
index 5dc174ac8cac..34ea219936e3 100644
@@ -2071,8 +2071,10 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
 		_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;
Signature · 1 line
MST
Signature · 2 lines
Michal Hocko
SUSE Labs
#4 lore raw
Quoted 22 lines · Michael S. Tsirkin
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

Quoted 7 lines

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

That one doesn't seem to be tagged for stable. Was it queued there in practice?

not marked for stable but it went in. At least to 4.4.

Signature · 2 lines
Michal Hocko
SUSE Labs
#5 lore raw
In reply to Michael S. Tsirkin
Quoted 22 lines · Michael S. Tsirkin
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

Quoted 7 lines

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

That one doesn't seem to be tagged for stable. Was it queued there in practice?

not marked for stable but it went in. At least to 4.4.

Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#6 lore raw
Quoted 28 lines · Michal Hocko
Quoted 27 lines · Michael S. Tsirkin
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

Quoted 4 lines
Quoted 2 lines

That one doesn't seem to be tagged for stable. Was it queued there in practice?

not marked for stable but it went in. At least to 4.4.

So I guess the answer is I don't know. If you feel it's justified, then sure, feel free to forward.

Signature · 1 line
MST
author maintainer
#7 lore raw
In reply to Michal Hocko
Quoted 28 lines · Michal Hocko
Quoted 27 lines · Michael S. Tsirkin
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

Quoted 4 lines
Quoted 2 lines

That one doesn't seem to be tagged for stable. Was it queued there in practice?

not marked for stable but it went in. At least to 4.4.

So I guess the answer is I don't know. If you feel it's justified, then sure, feel free to forward.

Signature · 1 line
MST
#8 lore raw
Quoted 29 lines · Michael S. Tsirkin
Quoted 28 lines · Michal Hocko
Quoted 27 lines · Michael S. Tsirkin
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

That one doesn't seem to be tagged for stable. Was it queued there in practice?

not marked for stable but it went in. At least to 4.4.

So I guess the answer is I don't know. If you feel it's justified, then sure, feel free to forward.

Well, that obviously depends on you as a maintainer but the point is that spectre gatgets are quite hard to find. There is a smack check AFAIK but that generates quite some false possitives and it is PITA to crawl through those. If you want an interesting (I am not saying vulnerable on purpose) gatget then it would be great to mark it for stable so all stable consumers (disclaimer: I am not one of those) and add that really great feeling of safety ;)

So take this as my 2c

Signature · 2 lines
Michal Hocko
SUSE Labs
#9 lore raw
In reply to Michael S. Tsirkin
Quoted 29 lines · Michael S. Tsirkin
Quoted 28 lines · Michal Hocko
Quoted 27 lines · Michael S. Tsirkin
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

That one doesn't seem to be tagged for stable. Was it queued there in practice?

not marked for stable but it went in. At least to 4.4.

So I guess the answer is I don't know. If you feel it's justified, then sure, feel free to forward.

Well, that obviously depends on you as a maintainer but the point is that spectre gatgets are quite hard to find. There is a smack check AFAIK but that generates quite some false possitives and it is PITA to crawl through those. If you want an interesting (I am not saying vulnerable on purpose) gatget then it would be great to mark it for stable so all stable consumers (disclaimer: I am not one of those) and add that really great feeling of safety ;)

So take this as my 2c

Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#10 lore raw
Quoted 46 lines · Michal Hocko
Quoted 29 lines · Michael S. Tsirkin
Quoted 28 lines · Michal Hocko
Quoted 27 lines · Michael S. Tsirkin
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

That one doesn't seem to be tagged for stable. Was it queued there in practice?

not marked for stable but it went in. At least to 4.4.

So I guess the answer is I don't know. If you feel it's justified, then sure, feel free to forward.

Well, that obviously depends on you as a maintainer but the point is that spectre gatgets are quite hard to find. There is a smack check AFAIK but that generates quite some false possitives and it is PITA to crawl through those. If you want an interesting (I am not saying vulnerable on purpose) gatget then it would be great to mark it for stable so all stable consumers (disclaimer: I am not one of those) and add that really great feeling of safety ;)

Quoted 1 line

So take this as my 2c

OK it seems [email protected] is the way to handle these things. I'll try that.

Quoted 3 lines
Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#11 lore raw
In reply to Michal Hocko
Quoted 46 lines · Michal Hocko
Quoted 29 lines · Michael S. Tsirkin
Quoted 28 lines · Michal Hocko
Quoted 27 lines · Michael S. Tsirkin
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Michael S. Tsirkin

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.

Quoted 7 lines
Quoted 3 lines

no need to mark fo stable? Other spectre fixes tend to be backported even when the security implications are not really clear. The risk should be low and better to be covered in case.

This is not really a fix - more a defence in depth thing, quite similar to e.g. commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd
x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec in scope.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

That one doesn't seem to be tagged for stable. Was it queued there in practice?

not marked for stable but it went in. At least to 4.4.

So I guess the answer is I don't know. If you feel it's justified, then sure, feel free to forward.

Well, that obviously depends on you as a maintainer but the point is that spectre gatgets are quite hard to find. There is a smack check AFAIK but that generates quite some false possitives and it is PITA to crawl through those. If you want an interesting (I am not saying vulnerable on purpose) gatget then it would be great to mark it for stable so all stable consumers (disclaimer: I am not one of those) and add that really great feeling of safety ;)

Quoted 1 line

So take this as my 2c

OK it seems [email protected] is the way to handle these things. I'll try that.

Quoted 3 lines
Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#12 lore raw
In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin

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.

Quoted 7 lines

Following the defence in depth principle, make sure the address is not validated out of node range.

---

Pls advise on whether you'd like me to merge this directly, Cc stable, or handle it in some other way.

Quoted 24 lines

changes from v1: fix build on 32 bit

 drivers/vhost/vhost.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +4 -2
index 5dc174ac8cac..34ea219936e3 100644
@@ -2071,8 +2071,10 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
 		_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;
Signature · 1 line
MST
author maintainer
#13 lore raw
In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin

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.

Quoted 7 lines

Following the defence in depth principle, make sure the address is not validated out of node range.

---

Pls advise on whether you'd like me to merge this directly, Cc stable, or handle it in some other way.

Quoted 24 lines

changes from v1: fix build on 32 bit

 drivers/vhost/vhost.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +4 -2
index 5dc174ac8cac..34ea219936e3 100644
@@ -2071,8 +2071,10 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len,
 		_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;
Signature · 1 line
MST
#14 lore raw
Quoted 18 lines · Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin

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.

Quoted 7 lines

Following the defence in depth principle, make sure the address is not validated out of node range.

---

Quoted 4 lines

Pls advise on whether you'd like me to merge this directly, Cc stable, or handle it in some other way.

I think you're fine taking it directly, with a cc stable and a Fixes: tag.

Cheers,

Will

#15 lore raw
In reply to Michael S. Tsirkin
Quoted 18 lines · Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin

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.

Quoted 7 lines

Following the defence in depth principle, make sure the address is not validated out of node range.

---

Quoted 4 lines

Pls advise on whether you'd like me to merge this directly, Cc stable, or handle it in some other way.

I think you're fine taking it directly, with a cc stable and a Fixes: tag.

Cheers,

Will