diff options
author | Simon Rettberg | 2022-02-08 10:46:04 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-03-04 12:04:14 +0100 |
commit | c70bade50e275f901e63d7564e99a7bdabe83509 (patch) | |
tree | d5f16ed7b16c8b7b5f8f25fa5e54fda72a693b8b | |
parent | README.md: State that qcow2 is read only (diff) | |
download | xloop-c70bade50e275f901e63d7564e99a7bdabe83509.tar.gz xloop-c70bade50e275f901e63d7564e99a7bdabe83509.tar.xz xloop-c70bade50e275f901e63d7564e99a7bdabe83509.zip |
Don't add byte offset to kmapped pointer
While the kunmap functions always round down to the current page,
and currently, we never map a region larger than a page, it should
be safer to do the pointer arithmetic after we acquired the mapped
pointer, to avoid the risk of ever passing an invalid pointer
to kunmap.
-rw-r--r-- | src/kernel/xloop_file_fmt_qcow_main.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/kernel/xloop_file_fmt_qcow_main.c b/src/kernel/xloop_file_fmt_qcow_main.c index 4fc2fe3..767698b 100644 --- a/src/kernel/xloop_file_fmt_qcow_main.c +++ b/src/kernel/xloop_file_fmt_qcow_main.c @@ -975,16 +975,16 @@ static int __qcow_file_fmt_read_compressed(struct xloop_file_fmt *xlo_fmt, struc ASSERT(bytes <= bvec->bv_len); #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) - data = bvec_kmap_local(bvec) + bytes_done; + data = bvec_kmap_local(bvec); #else - data = bvec_kmap_irq(bvec, &irq_flags) + bytes_done; + data = bvec_kmap_irq(bvec, &irq_flags); #endif - memcpy(data, qcow_data->cmp_out_buf + offset_in_cluster, bytes); + memcpy(data + bytes_done, qcow_data->cmp_out_buf + offset_in_cluster, bytes); flush_dcache_page(bvec->bv_page); #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) - kunmap_local(data); + kunmap_local(data); #else - bvec_kunmap_irq(data, &irq_flags); + bvec_kunmap_irq(data, &irq_flags); #endif out_free_in_buf: @@ -1029,11 +1029,11 @@ static int __qcow_file_fmt_read_bvec(struct xloop_file_fmt *xlo_fmt, struct bio_ case QCOW_SUBCLUSTER_UNALLOCATED_PLAIN: case QCOW_SUBCLUSTER_UNALLOCATED_ALLOC: #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) - data = bvec_kmap_local(bvec) + bytes_done; + data = bvec_kmap_local(bvec); #else - data = bvec_kmap_irq(bvec, &irq_flags) + bytes_done; + data = bvec_kmap_irq(bvec, &irq_flags); #endif - memset(data, 0, cur_bytes); + memset(data + bytes_done, 0, cur_bytes); flush_dcache_page(bvec->bv_page); #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) kunmap_local(data); @@ -1053,11 +1053,11 @@ static int __qcow_file_fmt_read_bvec(struct xloop_file_fmt *xlo_fmt, struct bio_ pos_read = host_offset; #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) - data = bvec_kmap_local(bvec) + bytes_done; + data = bvec_kmap_local(bvec); #else - data = bvec_kmap_irq(bvec, &irq_flags) + bytes_done; + data = bvec_kmap_irq(bvec, &irq_flags); #endif - len = kernel_read(xlo->xlo_backing_file, data, cur_bytes, &pos_read); + len = kernel_read(xlo->xlo_backing_file, data + bytes_done, cur_bytes, &pos_read); flush_dcache_page(bvec->bv_page); #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) kunmap_local(data); |