Skip to contentSkip to conversation

Prevent xl save from segfaulting when control/shutdown key is removed

PATCH In review Paul Durrant 3 participants 9 messages Nov 23, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Prevent xl save from segfaulting when control/shutdown key is removed

# HG changeset patch
# User Paul Durrant <[email protected]>
# Date 1322041530 0
# Node ID 3341e3e990568f459ae984cd9d2cac2d546eaa4e
# Parent 0a0c02a616768bfab16c072788cb76be1893c37f
Prevent xl save from segfaulting when control/shutdown key is removed

To acknowledge the tools' setting of control/shutdown it is normal for PV drivers to rm the key. This leads to libxl__xs_read() returning NULL and thus a subsequent strcmp on the return value will cause a segfault.

tools/libxl/libxl_dom.c +2 -0
diff -r 0a0c02a61676 -r 3341e3e99056 tools/libxl/libxl_dom.c
@@ -444,6 +444,7 @@ static int libxl__domain_suspend_common_
             usleep(100000);
 
             state = libxl__xs_read(si->gc, XBT_NULL, path);
+            if (!state) state = "";
 
             watchdog--;
         }
@@ -463,6 +464,7 @@ static int libxl__domain_suspend_common_
             t = xs_transaction_start(ctx->xsh);
 
             state = libxl__xs_read(si->gc, t, path);
+            if (!state) state = "";
 
             if (!strcmp(state, "suspend"))
                 libxl__xs_write(si->gc, t, path, "");
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Paul Durrant

# HG changeset patch
# User Paul Durrant <[email protected]>
# Date 1322041530 0
# Node ID 3341e3e990568f459ae984cd9d2cac2d546eaa4e
# Parent 0a0c02a616768bfab16c072788cb76be1893c37f
Prevent xl save from segfaulting when control/shutdown key is removed

To acknowledge the tools' setting of control/shutdown it is normal for PV drivers to rm the key. This leads to libxl__xs_read() returning NULL and thus a subsequent strcmp on the return value will cause a segfault.

The Linux PV drivers actually write "" rather than removing the key which is how this didn't get spotted already. We should be robust to PV drivers which remove it as well.

At start of day .../control is created ro (to the guest) whereas .../control/shutdown is created rw. Can you confirm that a second operation still succeeds if the guest rm's the node on the first action?

My concern is that while the first time the round the node will be rw the second time round the write will actually re-create the node (without setting the permissions) which might result in the node being ro for the guest (xenstore perms confuse me, but I think new nodes inherit the parent permissions).

That's assuming there's any chance of a second operation. I'm thinking of a wedged reboot followed by an attempt to shutdown instead or something like that. Perhaps in practice that wouldn't work anyway.

Apart form the above this change improves the robustness of the code so:

Quoted 1 line
Quoted 25 lines

diff -r 0a0c02a61676 -r 3341e3e99056 tools/libxl/libxl_dom.c

tools/libxl/libxl_dom.c +2 -0
@@ -444,6 +444,7 @@ static int libxl__domain_suspend_common_
             usleep(100000);
 
             state = libxl__xs_read(si->gc, XBT_NULL, path);
+            if (!state) state = "";
 
             watchdog--;
         }
@@ -463,6 +464,7 @@ static int libxl__domain_suspend_common_
             t = xs_transaction_start(ctx->xsh);
 
             state = libxl__xs_read(si->gc, t, path);
+            if (!state) state = "";
 
             if (!strcmp(state, "suspend"))
                 libxl__xs_write(si->gc, t, path, "");

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw
Quoted 23 lines

-----Original Message-----
From: Ian Campbell
Sent: 23 November 2011 10:13
To: Paul Durrant
Cc: [email protected]
Subject: Re: [Xen-devel] [PATCH] Prevent xl save from segfaulting when control/shutdown key is removed

Quoted 2 lines · Paul Durrant

# HG changeset patch
# User Paul Durrant <[email protected]> # Date 1322041530 0

#

Quoted 3 lines

Node ID 3341e3e990568f459ae984cd9d2cac2d546eaa4e
# Parent 0a0c02a616768bfab16c072788cb76be1893c37f Prevent xl save from segfaulting when control/shutdown key is

removed

Quoted 2 lines

To acknowledge the tools' setting of control/shutdown it is normal

for

Quoted 2 lines

PV drivers to rm the key. This leads to libxl__xs_read() returning NULL and thus a subsequent strcmp on the return value will cause a

segfault.

Quoted 9 lines

The Linux PV drivers actually write "" rather than removing the key which is how this didn't get spotted already. We should be robust to PV drivers which remove it as well.

At start of day .../control is created ro (to the guest) whereas .../control/shutdown is created rw. Can you confirm that a second operation still succeeds if the guest rm's the node on the first action?

At the moment I can't. I'm getting a complete VM wedge-up on restore somewhere in the region of re-connecting to store. I'll check the subsequent suspend behaviour once I can get the Vm to actually come back. BTW what is the reason for creating control ro to the guest? In XenServer we allow the guest to write the control key to advertise feature-shutdown, feature-suspend etc. so that the tools know what values of control/shutdown the guest will respond to.

Paul

Quoted 45 lines

My concern is that while the first time the round the node will be rw the second time round the write will actually re-create the node (without setting the permissions) which might result in the node being ro for the guest (xenstore perms confuse me, but I think new nodes inherit the parent permissions).

That's assuming there's any chance of a second operation. I'm thinking of a wedged reboot followed by an attempt to shutdown instead or something like that. Perhaps in practice that wouldn't work anyway.

Apart form the above this change improves the robustness of the code so:

Quoted 1 line
Quoted 25 lines

diff -r 0a0c02a61676 -r 3341e3e99056 tools/libxl/libxl_dom.c

tools/libxl/libxl_dom.c +2 -0
@@ -444,6 +444,7 @@ static int libxl__domain_suspend_common_
             usleep(100000);
 
             state = libxl__xs_read(si->gc, XBT_NULL, path);
+            if (!state) state = "";
 
             watchdog--;
         }
@@ -463,6 +464,7 @@ static int libxl__domain_suspend_common_
             t = xs_transaction_start(ctx->xsh);
 
             state = libxl__xs_read(si->gc, t, path);
+            if (!state) state = "";
 
             if (!strcmp(state, "suspend"))
                 libxl__xs_write(si->gc, t, path, "");

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 1 line · Paul Durrant

what is the reason for creating control ro to the guest?

In general libxl prefers to whitelist paths which the guest can write too, just to prevent a complete free for all, keep things somewhat under control and to help avoid situations where tools might inadvertently rely on a guest-writeable key in an unsafe way..

Quoted 3 lines

In XenServer we allow the guest to write the control key to advertise
feature-shutdown, feature-suspend etc. so that the tools know what values of control/shutdown the guest will respond to.

The libxl way would be to create these at build time (perhaps empty) with the appropriate permissions.

It's not clear how that functionality can be added in a way which is compatible with existing guests though, e.g. no Linux guest writes those but many can be suspended etc.

Ian.

Quoted 49 lines

Paul

Quoted 45 lines

My concern is that while the first time the round the node will be rw the second time round the write will actually re-create the node (without setting the permissions) which might result in the node being ro for the guest (xenstore perms confuse me, but I think new nodes inherit the parent permissions).

That's assuming there's any chance of a second operation. I'm thinking of a wedged reboot followed by an attempt to shutdown instead or something like that. Perhaps in practice that wouldn't work anyway.

Apart form the above this change improves the robustness of the code so:

Quoted 1 line
Quoted 25 lines

diff -r 0a0c02a61676 -r 3341e3e99056 tools/libxl/libxl_dom.c

tools/libxl/libxl_dom.c +2 -0
@@ -444,6 +444,7 @@ static int libxl__domain_suspend_common_
             usleep(100000);
 
             state = libxl__xs_read(si->gc, XBT_NULL, path);
+            if (!state) state = "";
 
             watchdog--;
         }
@@ -463,6 +464,7 @@ static int libxl__domain_suspend_common_
             t = xs_transaction_start(ctx->xsh);
 
             state = libxl__xs_read(si->gc, t, path);
+            if (!state) state = "";
 
             if (!strcmp(state, "suspend"))
                 libxl__xs_write(si->gc, t, path, "");

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#4 lore raw
Quoted 21 lines

-----Original Message-----
From: Ian Campbell
Sent: 23 November 2011 11:24
To: Paul Durrant
Cc: [email protected]
Subject: RE: [Xen-devel] [PATCH] Prevent xl save from segfaulting when control/shutdown key is removed

Quoted 1 line · Paul Durrant

what is the reason for creating control ro to the guest?

In general libxl prefers to whitelist paths which the guest can write too, just to prevent a complete free for all, keep things somewhat under control and to help avoid situations where tools might inadvertently rely on a guest-writeable key in an unsafe way..

Quoted 1 line

In XenServer we allow the guest to write the control key to

advertise

Quoted 2 lines

feature-shutdown, feature-suspend etc. so that the tools know what values of control/shutdown the guest will respond to.

Quoted 7 lines

The libxl way would be to create these at build time (perhaps empty) with the appropriate permissions.

It's not clear how that functionality can be added in a way which is compatible with existing guests though, e.g. no Linux guest writes those but many can be suspended etc.

So the simple solution, for compatibility's sake, is to make control rw isn't it?

Paul

#5 lore raw
Quoted 24 lines · Paul Durrant
Quoted 24 lines

-----Original Message-----
From: Ian Campbell
Sent: 23 November 2011 11:24
To: Paul Durrant
Cc: [email protected]
Subject: RE: [Xen-devel] [PATCH] Prevent xl save from segfaulting when control/shutdown key is removed

Quoted 1 line · Paul Durrant

what is the reason for creating control ro to the guest?

In general libxl prefers to whitelist paths which the guest can write too, just to prevent a complete free for all, keep things somewhat under control and to help avoid situations where tools might inadvertently rely on a guest-writeable key in an unsafe way..

Quoted 1 line

In XenServer we allow the guest to write the control key to

advertise

Quoted 2 lines

feature-shutdown, feature-suspend etc. so that the tools know what values of control/shutdown the guest will respond to.

The libxl way would be to create these at build time (perhaps empty) with the appropriate permissions.

Quoted 6 lines
Quoted 4 lines

It's not clear how that functionality can be added in a way which is compatible with existing guests though, e.g. no Linux guest writes those but many can be suspended etc.

So the simple solution, for compatibility's sake, is to make control rw isn't it?

The problem I'm thinking of exists even if control is rw.

Given an empty control directory how do you know if a guest supports suspend or not, given that most existing guests which do support suspend do not write any key there?

Ian.

#6 lore raw

True. I was conflating the key rm issue with the fact that the XenServer Windows PV guest agent gets unhappy because it can't advertise its features (which I hadn't mentioned before).

I suppose that libxl will just have to continue to speculatively write control/shutdown and timeout if it's not NUL-ed or rm-ed as it does now.

Paul

Quoted 54 lines

-----Original Message-----
From: Ian Campbell
Sent: 23 November 2011 13:05
To: Paul Durrant
Cc: [email protected]
Subject: RE: [Xen-devel] [PATCH] Prevent xl save from segfaulting when control/shutdown key is removed

Quoted 6 lines · Paul Durrant
Quoted 6 lines

-----Original Message-----
From: Ian Campbell
Sent: 23 November 2011 11:24
To: Paul Durrant
Cc: [email protected]
Subject: RE: [Xen-devel] [PATCH] Prevent xl save from

segfaulting

Quoted 9 lines
Quoted 9 lines

when control/shutdown key is removed

Quoted 1 line · Paul Durrant

what is the reason for creating control ro to the guest?

In general libxl prefers to whitelist paths which the guest can write too, just to prevent a complete free for all, keep things somewhat under control and to help avoid situations where tools might inadvertently rely on a guest-writeable key in an unsafe

way..

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

In XenServer we allow the guest to write the control key to

advertise

Quoted 1 line

feature-shutdown, feature-suspend etc. so that the tools know

what

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

values of control/shutdown the guest will respond to.

The libxl way would be to create these at build time (perhaps

empty)

Quoted 3 lines
Quoted 3 lines

with the appropriate permissions.

It's not clear how that functionality can be added in a way

which is

Quoted 1 line
Quoted 1 line

compatible with existing guests though, e.g. no Linux guest

writes

Quoted 4 lines
Quoted 2 lines

those but many can be suspended etc.

So the simple solution, for compatibility's sake, is to make

control rw isn't it?

The problem I'm thinking of exists even if control is rw.

Given an empty control directory how do you know if a guest supports suspend or not, given that most existing guests which do support suspend do not write any key there?

Ian.

#7 lore raw
Quoted 7 lines · Paul Durrant

True. I was conflating the key rm issue with the fact that the XenServer Windows PV guest agent gets unhappy because it can't advertise its features (which I hadn't mentioned before).

I suppose that libxl will just have to continue to speculatively write control/shutdown and timeout if it's not NUL-ed or rm-ed as it does now.

I suppose one option might be a "feature-will-write-features" flag. If it is not written to true then assume everything is supported, if it does get set to true then look for the flags and follow them. However if a protocol is going to be invented then it should be discussed here and documented etc.

Ian.

Quoted 58 lines

Paul

Quoted 54 lines

-----Original Message-----
From: Ian Campbell
Sent: 23 November 2011 13:05
To: Paul Durrant
Cc: [email protected]
Subject: RE: [Xen-devel] [PATCH] Prevent xl save from segfaulting when control/shutdown key is removed

Quoted 6 lines · Paul Durrant
Quoted 6 lines

-----Original Message-----
From: Ian Campbell
Sent: 23 November 2011 11:24
To: Paul Durrant
Cc: [email protected]
Subject: RE: [Xen-devel] [PATCH] Prevent xl save from

segfaulting

Quoted 9 lines
Quoted 9 lines

when control/shutdown key is removed

Quoted 1 line · Paul Durrant

what is the reason for creating control ro to the guest?

In general libxl prefers to whitelist paths which the guest can write too, just to prevent a complete free for all, keep things somewhat under control and to help avoid situations where tools might inadvertently rely on a guest-writeable key in an unsafe

way..

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

In XenServer we allow the guest to write the control key to

advertise

Quoted 1 line

feature-shutdown, feature-suspend etc. so that the tools know

what

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

values of control/shutdown the guest will respond to.

The libxl way would be to create these at build time (perhaps

empty)

Quoted 3 lines
Quoted 3 lines

with the appropriate permissions.

It's not clear how that functionality can be added in a way

which is

Quoted 1 line
Quoted 1 line

compatible with existing guests though, e.g. no Linux guest

writes

Quoted 4 lines
Quoted 2 lines

those but many can be suspended etc.

So the simple solution, for compatibility's sake, is to make

control rw isn't it?

The problem I'm thinking of exists even if control is rw.

Given an empty control directory how do you know if a guest supports suspend or not, given that most existing guests which do support suspend do not write any key there?

Ian.