Skip to contentSkip to conversation

tools/xenstore: fix a use after free problem in xenstored

PATCH Superseded Juergen Gross 1 participant 2 messages Mar 24, 2020 – Apr 2, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/xenstore: fix a use after free problem in xenstored

Commit 562a1c0f7ef3fb ("tools/xenstore: dont unlink connection object twice") introduced a potential use after free problem in domain_cleanup(): after calling talloc_unlink() for domain->conn domain->conn is set to NULL. The problem is that domain is registered as talloc child of domain->conn, so it might be freed by the talloc_unlink() call.

Fixes 562a1c0f7ef3fb ("tools/xenstore: dont unlink connection object twice")
---
 tools/xenstore/xenstored_domain.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/xenstore/xenstored_domain.c +4 -1
index baddaba5df..5858185211 100644
@@ -214,6 +214,7 @@ static void domain_cleanup(void)
 {
 	xc_dominfo_t dominfo;
 	struct domain *domain;
+	struct connection *conn;
 	int notify = 0;
 
  again:
@@ -230,8 +231,10 @@ static void domain_cleanup(void)
 				continue;
 		}
 		if (domain->conn) {
-			talloc_unlink(talloc_autofree_context(), domain->conn);
+			/* domain is a talloc child of domain->conn. */
+			conn = domain->conn;
 			domain->conn = NULL;
+			talloc_unlink(talloc_autofree_context(), conn);
 			notify = 0; /* destroy_domain() fires the watch */
 			goto again;
 		}
Signature · 1 line
2.16.4
#1 lore raw

Ping?

Quoted 38 lines · Juergen Gross

Commit 562a1c0f7ef3fb ("tools/xenstore: dont unlink connection object twice") introduced a potential use after free problem in domain_cleanup(): after calling talloc_unlink() for domain->conn domain->conn is set to NULL. The problem is that domain is registered as talloc child of domain->conn, so it might be freed by the talloc_unlink() call.

Fixes 562a1c0f7ef3fb ("tools/xenstore: dont unlink connection object twice")
---
  tools/xenstore/xenstored_domain.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
tools/xenstore/xenstored_domain.c +4 -1
index baddaba5df..5858185211 100644
@@ -214,6 +214,7 @@ static void domain_cleanup(void)
  {
  	xc_dominfo_t dominfo;
  	struct domain *domain;
+	struct connection *conn;
  	int notify = 0;
 
   again:
@@ -230,8 +231,10 @@ static void domain_cleanup(void)
  				continue;
  		}
  		if (domain->conn) {
-			talloc_unlink(talloc_autofree_context(), domain->conn);
+			/* domain is a talloc child of domain->conn. */
+			conn = domain->conn;
  			domain->conn = NULL;
+			talloc_unlink(talloc_autofree_context(), conn);
  			notify = 0; /* destroy_domain() fires the watch */
  			goto again;
  		}