All of lore.kernel.org
 help / color / mirror / Atom feed
* failed to launch qemu when running de-privileged (xen 4.8)
@ 2018-08-02  8:44 James Dingwall
  0 siblings, 0 replies; only message in thread
From: James Dingwall @ 2018-08-02  8:44 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian.Jackson

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-08-02  8:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-02  8:44 failed to launch qemu when running de-privileged (xen 4.8) James Dingwall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.