* [PATCH] libxc: Pause & unpause the domain in xc_mem_event_enable based on its initial state.
@ 2014-06-30 13:45 Tamas K Lengyel
2014-06-30 14:21 ` Andrew Cooper
0 siblings, 1 reply; 8+ messages in thread
From: Tamas K Lengyel @ 2014-06-30 13:45 UTC (permalink / raw)
To: xen-devel; +Cc: Tamas K Lengyel, ian.jackson, ian.campbell, stefano.stabellini
In an attempt to mitigate XSA-99, xc_mem_event_enable ensures that the domain is paused
for the duration of the event ring setup. However, it disregards the initial state of
the domain, which might already be paused, resulting in 1) an uneccessary hypercall to
pause it again and 2) unpauses it unconditionally which is an opaque and potentially
unwanted side-effect. This patch fixes both issues.
Signed-off-by: Tamas K Lengyel <tamas.k.lengyel@tum.de>
---
tools/libxc/xc_mem_event.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/tools/libxc/xc_mem_event.c b/tools/libxc/xc_mem_event.c
index 0b2eecb..5cf74d0 100644
--- a/tools/libxc/xc_mem_event.c
+++ b/tools/libxc/xc_mem_event.c
@@ -62,6 +62,7 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
void *ring_page = NULL;
unsigned long pfn;
xen_pfn_t ring_pfn, mmap_pfn;
+ xc_domaininfo_t dom_info;
unsigned int op, mode;
int rc1, rc2, saved_errno;
@@ -71,14 +72,24 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
return NULL;
}
- /* Pause the domain for ring page setup */
- rc1 = xc_domain_pause(xch, domain_id);
- if ( rc1 != 0 )
+ rc1 = xc_domain_getinfolist(xch, domain_id, 1, &dom_info);
+ if ( rc1 != 1 || dom_info.domain != domain_id )
{
- PERROR("Unable to pause domain\n");
+ PERROR("Error getting domain info\n");
return NULL;
}
+ /* Pause the domain for ring page setup if it isn't already */
+ if( !(dom_info.flags & XEN_DOMINF_paused) )
+ {
+ rc1 = xc_domain_pause(xch, domain_id);
+ if ( rc1 != 0 )
+ {
+ PERROR("Unable to pause domain\n");
+ return NULL;
+ }
+ }
+
/* Get the pfn of the ring page */
rc1 = xc_get_hvm_param(xch, domain_id, param, &pfn);
if ( rc1 != 0 )
@@ -154,7 +165,16 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
out:
saved_errno = errno;
- rc2 = xc_domain_unpause(xch, domain_id);
+ /* Only unpause the domain if it was running originally */
+ if( !(dom_info.flags & XEN_DOMINF_paused) )
+ {
+ rc2 = xc_domain_unpause(xch, domain_id);
+ }
+ else
+ {
+ rc2 = 0;
+ }
+
if ( rc1 != 0 || rc2 != 0 )
{
if ( rc2 != 0 )
--
2.0.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] libxc: Pause & unpause the domain in xc_mem_event_enable based on its initial state.
2014-06-30 13:45 [PATCH] libxc: Pause & unpause the domain in xc_mem_event_enable based on its initial state Tamas K Lengyel
@ 2014-06-30 14:21 ` Andrew Cooper
2014-06-30 14:33 ` Tamas K Lengyel
0 siblings, 1 reply; 8+ messages in thread
From: Andrew Cooper @ 2014-06-30 14:21 UTC (permalink / raw)
To: Tamas K Lengyel, xen-devel
Cc: Tamas K Lengyel, ian.jackson, ian.campbell, stefano.stabellini
On 30/06/14 14:45, Tamas K Lengyel wrote:
> In an attempt to mitigate XSA-99, xc_mem_event_enable ensures that the domain is paused
> for the duration of the event ring setup. However, it disregards the initial state of
> the domain, which might already be paused, resulting in 1) an uneccessary hypercall to
> pause it again and 2) unpauses it unconditionally which is an opaque and potentially
> unwanted side-effect. This patch fixes both issues.
>
> Signed-off-by: Tamas K Lengyel <tamas.k.lengyel@tum.de>
> ---
> tools/libxc/xc_mem_event.c | 30 +++++++++++++++++++++++++-----
> 1 file changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/tools/libxc/xc_mem_event.c b/tools/libxc/xc_mem_event.c
> index 0b2eecb..5cf74d0 100644
> --- a/tools/libxc/xc_mem_event.c
> +++ b/tools/libxc/xc_mem_event.c
> @@ -62,6 +62,7 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
> void *ring_page = NULL;
> unsigned long pfn;
> xen_pfn_t ring_pfn, mmap_pfn;
> + xc_domaininfo_t dom_info;
> unsigned int op, mode;
> int rc1, rc2, saved_errno;
>
> @@ -71,14 +72,24 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
> return NULL;
> }
>
> - /* Pause the domain for ring page setup */
> - rc1 = xc_domain_pause(xch, domain_id);
> - if ( rc1 != 0 )
> + rc1 = xc_domain_getinfolist(xch, domain_id, 1, &dom_info);
> + if ( rc1 != 1 || dom_info.domain != domain_id )
> {
> - PERROR("Unable to pause domain\n");
> + PERROR("Error getting domain info\n");
> return NULL;
> }
>
> + /* Pause the domain for ring page setup if it isn't already */
> + if( !(dom_info.flags & XEN_DOMINF_paused) )
> + {
> + rc1 = xc_domain_pause(xch, domain_id);
> + if ( rc1 != 0 )
> + {
> + PERROR("Unable to pause domain\n");
> + return NULL;
> + }
> + }
As indicated in the other thread regarding the correctness of properly
refcounting in Xen, this is a TOCTOU race which doesn't fix the problem
in the general case.
It is my opinion that this is impossible to correctly fix in the dom0
userspace.
~Andrew
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] libxc: Pause & unpause the domain in xc_mem_event_enable based on its initial state.
2014-06-30 14:21 ` Andrew Cooper
@ 2014-06-30 14:33 ` Tamas K Lengyel
2014-06-30 14:40 ` Andrew Cooper
0 siblings, 1 reply; 8+ messages in thread
From: Tamas K Lengyel @ 2014-06-30 14:33 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel, ian.jackson, Ian Campbell, stefano.stabellini
[-- Attachment #1.1: Type: text/plain, Size: 2589 bytes --]
On Mon, Jun 30, 2014 at 4:21 PM, Andrew Cooper <andrew.cooper3@citrix.com>
wrote:
> On 30/06/14 14:45, Tamas K Lengyel wrote:
> > In an attempt to mitigate XSA-99, xc_mem_event_enable ensures that the
> domain is paused
> > for the duration of the event ring setup. However, it disregards the
> initial state of
> > the domain, which might already be paused, resulting in 1) an
> uneccessary hypercall to
> > pause it again and 2) unpauses it unconditionally which is an opaque and
> potentially
> > unwanted side-effect. This patch fixes both issues.
> >
> > Signed-off-by: Tamas K Lengyel <tamas.k.lengyel@tum.de>
> > ---
> > tools/libxc/xc_mem_event.c | 30 +++++++++++++++++++++++++-----
> > 1 file changed, 25 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/libxc/xc_mem_event.c b/tools/libxc/xc_mem_event.c
> > index 0b2eecb..5cf74d0 100644
> > --- a/tools/libxc/xc_mem_event.c
> > +++ b/tools/libxc/xc_mem_event.c
> > @@ -62,6 +62,7 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t
> domain_id, int param,
> > void *ring_page = NULL;
> > unsigned long pfn;
> > xen_pfn_t ring_pfn, mmap_pfn;
> > + xc_domaininfo_t dom_info;
> > unsigned int op, mode;
> > int rc1, rc2, saved_errno;
> >
> > @@ -71,14 +72,24 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t
> domain_id, int param,
> > return NULL;
> > }
> >
> > - /* Pause the domain for ring page setup */
> > - rc1 = xc_domain_pause(xch, domain_id);
> > - if ( rc1 != 0 )
> > + rc1 = xc_domain_getinfolist(xch, domain_id, 1, &dom_info);
> > + if ( rc1 != 1 || dom_info.domain != domain_id )
> > {
> > - PERROR("Unable to pause domain\n");
> > + PERROR("Error getting domain info\n");
> > return NULL;
> > }
> >
> > + /* Pause the domain for ring page setup if it isn't already */
> > + if( !(dom_info.flags & XEN_DOMINF_paused) )
> > + {
> > + rc1 = xc_domain_pause(xch, domain_id);
> > + if ( rc1 != 0 )
> > + {
> > + PERROR("Unable to pause domain\n");
> > + return NULL;
> > + }
> > + }
>
> As indicated in the other thread regarding the correctness of properly
> refcounting in Xen, this is a TOCTOU race which doesn't fix the problem
> in the general case.
>
> It is my opinion that this is impossible to correctly fix in the dom0
> userspace.
>
> ~Andrew
>
Indeed, if there are multiple user-space tools trying to control the
domain, this patch doesn't ensure safety. That issue is however beyond the
scope of what this patch is trying to address.
[-- Attachment #1.2: Type: text/html, Size: 3524 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] libxc: Pause & unpause the domain in xc_mem_event_enable based on its initial state.
2014-06-30 14:33 ` Tamas K Lengyel
@ 2014-06-30 14:40 ` Andrew Cooper
2014-06-30 14:46 ` Tamas K Lengyel
0 siblings, 1 reply; 8+ messages in thread
From: Andrew Cooper @ 2014-06-30 14:40 UTC (permalink / raw)
To: Tamas K Lengyel; +Cc: xen-devel, ian.jackson, Ian Campbell, stefano.stabellini
[-- Attachment #1.1: Type: text/plain, Size: 3080 bytes --]
On 30/06/14 15:33, Tamas K Lengyel wrote:
> On Mon, Jun 30, 2014 at 4:21 PM, Andrew Cooper
> <andrew.cooper3@citrix.com <mailto:andrew.cooper3@citrix.com>> wrote:
>
> On 30/06/14 14:45, Tamas K Lengyel wrote:
> > In an attempt to mitigate XSA-99, xc_mem_event_enable ensures
> that the domain is paused
> > for the duration of the event ring setup. However, it disregards
> the initial state of
> > the domain, which might already be paused, resulting in 1) an
> uneccessary hypercall to
> > pause it again and 2) unpauses it unconditionally which is an
> opaque and potentially
> > unwanted side-effect. This patch fixes both issues.
> >
> > Signed-off-by: Tamas K Lengyel <tamas.k.lengyel@tum.de
> <mailto:tamas.k.lengyel@tum.de>>
> > ---
> > tools/libxc/xc_mem_event.c | 30 +++++++++++++++++++++++++-----
> > 1 file changed, 25 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/libxc/xc_mem_event.c b/tools/libxc/xc_mem_event.c
> > index 0b2eecb..5cf74d0 100644
> > --- a/tools/libxc/xc_mem_event.c
> > +++ b/tools/libxc/xc_mem_event.c
> > @@ -62,6 +62,7 @@ void *xc_mem_event_enable(xc_interface *xch,
> domid_t domain_id, int param,
> > void *ring_page = NULL;
> > unsigned long pfn;
> > xen_pfn_t ring_pfn, mmap_pfn;
> > + xc_domaininfo_t dom_info;
> > unsigned int op, mode;
> > int rc1, rc2, saved_errno;
> >
> > @@ -71,14 +72,24 @@ void *xc_mem_event_enable(xc_interface *xch,
> domid_t domain_id, int param,
> > return NULL;
> > }
> >
> > - /* Pause the domain for ring page setup */
> > - rc1 = xc_domain_pause(xch, domain_id);
> > - if ( rc1 != 0 )
> > + rc1 = xc_domain_getinfolist(xch, domain_id, 1, &dom_info);
> > + if ( rc1 != 1 || dom_info.domain != domain_id )
> > {
> > - PERROR("Unable to pause domain\n");
> > + PERROR("Error getting domain info\n");
> > return NULL;
> > }
> >
> > + /* Pause the domain for ring page setup if it isn't already */
> > + if( !(dom_info.flags & XEN_DOMINF_paused) )
> > + {
> > + rc1 = xc_domain_pause(xch, domain_id);
> > + if ( rc1 != 0 )
> > + {
> > + PERROR("Unable to pause domain\n");
> > + return NULL;
> > + }
> > + }
>
> As indicated in the other thread regarding the correctness of properly
> refcounting in Xen, this is a TOCTOU race which doesn't fix the
> problem
> in the general case.
>
> It is my opinion that this is impossible to correctly fix in the dom0
> userspace.
>
> ~Andrew
>
>
> Indeed, if there are multiple user-space tools trying to control the
> domain, this patch doesn't ensure safety. That issue is however beyond
> the scope of what this patch is trying to address.
This patch doesn't even assure safety for two threads in the same
process dealing with the same domain.
~Andrew
[-- Attachment #1.2: Type: text/html, Size: 5752 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] libxc: Pause & unpause the domain in xc_mem_event_enable based on its initial state.
2014-06-30 14:40 ` Andrew Cooper
@ 2014-06-30 14:46 ` Tamas K Lengyel
[not found] ` <CAGU+auv8ESpyu2QaE=_kO2AxuNrkn0AdyDzr2QOv5A01V3SEEA@mail.gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Tamas K Lengyel @ 2014-06-30 14:46 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel, ian.jackson, Ian Campbell, stefano.stabellini
[-- Attachment #1.1: Type: text/plain, Size: 3457 bytes --]
On Mon, Jun 30, 2014 at 4:40 PM, Andrew Cooper <andrew.cooper3@citrix.com>
wrote:
> On 30/06/14 15:33, Tamas K Lengyel wrote:
>
> On Mon, Jun 30, 2014 at 4:21 PM, Andrew Cooper <andrew.cooper3@citrix.com
> > wrote:
>
>> On 30/06/14 14:45, Tamas K Lengyel wrote:
>> > In an attempt to mitigate XSA-99, xc_mem_event_enable ensures that the
>> domain is paused
>> > for the duration of the event ring setup. However, it disregards the
>> initial state of
>> > the domain, which might already be paused, resulting in 1) an
>> uneccessary hypercall to
>> > pause it again and 2) unpauses it unconditionally which is an opaque
>> and potentially
>> > unwanted side-effect. This patch fixes both issues.
>> >
>> > Signed-off-by: Tamas K Lengyel <tamas.k.lengyel@tum.de>
>> > ---
>> > tools/libxc/xc_mem_event.c | 30 +++++++++++++++++++++++++-----
>> > 1 file changed, 25 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/tools/libxc/xc_mem_event.c b/tools/libxc/xc_mem_event.c
>> > index 0b2eecb..5cf74d0 100644
>> > --- a/tools/libxc/xc_mem_event.c
>> > +++ b/tools/libxc/xc_mem_event.c
>> > @@ -62,6 +62,7 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t
>> domain_id, int param,
>> > void *ring_page = NULL;
>> > unsigned long pfn;
>> > xen_pfn_t ring_pfn, mmap_pfn;
>> > + xc_domaininfo_t dom_info;
>> > unsigned int op, mode;
>> > int rc1, rc2, saved_errno;
>> >
>> > @@ -71,14 +72,24 @@ void *xc_mem_event_enable(xc_interface *xch,
>> domid_t domain_id, int param,
>> > return NULL;
>> > }
>> >
>> > - /* Pause the domain for ring page setup */
>> > - rc1 = xc_domain_pause(xch, domain_id);
>> > - if ( rc1 != 0 )
>> > + rc1 = xc_domain_getinfolist(xch, domain_id, 1, &dom_info);
>> > + if ( rc1 != 1 || dom_info.domain != domain_id )
>> > {
>> > - PERROR("Unable to pause domain\n");
>> > + PERROR("Error getting domain info\n");
>> > return NULL;
>> > }
>> >
>> > + /* Pause the domain for ring page setup if it isn't already */
>> > + if( !(dom_info.flags & XEN_DOMINF_paused) )
>> > + {
>> > + rc1 = xc_domain_pause(xch, domain_id);
>> > + if ( rc1 != 0 )
>> > + {
>> > + PERROR("Unable to pause domain\n");
>> > + return NULL;
>> > + }
>> > + }
>>
>> As indicated in the other thread regarding the correctness of properly
>> refcounting in Xen, this is a TOCTOU race which doesn't fix the problem
>> in the general case.
>>
>> It is my opinion that this is impossible to correctly fix in the dom0
>> userspace.
>>
>> ~Andrew
>>
>
> Indeed, if there are multiple user-space tools trying to control the
> domain, this patch doesn't ensure safety. That issue is however beyond the
> scope of what this patch is trying to address.
>
>
> This patch doesn't even assure safety for two threads in the same process
> dealing with the same domain.
>
> ~Andrew
>
Again, I agree, but that is not the problem this patch is trying to
address. The problem you are talking about is present xc_mem_event_enable
as it is right now as well. For example, nothing prevents another
thread/process from unpausing the domain while the event ring setup is in
process. This patch operates with the same assumption the current code
makes: only one user-space tool/thread is controlling the domain at a time.
This patch just ensures the domain is left in the same state it was before
the function was called.
[-- Attachment #1.2: Type: text/html, Size: 6525 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-07-01 16:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-30 13:45 [PATCH] libxc: Pause & unpause the domain in xc_mem_event_enable based on its initial state Tamas K Lengyel
2014-06-30 14:21 ` Andrew Cooper
2014-06-30 14:33 ` Tamas K Lengyel
2014-06-30 14:40 ` Andrew Cooper
2014-06-30 14:46 ` Tamas K Lengyel
[not found] ` <CAGU+auv8ESpyu2QaE=_kO2AxuNrkn0AdyDzr2QOv5A01V3SEEA@mail.gmail.com>
2014-06-30 22:54 ` Aravindh Puthiyaparambil (aravindp)
2014-07-01 8:02 ` Jan Beulich
2014-07-01 16:35 ` Aravindh Puthiyaparambil (aravindp)
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.