From 15997e67a559d3477d34613062725689fbfeab93 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Wed, 14 Jul 2021 17:47:22 +0100 Subject: [PATCH] jail: allow rootfs to be a symbolic link Follow symbolic link to rootfs so we can use autofs symlinks in /mnt to reference volumes in config.json. Signed-off-by: Daniel Golle --- jail/jail.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/jail/jail.c b/jail/jail.c index b8878b5..dca3992 100644 --- a/jail/jail.c +++ b/jail/jail.c @@ -1325,6 +1325,8 @@ static const struct blobmsg_policy oci_root_policy[] = { static int parseOCIroot(const char *jsonfile, struct blob_attr *msg) { static char extroot[PATH_MAX] = { 0 }; + char buf[PATH_MAX]; + ssize_t len; struct blob_attr *tb[__OCI_ROOT_MAX]; char *cur; char *root_path; @@ -1349,6 +1351,21 @@ static int parseOCIroot(const char *jsonfile, struct blob_attr *msg) strncat(extroot, root_path, PATH_MAX - (strlen(extroot) + 1)); + /* follow symbolic link(s) */ + while ((len = readlink(extroot, buf, sizeof(buf)-1)) != -1) { + buf[len] = '\0'; + if (buf[0] != '/') { + cur = strrchr(extroot, '/'); + if (!cur) + return ENOTDIR; + + *(++cur) = '\0'; + strncat(extroot, buf, sizeof(extroot)-1); + } else { + strncpy(extroot, buf, sizeof(extroot)-1); + } + } + opts.extroot = extroot; if (tb[OCI_ROOT_READONLY]) -- 2.30.2