hw/display/qxl-render.c: fix qxl_unpack_chunks() chunk size calculation
PATCH 1/1 hw/display/qxl-render.c: fix qxl_unpack_chunks() chunk size calculation
In case of multiple chunks, code in qxl_unpack_chunks() takes size of the wrong (next in the chain) chunk, instead of using current chunk size. This leads to wrong number of bytes being copied, and to crashes if next chunk size is larger than the current one.
Based on the code by Gao Yong.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1628
--- hw/display/qxl-render.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
hw/display/qxl-render.c +10 -1
@@ -222,6 +222,7 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,uint32_t max_chunks =32 ;size_t offset =0 ;size_t bytes; +QXLPHYSICAL next_chunk_phys =0 ;for (;;) { bytes =MIN (size - offset, chunk->data_size);
@@ -230,7 +231,15 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,if (offset == size) {return ; } - chunk =qxl_phys2virt (qxl, chunk->next_chunk, group_id, + next_chunk_phys = chunk->next_chunk; +/* fist time, only get the next chunk's data size */ + chunk =qxl_phys2virt (qxl, next_chunk_phys, group_id, +sizeof (QXLDataChunk)); +if (!chunk) { +return ; + } +/* second time, check data size and get data */ + chunk =qxl_phys2virt (qxl, next_chunk_phys, group_id,sizeof (QXLDataChunk) + chunk->data_size);if (!chunk) {return ;
Signature · 1 line
2.39.5
A friendly ping?
This one probably should go to qemu-stable too.
Thanks,
/mjt
Quoted 42 lines · Michael Tokarev
In case of multiple chunks, code in
qxl_unpack_chunks()takes size of the wrong (next in the chain) chunk, instead of using current chunk size. This leads to wrong number of bytes being copied, and to crashes if next chunk size is larger than the current one.Based on the code by Gao Yong.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1628
Signed-off-by Michael Tokarev <[email protected]>--- hw/display/qxl-render.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/display/qxl-render.c +10
-1@@ -222,6 +222,7 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,uint32_t max_chunks =32 ;size_t offset =0 ;size_t bytes; +QXLPHYSICAL next_chunk_phys =0 ;for (;;) { bytes =MIN (size - offset, chunk->data_size);@@ -230,7 +231,15 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,if (offset == size) {return ; } - chunk =qxl_phys2virt (qxl, chunk->next_chunk, group_id, + next_chunk_phys = chunk->next_chunk; +/* fist time, only get the next chunk's data size */ + chunk =qxl_phys2virt (qxl, next_chunk_phys, group_id, +sizeof (QXLDataChunk)); +if (!chunk) { +return ; + } +/* second time, check data size and get data */ + chunk =qxl_phys2virt (qxl, next_chunk_phys, group_id,sizeof (QXLDataChunk) + chunk->data_size);if (!chunk) {return ;
Quoted 30 lines · Michael Tokarev
In case of multiple chunks, code in
qxl_unpack_chunks()takes size of the wrong (next in the chain) chunk, instead of using current chunk size. This leads to wrong number of bytes being copied, and to crashes if next chunk size is larger than the current one.Based on the code by Gao Yong.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1628
Signed-off-by Michael Tokarev <[email protected]>--- hw/display/qxl-render.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/display/qxl-render.c +1
-1@@ -222,6 +222,7 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,uint32_t max_chunks =32 ;size_t offset =0 ;size_t bytes; +QXLPHYSICAL next_chunk_phys =0 ;for (;;) { bytes =MIN (size - offset, chunk->data_size);@@ -230,7 +231,15 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,if (offset == size) {return ; } - chunk = qxl_phys2virt(qxl, chunk->next_chunk, group_id,
hw/display/qxl-render.c static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl, · line 243
Quoted 10 lines
hw/display/qxl-render.c +9
-0+ next_chunk_phys = chunk->next_chunk; +/* fist time, only get the next chunk's data size */ + chunk =qxl_phys2virt (qxl, next_chunk_phys, group_id, +sizeof (QXLDataChunk)); +if (!chunk) { +return ; + } +/* second time, check data size and get data */ + chunk =qxl_phys2virt (qxl, next_chunk_phys, group_id,sizeof (QXLDataChunk) + chunk->data_size);
Looks reasonable to me, and I think it's also simple enough for qemu-trivial (now on CC:).
Quoted 18 lines · Michael Tokarev
In case of multiple chunks, code in
qxl_unpack_chunks()takes size of the wrong (next in the chain) chunk, instead of using current chunk size. This leads to wrong number of bytes being copied, and to crashes if next chunk size is larger than the current one.Based on the code by Gao Yong.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1628
Signed-off-by Michael Tokarev <[email protected]>--- hw/display/qxl-render.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/display/qxl-render.c +0
-0
hw/display/qxl-render.c static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl, · line 225
Quoted 4 lines
hw/display/qxl-render.c +1
-0@@ -222,6 +222,7 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,uint32_t max_chunks =32 ;size_t offset =0 ;size_t bytes; +QXLPHYSICAL next_chunk_phys =0 ;
Thanks, queued (without zero-initialization).
Quoted 20 lines
hw/display/qxl-render.c +9
-1for (;;) { bytes =MIN (size - offset, chunk->data_size);@@ -230,7 +231,15 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,if (offset == size) {return ; } - chunk =qxl_phys2virt (qxl, chunk->next_chunk, group_id, + next_chunk_phys = chunk->next_chunk; +/* fist time, only get the next chunk's data size */ + chunk =qxl_phys2virt (qxl, next_chunk_phys, group_id, +sizeof (QXLDataChunk)); +if (!chunk) { +return ; + } +/* second time, check data size and get data */ + chunk =qxl_phys2virt (qxl, next_chunk_phys, group_id,sizeof (QXLDataChunk) + chunk->data_size);if (!chunk) {return ;
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Michael Tokarev
In case of multiple chunks, code in
qxl_unpack_chunks()takes size of the wrong (next in the chain) chunk, instead of using current chunk size. This leads to wrong number of bytes being copied, and to crashes if next chunk size is larger than the current one.Based on the code by Gao Yong.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1628
Signed-off-by Michael Tokarev <[email protected]>---
hw/display/qxl-render.c| 11 ++++++++++-1 file changed, 10 insertions(+), 1 deletion(-)
Quoted 12 lines
hw/display/qxl-render.c static void qxl_unpack_chunks(void *dest, size_t · line 226
Quoted 10 lines
hw/display/qxl-render.c +1
-0@@ -222,6 +222,7 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl, uint32_t max_chunks = 32; size_t offset = 0; size_t bytes; + QXLPHYSICAL next_chunk_phys = 0;Thanks, queued (without zero-initialization).
Heh. Indeed, the init isn't needed here.
But you're a bit too late: this version has already been applied. Dunno if it's worth the effort to remove the initializer here, - probably not.
Philippe, you can at least pick up another patch from the trivial patches queue (since I don't have any other patches) - this is "roms/Makefile: fix npcmNxx_bootrom build rules". (There are 2 more changes pending in this area though - it is the rules for ast270x0 vbootrom, waiting for the upstream git tree to fix a build bug in there).
Thanks,
/mjt