libvhost-user: fix VHOST_USER_REM_MEM_REG skipping mmap_addr
PATCH 1/1 libvhost-user: fix VHOST_USER_REM_MEM_REG skipping mmap_addr
We end up not copying the mmap_addr of all existing regions, resulting in a SEGFAULT once we actually try to map/access anything within our memory regions.
--- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+)
subprojects/libvhost-user/libvhost-user.c +1 -0
@@ -816,6 +816,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { shadow_regions[j].gpa = dev->regions[i].gpa; shadow_regions[j].size = dev->regions[i].size; shadow_regions[j].qva = dev->regions[i].qva; + shadow_regions[j].mmap_addr = dev->regions[i].mmap_addr; shadow_regions[j].mmap_offset = dev->regions[i].mmap_offset; j++; }else {
Signature · 1 line
2.31.1
Quoted 4 lines · David Hildenbrand
We end up not copying the
mmap_addrof all existing regions, resulting in a SEGFAULT once we actually try to map/access anything within our memory regions.
Quoted 9 lines
Fixes 875b9fd97b34 ("Support individual region unmap in libvhost-user")Cc Michael S. Tsirkin <[email protected]>Cc Raphael Norwitz <[email protected]>Cc "Marc-André Lureau" <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Coiby Xu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Quoted 19 lines
--- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+)subprojects/libvhost-user/libvhost-user.c +1
-0@@ -816,6 +816,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { shadow_regions[j].gpa = dev->regions[i].gpa; shadow_regions[j].size = dev->regions[i].size; shadow_regions[j].qva = dev->regions[i].qva; + shadow_regions[j].mmap_addr = dev->regions[i].mmap_addr; shadow_regions[j].mmap_offset = dev->regions[i].mmap_offset; j++; }else {Signature · 1 line
2.31.1
Quoted 22 lines · David Hildenbrand
We end up not copying the
mmap_addrof all existing regions, resulting in a SEGFAULT once we actually try to map/access anything within our memory regions.Fixes 875b9fd97b34 ("Support individual region unmap in libvhost-user")Cc Michael S. Tsirkin <[email protected]>Cc Raphael Norwitz <[email protected]>Cc "Marc-André Lureau" <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Coiby Xu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+)subprojects/libvhost-user/libvhost-user.c +0
-0
subprojects/libvhost-user/libvhost-user.c vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { · line 822
Quoted 7 lines
subprojects/libvhost-user/libvhost-user.c +1
-0@@ -816,6 +816,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { shadow_regions[j].gpa = dev->regions[i].gpa; shadow_regions[j].size = dev->regions[i].size; shadow_regions[j].qva = dev->regions[i].qva; + shadow_regions[j].mmap_addr = dev->regions[i].mmap_addr; shadow_regions[j].mmap_offset = dev->regions[i].mmap_offset; j++; }else {
Raphael: Some questions about vu_rem_mem_reg():
- What ensures that shadow_regions[VHOST_USER_MAX_RAM_SLOTS] is large enough? The add_mem_reg/set_mem_table code doesn't seem to check whether there is enough space in dev->regions[] before adding regions.
- What happens when the master populated dev->regions[] with multiple copies of the same region? dev->nregions is only decremented once and no longer accurately reflects the number of elements in dev->regions[].
libvhost-user must not trust the vhost-user master since vhost-user needs to provide process isolation. Please add input validation.
Stefan
Quoted 33 lines · Stefan Hajnoczi
Quoted 22 lines · David Hildenbrand
We end up not copying the
mmap_addrof all existing regions, resulting in a SEGFAULT once we actually try to map/access anything within our memory regions.Fixes 875b9fd97b34 ("Support individual region unmap in libvhost-user")Cc Michael S. Tsirkin <[email protected]>Cc Raphael Norwitz <[email protected]>Cc "Marc-André Lureau" <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Coiby Xu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+)subprojects/libvhost-user/libvhost-user.c +0
-0subprojects/libvhost-user/libvhost-user.c vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { · line 822
Quoted 7 lines
subprojects/libvhost-user/libvhost-user.c +1
-0@@ -816,6 +816,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { shadow_regions[j].gpa = dev->regions[i].gpa; shadow_regions[j].size = dev->regions[i].size; shadow_regions[j].qva = dev->regions[i].qva; + shadow_regions[j].mmap_addr = dev->regions[i].mmap_addr; shadow_regions[j].mmap_offset = dev->regions[i].mmap_offset; j++; }else {Raphael: Some questions about
vu_rem_mem_reg():
Quoted 4 lines
- What ensures that shadow_regions[VHOST_USER_MAX_RAM_SLOTS] is large enough? The add_mem_reg/set_mem_table code doesn't seem to check whether there is enough space in dev->regions[] before adding regions.
Correct - it does not check if there is enough space as is. I can add that.
Quoted 4 lines
- What happens when the master populated dev->regions[] with multiple copies of the same region?
dev->nregionsis only decremented once and no longer accurately reflects the number of elements in dev->regions[].
That case is also not accounted for. I will add it.
Quoted 4 lines
libvhost-user must not trust the vhost-user master since vhost-user needs to provide process isolation. Please add input validation.
Got it - let me start working on a series.
Quoted 1 line
Stefan
Quoted 46 lines · Raphael Norwitz
Quoted 33 lines · Stefan Hajnoczi
Quoted 22 lines · David Hildenbrand
We end up not copying the
mmap_addrof all existing regions, resulting in a SEGFAULT once we actually try to map/access anything within our memory regions.Fixes 875b9fd97b34 ("Support individual region unmap in libvhost-user")Cc Michael S. Tsirkin <[email protected]>Cc Raphael Norwitz <[email protected]>Cc "Marc-André Lureau" <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Coiby Xu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+)subprojects/libvhost-user/libvhost-user.c +0
-0subprojects/libvhost-user/libvhost-user.c vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { · line 822
Quoted 7 lines
subprojects/libvhost-user/libvhost-user.c +1
-0@@ -816,6 +816,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { shadow_regions[j].gpa = dev->regions[i].gpa; shadow_regions[j].size = dev->regions[i].size; shadow_regions[j].qva = dev->regions[i].qva; + shadow_regions[j].mmap_addr = dev->regions[i].mmap_addr; shadow_regions[j].mmap_offset = dev->regions[i].mmap_offset; j++; }else {Raphael: Some questions about
vu_rem_mem_reg():Quoted 4 lines
- What ensures that shadow_regions[VHOST_USER_MAX_RAM_SLOTS] is large enough? The add_mem_reg/set_mem_table code doesn't seem to check whether there is enough space in dev->regions[] before adding regions.
Correct - it does not check if there is enough space as is. I can add that.
Quoted 4 lines
- What happens when the master populated dev->regions[] with multiple copies of the same region?
dev->nregionsis only decremented once and no longer accurately reflects the number of elements in dev->regions[].
Quoted 8 lines
That case is also not accounted for. I will add it.
Quoted 4 lines
libvhost-user must not trust the vhost-user master since vhost-user needs to provide process isolation. Please add input validation.
Got it - let me start working on a series.
Great, thank you!
Stefan
Quoted 34 lines · Raphael Norwitz
Quoted 33 lines · Stefan Hajnoczi
Quoted 22 lines · David Hildenbrand
We end up not copying the
mmap_addrof all existing regions, resulting in a SEGFAULT once we actually try to map/access anything within our memory regions.Fixes 875b9fd97b34 ("Support individual region unmap in libvhost-user")Cc Michael S. Tsirkin <[email protected]>Cc Raphael Norwitz <[email protected]>Cc "Marc-André Lureau" <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Coiby Xu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+)subprojects/libvhost-user/libvhost-user.c +0
-0subprojects/libvhost-user/libvhost-user.c vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { · line 822
Quoted 7 lines
subprojects/libvhost-user/libvhost-user.c +1
-0@@ -816,6 +816,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { shadow_regions[j].gpa = dev->regions[i].gpa; shadow_regions[j].size = dev->regions[i].size; shadow_regions[j].qva = dev->regions[i].qva; + shadow_regions[j].mmap_addr = dev->regions[i].mmap_addr; shadow_regions[j].mmap_offset = dev->regions[i].mmap_offset; j++; }else {Raphael: Some questions about
vu_rem_mem_reg():
Quoted 6 lines
Quoted 4 lines
- What ensures that shadow_regions[VHOST_USER_MAX_RAM_SLOTS] is large enough? The add_mem_reg/set_mem_table code doesn't seem to check whether there is enough space in dev->regions[] before adding regions.
Correct - it does not check if there is enough space as is. I can add that.
Just making sure - you are now working on series supreceding this patch? Is that right?
Quoted 15 lines
Quoted 4 lines
- What happens when the master populated dev->regions[] with multiple copies of the same region?
dev->nregionsis only decremented once and no longer accurately reflects the number of elements in dev->regions[].That case is also not accounted for. I will add it.
Quoted 4 lines
libvhost-user must not trust the vhost-user master since vhost-user needs to provide process isolation. Please add input validation.
Got it - let me start working on a series.
Quoted 1 line
Stefan
Quoted 40 lines · Michael S. Tsirkin
Quoted 39 lines · Raphael Norwitz
Quoted 37 lines · Stefan Hajnoczi
Quoted 22 lines · David Hildenbrand
We end up not copying the
mmap_addrof all existing regions, resulting in a SEGFAULT once we actually try to map/access anything within our memory regions.Fixes 875b9fd97b34 ("Support individual region unmap in libvhost-user")Cc Michael S. Tsirkin <[email protected]>Cc Raphael Norwitz <[email protected]>Cc "Marc-André Lureau" <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Coiby Xu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+)subprojects/libvhost-user/libvhost-user.c +0
-0subprojects/libvhost-user/libvhost-user.c vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { · line 822
Quoted 7 lines
subprojects/libvhost-user/libvhost-user.c +1
-0@@ -816,6 +816,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { shadow_regions[j].gpa = dev->regions[i].gpa; shadow_regions[j].size = dev->regions[i].size; shadow_regions[j].qva = dev->regions[i].qva; + shadow_regions[j].mmap_addr = dev->regions[i].mmap_addr; shadow_regions[j].mmap_offset = dev->regions[i].mmap_offset; j++; }else {Raphael: Some questions about
vu_rem_mem_reg():- What ensures that shadow_regions[VHOST_USER_MAX_RAM_SLOTS] is large enough? The add_mem_reg/set_mem_table code doesn't seem to check whether there is enough space in dev->regions[] before adding regions.
Quoted 5 lines
Quoted 1 line
Correct - it does not check if there is enough space as is. I can add that.
Just making sure - you are now working on series supreceding this patch? Is that right?
I was just going to fix the missing input validation. This looks like a standalone issue and in my opinon the fix should go in as is. I will base my changes on top of it.
Quoted 17 lines
Quoted 16 lines
Quoted 5 lines
- What happens when the master populated dev->regions[] with multiple copies of the same region?
dev->nregionsis only decremented once and no longer accurately reflects the number of elements in dev->regions[].That case is also not accounted for. I will add it.
Quoted 4 lines
libvhost-user must not trust the vhost-user master since vhost-user needs to provide process isolation. Please add input validation.
Got it - let me start working on a series.
Quoted 1 line
Stefan
Quoted 13 lines · David Hildenbrand
We end up not copying the
mmap_addrof all existing regions, resulting in a SEGFAULT once we actually try to map/access anything within our memory regions.Fixes 875b9fd97b34 ("Support individual region unmap in libvhost-user")Cc Michael S. Tsirkin <[email protected]>Cc Raphael Norwitz <[email protected]>Cc "Marc-André Lureau" <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Coiby Xu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Quoted 3 lines
--- subprojects/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+)