xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@suse.com>
To: Ian Campbell <Ian.Campbell@citrix.com>,
	David Scott <dave.scott@eu.citrix.com>
Cc: xen-devel@lists.xenproject.org,
	"Luis R. Rodriguez" <mcgrof@do-not-panic.com>
Subject: Re: [PATCH v6 02/13] cxenstored: add support for	systemd active sockets
Date: Thu, 3 Jul 2014 19:06:24 +0200	[thread overview]
Message-ID: <20140703170624.GE27687@wotan.suse.de> (raw)
In-Reply-To: <1404378785.14865.8.camel@kazak.uk.xensource.com>

On Thu, Jul 03, 2014 at 10:13:05AM +0100, Ian Campbell wrote:
> On Wed, 2014-07-02 at 21:00 +0200, Luis R. Rodriguez wrote:
> > On Wed, Jul 02, 2014 at 02:02:38PM +0100, Ian Campbell wrote:
> > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > +int xs_validate_active_socket(const char *connect_to)
> > > > +{
> > > > +	char sock[30];
> > > > +
> > > > +	/* We have to null terminate the socket path */
> > > > +	memset(sock, '\0', sizeof(sock));
> > > > +	memcpy(sock, connect_to, strlen(connect_to));
> > > 
> > > This risks overrunning sock if connect_to is longer than 30 characters.
> > 
> > Yuk, yes. A size check is required.
> > 
> > > But your use of strlen suggests that connect_to is already NULL
> > > terminated, so what is this for?
> > 
> > strlen() seems to want the string to also be null terminated
> > in order to work, and I also see that snprintf() is ultimately
> > used on the C version of the library, that should ensure its null
> > terminated. This however is not true for the ocaml version and
> > I suppose that is the root of the issue I saw that got me to
> > force null terimination as I did run into issues with this path
> > IIRC when not null terminated.
> > 
> > > > +	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
> > > > +	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {
> > > 
> > > Given that sock (or connect_to) is NULL terminated, why strncmp and not
> > > the straightforward strcmp?
> > 
> > See above.
> > 
> > > As it is I think your code would accept
> > > e.g. /var/run/xenstored/socketwibble, no?
> > 
> > It indeed would, its best if we resolve the null termination
> > issue internally then.
> 
> Yeah, I think we should write the C version according to normal C string
> conventions. If the ocaml idea of a string differs then perhaps that
> version needs to be different.

OK, or we ensure Ocaml's implementation provides a null terminated
string to try to keep the systemd interface similar, poking Dave for
feedback:

String_val() is used for the static string connect_to passed to the
C wrapper, the String_val() documentation [0] says that "there is a null
character after the last character in the string" however its unclear
if this is guaranteed if the string was originally a static Ocaml string
which was not null terminated. 

Now, its unclear which xenstored (cxenstored or oxenstored) gave me issues
that pushed me to ensure I give systemd null terminated strings but
I do know that it was one for sure and it took me quite a bit to figure
out this was needed and that this was the issue. Based on my review just
now since the cxenstored uses snprintf() for both xs_daemon_socket_ro()
and xs_daemon_socket() and since snprintf() man page says that it will
write at most size bytes (including the terminating null byte ('\0') I
am left to only grow suspcicious of the oxenstored as the probable
cause of the issues I saw. I should also highlight that the socket path
can also come from environment variables on cxenstored, XENSTORED_PATH,
and getenv() documentation doesn't say whether or not strings will be
null terminated for us, that might cause unexpected issues if used and
if it doesn't on systemd.

In v5 systemd integration implementation in which I used static structs
for the strings in C I had no issues but note that in that case I simply
used the Ocaml string (after String_val()) to and compare it to the one
on the static C array with:

	(!strcmp(connect_to, xenstore_active_sockets[i].path))

I then used the C static string for sd_is_socket_unix(), not the one
passed from cxenstored or oxenstored.

[0] http://caml.inria.fr/pub/docs/manual-ocaml-400/manual033.html

> > > Is it common in systemd support to validate the input socket's path in
> > > this way? As opposed to trusting that the systemd unit file is correct.
> > 
> > sd_is_socket_unix() is certainly advised and highly encourged. As
> > for the other check -- yes we want that given that we are using
> > two socket files specifically in order to avoid having to chmod()
> > the socket ourelves. Systemd currently doesn't support having two
> > separate sockets in one file with different permissions. From
> > what I have seen the order in which systemd sets the sockets and
> > maps them to fds will very on the unit socket files you use, this
> > approach lets us allow systemd to give them to us in any order
> > while my hope is that systemd upstream gets support for just one
> > stocket file with multiple permissions.
> 
> OK.
> 
> BTW, the permissions on these two sockets should be the same
> (read/write),

tools/xenstore/xenstored_core.c uses chmod to change the
permissions:

        if (chmod(soc_str, 0600) != 0
            || chmod(soc_str_ro, 0660) != 0)
                barf_perror("Could not chmod sockets");

> it's the owner/group which might differ.

On my latest Debian install of the master branch for legacy init
my sockets end up being owned by root, who should be owning the
sockets?

> (You need to be able to write to the ro socket to send operations,

BTW what is the _ro socket used for exactly? I couldn't find usage for
it in existing code.

> the distinction is that the ro socket will reject XS_WRITE messages)

OK, got it.

  Luis

  reply	other threads:[~2014-07-03 17:06 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 01/13] xenstored: enable usage of config.h on both xenstored and oxenstored Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 02/13] cxenstored: add support for systemd active sockets Luis R. Rodriguez
2014-07-02 13:02   ` Ian Campbell
2014-07-02 19:00     ` Luis R. Rodriguez
2014-07-03  9:13       ` Ian Campbell
2014-07-03 17:06         ` Luis R. Rodriguez [this message]
2014-07-04 14:32           ` Ian Campbell
2014-07-08  3:08             ` Luis R. Rodriguez
2014-07-17 19:45           ` Luis R. Rodriguez
2014-07-17 20:16             ` Dave Scott
2014-07-17 23:13               ` Luis R. Rodriguez
2014-07-18  9:27                 ` Anil Madhavapeddy
2014-06-13  1:18 ` [PATCH v6 03/13] oxenstored: " Luis R. Rodriguez
2014-07-02 13:08   ` Ian Campbell
2014-07-02 19:09     ` Luis R. Rodriguez
2014-07-03  8:42       ` Dave Scott
2014-07-03 17:43         ` Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 04/13] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init Luis R. Rodriguez
2014-07-02 13:08   ` Ian Campbell
2014-06-13  1:18 ` [PATCH v6 05/13] tools/xendomains: make xl the default and remove xm usage Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 06/13] tools/xendomains: do space cleanups Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper Luis R. Rodriguez
2014-06-13  7:06   ` Jacek Konieczny
2014-06-13 18:32     ` Luis R. Rodriguez
2014-07-02 13:12   ` Ian Campbell
2014-06-13  1:18 ` [PATCH v6 08/13] autoconf: xen: force a refresh with autoconf Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 09/13] autoconf: update m4/pkg.m4 Luis R. Rodriguez
2014-07-02 13:13   ` Ian Campbell
2014-07-02 19:10     ` Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in Luis R. Rodriguez
2014-07-02 13:34   ` Ian Campbell
2014-07-02 19:32     ` Luis R. Rodriguez
2014-07-03  9:15       ` Ian Campbell
2014-07-03 18:30         ` Luis R. Rodriguez
2014-07-04 14:33           ` Ian Campbell
2014-07-08 18:41             ` Luis R. Rodriguez
2014-07-08 18:53               ` Luis R. Rodriguez
2014-07-10 16:18                 ` Ian Campbell
2014-07-14 23:41                   ` Luis R. Rodriguez
2014-07-03 18:53     ` Luis R. Rodriguez
2014-07-04 14:36       ` Ian Campbell
2014-07-08 18:52         ` Luis R. Rodriguez
2014-07-10 16:16           ` Ian Campbell
2014-07-14 23:42             ` Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 11/13] xencommons: move module list into a generic place Luis R. Rodriguez
2014-07-02 13:44   ` Ian Campbell
2014-07-02 21:56     ` Luis R. Rodriguez
2014-07-03  9:15       ` Ian Campbell
2014-06-13  1:18 ` [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference Luis R. Rodriguez
2014-07-02 13:54   ` Ian Campbell
2014-07-02 20:09     ` Luis R. Rodriguez
2014-07-03  9:20       ` Ian Campbell
2014-07-03 18:57         ` Luis R. Rodriguez
2014-07-04 14:37           ` Ian Campbell
2014-07-08 18:54             ` Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 13/13] systemd: add xen systemd service and module files Luis R. Rodriguez
2014-06-13 19:55   ` Luis R. Rodriguez
2014-06-19 19:47   ` Bastian Blank
2014-06-19 20:21     ` Luis R. Rodriguez
2014-06-19 20:26       ` Luis R. Rodriguez
2014-06-20  5:59         ` David Sutton
2014-07-02 14:02   ` Ian Campbell
2014-07-02 20:25     ` Luis R. Rodriguez
2014-06-19 19:03 ` [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
2014-07-02 14:48 ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140703170624.GE27687@wotan.suse.de \
    --to=mcgrof@suse.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=dave.scott@eu.citrix.com \
    --cc=mcgrof@do-not-panic.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).