]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
better check for lock dir
authorTycho Andersen <tycho@tycho.ws>
Fri, 26 Jan 2018 17:43:12 +0000 (17:43 +0000)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 6 Feb 2018 12:34:36 +0000 (13:34 +0100)
Consider the case where we're running in a user namespace but in the host's
mount ns with the host's filesystem (something like
lxc-usernsexec ... lxc-execute ...), in this case, we'll be euid 0, but we
can't actually write to /run. Let's improve this locking check to make sure
we can actually write to /run before we decide to actually use it as our
locking dir.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
src/lxc/utils.c

index ec451bcd622520dc970d8c0059c71123e99d3b0f..b59caad01a6f7c347dd87244325179f90a7defd9 100644 (file)
@@ -245,8 +245,13 @@ char *get_rundir()
 {
        char *rundir;
        const char *homedir;
+       struct stat sb;
+
+       if (stat(RUNTIME_PATH, &sb) < 0) {
+               return NULL;
+       }
 
-       if (geteuid() == 0) {
+       if (geteuid() == sb.st_uid || getegid() == sb.st_gid) {
                rundir = strdup(RUNTIME_PATH);
                return rundir;
        }