From df3301046fc5f31881a2d4736cc5c381342ecc3d Mon Sep 17 00:00:00 2001 From: srd424 Date: Sun, 3 Jul 2022 10:21:30 +0100 Subject: [PATCH 1/2] Fix off-by-one error constructing mount options This fixes a really subtle off-by-one error constructing overlay mount options if rootfs options are provided and modern overlayfs (i.e. requiring a workdir) is used. We need to allow for the extra "," required to separate the extra options when computing the length! Signed-off-by: srd424 --- src/lxc/storage/overlay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/storage/overlay.c b/src/lxc/storage/overlay.c index f8094fada..0c3fa1220 100644 --- a/src/lxc/storage/overlay.c +++ b/src/lxc/storage/overlay.c @@ -445,7 +445,7 @@ int ovl_mount(struct lxc_storage *bdev) upper, lower, mntdata); len2 = strlen(lower) + strlen(upper) + strlen(work) + - strlen("upperdir=,lowerdir=,workdir=") + + strlen("upperdir=,lowerdir=,workdir=,") + strlen(mntdata) + 1; options_work = must_realloc(NULL, len2); ret2 = snprintf(options, len2, From 3d360cf9dbf556e5ff90b562fa3baac73821a342 Mon Sep 17 00:00:00 2001 From: srd424 Date: Sun, 3 Jul 2022 18:18:23 +0100 Subject: [PATCH 2/2] Store mount options in correct variable This was exposed by the fix in the previous commit. Signed-off-by: srd424 --- src/lxc/storage/overlay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/storage/overlay.c b/src/lxc/storage/overlay.c index 0c3fa1220..f38f3a740 100644 --- a/src/lxc/storage/overlay.c +++ b/src/lxc/storage/overlay.c @@ -448,7 +448,7 @@ int ovl_mount(struct lxc_storage *bdev) strlen("upperdir=,lowerdir=,workdir=,") + strlen(mntdata) + 1; options_work = must_realloc(NULL, len2); - ret2 = snprintf(options, len2, + ret2 = snprintf(options_work, len2, "upperdir=%s,lowerdir=%s,workdir=%s,%s", upper, lower, work, mntdata); } else {