tools/libxencall: enforce proper alignment of hypercall buffers
PATCH 1/1 tools/libxencall: enforce proper alignment of hypercall buffers
xencall_alloc_buffer() is used throughout Xen tools for allocating hypercall buffers. Allocation is done at page granularity. For simple administration each allocated set of pages contains a small header holding the number of pages of that set. The hypercall buffer is located directly after the 4 byte sized header, leading to a wrong alignment for e.g. pointers.
Repair that by using a 16 byte sized header enforcing the same alignment as malloc().
---
Not sure whether this wants to be backported. In case the answer is "yes" I think it should be part of 4.11.
--- tools/libs/call/buffer.c | 1 + 1 file changed, 1 insertion(+)
tools/libs/call/buffer.c +1 -0
@@ -151,6 +151,7 @@ void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages)struct allocation_header {int nr_pages; +int pad[3 ]; };void *xencall_alloc_buffer (xencall_handle *xcall,size_t size)
Signature · 7 lines
2.13.7 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 23 lines · Juergen Gross
xencall_alloc_buffer()is used throughout Xen tools for allocating hypercall buffers. Allocation is done at page granularity. For simple administration each allocated set of pages contains a small header holding the number of pages of that set. The hypercall buffer is located directly after the 4 byte sized header, leading to a wrong alignment for e.g. pointers.Repair that by using a 16 byte sized header enforcing the same alignment as
malloc().Signed-off-by Juergen Gross <[email protected]>---
Not sure whether this wants to be backported. In case the answer is "yes" I think it should be part of 4.11.--- tools/libs/call/buffer.c | 1 + 1 file changed, 1 insertion(+)tools/libs/call/buffer.c +0
-0
tools/libs/call/buffer.c void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages) · line 153
Quoted 3 lines
tools/libs/call/buffer.c +0
-0@@ -151,6 +151,7 @@ void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages)struct allocation_header {int nr_pages;
This hunk reveals another bug...
There are a rather large number of size_t => int truncations in the code, which is surely going to catch people by surprise. (Again - I was certain I commented on this during the original review of this library.)
tools/libs/call/buffer.c void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages) · line 154
Quoted 1 line
tools/libs/call/buffer.c +1
-0+int pad[3 ];
This brings it to 16 byte alignment, but is that enough? An xsave state block in x86 for example has 64 byte alignment. I suppose we mostly care about ARM here, as its memcpy() will be most impacted by this misalignment.
Irrespective, might be easier to accomplish with an __attribute__((__aligned__($N))) rather than explicit padding?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 25 lines · Andrew Cooper
Quoted 24 lines · Juergen Gross
xencall_alloc_buffer()is used throughout Xen tools for allocating hypercall buffers. Allocation is done at page granularity. For simple administration each allocated set of pages contains a small header holding the number of pages of that set. The hypercall buffer is located directly after the 4 byte sized header, leading to a wrong alignment for e.g. pointers.Repair that by using a 16 byte sized header enforcing the same alignment as
malloc().Signed-off-by Juergen Gross <[email protected]>---
Not sure whether this wants to be backported. In case the answer is "yes" I think it should be part of 4.11.--- tools/libs/call/buffer.c | 1 + 1 file changed, 1 insertion(+)tools/libs/call/buffer.c +0
-0@@ -151,6 +151,7 @@ void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages)
Quoted 8 lines
tools/libs/call/buffer.c void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages) · line 153
Quoted 2 lines
tools/libs/call/buffer.c +0
-0struct allocation_header {int nr_pages;This hunk reveals another bug...
There are a rather large number of
size_t=> int truncations in the code, which is surely going to catch people by surprise. (Again - I was certain I commented on this during the original review of this library.)
On the practical side I don't think this really matters here. Passing more than 2GB as a hypercall buffer is nothing we want to support...
Quoted 7 lines
tools/libs/call/buffer.c void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages) · line 154
Quoted 2 lines
tools/libs/call/buffer.c +1
-0+int pad[3 ];This brings it to 16 byte alignment, but is that enough? An xsave state block in x86 for example has 64 byte alignment. I suppose we mostly care about ARM here, as its
memcpy()will be most impacted by this misalignment.
Special purpose buffers can still be directly allocated via xencall_alloc_buffer_pages(). I don't think we'll need alignment better than malloc().
Quoted 2 lines
Irrespective, might be easier to accomplish with an __attribute__((__aligned__($N))) rather than explicit padding?
I don't mind which way to go here. I'll leave the decision for the maintainers. :-)
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 50 lines · Juergen Gross
Quoted 25 lines · Andrew Cooper
Quoted 24 lines · Juergen Gross
xencall_alloc_buffer()is used throughout Xen tools for allocating hypercall buffers. Allocation is done at page granularity. For simple administration each allocated set of pages contains a small header holding the number of pages of that set. The hypercall buffer is located directly after the 4 byte sized header, leading to a wrong alignment for e.g. pointers.Repair that by using a 16 byte sized header enforcing the same alignment as
malloc().Signed-off-by Juergen Gross <[email protected]>---
Not sure whether this wants to be backported. In case the answer is "yes" I think it should be part of 4.11.--- tools/libs/call/buffer.c | 1 + 1 file changed, 1 insertion(+)tools/libs/call/buffer.c +0
-0@@ -151,6 +151,7 @@ void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages)Quoted 8 lines
tools/libs/call/buffer.c void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages) · line 153
Quoted 2 lines
tools/libs/call/buffer.c +0
-0struct allocation_header {int nr_pages;This hunk reveals another bug...
There are a rather large number of
size_t=> int truncations in the code, which is surely going to catch people by surprise. (Again - I was certain I commented on this during the original review of this library.)On the practical side I don't think this really matters here. Passing more than 2GB as a hypercall buffer is nothing we want to support...
Quoted 7 lines
tools/libs/call/buffer.c void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages) · line 154
Quoted 2 lines
tools/libs/call/buffer.c +1
-0+int pad[3 ];This brings it to 16 byte alignment, but is that enough? An xsave state block in x86 for example has 64 byte alignment. I suppose we mostly care about ARM here, as its
memcpy()will be most impacted by this misalignment.Special purpose buffers can still be directly allocated via
xencall_alloc_buffer_pages(). I don't think we'll need alignment better thanmalloc().
Quoted 5 lines
Quoted 2 lines
Irrespective, might be easier to accomplish with an __attribute__((__aligned__($N))) rather than explicit padding?
I don't mind which way to go here. I'll leave the decision for the maintainers. :-)
Ping?
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 51 lines · Juergen Gross
Quoted 50 lines · Juergen Gross
Quoted 25 lines · Andrew Cooper
Quoted 24 lines · Juergen Gross
xencall_alloc_buffer()is used throughout Xen tools for allocating hypercall buffers. Allocation is done at page granularity. For simple administration each allocated set of pages contains a small header holding the number of pages of that set. The hypercall buffer is located directly after the 4 byte sized header, leading to a wrong alignment for e.g. pointers.Repair that by using a 16 byte sized header enforcing the same alignment as
malloc().Signed-off-by Juergen Gross <[email protected]>---
Not sure whether this wants to be backported. In case the answer is "yes" I think it should be part of 4.11.--- tools/libs/call/buffer.c | 1 + 1 file changed, 1 insertion(+)tools/libs/call/buffer.c +0
-0@@ -151,6 +151,7 @@ void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages)Quoted 8 lines
tools/libs/call/buffer.c void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages) · line 153
Quoted 2 lines
tools/libs/call/buffer.c +0
-0struct allocation_header {int nr_pages;This hunk reveals another bug...
There are a rather large number of
size_t=> int truncations in the code, which is surely going to catch people by surprise. (Again - I was certain I commented on this during the original review of this library.)On the practical side I don't think this really matters here. Passing more than 2GB as a hypercall buffer is nothing we want to support...
Quoted 7 lines
tools/libs/call/buffer.c void xencall_free_buffer_pages(xencall_handle *xcall, void *p, size_t nr_pages) · line 154
Quoted 2 lines
tools/libs/call/buffer.c +1
-0+int pad[3 ];This brings it to 16 byte alignment, but is that enough? An xsave state block in x86 for example has 64 byte alignment. I suppose we mostly care about ARM here, as its
memcpy()will be most impacted by this misalignment.Special purpose buffers can still be directly allocated via
xencall_alloc_buffer_pages(). I don't think we'll need alignment better thanmalloc().
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Irrespective, might be easier to accomplish with an __attribute__((__aligned__($N))) rather than explicit padding?
I don't mind which way to go here. I'll leave the decision for the maintainers. :-)
Ping?
Either is fine. I will apply this patch as-is.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel