Skip to contentSkip to conversation

block/io: fix bdrv_co_do_copy_on_readv

PATCH Applied Vladimir Sementsov-Ogievskiy 3 participants 4 messages Mar 12, 2020 – Mar 16, 2020 Block layer

v1 of 7 Applied Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/io: fix bdrv_co_do_copy_on_readv

Prior to 1143ec5ebf4 it was OK to qemu_iovec_from_buf() from aligned-up buffer to original qiov, as qemu_iovec_from_buf() will stop at qiov end anyway.

But after 1143ec5ebf4 we assume that bdrv_co_do_copy_on_readv works on part of original qiov, defined by qiov_offset and bytes. So we must not touch qiov behind qiov_offset+bytes bound. Fix it.

---
 block/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/io.c +1 -1
index 7e4cb74cf4..aba67f66b9 100644
@@ -1399,7 +1399,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
             if (!(flags & BDRV_REQ_PREFETCH)) {
                 qemu_iovec_from_buf(qiov, qiov_offset + progress,
                                     bounce_buffer + skip_bytes,
-                                    pnum - skip_bytes);
+                                    MIN(pnum - skip_bytes, bytes - progress));
             }
         } else if (!(flags & BDRV_REQ_PREFETCH)) {
             /* Read directly into the destination */
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Vladimir Sementsov-Ogievskiy

Prior to 1143ec5ebf4 it was OK to qemu_iovec_from_buf() from aligned-up buffer to original qiov, as qemu_iovec_from_buf() will stop at qiov end anyway.

But after 1143ec5ebf4 we assume that bdrv_co_do_copy_on_readv works on part of original qiov, defined by qiov_offset and bytes. So we must not touch qiov behind qiov_offset+bytes bound. Fix it.

For the purposes of the stable branch commit log, how does the bug manifest? Are there known cases? What's the impact?

(Do we have tests?)

Quoted 13 lines
---
 block/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/io.c +0 -0
index 7e4cb74cf4..aba67f66b9 100644

block/io.c static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, · line 1405

Quoted 8 lines
block/io.c +1 -1
@@ -1399,7 +1399,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
             if (!(flags & BDRV_REQ_PREFETCH)) {
                 qemu_iovec_from_buf(qiov, qiov_offset + progress,
                                     bounce_buffer + skip_bytes,
-                                    pnum - skip_bytes);
+                                    MIN(pnum - skip_bytes, bytes - progress));
             }
         } else if (!(flags & BDRV_REQ_PREFETCH)) {
             /* Read directly into the destination */

Even if I don't understand the bug, the tighter bound seems provably correct anyway, so...

#2 lore raw
Quoted 12 lines · John Snow
Quoted 8 lines · Vladimir Sementsov-Ogievskiy

Prior to 1143ec5ebf4 it was OK to qemu_iovec_from_buf() from aligned-up buffer to original qiov, as qemu_iovec_from_buf() will stop at qiov end anyway.

But after 1143ec5ebf4 we assume that bdrv_co_do_copy_on_readv works on part of original qiov, defined by qiov_offset and bytes. So we must not touch qiov behind qiov_offset+bytes bound. Fix it.

Quoted 4 lines

For the purposes of the stable branch commit log, how does the bug manifest? Are there known cases? What's the impact?

(Do we have tests?)

Sorry, nothing of these things. I just saw it while working with this code.

Quoted 25 lines
Quoted 14 lines
---
  block/io.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
block/io.c +0 -0
index 7e4cb74cf4..aba67f66b9 100644

block/io.c static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, · line 1405

Quoted 8 lines
block/io.c +1 -1
@@ -1399,7 +1399,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
              if (!(flags & BDRV_REQ_PREFETCH)) {
                  qemu_iovec_from_buf(qiov, qiov_offset + progress,
                                      bounce_buffer + skip_bytes,
-                                    pnum - skip_bytes);
+                                    MIN(pnum - skip_bytes, bytes - progress));
              }
          } else if (!(flags & BDRV_REQ_PREFETCH)) {
              /* Read directly into the destination */

Even if I don't understand the bug, the tighter bound seems provably correct anyway, so...

Quoted 2 lines

Thanks!

Signature · 2 lines
Best regards,
Vladimir
#3 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 8 lines · Vladimir Sementsov-Ogievskiy

Prior to 1143ec5ebf4 it was OK to qemu_iovec_from_buf() from aligned-up buffer to original qiov, as qemu_iovec_from_buf() will stop at qiov end anyway.

But after 1143ec5ebf4 we assume that bdrv_co_do_copy_on_readv works on part of original qiov, defined by qiov_offset and bytes. So we must not touch qiov behind qiov_offset+bytes bound. Fix it.

Quoted 6 lines
---
 block/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan