[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] failed to launch qemu when running de-privileged (xen 4.8)



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@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.