]> 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>
Wed, 7 Feb 2018 11:31:51 +0000 (12:31 +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 dbe2e810b6342e37e84e492e86aea63f7858f8ed..97892ad1e9bd77a5aaf18808ac68942efb7fbb9f 100644 (file)
@@ -214,8 +214,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;
        }