From c9ad05104c83bc4890aabedc678575aad5ffa72a Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Fri, 15 Mar 2024 16:21:46 +0100 Subject: [PATCH 1/3] shmounts: terminate the forked off mount namespace capture helper Make sure to terminate the forked off mount namespace capture helper, otherwise the child will continue execution of the remaining setup code and thus cause a race with the parent which occasionally manifests itself with the /var/snap/lxd/common/shmounts being missing from the parennt's mount namespace after it has switched back to the moutn ns of pid 1. Signed-off-by: Maciej Borzecki (cherry picked from commit ab8c018506f5c735165873dc7c23df45dafe7b8b) --- shmounts/setup-shmounts.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/shmounts/setup-shmounts.c b/shmounts/setup-shmounts.c index c4ae80ab4..c5ceece03 100644 --- a/shmounts/setup-shmounts.c +++ b/shmounts/setup-shmounts.c @@ -66,6 +66,12 @@ int mkdir_p(const char *dir, mode_t mode) return 0; } +__attribute__((noreturn)) +static void die(const char *s) { + perror(s); + exit(1); +} + int setup_ns() { int wstatus; ssize_t ret; @@ -94,40 +100,41 @@ int setup_ns() { ret = lxc_read_nointr(pipe_fds[0], nspath, 1); close(pipe_fds[0]); if (ret < 0) { - return -1; + die("cannot read from pipe"); } // Create the mountpoint if (mkdir("/var/snap/lxd/common/ns", 0700) < 0 && errno != EEXIST) { - return -1; + die("cannot mkdir /var/snap/lxd/common/ns"); } // Mount a tmpfs if (mount("tmpfs", "/var/snap/lxd/common/ns", "tmpfs", 0, "size=1M,mode=0700") < 0) { - return -1; + die("cannot mount tmpfs on /var/snap/lxd/common/ns"); } // Mark the tmpfs mount as MS_PRIVATE if (mount("none", "/var/snap/lxd/common/ns", NULL, MS_REC|MS_PRIVATE, NULL) < 0) { - return -1; + die("cannot change propagation on /var/snap/lxd/common/ns"); } // Store reference to the mntns if (snprintf(nspath, PATH_MAX, "/proc/%u/ns/mnt", (unsigned)getppid()) < 0) { - return -1; + die("cannot capture reference to parent's mount ns"); } fd = open("/var/snap/lxd/common/ns/shmounts", O_CREAT | O_RDWR, 0600); if (fd < 0) { - return -1; + die("cannot open /var/snap/lxd/common/ns/shmounts"); } close(fd); if (mount(nspath, "/var/snap/lxd/common/ns/shmounts", NULL, MS_BIND, NULL) < 0) { - return -1; + die("cannot bind mount ns to /var/snap/lxd/common/ns/shmounts"); } - return 0; + /* the child is done */ + exit(0); } close(pipe_fds[0]); From 7a2d3270aba8e19b49ac6686652a4f02ff371b9e Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Tue, 22 Oct 2024 08:39:35 +0100 Subject: [PATCH 2/3] lxd: Pre LXD 5.0.4 Signed-off-by: Thomas Parrott --- snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snapcraft.yaml b/snapcraft.yaml index 4c8180281..1a672ea96 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1331,7 +1331,7 @@ parts: build-attributes: [core22-step-dependencies] source: https://github.com/canonical/lxd source-type: git - source-commit: 74f9b301a8e82d5a546a29aae8aed42637124512 # pre lxd-5.0.4 + source-commit: 2d43282f8a98e30fee355b66c8d719ef52bb8ada # pre lxd-5.0.4 after: - lxc - dqlite From 22aaef09003d1396fe678cce798f55777894b0d5 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Tue, 22 Oct 2024 08:39:48 +0100 Subject: [PATCH 3/3] go: Bump to 1.23 Signed-off-by: Thomas Parrott --- snapcraft.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snapcraft.yaml b/snapcraft.yaml index 1a672ea96..90f647141 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1341,7 +1341,7 @@ parts: - libudev-dev - pkg-config build-snaps: - - go/1.22/stable + - go/1.23/stable stage-packages: - acl - attr @@ -1433,7 +1433,7 @@ parts: - lxd - sqlite build-snaps: - - go/1.22/stable + - go/1.23/stable plugin: nil override-pull: | snapcraftctl pull @@ -1499,7 +1499,7 @@ parts: build-attributes: [core22-step-dependencies] source: snap-query/ build-snaps: - - go/1.22/stable + - go/1.23/stable plugin: nil override-build: | set -ex