block/io: fix bdrv_co_do_copy_on_readv
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
@@ -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
Quoted 8 lines · Vladimir Sementsov-Ogievskiy
Prior to
1143ec5ebf4it was OK toqemu_iovec_from_buf()from aligned-up buffer to original qiov, asqemu_iovec_from_buf()will stop at qiov end anyway.But after
1143ec5ebf4we assume thatbdrv_co_do_copy_on_readvworks on part of original qiov, defined byqiov_offsetand 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
Cc [email protected] # v4.2Fixes 1143ec5ebf4Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/io.c +0
-0
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 12 lines · John Snow
Quoted 8 lines · Vladimir Sementsov-Ogievskiy
Prior to
1143ec5ebf4it was OK toqemu_iovec_from_buf()from aligned-up buffer to original qiov, asqemu_iovec_from_buf()will stop at qiov end anyway.But after
1143ec5ebf4we assume thatbdrv_co_do_copy_on_readvworks on part of original qiov, defined byqiov_offsetand 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
Cc [email protected] # v4.2Fixes 1143ec5ebf4Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/io.c +0
-0block/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
Reviewed-by John Snow <[email protected]>
Thanks!
Signature · 2 lines
Best regards, Vladimir
Stefan Hajnoczi
AppliedQuoted 8 lines · Vladimir Sementsov-Ogievskiy
Prior to
1143ec5ebf4it was OK toqemu_iovec_from_buf()from aligned-up buffer to original qiov, asqemu_iovec_from_buf()will stop at qiov end anyway.But after
1143ec5ebf4we assume thatbdrv_co_do_copy_on_readvworks on part of original qiov, defined byqiov_offsetand bytes. So we must not touch qiov behind qiov_offset+bytes bound. Fix it.
Quoted 6 lines
Cc [email protected] # v4.2Fixes 1143ec5ebf4Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- 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