x86/hvm/dmop: Only copy what is needed to/from the guest
PATCH 1/1 x86/hvm/dmop: Only copy what is needed to/from the guest
dm_op() fails with -EFAULT if the struct xen_dm_op given by the guest is smaller than Xen's struct xen_dm_op. This is a problem because DMOP is meant to be a stable ABI but it breaks whenever the size of struct xen_dm_op changes.
To fix this, change how the copying to and from the guest is done. When copying from the guest, first copy the header and inspect the op. Then, only copy the correct amount needed for that op. When copying to the guest, don't copy the header. Rather, copy only the correct amount needed for that particular op.
So now the dm_op() will fail if the guest does not supply enough bytes for the specific op. It will not fail if the guest supplies too many bytes for the specific op, but Xen will not copy the extra bytes.
Remove some now unused macros and helper functions.
--- xen/arch/x86/hvm/dm.c | 78 +++++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 36 deletions(-)
xen/arch/x86/hvm/dm.c +42 -36
@@ -54,42 +54,10 @@ static bool _raw_copy_from_guest_buf_offset(void *dst, offset_bytes, dst_bytes); } -static bool _raw_copy_to_guest_buf_offset (const struct dmop_args *args, -unsigned int buf_idx, -size_t offset_bytes, -const void *src, -size_t src_bytes) -{ -size_t buf_bytes; - -if ( buf_idx >= args->nr_bufs ) -return false; - - buf_bytes = args->buf[buf_idx].size; - - -if ( (offset_bytes + src_bytes) < offset_bytes || - (offset_bytes + src_bytes) > buf_bytes ) -return false; - -return !copy_to_guest_offset (args->buf[buf_idx].h, offset_bytes, - src, src_bytes); -} -#define COPY_FROM_GUEST_BUF_OFFSET (dst, bufs, buf_idx, offset_bytes) \ _raw_copy_from_guest_buf_offset(&(dst), bufs, buf_idx, offset_bytes, \ sizeof(dst)) -#define COPY_TO_GUEST_BUF_OFFSET (bufs, buf_idx, offset_bytes, src) \ - _raw_copy_to_guest_buf_offset(bufs, buf_idx, offset_bytes, \ - &(src), sizeof(src)) - -#define COPY_FROM_GUEST_BUF (dst, bufs, buf_idx) \ - COPY_FROM_GUEST_BUF_OFFSET(dst, bufs, buf_idx, 0) - -#define COPY_TO_GUEST_BUF (bufs, buf_idx, src) \ - COPY_TO_GUEST_BUF_OFFSET(bufs, buf_idx, 0, src) -static int track_dirty_vram (struct domain *d,xen_pfn_t first_pfn,unsigned int nr,const struct xen_dm_op_buf *buf) {
@@ -372,6 +340,28 @@ static int dm_op(const struct dmop_args *op_args)struct xen_dm_op op;bool const_op = true;long rc; +size_t offset; + +static const uint8_t op_size[] = { + [XEN_DMOP_create_ioreq_server] =sizeof (struct xen_dm_op_create_ioreq_server ), + [XEN_DMOP_get_ioreq_server_info] =sizeof (struct xen_dm_op_get_ioreq_server_info ), + [XEN_DMOP_map_io_range_to_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range ), + [XEN_DMOP_unmap_io_range_from_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range ), + [XEN_DMOP_set_ioreq_server_state] =sizeof (struct xen_dm_op_set_ioreq_server_state ), + [XEN_DMOP_destroy_ioreq_server] =sizeof (struct xen_dm_op_destroy_ioreq_server ), + [XEN_DMOP_track_dirty_vram] =sizeof (struct xen_dm_op_track_dirty_vram ), + [XEN_DMOP_set_pci_intx_level] =sizeof (struct xen_dm_op_set_pci_intx_level ), + [XEN_DMOP_set_isa_irq_level] =sizeof (struct xen_dm_op_set_isa_irq_level ), + [XEN_DMOP_set_pci_link_route] =sizeof (struct xen_dm_op_set_pci_link_route ), + [XEN_DMOP_modified_memory] =sizeof (struct xen_dm_op_modified_memory ), + [XEN_DMOP_set_mem_type] =sizeof (struct xen_dm_op_set_mem_type ), + [XEN_DMOP_inject_event] =sizeof (struct xen_dm_op_inject_event ), + [XEN_DMOP_inject_msi] =sizeof (struct xen_dm_op_inject_msi ), + [XEN_DMOP_map_mem_type_to_ioreq_server] =sizeof (struct xen_dm_op_map_mem_type_to_ioreq_server ), + [XEN_DMOP_remote_shutdown] =sizeof (struct xen_dm_op_remote_shutdown ), + [XEN_DMOP_relocate_memory] =sizeof (struct xen_dm_op_relocate_memory ), + [XEN_DMOP_pin_memory_cacheattr] =sizeof (struct xen_dm_op_pin_memory_cacheattr ), + }; rc =rcu_lock_remote_domain_by_id (op_args->domid, &d);if ( rc )
@@ -384,12 +374,27 @@ static int dm_op(const struct dmop_args *op_args)if ( rc ) goto out; -if ( !COPY_FROM_GUEST_BUF (op, op_args,0 ) ) - { - rc = -EFAULT ; + offset = offsetof(struct xen_dm_op , u); + + rc = -EFAULT ; +if ( op_args->buf[0 ].size < offset ) + goto out; + +if (copy_from_guest_offset ((void *)&op, op_args->buf[0 ].h,0 , offset) ) + goto out; + +if ( op.op >=ARRAY_SIZE (op_size) ) { + rc = -EOPNOTSUPP ; goto out; } +if ( op_args->buf[0 ].size < offset + op_size[op.op] ) + goto out; + +if (copy_from_guest_offset ((void *)&op.u, op_args->buf[0 ].h, offset, + op_size[op.op]) ) + goto out; + rc = -EINVAL ;if ( op.pad ) goto out;
@@ -694,7 +699,8 @@ static int dm_op(const struct dmop_args *op_args) }if ( (!rc || rc == -ERESTART ) && - !const_op && !COPY_TO_GUEST_BUF (op_args,0 , op) ) + !const_op &©_to_guest_offset (op_args->buf[0 ].h, offset, + (void *)&op.u, op_size[op.op]) ) rc = -EFAULT ; out:
Signature · 7 lines
2.9.5 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 21 lines
-----Original Message-----
From: Ross Lagerwall [mailto:[email protected]]
Sent: 09 February 2018 15:34
To: [email protected]
Cc: Ross Lagerwall <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] x86/hvm/dmop: Only copy what is needed to/from the guest
dm_op()fails with-EFAULTif the structxen_dm_opgiven by the guest is smaller than Xen's structxen_dm_op. This is a problem because DMOP is meant to be a stable ABI but it breaks whenever the size of structxen_dm_opchanges.To fix this, change how the copying to and from the guest is done. When copying from the guest, first copy the header and inspect the op. Then, only copy the correct amount needed for that op. When copying to the guest, don't copy the header. Rather, copy only the correct amount needed for that particular op.
Quoted 7 lines
So now the
dm_op()will fail if the guest does not supply enough bytes for the specific op. It will not fail if the guest supplies too many bytes for the specific op, but Xen will not copy the extra bytes.Remove some now unused macros and helper functions.
Signed-off-by Ross Lagerwall <[email protected]>
I'm sure that was how it was supposed to work originally but it got lost somewhere along the way.
Quoted 55 lines
--- xen/arch/x86/hvm/dm.c | 78 +++++++++++++++++++++++++++-------------- ---------- 1 file changed, 42 insertions(+), 36 deletions(-)xen/arch/x86/hvm/dm.c +0
-32@@ -54,42 +54,10 @@ static bool _raw_copy_from_guest_buf_offset(void *dst, offset_bytes, dst_bytes); } -static bool _raw_copy_to_guest_buf_offset (const struct dmop_args *args, -unsigned int buf_idx, -size_t offset_bytes, -const void *src, -size_t src_bytes) -{ -size_t buf_bytes; - -if ( buf_idx >= args->nr_bufs ) -return false; - - buf_bytes = args->buf[buf_idx].size; - - -if ( (offset_bytes + src_bytes) < offset_bytes || - (offset_bytes + src_bytes) > buf_bytes ) -return false; - -return !copy_to_guest_offset (args->buf[buf_idx].h, offset_bytes, - src, src_bytes); -} -#define COPY_FROM_GUEST_BUF_OFFSET (dst, bufs, buf_idx, offset_bytes) \ _raw_copy_from_guest_buf_offset(&(dst), bufs, buf_idx, offset_bytes, \ sizeof(dst)) -#define COPY_TO_GUEST_BUF_OFFSET (bufs, buf_idx, offset_bytes, src) \ - _raw_copy_to_guest_buf_offset(bufs, buf_idx, offset_bytes, \ - &(src), sizeof(src)) - -#define COPY_FROM_GUEST_BUF (dst, bufs, buf_idx) \ - COPY_FROM_GUEST_BUF_OFFSET(dst, bufs, buf_idx, 0) - -#define COPY_TO_GUEST_BUF (bufs, buf_idx, src) \ - COPY_TO_GUEST_BUF_OFFSET(bufs, buf_idx, 0, src) - static int track_dirty_vram(struct domain *d, xen_pfn_t first_pfn,unsigned int nr, const struct
xen_dm_op_buf*buf)
{
xen/arch/x86/hvm/dm.c static int dm_op(const struct dmop_args *op_args) · line 345
Quoted 6 lines
xen/arch/x86/hvm/dm.c +3
-0@@ -372,6 +340,28 @@ static int dm_op(const struct dmop_args *op_args)struct xen_dm_op op;bool const_op = true;long rc; +size_t offset; + +static const uint8_t op_size[] = {
Given the correspondence between the op code name and the struct name, it might be worth using a macro to help with this array declaration.
Paul
Quoted 82 lines
xen/arch/x86/hvm/dm.c +4
-0+ [XEN_DMOP_create_ioreq_server] = sizeof(struct xen_dm_op_create_ioreq_server), + [XEN_DMOP_get_ioreq_server_info] =sizeof (struct xen_dm_op_get_ioreq_server_info), + [XEN_DMOP_map_io_range_to_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range), + [XEN_DMOP_unmap_io_range_from_ioreq_server] = sizeof(struct
xen_dm_op_ioreq_server_range),
+ [XEN_DMOP_set_ioreq_server_state] = sizeof(structxen_dm_op_set_ioreq_server_state),
+ [XEN_DMOP_destroy_ioreq_server] = sizeof(structxen_dm_op_destroy_ioreq_server),
+ [XEN_DMOP_track_dirty_vram] = sizeof(structxen_dm_op_track_dirty_vram),
+ [XEN_DMOP_set_pci_intx_level] = sizeof(structxen_dm_op_set_pci_intx_level),
+ [XEN_DMOP_set_isa_irq_level] = sizeof(structxen_dm_op_set_isa_irq_level),
+ [XEN_DMOP_set_pci_link_route] = sizeof(structxen_dm_op_set_pci_link_route),
+ [XEN_DMOP_modified_memory] = sizeof(structxen_dm_op_modified_memory),
+ [XEN_DMOP_set_mem_type] = sizeof(structxen_dm_op_set_mem_type),
+ [XEN_DMOP_inject_event] = sizeof(structxen_dm_op_inject_event),
+ [XEN_DMOP_inject_msi] = sizeof(structxen_dm_op_inject_msi),
+ [XEN_DMOP_map_mem_type_to_ioreq_server] = sizeof(structxen_dm_op_map_mem_type_to_ioreq_server),
+ [XEN_DMOP_remote_shutdown] = sizeof(structxen_dm_op_remote_shutdown),
+ [XEN_DMOP_relocate_memory] = sizeof(structxen_dm_op_relocate_memory),
+ [XEN_DMOP_pin_memory_cacheattr] = sizeof(structxen_dm_op_pin_memory_cacheattr),xen/arch/x86/hvm/dm.c +21
-5+ }; rc =rcu_lock_remote_domain_by_id (op_args->domid, &d);if ( rc )@@ -384,12 +374,27 @@ static int dm_op(const struct dmop_args *op_args)if ( rc ) goto out; -if ( !COPY_FROM_GUEST_BUF (op, op_args,0 ) ) - { - rc = -EFAULT ; + offset = offsetof(struct xen_dm_op , u); + + rc = -EFAULT ; +if ( op_args->buf[0 ].size < offset ) + goto out; + +if (copy_from_guest_offset ((void *)&op, op_args->buf[0 ].h,0 , offset) ) + goto out; + +if ( op.op >=ARRAY_SIZE (op_size) ) { + rc = -EOPNOTSUPP ; goto out; } +if ( op_args->buf[0 ].size < offset + op_size[op.op] ) + goto out; + +if (copy_from_guest_offset ((void *)&op.u, op_args->buf[0 ].h, offset, + op_size[op.op]) ) + goto out; + rc = -EINVAL ;if ( op.pad ) goto out;@@ -694,7 +699,8 @@ static int dm_op(const struct dmop_args *op_args) }if ( (!rc || rc == -ERESTART ) && - !const_op && !COPY_TO_GUEST_BUF (op_args,0 , op) ) + !const_op &©_to_guest_offset (op_args->buf[0 ].h, offset, + (void *)&op.u, op_size[op.op]) ) rc = -EFAULT ; out: --
Quoted 1 line
2.9.5
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 25 lines · Paul Durrant
Quoted 25 lines
-----Original Message-----
From: Ross Lagerwall [mailto:[email protected]]
Sent: 09 February 2018 15:34
To: [email protected]
Cc: Ross Lagerwall <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] x86/hvm/dmop: Only copy what is needed to/from the guest
dm_op()fails with-EFAULTif the structxen_dm_opgiven by the guest is smaller than Xen's structxen_dm_op. This is a problem because DMOP is meant to be a stable ABI but it breaks whenever the size of structxen_dm_opchanges.To fix this, change how the copying to and from the guest is done. When copying from the guest, first copy the header and inspect the op. Then, only copy the correct amount needed for that op. When copying to the guest, don't copy the header. Rather, copy only the correct amount needed for that particular op.
So now the
dm_op()will fail if the guest does not supply enough bytes for the specific op. It will not fail if the guest supplies too many bytes for the specific op, but Xen will not copy the extra bytes.
Quoted 6 lines
Quoted 3 lines
Remove some now unused macros and helper functions.
Signed-off-by Ross Lagerwall <[email protected]>I'm sure that was how it was supposed to work originally but it got lost somewhere along the way.
This needs backporting to 4.9(?) and later.
Quoted 55 lines
Quoted 55 lines
--- xen/arch/x86/hvm/dm.c | 78 +++++++++++++++++++++++++++-------------- ---------- 1 file changed, 42 insertions(+), 36 deletions(-)xen/arch/x86/hvm/dm.c +0
-32@@ -54,42 +54,10 @@ static bool _raw_copy_from_guest_buf_offset(void *dst, offset_bytes, dst_bytes); } -static bool _raw_copy_to_guest_buf_offset (const struct dmop_args *args, -unsigned int buf_idx, -size_t offset_bytes, -const void *src, -size_t src_bytes) -{ -size_t buf_bytes; - -if ( buf_idx >= args->nr_bufs ) -return false; - - buf_bytes = args->buf[buf_idx].size; - - -if ( (offset_bytes + src_bytes) < offset_bytes || - (offset_bytes + src_bytes) > buf_bytes ) -return false; - -return !copy_to_guest_offset (args->buf[buf_idx].h, offset_bytes, - src, src_bytes); -} -#define COPY_FROM_GUEST_BUF_OFFSET (dst, bufs, buf_idx, offset_bytes) \ _raw_copy_from_guest_buf_offset(&(dst), bufs, buf_idx, offset_bytes, \ sizeof(dst)) -#define COPY_TO_GUEST_BUF_OFFSET (bufs, buf_idx, offset_bytes, src) \ - _raw_copy_to_guest_buf_offset(bufs, buf_idx, offset_bytes, \ - &(src), sizeof(src)) - -#define COPY_FROM_GUEST_BUF (dst, bufs, buf_idx) \ - COPY_FROM_GUEST_BUF_OFFSET(dst, bufs, buf_idx, 0) - -#define COPY_TO_GUEST_BUF (bufs, buf_idx, src) \ - COPY_TO_GUEST_BUF_OFFSET(bufs, buf_idx, 0, src) - static int track_dirty_vram(struct domain *d, xen_pfn_t first_pfn,unsigned int nr, const struct
xen_dm_op_buf*buf)
{
Quoted 8 lines
xen/arch/x86/hvm/dm.c static int dm_op(const struct dmop_args *op_args) · line 345
Quoted 7 lines
xen/arch/x86/hvm/dm.c +3
-0@@ -372,6 +340,28 @@ static int dm_op(const struct dmop_args *op_args)struct xen_dm_op op;bool const_op = true;long rc; +size_t offset; + +static const uint8_t op_size[] = {Given the correspondence between the op code name and the struct name, it might be worth using a macro to help with this array declaration.
They aren't as 1:1 as you'd expect, and mixing&matching macros is going to be far more obscure to read than this.
Quoted 47 lines
Paul
Quoted 44 lines
xen/arch/x86/hvm/dm.c +4
-0+ [XEN_DMOP_create_ioreq_server] = sizeof(struct xen_dm_op_create_ioreq_server), + [XEN_DMOP_get_ioreq_server_info] =sizeof (struct xen_dm_op_get_ioreq_server_info), + [XEN_DMOP_map_io_range_to_ioreq_server] =sizeof (struct xen_dm_op_ioreq_server_range), + [XEN_DMOP_unmap_io_range_from_ioreq_server] = sizeof(struct
xen_dm_op_ioreq_server_range),
+ [XEN_DMOP_set_ioreq_server_state] = sizeof(structxen_dm_op_set_ioreq_server_state),
+ [XEN_DMOP_destroy_ioreq_server] = sizeof(structxen_dm_op_destroy_ioreq_server),
+ [XEN_DMOP_track_dirty_vram] = sizeof(structxen_dm_op_track_dirty_vram),
+ [XEN_DMOP_set_pci_intx_level] = sizeof(structxen_dm_op_set_pci_intx_level),
+ [XEN_DMOP_set_isa_irq_level] = sizeof(structxen_dm_op_set_isa_irq_level),
+ [XEN_DMOP_set_pci_link_route] = sizeof(structxen_dm_op_set_pci_link_route),
+ [XEN_DMOP_modified_memory] = sizeof(structxen_dm_op_modified_memory),
+ [XEN_DMOP_set_mem_type] = sizeof(structxen_dm_op_set_mem_type),
+ [XEN_DMOP_inject_event] = sizeof(structxen_dm_op_inject_event),
+ [XEN_DMOP_inject_msi] = sizeof(structxen_dm_op_inject_msi),
+ [XEN_DMOP_map_mem_type_to_ioreq_server] = sizeof(structxen_dm_op_map_mem_type_to_ioreq_server),
+ [XEN_DMOP_remote_shutdown] = sizeof(structxen_dm_op_remote_shutdown),
+ [XEN_DMOP_relocate_memory] = sizeof(structxen_dm_op_relocate_memory),
+ [XEN_DMOP_pin_memory_cacheattr] = sizeof(structxen_dm_op_pin_memory_cacheattr),xen/arch/x86/hvm/dm.c +1
-0+ }; rc =rcu_lock_remote_domain_by_id (op_args->domid, &d);if ( rc )@@ -384,12 +374,27 @@ static int dm_op(const struct dmop_args *op_args)if ( rc ) goto out;
Quoted 13 lines
xen/arch/x86/hvm/dm.c static int dm_op(const struct dmop_args *op_args) · line 386
Quoted 13 lines
xen/arch/x86/hvm/dm.c +10
-3-if ( !COPY_FROM_GUEST_BUF (op, op_args,0 ) ) - { - rc = -EFAULT ; + offset = offsetof(struct xen_dm_op , u); + + rc = -EFAULT ; +if ( op_args->buf[0 ].size < offset ) + goto out; + +if (copy_from_guest_offset ((void *)&op, op_args->buf[0 ].h,0 , offset) ) + goto out; + +if ( op.op >=ARRAY_SIZE (op_size) ) {
Style, which can be fixed on commit. Otherwise, Acked-by: Andrew Cooper <[email protected]>
Quoted 23 lines
Quoted 23 lines
xen/arch/x86/hvm/dm.c +10
-1+ rc = -EOPNOTSUPP ; goto out; } +if ( op_args->buf[0 ].size < offset + op_size[op.op] ) + goto out; + +if (copy_from_guest_offset ((void *)&op.u, op_args->buf[0 ].h, offset, + op_size[op.op]) ) + goto out; + rc = -EINVAL ;if ( op.pad ) goto out;@@ -694,7 +699,8 @@ static int dm_op(const struct dmop_args *op_args) }if ( (!rc || rc == -ERESTART ) && - !const_op && !COPY_TO_GUEST_BUF (op_args,0 , op) ) + !const_op &©_to_guest_offset (op_args->buf[0 ].h, offset, + (void *)&op.u, op_size[op.op]) ) rc = -EFAULT ;
Quoted 3 lines
Quoted 3 lines
xen/arch/x86/hvm/dm.c +0
-1out: --2.9.5
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 25 lines · Paul Durrant
Quoted 25 lines
-----Original Message-----
From: Ross Lagerwall [mailto:[email protected]]
Sent: 09 February 2018 15:34
To: [email protected]
Cc: Ross Lagerwall <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] x86/hvm/dmop: Only copy what is needed to/from the guest
dm_op()fails with-EFAULTif the structxen_dm_opgiven by the guest is smaller than Xen's structxen_dm_op. This is a problem because DMOP is meant to be a stable ABI but it breaks whenever the size of structxen_dm_opchanges.To fix this, change how the copying to and from the guest is done. When copying from the guest, first copy the header and inspect the op. Then, only copy the correct amount needed for that op. When copying to the guest, don't copy the header. Rather, copy only the correct amount needed for that particular op.
So now the
dm_op()will fail if the guest does not supply enough bytes for the specific op. It will not fail if the guest supplies too many bytes for the specific op, but Xen will not copy the extra bytes.
Quoted 5 lines
Quoted 3 lines
Remove some now unused macros and helper functions.
Signed-off-by Ross Lagerwall <[email protected]>I'm sure that was how it was supposed to work originally but it got lost somewhere along the way.
Originally it zeroed struct xen_dm_op and then copied whatever the guest provided (up to the size of struct xen_dm_op) which is similar to this but not quite the same.
Quoted 17 lines
Quoted 14 lines
--- xen/arch/x86/hvm/dm.c | 78 +++++++++++++++++++++++++++-------------- ---------- 1 file changed, 42 insertions(+), 36 deletions(-)xen/arch/x86/hvm/dm.c +0
-0@@ -54,42 +54,10 @@ static bool _raw_copy_from_guest_buf_offset(void *dst, offset_bytes, dst_bytes); }
snip
Quoted 9 lines
xen/arch/x86/hvm/dm.c static int dm_op(const struct dmop_args *op_args) · line 345
Quoted 7 lines
xen/arch/x86/hvm/dm.c +3
-0@@ -372,6 +340,28 @@ static int dm_op(const struct dmop_args *op_args)struct xen_dm_op op;bool const_op = true;long rc; +size_t offset; + +static const uint8_t op_size[] = {Given the correspondence between the op code name and the struct name, it might be worth using a macro to help with this array declaration.
Probably... there are a couple of exceptions to the correspondence though.
Signature · 6 lines
Ross Lagerwall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 77 lines
-----Original Message-----
From: Ross Lagerwall [mailto:[email protected]]
Sent: 09 February 2018 15:49
To: Paul Durrant <[email protected]>; [email protected]
Cc: Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>
Subject: Re: [PATCH] x86/hvm/dmop: Only copy what is needed to/from the guestQuoted 6 lines · Paul Durrant
Quoted 6 lines
-----Original Message-----
From: Ross Lagerwall [mailto:[email protected]]
Sent: 09 February 2018 15:34
To: [email protected]
Cc: Ross Lagerwall <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>;Paul
Quoted 19 lines
Quoted 19 lines
Durrant <[email protected]>
Subject: [PATCH] x86/hvm/dmop: Only copy what is needed to/from the guest
dm_op()fails with-EFAULTif the structxen_dm_opgiven by the guest is smaller than Xen's structxen_dm_op. This is a problem because DMOP is meant to be a stable ABI but it breaks whenever the size of structxen_dm_opchanges.To fix this, change how the copying to and from the guest is done. When copying from the guest, first copy the header and inspect the op. Then, only copy the correct amount needed for that op. When copying to the guest, don't copy the header. Rather, copy only the correct amount needed for that particular op.
So now the
dm_op()will fail if the guest does not supply enough bytes for the specific op. It will not fail if the guest supplies too many bytes for the specific op, but Xen will not copy the extra bytes.Quoted 5 lines
Quoted 3 lines
Remove some now unused macros and helper functions.
Signed-off-by Ross Lagerwall <[email protected]>I'm sure that was how it was supposed to work originally but it got lost
somewhere along the way.
Originally it zeroed struct
xen_dm_opand then copied whatever the guest provided (up to the size of structxen_dm_op) which is similar to this but not quite the same.Quoted 2 lines
Reviewed-by Paul Durrant <[email protected]>, with onesuggestion...
Quoted 3 lines
Quoted 3 lines
--- xen/arch/x86/hvm/dm.c | 78 +++++++++++++++++++++++++++--------------
Quoted 8 lines
xen/arch/x86/hvm/dm.c static bool
Quoted 8 lines
----------
1 file changed, 42 insertions(+), 36 deletions(-)xen/arch/x86/hvm/dm.c +0
-0@@ -54,42 +54,10 @@ static bool_raw_copy_from_guest_buf_offset(void
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/hvm/dm.c +0
-0*dst, offset_bytes, dst_bytes); }snip
Quoted 1 line
xen/arch/x86/hvm/dm.c static int dm_op(const struct dmop_args
Quoted 1 line
xen/arch/x86/hvm/dm.c +0
-0@@ -372,6 +340,28 @@ static int dm_op(const struct dmop_args
*op_args)Quoted 7 lines
Quoted 6 lines
xen/arch/x86/hvm/dm.c +3
-0struct xen_dm_op op;bool const_op = true;long rc; +size_t offset; + +static const uint8_t op_size[] = {
Quoted 4 lines
Quoted 1 line
Given the correspondence between the op code name and the struct
name, it might be worth using a macro to help with this array declaration.
Probably... there are a couple of exceptions to the correspondence though.
Yeah, I know. Just thought it might look neater overall, but doesn't matter.
Paul
Quoted 2 lines
--
Ross Lagerwall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel