Skip to contentSkip to conversation

tools/xenstore: remove read-only socket

PATCH In review Juergen Gross 3 participants 12 messages Oct 2, 2020 – Oct 8, 2020 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

cover tools/xenstore: remove read-only socket

The read-only socket of Xenstore is usable for the daemon case only and even there it is not really worth to be kept, as not all Xesntore operations changing the state of Xenstore are blocked, oxenstored ignoring the read-only semantics completely, and the privileges for using the ro-socket being the same as for the normal rw-socket.

So remove this feature with switching the related use cases to the Xenstore-type agnostic open- and close-functions..

Juergen Gross (5):
tools/xenstore: remove socket-only option from xenstore client tools/libs/store: ignore XS_OPEN_SOCKETONLY flag tools/libs/store: drop read-only functionality
tools: drop all deprecated usages of xs_*_open() and friends in tools tools/xenstore: drop creation of read-only socket in xenstored

 docs/man/xenstore-chmod.1.pod           |  4 --
 docs/man/xenstore-ls.1.pod              |  4 --
 docs/man/xenstore-read.1.pod            |  4 --
 docs/man/xenstore-write.1.pod           |  4 --
 tools/console/client/main.c             |  2 +-
 tools/console/daemon/utils.c            |  4 +-
 tools/libs/light/libxl.c                |  6 +--
 tools/libs/light/libxl_exec.c           |  6 +--
 tools/libs/light/libxl_fork.c           |  2 +-
 tools/libs/stat/xenstat.c               |  4 +-
 tools/libs/store/include/xenstore.h     | 10 -----
 tools/libs/store/xs.c                   |  9 ++--
 tools/libs/vchan/init.c                 | 10 ++---
 tools/misc/xen-lowmemd.c                |  4 +-
 tools/python/xen/lowlevel/xs/xs.c       |  6 +--
 tools/tests/mce-test/tools/xen-mceinj.c |  4 +-
 tools/xenbackendd/xenbackendd.c         |  4 +-
 tools/xenpmd/xenpmd.c                   |  6 +--
 tools/xenstore/xenstore_client.c        |  8 +---
 tools/xenstore/xenstored_core.c         | 55 +++++--------------------
 tools/xenstore/xenstored_core.h         |  3 --
 tools/xenstore/xenstored_domain.c       |  4 +-
 tools/xenstore/xs_lib.c                 |  8 +---
 23 files changed, 46 insertions(+), 125 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/5 tools/xenstore: remove socket-only option from xenstore client

The Xenstore access commands (xenstore-*) have the possibility to limit connection to Xenstore to a local socket (option "-s"). This is an option making no sense at all, as either there is only a socket, so the option would be a nop, or there is no socket at all (in case Xenstore is running in a stubdom or the client is called in a domU), so specifying the option would just lead to failure.

So drop that option completely.

---
 docs/man/xenstore-chmod.1.pod    | 4 ----
 docs/man/xenstore-ls.1.pod       | 4 ----
 docs/man/xenstore-read.1.pod     | 4 ----
 docs/man/xenstore-write.1.pod    | 4 ----
 tools/xenstore/xenstore_client.c | 8 ++------
 5 files changed, 2 insertions(+), 22 deletions(-)
docs/man/xenstore-chmod.1.pod +0 -4
index d76f34723d..d221f5dffc 100644
@@ -46,10 +46,6 @@ write, and set permissions).
 
 Apply the permissions to the key and all its I<children>.
 
-=item B<-s>
-
-Connect to the Xenstore daemon using a local socket only.
-
 =item B<-u>
 
 Apply the permissions to the key and all its I<parents>.
docs/man/xenstore-ls.1.pod +0 -4
index 8dac931e94..a9f8b32653 100644
@@ -50,10 +50,6 @@ I<and> the permissions for any domain not explicitly listed in
 subsequent entries.  The key owner always has full access (read,
 write, and set permissions).
 
-=item B<-s>
-
-Connect to the Xenstore daemon using a local socket only.
-
 =back
 
 =head1 BUGS
docs/man/xenstore-read.1.pod +0 -4
index f5a7bb7e46..c7768cbbe5 100644
@@ -16,10 +16,6 @@ Read values of one or more Xenstore I<PATH>s.
 
 Prefix value with key name.
 
-=item B<-s>
-
-Connect to the Xenstore daemon using a local socket only.
-
 =item B<-R>
 
 Read raw value, skip escaping non-printable characters (\x..).
docs/man/xenstore-write.1.pod +0 -4
index d1b011236a..a0b1bca333 100644
@@ -13,10 +13,6 @@ provided to write them at once - in one Xenstore transaction.
 
 =over
 
-=item B<-s>
-
-Connect to the Xenstore daemon using a local socket only.
-
 =item B<-R>
 
 Write raw value, skip parsing escaped characters (\x..).
tools/xenstore/xenstore_client.c +2 -6
index ae7ed3eb9e..8015bfe5be 100644
@@ -530,7 +530,7 @@ main(int argc, char **argv)
 {
     struct xs_handle *xsh;
     xs_transaction_t xth = XBT_NULL;
-    int ret = 0, socket = 0;
+    int ret = 0;
     int prefix = 0;
     int tidy = 0;
     int upto = 0;
@@ -565,7 +565,6 @@ main(int argc, char **argv)
 	static struct option long_options[] = {
 	    {"help",    0, 0, 'h'},
 	    {"flat",    0, 0, 'f'}, /* MODE_ls */
-	    {"socket",  0, 0, 's'},
 	    {"prefix",  0, 0, 'p'}, /* MODE_read || MODE_list || MODE_ls */
 	    {"tidy",    0, 0, 't'}, /* MODE_rm */
 	    {"upto",    0, 0, 'u'}, /* MODE_chmod */
@@ -593,9 +592,6 @@ main(int argc, char **argv)
 		usage(mode, switch_argv, argv[0]);
 	    }
             break;
-        case 's':
-            socket = 1;
-            break;
 	case 'p':
 	    if ( mode == MODE_read || mode == MODE_list || mode == MODE_ls )
 		prefix = 1;
@@ -675,7 +671,7 @@ main(int argc, char **argv)
 	    max_width = ws.ws_col - 2;
     }
 
-    xsh = xs_open(socket ? XS_OPEN_SOCKETONLY : 0);
+    xsh = xs_open(0);
     if (xsh == NULL) err(1, "xs_open");
 
 again:
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/5 tools/libs/store: ignore XS_OPEN_SOCKETONLY flag

In reply to Juergen Gross

When opening the connection to Xenstore via xs_open() it makes no sense to limit the connection to the socket based one. So just ignore the XS_OPEN_SOCKETONLY flag.

---
 tools/libs/store/include/xenstore.h | 2 --
 tools/libs/store/xs.c               | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
tools/libs/store/include/xenstore.h +0 -2
index 25b31881c8..cbc7206a0f 100644
@@ -66,8 +66,6 @@ typedef uint32_t xs_transaction_t;
  * * Connections made with xs_open(0) (which might be shared page or
  *   socket based) are only guaranteed to work in the parent after
  *   fork.
- * * Connections made with xs_open(XS_OPEN_SOCKETONLY) will be usable
- *   in either the parent or the child after fork, but not both.
  * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
  *   for xs_open(0).
  * * XS_OPEN_READONLY has no bearing on any of this.
tools/libs/store/xs.c +1 -1
index aa1d24b8b9..320734416f 100644
@@ -319,7 +319,7 @@ struct xs_handle *xs_open(unsigned long flags)
 	else
 		xsh = get_handle(xs_daemon_socket());
 
-	if (!xsh && !(flags & XS_OPEN_SOCKETONLY))
+	if (!xsh)
 		xsh = get_handle(xs_domain_dev());
 
 	if (xsh && (flags & XS_UNWATCH_FILTER))
Signature · 1 line
2.26.2
#3 lore raw

PATCH 3/5 tools/libs/store: drop read-only functionality

In reply to Juergen Gross

Today it is possible to open the connection in read-only mode via xs_daemon_open_readonly(). This is working only with Xenstore running as a daemon in the same domain as the user. Additionally it doesn't add any security as accessing the socket used for that functionality requires the same privileges as the socket used for full Xenstore access.

So just drop the read-only semantics in all cases, leaving the interface existing only for compatibility reasons. This in turn requires to just ignore the XS_OPEN_READONLY flag.

---
 tools/libs/store/include/xenstore.h | 8 --------
 tools/libs/store/xs.c               | 7 ++-----
 2 files changed, 2 insertions(+), 13 deletions(-)
tools/libs/store/include/xenstore.h +0 -8
index cbc7206a0f..158e69ef83 100644
@@ -60,15 +60,12 @@ typedef uint32_t xs_transaction_t;
 /* Open a connection to the xs daemon.
  * Attempts to make a connection over the socket interface,
  * and if it fails, then over the  xenbus interface.
- * Mode 0 specifies read-write access, XS_OPEN_READONLY for
- * read-only access.
  *
  * * Connections made with xs_open(0) (which might be shared page or
  *   socket based) are only guaranteed to work in the parent after
  *   fork.
  * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
  *   for xs_open(0).
- * * XS_OPEN_READONLY has no bearing on any of this.
  *
  * Returns a handle or NULL.
  */
@@ -83,11 +80,6 @@ void xs_close(struct xs_handle *xsh /* NULL ok */);
  */
 struct xs_handle *xs_daemon_open(void);
 struct xs_handle *xs_domain_open(void);
-
-/* Connect to the xs daemon (readonly for non-root clients).
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
- */
 struct xs_handle *xs_daemon_open_readonly(void);
 
 /* Close the connection to the xs daemon.
tools/libs/store/xs.c +2 -5
index 320734416f..4ac73ec317 100644
@@ -302,7 +302,7 @@ struct xs_handle *xs_daemon_open(void)
 
 struct xs_handle *xs_daemon_open_readonly(void)
 {
-	return xs_open(XS_OPEN_READONLY);
+	return xs_open(0);
 }
 
 struct xs_handle *xs_domain_open(void)
@@ -314,10 +314,7 @@ struct xs_handle *xs_open(unsigned long flags)
 {
 	struct xs_handle *xsh = NULL;
 
-	if (flags & XS_OPEN_READONLY)
-		xsh = get_handle(xs_daemon_socket_ro());
-	else
-		xsh = get_handle(xs_daemon_socket());
+	xsh = get_handle(xs_daemon_socket());
 
 	if (!xsh)
 		xsh = get_handle(xs_domain_dev());
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH 3/5] tools/libs/store: drop read-only functionality

Quoted 54 lines · Juergen Gross

Today it is possible to open the connection in read-only mode via xs_daemon_open_readonly(). This is working only with Xenstore running as a daemon in the same domain as the user. Additionally it doesn't add any security as accessing the socket used for that functionality requires the same privileges as the socket used for full Xenstore access.

So just drop the read-only semantics in all cases, leaving the interface existing only for compatibility reasons. This in turn requires to just ignore the XS_OPEN_READONLY flag.

---
 tools/libs/store/include/xenstore.h | 8 --------
 tools/libs/store/xs.c               | 7 ++-----
 2 files changed, 2 insertions(+), 13 deletions(-)
tools/libs/store/include/xenstore.h +0 -8
index cbc7206a0f..158e69ef83 100644
@@ -60,15 +60,12 @@ typedef uint32_t xs_transaction_t;
 /* Open a connection to the xs daemon.
  * Attempts to make a connection over the socket interface,
  * and if it fails, then over the  xenbus interface.
- * Mode 0 specifies read-write access, XS_OPEN_READONLY for
- * read-only access.
  *
  * * Connections made with xs_open(0) (which might be shared page or
  *   socket based) are only guaranteed to work in the parent after
  *   fork.
  * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
  *   for xs_open(0).
- * * XS_OPEN_READONLY has no bearing on any of this.
  *
  * Returns a handle or NULL.
  */
@@ -83,11 +80,6 @@ void xs_close(struct xs_handle *xsh /* NULL ok */);
  */
 struct xs_handle *xs_daemon_open(void);
 struct xs_handle *xs_domain_open(void);
-
-/* Connect to the xs daemon (readonly for non-root clients).
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
- */
 struct xs_handle *xs_daemon_open_readonly(void);
 
 /* Close the connection to the xs daemon.
tools/libs/store/xs.c +0 -0
index 320734416f..4ac73ec317 100644

tools/libs/store/xs.c struct xs_handle *xs_daemon_open(void) · line 306

Quoted 6 lines
tools/libs/store/xs.c +1 -1
@@ -302,7 +302,7 @@ struct xs_handle *xs_daemon_open(void)
 
 struct xs_handle *xs_daemon_open_readonly(void)
 {
-	return xs_open(XS_OPEN_READONLY);
+	return xs_open(0);
 }

This changes the semantics of this function, isn't it? In that the user expects a readonly connection but in fact a read-write connection is returned.

Maybe we should return an error here?

Wei.

#5 lore raw

Re: [PATCH 3/5] tools/libs/store: drop read-only functionality

Quoted 66 lines · Wei Liu
Quoted 54 lines · Juergen Gross

Today it is possible to open the connection in read-only mode via xs_daemon_open_readonly(). This is working only with Xenstore running as a daemon in the same domain as the user. Additionally it doesn't add any security as accessing the socket used for that functionality requires the same privileges as the socket used for full Xenstore access.

So just drop the read-only semantics in all cases, leaving the interface existing only for compatibility reasons. This in turn requires to just ignore the XS_OPEN_READONLY flag.

---
  tools/libs/store/include/xenstore.h | 8 --------
  tools/libs/store/xs.c               | 7 ++-----
  2 files changed, 2 insertions(+), 13 deletions(-)
tools/libs/store/include/xenstore.h +0 -8
index cbc7206a0f..158e69ef83 100644
@@ -60,15 +60,12 @@ typedef uint32_t xs_transaction_t;
  /* Open a connection to the xs daemon.
   * Attempts to make a connection over the socket interface,
   * and if it fails, then over the  xenbus interface.
- * Mode 0 specifies read-write access, XS_OPEN_READONLY for
- * read-only access.
   *
   * * Connections made with xs_open(0) (which might be shared page or
   *   socket based) are only guaranteed to work in the parent after
   *   fork.
   * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
   *   for xs_open(0).
- * * XS_OPEN_READONLY has no bearing on any of this.
   *
   * Returns a handle or NULL.
   */
@@ -83,11 +80,6 @@ void xs_close(struct xs_handle *xsh /* NULL ok */);
   */
  struct xs_handle *xs_daemon_open(void);
  struct xs_handle *xs_domain_open(void);
-
-/* Connect to the xs daemon (readonly for non-root clients).
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
- */
  struct xs_handle *xs_daemon_open_readonly(void);
 
  /* Close the connection to the xs daemon.
tools/libs/store/xs.c +0 -0
index 320734416f..4ac73ec317 100644

tools/libs/store/xs.c struct xs_handle *xs_daemon_open(void) · line 306

Quoted 6 lines
tools/libs/store/xs.c +1 -1
@@ -302,7 +302,7 @@ struct xs_handle *xs_daemon_open(void)
 
  struct xs_handle *xs_daemon_open_readonly(void)
  {
-	return xs_open(XS_OPEN_READONLY);
+	return xs_open(0);
  }

This changes the semantics of this function, isn't it? In that the user expects a readonly connection but in fact a read-write connection is returned.

Quoted 1 line

Maybe we should return an error here?

No, as the behavior is this way already if any of the following is true:

- a guest is opening the connection
- Xenstore is running in a stubdom
- oxenstored is being used

Juergen

#6 lore raw

Re: [PATCH 3/5] tools/libs/store: drop read-only functionality

Quoted 66 lines · Jürgen Groß
Quoted 65 lines · Wei Liu
Quoted 54 lines · Juergen Gross

Today it is possible to open the connection in read-only mode via xs_daemon_open_readonly(). This is working only with Xenstore running as a daemon in the same domain as the user. Additionally it doesn't add any security as accessing the socket used for that functionality requires the same privileges as the socket used for full Xenstore access.

So just drop the read-only semantics in all cases, leaving the interface existing only for compatibility reasons. This in turn requires to just ignore the XS_OPEN_READONLY flag.

---
  tools/libs/store/include/xenstore.h | 8 -------- tools/libs/store/xs.c               | 7 ++-----

  2 files changed, 2 insertions(+), 13 deletions(-)
tools/libs/store/include/xenstore.h +0 -8
index cbc7206a0f..158e69ef83 100644
@@ -60,15 +60,12 @@ typedef uint32_t xs_transaction_t;
   /* Open a connection to the xs daemon.
    * Attempts to make a connection over the socket interface,
    * and if it fails, then over the  xenbus interface.
- * Mode 0 specifies read-write access, XS_OPEN_READONLY for
- * read-only access.
    *
    * * Connections made with xs_open(0) (which might be shared page or
    *   socket based) are only guaranteed to work in the parent after
    *   fork.
    * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
    *   for xs_open(0).
- * * XS_OPEN_READONLY has no bearing on any of this.
    *
    * Returns a handle or NULL.
    */
@@ -83,11 +80,6 @@ void xs_close(struct xs_handle *xsh /* NULL ok */);
    */
   struct xs_handle *xs_daemon_open(void);
   struct xs_handle *xs_domain_open(void);
-
-/* Connect to the xs daemon (readonly for non-root clients).
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
- */
   struct xs_handle *xs_daemon_open_readonly(void);
     /* Close the connection to the xs daemon.
tools/libs/store/xs.c +0 -0
index 320734416f..4ac73ec317 100644

tools/libs/store/xs.c struct xs_handle *xs_daemon_open(void) · line 305

Quoted 5 lines
tools/libs/store/xs.c +1 -1
@@ -302,7 +302,7 @@ struct xs_handle *xs_daemon_open(void)
     struct xs_handle *xs_daemon_open_readonly(void)
   {
-    return xs_open(XS_OPEN_READONLY);
+    return xs_open(0);
   }

This changes the semantics of this function, isn't it? In that the user expects a readonly connection but in fact a read-write connection is returned.

Quoted 7 lines
Quoted 1 line

Maybe we should return an error here?

No, as the behavior is this way already if any of the following is true:

- a guest is opening the connection
- Xenstore is running in a stubdom
- oxenstored is being used

Right, and these are just some of the reasons why dropping the R/O socket is a sensible thing to do.

However, I do think xenstore.h needs large disclaimers next to the relevant constants and functions that both XS_OPEN_* flags are now obsolete and ignored (merged into appropriate patches in the series).

~Andrew

#7 lore raw

Re: [PATCH 3/5] tools/libs/store: drop read-only functionality

Quoted 75 lines · Andrew Cooper
Quoted 66 lines · Jürgen Groß
Quoted 65 lines · Wei Liu
Quoted 54 lines · Juergen Gross

Today it is possible to open the connection in read-only mode via xs_daemon_open_readonly(). This is working only with Xenstore running as a daemon in the same domain as the user. Additionally it doesn't add any security as accessing the socket used for that functionality requires the same privileges as the socket used for full Xenstore access.

So just drop the read-only semantics in all cases, leaving the interface existing only for compatibility reasons. This in turn requires to just ignore the XS_OPEN_READONLY flag.

---
   tools/libs/store/include/xenstore.h | 8 --------
   tools/libs/store/xs.c               | 7 ++-----
   2 files changed, 2 insertions(+), 13 deletions(-)
tools/libs/store/include/xenstore.h +0 -8
index cbc7206a0f..158e69ef83 100644
@@ -60,15 +60,12 @@ typedef uint32_t xs_transaction_t;
   /* Open a connection to the xs daemon.
    * Attempts to make a connection over the socket interface,
    * and if it fails, then over the  xenbus interface.
- * Mode 0 specifies read-write access, XS_OPEN_READONLY for
- * read-only access.
    *
    * * Connections made with xs_open(0) (which might be shared page or
    *   socket based) are only guaranteed to work in the parent after
    *   fork.
    * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
    *   for xs_open(0).
- * * XS_OPEN_READONLY has no bearing on any of this.
    *
    * Returns a handle or NULL.
    */
@@ -83,11 +80,6 @@ void xs_close(struct xs_handle *xsh /* NULL ok */);
    */
   struct xs_handle *xs_daemon_open(void);
   struct xs_handle *xs_domain_open(void);
-
-/* Connect to the xs daemon (readonly for non-root clients).
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
- */
   struct xs_handle *xs_daemon_open_readonly(void);
     /* Close the connection to the xs daemon.
tools/libs/store/xs.c +0 -0
index 320734416f..4ac73ec317 100644

tools/libs/store/xs.c struct xs_handle *xs_daemon_open(void) · line 305

Quoted 5 lines
tools/libs/store/xs.c +1 -1
@@ -302,7 +302,7 @@ struct xs_handle *xs_daemon_open(void)
     struct xs_handle *xs_daemon_open_readonly(void)
   {
-    return xs_open(XS_OPEN_READONLY);
+    return xs_open(0);
   }

This changes the semantics of this function, isn't it? In that the user expects a readonly connection but in fact a read-write connection is returned.

Quoted 7 lines
Quoted 1 line

Maybe we should return an error here?

No, as the behavior is this way already if any of the following is true:

- a guest is opening the connection
- Xenstore is running in a stubdom
- oxenstored is being used

Quoted 6 lines

Right, and these are just some of the reasons why dropping the R/O socket is a sensible thing to do.

However, I do think xenstore.h needs large disclaimers next to the relevant constants and functions that both XS_OPEN_* flags are now obsolete and ignored (merged into appropriate patches in the series).

Fine with me.

Juergen

#8 lore raw

Re: [PATCH 3/5] tools/libs/store: drop read-only functionality

Quoted 76 lines · Jürgen Groß
Quoted 75 lines · Andrew Cooper
Quoted 73 lines · Jürgen Groß
Quoted 65 lines · Wei Liu
Quoted 54 lines · Juergen Gross

Today it is possible to open the connection in read-only mode via xs_daemon_open_readonly(). This is working only with Xenstore running as a daemon in the same domain as the user. Additionally it doesn't add any security as accessing the socket used for that functionality requires the same privileges as the socket used for full Xenstore access.

So just drop the read-only semantics in all cases, leaving the interface existing only for compatibility reasons. This in turn requires to just ignore the XS_OPEN_READONLY flag.

---
   tools/libs/store/include/xenstore.h | 8 --------
   tools/libs/store/xs.c               | 7 ++-----
   2 files changed, 2 insertions(+), 13 deletions(-)
tools/libs/store/include/xenstore.h +0 -8
index cbc7206a0f..158e69ef83 100644
@@ -60,15 +60,12 @@ typedef uint32_t xs_transaction_t;
   /* Open a connection to the xs daemon.
    * Attempts to make a connection over the socket interface,
    * and if it fails, then over the  xenbus interface.
- * Mode 0 specifies read-write access, XS_OPEN_READONLY for
- * read-only access.
    *
    * * Connections made with xs_open(0) (which might be shared page or
    *   socket based) are only guaranteed to work in the parent after
    *   fork.
    * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
    *   for xs_open(0).
- * * XS_OPEN_READONLY has no bearing on any of this.
    *
    * Returns a handle or NULL.
    */
@@ -83,11 +80,6 @@ void xs_close(struct xs_handle *xsh /* NULL ok */);
    */
   struct xs_handle *xs_daemon_open(void);
   struct xs_handle *xs_domain_open(void);
-
-/* Connect to the xs daemon (readonly for non-root clients).
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
- */
   struct xs_handle *xs_daemon_open_readonly(void);
     /* Close the connection to the xs daemon.
tools/libs/store/xs.c +0 -0
index 320734416f..4ac73ec317 100644

tools/libs/store/xs.c struct xs_handle *xs_daemon_open(void) · line 305

Quoted 5 lines
tools/libs/store/xs.c +1 -1
@@ -302,7 +302,7 @@ struct xs_handle *xs_daemon_open(void)
     struct xs_handle *xs_daemon_open_readonly(void)
   {
-    return xs_open(XS_OPEN_READONLY);
+    return xs_open(0);
   }

This changes the semantics of this function, isn't it? In that the user expects a readonly connection but in fact a read-write connection is returned.

Quoted 1 line

Maybe we should return an error here?

No, as the behavior is this way already if any of the following is true:

- a guest is opening the connection
- Xenstore is running in a stubdom
- oxenstored is being used

Quoted 8 lines
Quoted 6 lines

Right, and these are just some of the reasons why dropping the R/O socket is a sensible thing to do.

However, I do think xenstore.h needs large disclaimers next to the relevant constants and functions that both XS_OPEN_* flags are now obsolete and ignored (merged into appropriate patches in the series).

Fine with me.

+1 on this. Let me check other patches first. If there is no need for another round of posting of this series, the addition of the disclaimers can come in a separate patch.

Wei.

Quoted 4 lines

Juergen

#9 lore raw

PATCH 4/5 tools: drop all deprecated usages of xs_*_open() and friends in tools

In reply to Juergen Gross

Switch all usages of xs_daemon_open*() and xs_domain_open() to use xs_open() instead. While at it switch xs_daemon_close() users to xs_close().

---
 tools/console/client/main.c             |  2 +-
 tools/console/daemon/utils.c            |  4 ++--
 tools/libs/light/libxl.c                |  6 ++----
 tools/libs/light/libxl_exec.c           |  6 +++---
 tools/libs/light/libxl_fork.c           |  2 +-
 tools/libs/stat/xenstat.c               |  4 ++--
 tools/libs/vchan/init.c                 | 10 ++++------
 tools/misc/xen-lowmemd.c                |  4 ++--
 tools/python/xen/lowlevel/xs/xs.c       |  6 +++---
 tools/tests/mce-test/tools/xen-mceinj.c |  4 ++--
 tools/xenbackendd/xenbackendd.c         |  4 ++--
 tools/xenpmd/xenpmd.c                   |  6 +++---
 12 files changed, 27 insertions(+), 31 deletions(-)
tools/console/client/main.c +1 -1
index f92ad3d8cf..088be28dff 100644
@@ -398,7 +398,7 @@ int main(int argc, char **argv)
 		exit(EINVAL);
 	}
 
-	xs = xs_daemon_open();
+	xs = xs_open(0);
 	if (xs == NULL) {
 		err(errno, "Could not contact XenStore");
 	}
tools/console/daemon/utils.c +2 -2
index 97d7798b33..f9dd8a60c5 100644
@@ -104,7 +104,7 @@ void daemonize(const char *pidfile)
 bool xen_setup(void)
 {
 	
-	xs = xs_daemon_open();
+	xs = xs_open(0);
 	if (xs == NULL) {
 		dolog(LOG_ERR,
 		      "Failed to contact xenstore (%m).  Is it running?");
@@ -131,7 +131,7 @@ bool xen_setup(void)
 
  out:
 	if (xs)
-		xs_daemon_close(xs);
+		xs_close(xs);
 	if (xc)
 		xc_interface_close(xc);
 	return false;
tools/libs/light/libxl.c +2 -4
index 621acc88f3..d2a87157a2 100644
@@ -103,9 +103,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
         rc = ERROR_FAIL; goto out;
     }
 
-    ctx->xsh = xs_daemon_open();
-    if (!ctx->xsh)
-        ctx->xsh = xs_domain_open();
+    ctx->xsh = xs_open(0);
     if (!ctx->xsh) {
         LOGEV(ERROR, errno, "cannot connect to xenstore");
         rc = ERROR_FAIL; goto out;
@@ -171,7 +169,7 @@ int libxl_ctx_free(libxl_ctx *ctx)
 
     if (ctx->xch) xc_interface_close(ctx->xch);
     libxl_version_info_dispose(&ctx->version_info);
-    if (ctx->xsh) xs_daemon_close(ctx->xsh);
+    if (ctx->xsh) xs_close(ctx->xsh);
     if (ctx->xce) xenevtchn_close(ctx->xce);
 
     libxl__poller_put(ctx, ctx->poller_app);
tools/libs/light/libxl_exec.c +3 -3
index 47c9c8f1ba..a8b949b193 100644
@@ -178,7 +178,7 @@ int libxl__xenstore_child_wait_deprecated(libxl__gc *gc,
     unsigned int num;
     char **l = NULL;
 
-    xsh = xs_daemon_open();
+    xsh = xs_open(0);
     if (xsh == NULL) {
         LOG(ERROR, "Unable to open xenstore connection");
         goto err;
@@ -206,7 +206,7 @@ int libxl__xenstore_child_wait_deprecated(libxl__gc *gc,
 
         free(p);
         xs_unwatch(xsh, path, path);
-        xs_daemon_close(xsh);
+        xs_close(xsh);
         return rc;
 again:
         free(p);
@@ -226,7 +226,7 @@ again:
     LOG(ERROR, "%s not ready", what);
 
     xs_unwatch(xsh, path, path);
-    xs_daemon_close(xsh);
+    xs_close(xsh);
 err:
     return -1;
 }
tools/libs/light/libxl_fork.c +1 -1
index 9a4709b9a4..5d47dceb8a 100644
@@ -663,7 +663,7 @@ int libxl__ev_child_xenstore_reopen(libxl__gc *gc, const char *what) {
     int rc;
 
     assert(!CTX->xsh);
-    CTX->xsh = xs_daemon_open();
+    CTX->xsh = xs_open(0);
     if (!CTX->xsh) {
         LOGE(ERROR, "%s: xenstore reopen failed", what);
         rc = ERROR_FAIL;  goto out;
tools/libs/stat/xenstat.c +2 -2
index 6f93d4e982..e49689aa2d 100644
@@ -107,7 +107,7 @@ xenstat_handle *xenstat_init(void)
 		return NULL;
 	}
 
-	handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/
+	handle->xshandle = xs_open(0); /* open handle to xenstore*/
 	if (handle->xshandle == NULL) {
 		perror("unable to open xenstore");
 		xc_interface_close(handle->xc_handle);
@@ -125,7 +125,7 @@ void xenstat_uninit(xenstat_handle * handle)
 		for (i = 0; i < NUM_COLLECTORS; i++)
 			collectors[i].uninit(handle);
 		xc_interface_close(handle->xc_handle);
-		xs_daemon_close(handle->xshandle);
+		xs_close(handle->xshandle);
 		free(handle->priv);
 		free(handle);
 	}
tools/libs/vchan/init.c +4 -6
index ad4b64fbe3..c8510e6ce9 100644
@@ -251,7 +251,7 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base
 	char ref[16];
 	char* domid_str = NULL;
 	xs_transaction_t xs_trans = XBT_NULL;
-	xs = xs_domain_open();
+	xs = xs_open(0);
 	if (!xs)
 		goto fail;
 	domid_str = xs_read(xs, 0, "domid", NULL);
@@ -293,7 +293,7 @@ retry_transaction:
 	}
  fail_xs_open:
 	free(domid_str);
-	xs_daemon_close(xs);
+	xs_close(xs);
  fail:
 	return ret;
 }
@@ -408,9 +408,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
 	ctrl->write.order = ctrl->read.order = 0;
 	ctrl->is_server = 0;
 
-	xs = xs_daemon_open();
-	if (!xs)
-		xs = xs_domain_open();
+	xs = xs_open(0);
 	if (!xs)
 		goto fail;
 
@@ -452,7 +450,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
 
  out:
 	if (xs)
-		xs_daemon_close(xs);
+		xs_close(xs);
 	return ctrl;
  fail:
 	libxenvchan_close(ctrl);
tools/misc/xen-lowmemd.c +2 -2
index 79ad34cb4a..a3a2741242 100644
@@ -24,7 +24,7 @@ void cleanup(void)
     if (xch)
         xc_interface_close(xch);
     if (xs_handle)
-        xs_daemon_close(xs_handle);
+        xs_close(xs_handle);
 }
 
 /* Never shrink dom0 below 1 GiB */
@@ -102,7 +102,7 @@ int main(int argc, char *argv[])
         return 2;
     }
 
-    xs_handle = xs_daemon_open();
+    xs_handle = xs_open(0);
     if (xs_handle == NULL)
     {
         perror("Failed to open xenstore connection");
tools/python/xen/lowlevel/xs/xs.c +3 -3
index b7d4b6ef5d..0dad7fa5f2 100644
@@ -791,7 +791,7 @@ static PyObject *xspy_close(XsHandle *self)
         PySequence_SetItem(self->watches, i, Py_None);
     }
 
-    xs_daemon_close(xh);
+    xs_close(xh);
     self->xh = NULL;
 
     Py_INCREF(Py_None);
@@ -985,7 +985,7 @@ xshandle_init(XsHandle *self, PyObject *args, PyObject *kwds)
                                      &readonly))
         goto fail;
 
-    self->xh = (readonly ? xs_daemon_open_readonly() : xs_daemon_open());
+    self->xh = xs_open(0);
     if (!self->xh)
         goto fail;
 
@@ -999,7 +999,7 @@ xshandle_init(XsHandle *self, PyObject *args, PyObject *kwds)
 static void xshandle_dealloc(XsHandle *self)
 {
     if (self->xh) {
-        xs_daemon_close(self->xh);
+        xs_close(self->xh);
         self->xh = NULL;
     }
 
tools/tests/mce-test/tools/xen-mceinj.c +2 -2
index 380e42190c..1187d01e5f 100644
@@ -411,13 +411,13 @@ static long xs_get_dom_mem(int domid)
     unsigned int plen;
     struct xs_handle *xs;
 
-    xs = xs_daemon_open();
+    xs = xs_open(0);
     if (!xs)
         return -1;
 
     sprintf(path, "/local/domain/%d/memory/target", domid);
     memstr = xs_read(xs, XBT_NULL, path, &plen);
-    xs_daemon_close(xs);
+    xs_close(xs);
 
     if (!memstr || !plen)
         return -1;
tools/xenbackendd/xenbackendd.c +2 -2
index b6d92984e0..21884af772 100644
@@ -122,7 +122,7 @@ usage(void)
 static int
 xen_setup(void)
 {
-	xs = xs_daemon_open();
+	xs = xs_open(0);
 	if (xs == NULL) {
 		dolog(LOG_ERR,
 		    "Failed to contact xenstore (%s).  Is it running?",
@@ -138,7 +138,7 @@ xen_setup(void)
 
  out:
 	if (xs) {
-		xs_daemon_close(xs);
+		xs_close(xs);
 		xs = NULL;
 	}
 	return -1;
tools/xenpmd/xenpmd.c +3 -3
index 1c801caa71..35fd1c931a 100644
@@ -502,18 +502,18 @@ int main(int argc, char *argv[])
 #ifndef RUN_STANDALONE
     daemonize();
 #endif
-    xs = (struct xs_handle *)xs_daemon_open();
+    xs = xs_open(0);
     if ( xs == NULL ) 
         return -1;
 
     if ( write_one_time_battery_info() == 0 ) 
     {
-        xs_daemon_close(xs);
+        xs_close(xs);
         return -1;
     }
 
     wait_for_and_update_battery_status_request();
-    xs_daemon_close(xs);
+    xs_close(xs);
     return 0;
 }
 
Signature · 1 line
2.26.2
#10 lore raw

PATCH 5/5 tools/xenstore: drop creation of read-only socket in xenstored

In reply to Juergen Gross

With xs_daemon_open_readonly() now no longer using the read-only socket the creation of that socket can be dropped.

---
 tools/xenstore/xenstored_core.c   | 55 +++++++------------------------
 tools/xenstore/xenstored_core.h   |  3 --
 tools/xenstore/xenstored_domain.c |  4 +--
 tools/xenstore/xs_lib.c           |  8 +----
 4 files changed, 14 insertions(+), 56 deletions(-)
tools/xenstore/xenstored_core.c +11 -44
index 9700772d40..b4be374d3f 100644
@@ -71,7 +71,6 @@ static unsigned int current_array_size;
 static unsigned int nr_fds;
 
 static int sock = -1;
-static int ro_sock = -1;
 
 static bool verbose = false;
 LIST_HEAD(connections);
@@ -311,8 +310,7 @@ fail:
 	return -1;
 }
 
-static void initialize_fds(int *p_sock_pollfd_idx, int *p_ro_sock_pollfd_idx,
-			   int *ptimeout)
+static void initialize_fds(int *p_sock_pollfd_idx, int *ptimeout)
 {
 	struct connection *conn;
 	struct wrl_timestampt now;
@@ -325,8 +323,6 @@ static void initialize_fds(int *p_sock_pollfd_idx, int *p_ro_sock_pollfd_idx,
 
 	if (sock != -1)
 		*p_sock_pollfd_idx = set_fd(sock, POLLIN|POLLPRI);
-	if (ro_sock != -1)
-		*p_ro_sock_pollfd_idx = set_fd(ro_sock, POLLIN|POLLPRI);
 	if (reopen_log_pipe[0] != -1)
 		reopen_log_pipe0_pollfd_idx =
 			set_fd(reopen_log_pipe[0], POLLIN|POLLPRI);
@@ -472,9 +468,6 @@ static enum xs_perm_type perm_for_conn(struct connection *conn,
 	unsigned int i;
 	enum xs_perm_type mask = XS_PERM_READ|XS_PERM_WRITE|XS_PERM_OWNER;
 
-	if (!conn->can_write)
-		mask &= ~XS_PERM_WRITE;
-
 	/* Owners and tools get it all... */
 	if (!domain_is_unprivileged(conn) || perms[0].id == conn->id
                 || (conn->target && perms[0].id == conn->target->id))
@@ -1422,7 +1415,6 @@ struct connection *new_connection(connwritefn_t *write, connreadfn_t *read)
 	new->pollfd_idx = -1;
 	new->write = write;
 	new->read = read;
-	new->can_write = true;
 	new->transaction_started = 0;
 	INIT_LIST_HEAD(&new->out_list);
 	INIT_LIST_HEAD(&new->watches);
@@ -1435,7 +1427,7 @@ struct connection *new_connection(connwritefn_t *write, connreadfn_t *read)
 }
 
 #ifdef NO_SOCKETS
-static void accept_connection(int sock, bool canwrite)
+static void accept_connection(int sock)
 {
 }
 #else
@@ -1477,7 +1469,7 @@ static int readfd(struct connection *conn, void *data, unsigned int len)
 	return rc;
 }
 
-static void accept_connection(int sock, bool canwrite)
+static void accept_connection(int sock)
 {
 	int fd;
 	struct connection *conn;
@@ -1487,10 +1479,9 @@ static void accept_connection(int sock, bool canwrite)
 		return;
 
 	conn = new_connection(writefd, readfd);
-	if (conn) {
+	if (conn)
 		conn->fd = fd;
-		conn->can_write = canwrite;
-	} else
+	else
 		close(fd);
 }
 #endif
@@ -1794,28 +1785,21 @@ static void destroy_fds(void)
 {
 	if (sock >= 0)
 		close(sock);
-	if (ro_sock >= 0)
-		close(ro_sock);
 }
 
 static void init_sockets(void)
 {
 	struct sockaddr_un addr;
 	const char *soc_str = xs_daemon_socket();
-	const char *soc_str_ro = xs_daemon_socket_ro();
 
 	/* Create sockets for them to listen to. */
 	atexit(destroy_fds);
 	sock = socket(PF_UNIX, SOCK_STREAM, 0);
 	if (sock < 0)
 		barf_perror("Could not create socket");
-	ro_sock = socket(PF_UNIX, SOCK_STREAM, 0);
-	if (ro_sock < 0)
-		barf_perror("Could not create socket");
 
 	/* FIXME: Be more sophisticated, don't mug running daemon. */
 	unlink(soc_str);
-	unlink(soc_str_ro);
 
 	addr.sun_family = AF_UNIX;
 
@@ -1825,17 +1809,10 @@ static void init_sockets(void)
 	if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0)
 		barf_perror("Could not bind socket to %s", soc_str);
 
-	if(strlen(soc_str_ro) >= sizeof(addr.sun_path))
-		barf_perror("socket string '%s' too long", soc_str_ro);
-	strcpy(addr.sun_path, soc_str_ro);
-	if (bind(ro_sock, (struct sockaddr *)&addr, sizeof(addr)) != 0)
-		barf_perror("Could not bind socket to %s", soc_str_ro);
-
-	if (chmod(soc_str, 0600) != 0
-	    || chmod(soc_str_ro, 0660) != 0)
+	if (chmod(soc_str, 0600) != 0)
 		barf_perror("Could not chmod sockets");
 
-	if (listen(sock, 1) != 0 || listen(ro_sock, 1) != 0)
+	if (listen(sock, 1) != 0)
 		barf_perror("Could not listen on sockets");
 }
 #endif
@@ -1893,7 +1870,7 @@ int priv_domid = 0;
 int main(int argc, char *argv[])
 {
 	int opt;
-	int sock_pollfd_idx = -1, ro_sock_pollfd_idx = -1;
+	int sock_pollfd_idx = -1;
 	bool dofork = true;
 	bool outputpid = false;
 	bool no_domain_init = false;
@@ -2010,7 +1987,7 @@ int main(int argc, char *argv[])
 		tracefile = talloc_strdup(NULL, tracefile);
 
 	/* Get ready to listen to the tools. */
-	initialize_fds(&sock_pollfd_idx, &ro_sock_pollfd_idx, &timeout);
+	initialize_fds(&sock_pollfd_idx, &timeout);
 
 	/* Tell the kernel we're up and running. */
 	xenbus_notify_running();
@@ -2051,21 +2028,11 @@ int main(int argc, char *argv[])
 				barf_perror("sock poll failed");
 				break;
 			} else if (fds[sock_pollfd_idx].revents & POLLIN) {
-				accept_connection(sock, true);
+				accept_connection(sock);
 				sock_pollfd_idx = -1;
 			}
 		}
 
-		if (ro_sock_pollfd_idx != -1) {
-			if (fds[ro_sock_pollfd_idx].revents & ~POLLIN) {
-				barf_perror("ro sock poll failed");
-				break;
-			} else if (fds[ro_sock_pollfd_idx].revents & POLLIN) {
-				accept_connection(ro_sock, false);
-				ro_sock_pollfd_idx = -1;
-			}
-		}
-
 		if (xce_pollfd_idx != -1) {
 			if (fds[xce_pollfd_idx].revents & ~POLLIN) {
 				barf_perror("xce_handle poll failed");
@@ -2128,7 +2095,7 @@ int main(int argc, char *argv[])
 			}
 		}
 
-		initialize_fds(&sock_pollfd_idx, &ro_sock_pollfd_idx, &timeout);
+		initialize_fds(&sock_pollfd_idx, &timeout);
 	}
 }
 
tools/xenstore/xenstored_core.h +0 -3
index c4c32bc88f..1df6ad94ab 100644
@@ -77,9 +77,6 @@ struct connection
 	/* Who am I? 0 for socket connections. */
 	unsigned int id;
 
-	/* Is this a read-only connection? */
-	bool can_write;
-
 	/* Buffered incoming data. */
 	struct buffered_data *in;
 
tools/xenstore/xenstored_domain.c +2 -2
index 0d5495745b..a2f144f6dd 100644
@@ -372,7 +372,7 @@ int do_introduce(struct connection *conn, struct buffered_data *in)
 	if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec))
 		return EINVAL;
 
-	if (domain_is_unprivileged(conn) || !conn->can_write)
+	if (domain_is_unprivileged(conn))
 		return EACCES;
 
 	domid = atoi(vec[0]);
@@ -438,7 +438,7 @@ int do_set_target(struct connection *conn, struct buffered_data *in)
 	if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec))
 		return EINVAL;
 
-	if (domain_is_unprivileged(conn) || !conn->can_write)
+	if (domain_is_unprivileged(conn))
 		return EACCES;
 
 	domid = atoi(vec[0]);
tools/xenstore/xs_lib.c +1 -7
index 3e43f8809d..9f1dc6d559 100644
@@ -63,13 +63,7 @@ const char *xs_daemon_socket(void)
 
 const char *xs_daemon_socket_ro(void)
 {
-	static char buf[PATH_MAX];
-	const char *s = xs_daemon_path();
-	if (s == NULL)
-		return NULL;
-	if (snprintf(buf, sizeof(buf), "%s_ro", s) >= PATH_MAX)
-		return NULL;
-	return buf;
+	return xs_daemon_path();
 }
 
 const char *xs_domain_dev(void)
Signature · 1 line
2.26.2
#11 lore raw
In reply to Juergen Gross
Quoted 10 lines · Juergen Gross

The read-only socket of Xenstore is usable for the daemon case only and even there it is not really worth to be kept, as not all Xesntore operations changing the state of Xenstore are blocked, oxenstored ignoring the read-only semantics completely, and the privileges for using the ro-socket being the same as for the normal rw-socket.

So remove this feature with switching the related use cases to the Xenstore-type agnostic open- and close-functions..

Quoted 6 lines

Juergen Gross (5):
tools/xenstore: remove socket-only option from xenstore client tools/libs/store: ignore XS_OPEN_SOCKETONLY flag tools/libs/store: drop read-only functionality
tools: drop all deprecated usages of xs_*_open() and friends in tools tools/xenstore: drop creation of read-only socket in xenstored

Acked + applied.

Please submit a follow-up patch for adding some comments to xenstore.h.

Wei.