Skip to contentSkip to conversation

tools/xenstored: Don't crash xenstored when Live-Update is cancelled

PATCH In review Julien Grall 3 participants 10 messages Jun 17, 2021 – Jun 24, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/xenstored: Don't crash xenstored when Live-Update is cancelled

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Rework do_lu_start() to check if lu_status is NULL and return an error in this case.

Fixes af216a99fb ("tools/xenstore: add the basic framework for doing the live update")

----

This is currently based on top of:

https://lore.kernel.org/xen-devel/[email protected]

This can be re-ordered if necessary.

---
 tools/xenstore/xenstored_control.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
tools/xenstore/xenstored_control.c +13 -2
index a045f102a420..37a3d39f20b5 100644
@@ -696,7 +696,18 @@ static bool do_lu_start(struct delayed_request *req)
 	time_t now = time(NULL);
 	const char *ret;
 	struct buffered_data *saved_in;
-	struct connection *conn = lu_status->conn;
+	struct connection *conn = req->data;
+
+	/*
+	 * Cancellation may have been requested asynchronously. In this
+	 * case, lu_status will be NULL.
+	 */
+	if (!lu_status) {
+		ret = "Cancellation was requested";
+		conn = req->data;
+		goto out;
+	} else
+		assert(lu_status->conn == conn);
 
 	if (!lu_check_lu_allowed()) {
 		if (now < lu_status->started_at + lu_status->timeout)
@@ -747,7 +758,7 @@ static const char *lu_start(const void *ctx, struct connection *conn,
 	lu_status->timeout = to;
 	lu_status->started_at = time(NULL);
 
-	errno = delay_request(conn, conn->in, do_lu_start, NULL, false);
+	errno = delay_request(conn, conn->in, do_lu_start, conn, false);
 
 	return NULL;
 }
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Julien Grall

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Quoted 5 lines

Rework do_lu_start() to check if lu_status is NULL and return an error in this case.

Fixes af216a99fb ("tools/xenstore: add the basic framework for doing the live update")
Quoted 49 lines

----

This is currently based on top of:

https://lore.kernel.org/xen-devel/[email protected]

This can be re-ordered if necessary.
---
tools/xenstore/xenstored_control.c | 15 +++++++++++++--

1 file changed, 13 insertions(+), 2 deletions(-)
tools/xenstore/xenstored_control.c +13 -2
index a045f102a420..37a3d39f20b5 100644
@@ -696,7 +696,18 @@ static bool do_lu_start(struct delayed_request *req)
 	time_t now = time(NULL);
 	const char *ret;
 	struct buffered_data *saved_in;
-	struct connection *conn = lu_status->conn;
+	struct connection *conn = req->data;
+
+	/*
+	 * Cancellation may have been requested asynchronously. In this
+	 * case, lu_status will be NULL.
+	 */
+	if (!lu_status) {
+		ret = "Cancellation was requested";
+		conn = req->data;
+		goto out;
+	} else
+		assert(lu_status->conn == conn);
 
 	if (!lu_check_lu_allowed()) {
 		if (now < lu_status->started_at + lu_status->timeout)
@@ -747,7 +758,7 @@ static const char *lu_start(const void *ctx, struct connection *conn,
 	lu_status->timeout = to;
 	lu_status->started_at = time(NULL);
 
-	errno = delay_request(conn, conn->in, do_lu_start, NULL, false);
+	errno = delay_request(conn, conn->in, do_lu_start, conn, false);
 
 	return NULL;
 }
Signature · 1 line
2.17.1
#2 lore raw
In reply to Julien Grall
Quoted 9 lines · Julien Grall

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Umm, you introduced that bug in "[PATCH 03/10] tools/xenstore: Don't assume conn->in points to the LU request".

So I think you should fold your fix into that series.

Juergen

#3 lore raw

Hi Juergen,

Quoted 6 lines · Juergen Gross
Quoted 5 lines · Julien Grall

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Quoted 7 lines
Quoted 4 lines

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Umm, you introduced that bug in "[PATCH 03/10] tools/xenstore: Don't assume conn->in points to the LU request".

No. I did reproduced this one without my series. If there are in-flight transaction this will crash in lu_check_lu_allowed() otherwise, it will crash when calling lu_dump_state().

The easiest way to reproduce is requesting live-update when there are long transactions and from a different connection (still in dom0) requesting to abort the connection.

In this case, lu_abort() will free lu_status and the destructor will set it to NULL. But the actual request is still in the delayed request queue for the other connection.

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw
Quoted 14 lines · Julien Grall

Hi Juergen,

Quoted 11 lines · Juergen Gross
Quoted 9 lines · Julien Grall

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Quoted 8 lines
Quoted 2 lines

Umm, you introduced that bug in "[PATCH 03/10] tools/xenstore: Don't assume conn->in points to the LU request".

No. I did reproduced this one without my series. If there are in-flight

transaction this will crash in lu_check_lu_allowed() otherwise, it will

crash when calling lu_dump_state().

Oh, right, I missed the indirection via delay_request().

Sorry.

Juergen

Reviewed-by on v1 1/1
#5 lore raw
In reply to Julien Grall
Quoted 35 lines · Julien Grall

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Rework do_lu_start() to check if lu_status is NULL and return an error in this case.

Fixes af216a99fb ("tools/xenstore: add the basic framework for doing the live update")

----

This is currently based on top of:

https://lore.kernel.org/xen-devel/[email protected]

This can be re-ordered if necessary.

---
  tools/xenstore/xenstored_control.c | 15 +++++++++++++--
  1 file changed, 13 insertions(+), 2 deletions(-)
tools/xenstore/xenstored_control.c +0 -0
index a045f102a420..37a3d39f20b5 100644
@@ -696,7 +696,18 @@ static bool do_lu_start(struct delayed_request *req)
  	time_t now = time(NULL);
  	const char *ret;
  	struct buffered_data *saved_in;

tools/xenstore/xenstored_control.c static bool do_lu_start(struct delayed_request *req) · line 707

Quoted 10 lines
tools/xenstore/xenstored_control.c +9 -1
-	struct connection *conn = lu_status->conn;
+	struct connection *conn = req->data;
+
+	/*
+	 * Cancellation may have been requested asynchronously. In this
+	 * case, lu_status will be NULL.
+	 */
+	if (!lu_status) {
+		ret = "Cancellation was requested";
+		conn = req->data;

This will set conn to the same value it already has.

Other than that:

Juergen

#6 lore raw

Hi Juergen,

Quoted 40 lines · Juergen Gross
Quoted 39 lines · Julien Grall

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Rework do_lu_start() to check if lu_status is NULL and return an error in this case.

Fixes af216a99fb ("tools/xenstore: add the basic framework for doing the live update")

----

This is currently based on top of:

https://lore.kernel.org/xen-devel/[email protected]

This can be re-ordered if necessary.
---
  tools/xenstore/xenstored_control.c | 15 +++++++++++++--

  1 file changed, 13 insertions(+), 2 deletions(-)
tools/xenstore/xenstored_control.c +3 -1
index a045f102a420..37a3d39f20b5 100644
@@ -696,7 +696,18 @@ static bool do_lu_start(struct delayed_request *req)
       time_t now = time(NULL);
       const char *ret;
       struct buffered_data *saved_in;
-    struct connection *conn = lu_status->conn;
+    struct connection *conn = req->data;
+
+    /*
Quoted 8 lines

tools/xenstore/xenstored_control.c static bool do_lu_start(struct delayed_request *req) · line 707

Quoted 6 lines
tools/xenstore/xenstored_control.c +6 -0
+     * Cancellation may have been requested asynchronously. In this
+     * case, lu_status will be NULL.
+     */
+    if (!lu_status) {
+        ret = "Cancellation was requested";
+        conn = req->data;

This will set conn to the same value it already has.

Ah yes. I will drop this line.

Also, I took the opportunity to replace

} else
assert(...)

with just

assert(...)

This should improve a bit the readability. Let me know if you want me to resend the patch for that.

Quoted 5 lines

Other than that:

Thank you!

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw
Quoted 43 lines · Julien Grall

Hi Juergen,

Quoted 40 lines · Juergen Gross
Quoted 39 lines · Julien Grall

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Rework do_lu_start() to check if lu_status is NULL and return an error in this case.

Fixes af216a99fb ("tools/xenstore: add the basic framework for doing

the live update")

----

This is currently based on top of:

https://lore.kernel.org/xen-devel/[email protected]

This can be re-ordered if necessary.
---
  tools/xenstore/xenstored_control.c | 15 +++++++++++++--

  1 file changed, 13 insertions(+), 2 deletions(-)
tools/xenstore/xenstored_control.c +0 -1
index a045f102a420..37a3d39f20b5 100644
@@ -696,7 +696,18 @@ static bool do_lu_start(struct delayed_request 
 *req)
       time_t now = time(NULL);
       const char *ret;
       struct buffered_data *saved_in;
-    struct connection *conn = lu_status->conn;
Quoted 8 lines
Quoted 8 lines

tools/xenstore/xenstored_control.c static bool do_lu_start(struct delayed_request *req)

Quoted 8 lines
tools/xenstore/xenstored_control.c +8 -0
+    struct connection *conn = req->data;
+
+    /*
+     * Cancellation may have been requested asynchronously. In this
+     * case, lu_status will be NULL.
+     */
+    if (!lu_status) {
+        ret = "Cancellation was 

requested";

Quoted 8 lines
Quoted 3 lines

tools/xenstore/xenstored_control.c static bool do_lu_start(struct delayed_request *req) · line 707

Quoted 1 line
tools/xenstore/xenstored_control.c +1 -0
+        conn = req->data;

This will set conn to the same value it already has.

Ah yes. I will drop this line.

Also, I took the opportunity to replace

Quoted 8 lines

} else
 assert(...)

with just

assert(...)

This should improve a bit the readability. Let me know if you want me to resend the patch for that.

I guess you are planning to do the commit?

If yes, there is no need for resending the patch.

Juergen

#8 lore raw

Hi Juergen,

Quoted 64 lines · Juergen Gross
Quoted 43 lines · Julien Grall

Hi Juergen,

Quoted 40 lines · Juergen Gross
Quoted 39 lines · Julien Grall

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Rework do_lu_start() to check if lu_status is NULL and return an error in this case.

Fixes af216a99fb ("tools/xenstore: add the basic framework for doing

the live update")

----

This is currently based on top of:

https://lore.kernel.org/xen-devel/[email protected]

This can be re-ordered if necessary.
---
  tools/xenstore/xenstored_control.c | 15 +++++++++++++--

  1 file changed, 13 insertions(+), 2 deletions(-)
tools/xenstore/xenstored_control.c +0 -1
index a045f102a420..37a3d39f20b5 100644
@@ -696,7 +696,18 @@ static bool do_lu_start(struct delayed_request 
 *req)
       time_t now = time(NULL);
       const char *ret;
       struct buffered_data *saved_in;
-    struct connection *conn = lu_status->conn;
Quoted 8 lines
Quoted 8 lines

tools/xenstore/xenstored_control.c static bool do_lu_start(struct delayed_request *req)

Quoted 8 lines
tools/xenstore/xenstored_control.c +8 -0
+    struct connection *conn = req->data;
+
+    /*
+     * Cancellation may have been requested asynchronously. In this
+     * case, lu_status will be NULL.
+     */
+    if (!lu_status) {
+        ret = "Cancellation was 

requested";

Quoted 11 lines
Quoted 3 lines

tools/xenstore/xenstored_control.c static bool do_lu_start(struct delayed_request *req) · line 707

Quoted 1 line
tools/xenstore/xenstored_control.c +1 -0
+        conn = req->data;

This will set conn to the same value it already has.

Ah yes. I will drop this line.

Also, I took the opportunity to replace

} else
  assert(...)

Quoted 7 lines
Quoted 5 lines

with just

assert(...)

This should improve a bit the readability. Let me know if you want me to resend the patch for that.

I guess you are planning to do the commit?

That's my plan.

Quoted 2 lines

If yes, there is no need for resending the patch.

Thanks!

Cheers,

Signature · 1 line
Julien Grall
#9 lore raw
Quoted 70 lines · Julien Grall

Hi Juergen,

Quoted 67 lines · Juergen Gross
Quoted 44 lines · Julien Grall

Hi Juergen,

Quoted 41 lines · Juergen Gross
Quoted 40 lines · Julien Grall

From: Julien GralL <[email protected]>

As Live-Update is asynchronous, it is possible to receive a request to cancel it (either on the same connection or from a different one).

Currently, this will crash xenstored because do_lu_start() assumes lu_status will be valid. This is not the case when Live-Update has been cancelled. This will result to dereference a NULL pointer and crash Xenstored.

Rework do_lu_start() to check if lu_status is NULL and return an error in this case.

Fixes af216a99fb ("tools/xenstore: add the basic framework for doing

the live update")

----

This is currently based on top of:

https://lore.kernel.org/xen-devel/[email protected]

This can be re-ordered if necessary.
---
  tools/xenstore/xenstored_control.c | 15 +++++++++++++--

  1 file changed, 13 insertions(+), 2 deletions(-)
tools/xenstore/xenstored_control.c +0 -1
index a045f102a420..37a3d39f20b5 100644
@@ -696,7 +696,18 @@ static bool do_lu_start(struct delayed_request 
 *req)
       time_t now = time(NULL);
       const char *ret;
       struct buffered_data *saved_in;
-    struct connection *conn = lu_status->conn;
Quoted 8 lines
Quoted 8 lines

tools/xenstore/xenstored_control.c static bool do_lu_start(struct delayed_request *req)

Quoted 8 lines
tools/xenstore/xenstored_control.c +8 -0
+    struct connection *conn = req->data;
+
+    /*
+     * Cancellation may have been requested asynchronously. In this
+     * case, lu_status will be NULL.
+     */
+    if (!lu_status) {
+        ret = "Cancellation was 

requested";

Quoted 13 lines
Quoted 3 lines

tools/xenstore/xenstored_control.c static bool do_lu_start(struct delayed_request *req) · line 707

Quoted 1 line
tools/xenstore/xenstored_control.c +1 -0
+        conn = req->data;

This will set conn to the same value it already has.

Ah yes. I will drop this line.

Also, I took the opportunity to replace

} else
  assert(...)

with just

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

assert(...)

This should improve a bit the readability. Let me know if you want me to resend the patch for that.

I guess you are planning to do the commit?

That's my plan.

Committed.

Quoted 8 lines
Quoted 3 lines

If yes, there is no need for resending the patch.

Thanks!

Cheers,

Signature · 1 line
Julien Grall