jail: open() extroot folder before mounting
authorDaniel Golle <daniel@makrotopia.org>
Thu, 15 Jul 2021 01:49:23 +0000 (02:49 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Thu, 15 Jul 2021 17:08:08 +0000 (18:08 +0100)
Use open() to trigger autofs mount and check extroot folder exists
before mount-binding it.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
jail/jail.c

index dca3992256d32af39441395ea5033fdb30bc713b..4cc16c8a9bb9ac5319dac63934dd3ad8b180cfbc 100644 (file)
@@ -641,6 +641,14 @@ static int build_jail_fs(void)
        }
 
        if (opts.extroot) {
+               /* use stat to trigger autofs mount */
+               DEBUG("mounting extroot from %s\n", opts.extroot);
+               int rootdirfd = open(opts.extroot, O_RDONLY | O_DIRECTORY);
+               if (rootdirfd == -1) {
+                       ERROR("extroot %s open failed %m\n", opts.extroot);
+                       return -1;
+               }
+               close(rootdirfd);
                if (mount(opts.extroot, jail_root, "bind", MS_BIND, NULL)) {
                        ERROR("extroot mount failed %m\n");
                        return -1;