xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: James Dingwall <james-xen@dingwall.me.uk>
To: xen-devel@lists.xenproject.org
Cc: Ian.Jackson@eu.citrix.com
Subject: failed to launch qemu when running de-privileged (xen 4.8)
Date: Thu, 2 Aug 2018 09:44:47 +0100	[thread overview]
Message-ID: <20180802084447.GA212987@dingwall.me.uk> (raw)

Hi,

I had a bit of a head scratcher while writing a patch for 4.8 which 
allows the qemu-dm process for a stubdom to be executed as an 
unprivileged user.  After a liberal sprinkling of log messages I found 
that my problem was related to the check of the return code from 
getpwnam_r.  In 4.11 the relevant code looks like this:


            ret = NAME##_r(spec, resultbuf, buf, buf_size, &resultp);   \
            if (ret == ERANGE) {                                        \
                buf_size += 128;                                        \
                continue;                                               \
            }                                                           \
            if (ret != 0)                                               \
                return ERROR_FAIL;                                      \
            if (resultp != NULL) {                                      \
                if (out) *out = resultp;                                \
                return 1;                                               \
            }                                                           \
            return 0;                                                   \


            if (ret != 0)                                               \
                return ERROR_FAIL;                                      \


However checking the man page for getpwnam_r (and getpwuid_r now for 
4.11) it is not just 0 which can indicate an entry is not found:

       0 or ENOENT or ESRCH or EBADF or EPERM or ...
              The given name or uid was not found.
       EINTR  A signal was caught; see signal(7).
       EIO    I/O error.
       EMFILE The per-process limit on the number of open file descriptors has been reached.
       ENFILE The system-wide limit on the total number of open files has been reached.
       ENOMEM Insufficient memory to allocate passwd structure.
       ERANGE Insufficient buffer space supplied.

In my case the domid specific qemu user was not present (just using 
xen-qemuuser-shared) and I was getting an ENOENT from getpwnam_r.
I'm sure there should be a more elegant way to write the check but
it solved my case.

+        ret = getpwnam_r(username, &pwd, buf, buf_size, &user);
+        if (ret == ERANGE) {
+            buf_size += 128;
+            continue;
+        }
+        if (ret == EINTR || ret == EIO || ret == EMFILE || ret == ENFILE || ret == ENOMEM)
+            return ERROR_FAIL;
+        if (user != NULL)
+            return 1;
+        return 0;

Thanks,
James

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

                 reply	other threads:[~2018-08-02  8:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180802084447.GA212987@dingwall.me.uk \
    --to=james-xen@dingwall.me.uk \
    --cc=Ian.Jackson@eu.citrix.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).