* [PATCH] tools/libxencall: enforce proper alignment of hypercall buffers
@ 2018-06-08 9:51 Juergen Gross
2018-06-08 10:09 ` Andrew Cooper
0 siblings, 1 reply; 5+ messages in thread
From: Juergen Gross @ 2018-06-08 9:51 UTC (permalink / raw)
To: xen-devel; +Cc: Juergen Gross, wei.liu2, ian.jackson
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 <jgross@suse.com>
---
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(+)
diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c
index 2d8fc29ac6..0b6af2db60 100644
--- a/tools/libs/call/buffer.c
+++ b/tools/libs/call/buffer.c
@@ -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)
--
2.13.7
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] tools/libxencall: enforce proper alignment of hypercall buffers
2018-06-08 9:51 [PATCH] tools/libxencall: enforce proper alignment of hypercall buffers Juergen Gross
@ 2018-06-08 10:09 ` Andrew Cooper
2018-06-08 10:25 ` Juergen Gross
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cooper @ 2018-06-08 10:09 UTC (permalink / raw)
To: Juergen Gross, xen-devel; +Cc: ian.jackson, wei.liu2
On 08/06/18 10:51, Juergen Gross wrote:
> 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 <jgross@suse.com>
> ---
> 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(+)
>
> diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c
> index 2d8fc29ac6..0b6af2db60 100644
> --- a/tools/libs/call/buffer.c
> +++ b/tools/libs/call/buffer.c
> @@ -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.)
> + 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
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tools/libxencall: enforce proper alignment of hypercall buffers
2018-06-08 10:09 ` Andrew Cooper
@ 2018-06-08 10:25 ` Juergen Gross
2018-07-10 13:25 ` Juergen Gross
0 siblings, 1 reply; 5+ messages in thread
From: Juergen Gross @ 2018-06-08 10:25 UTC (permalink / raw)
To: Andrew Cooper, xen-devel; +Cc: wei.liu2, ian.jackson
On 08/06/18 12:09, Andrew Cooper wrote:
> On 08/06/18 10:51, Juergen Gross wrote:
>> 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 <jgross@suse.com>
>> ---
>> 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(+)
>>
>> diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c
>> index 2d8fc29ac6..0b6af2db60 100644
>> --- a/tools/libs/call/buffer.c
>> +++ b/tools/libs/call/buffer.c
>> @@ -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.)
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...
>
>> + 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().
> 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
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tools/libxencall: enforce proper alignment of hypercall buffers
2018-06-08 10:25 ` Juergen Gross
@ 2018-07-10 13:25 ` Juergen Gross
2018-07-10 15:02 ` Wei Liu
0 siblings, 1 reply; 5+ messages in thread
From: Juergen Gross @ 2018-07-10 13:25 UTC (permalink / raw)
To: Andrew Cooper, xen-devel; +Cc: ian.jackson, wei.liu2
On 08/06/18 12:25, Juergen Gross wrote:
> On 08/06/18 12:09, Andrew Cooper wrote:
>> On 08/06/18 10:51, Juergen Gross wrote:
>>> 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 <jgross@suse.com>
>>> ---
>>> 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(+)
>>>
>>> diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c
>>> index 2d8fc29ac6..0b6af2db60 100644
>>> --- a/tools/libs/call/buffer.c
>>> +++ b/tools/libs/call/buffer.c
>>> @@ -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.)
>
> 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...
>
>>
>>> + 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().
>
>> 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
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tools/libxencall: enforce proper alignment of hypercall buffers
2018-07-10 13:25 ` Juergen Gross
@ 2018-07-10 15:02 ` Wei Liu
0 siblings, 0 replies; 5+ messages in thread
From: Wei Liu @ 2018-07-10 15:02 UTC (permalink / raw)
To: Juergen Gross; +Cc: Andrew Cooper, wei.liu2, ian.jackson, xen-devel
On Tue, Jul 10, 2018 at 03:25:07PM +0200, Juergen Gross wrote:
> On 08/06/18 12:25, Juergen Gross wrote:
> > On 08/06/18 12:09, Andrew Cooper wrote:
> >> On 08/06/18 10:51, Juergen Gross wrote:
> >>> 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 <jgross@suse.com>
> >>> ---
> >>> 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(+)
> >>>
> >>> diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c
> >>> index 2d8fc29ac6..0b6af2db60 100644
> >>> --- a/tools/libs/call/buffer.c
> >>> +++ b/tools/libs/call/buffer.c
> >>> @@ -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.)
> >
> > 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...
> >
> >>
> >>> + 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().
> >
> >> 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
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-07-10 15:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-08 9:51 [PATCH] tools/libxencall: enforce proper alignment of hypercall buffers Juergen Gross
2018-06-08 10:09 ` Andrew Cooper
2018-06-08 10:25 ` Juergen Gross
2018-07-10 13:25 ` Juergen Gross
2018-07-10 15:02 ` Wei Liu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.