Skip to content

Commit fc7adb3

Browse files
committed
lxc/start: assume CLONE_PIDFD and clone3 are supported
We agreed to set 6.12 as a Linux kernel requirement for LXC 7.x line, it was released in Nov 2024 [1]. Let's drop fallback code for cases when CLONE_PIDFD or clone3 are not supported. CLONE_PIDFD was added in 5.2 clone3 was added in 5.3 I decided to keep fallback logic for non-supported CLONE_INTO_CGROUP for now, while it was added in 5.7. Link: torvalds/linux@adc2186 [1] Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
1 parent eed40be commit fc7adb3

1 file changed

Lines changed: 14 additions & 28 deletions

File tree

src/lxc/start.c

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,8 +1756,17 @@ static inline int do_share_ns(void *arg)
17561756
flags |= CLONE_PARENT;
17571757
handler->pid = lxc_raw_clone_cb(do_start, handler, CLONE_PIDFD | flags,
17581758
&handler->pidfd);
1759-
if (handler->pid < 0)
1759+
if (handler->pid < 0) {
1760+
ERROR("Failed to clone process");
17601761
return -1;
1762+
}
1763+
1764+
if (handler->pidfd < 0) {
1765+
kill(handler->pid, SIGKILL);
1766+
handler->pid = -1;
1767+
ERROR("CLONE_PIDFD isn't supported");
1768+
return -1;
1769+
}
17611770

17621771
return 0;
17631772
}
@@ -1902,7 +1911,7 @@ static int lxc_spawn(struct lxc_handler *handler)
19021911
/* Try to spawn directly into target cgroup. */
19031912
handler->pid = lxc_clone3(&clone_args, CLONE_ARGS_SIZE_VER2);
19041913
if (handler->pid < 0) {
1905-
SYSTRACE("Failed to spawn container directly into target cgroup");
1914+
SYSWARN("Failed to spawn container directly into target cgroup");
19061915

19071916
/* Kernel might simply be too old for CLONE_INTO_CGROUP. */
19081917
resolve_cgroup_clone_flags(handler);
@@ -1913,31 +1922,6 @@ static int lxc_spawn(struct lxc_handler *handler)
19131922
TRACE("Spawned container directly into target cgroup via cgroup2 fd %d", cgroup_fd);
19141923
}
19151924

1916-
/* Kernel might be too old for clone3(). */
1917-
if (handler->pid < 0) {
1918-
SYSTRACE("Failed to spawn container via clone3()");
1919-
1920-
/*
1921-
* In contrast to all other architectures arm64 verifies that
1922-
* the argument we use to retrieve the pidfd with is
1923-
* initialized to 0. But we need to be able to initialize it to
1924-
* a negative value such as our customary -EBADF so we can
1925-
* detect whether this kernel supports pidfds. If the syscall
1926-
* returns and the pidfd variable is set to something >= 0 then
1927-
* we know this is a kernel supporting pidfds. But if we can't
1928-
* set it to -EBADF then this won't work since 0 is a valid
1929-
* file descriptor too. And since legacy clone silently ignores
1930-
* unknown flags we are left without any way to detect support
1931-
* for pidfds. So let's special-case arm64 to not fail starting
1932-
* containers.
1933-
*/
1934-
#if defined(__aarch64__)
1935-
handler->pid = lxc_raw_legacy_clone(handler->clone_flags & ~CLONE_PIDFD, NULL);
1936-
#else
1937-
handler->pid = lxc_raw_legacy_clone(handler->clone_flags, &handler->pidfd);
1938-
#endif
1939-
}
1940-
19411925
if (handler->pid < 0) {
19421926
SYSERROR(LXC_CLONE_ERROR);
19431927
goto out_delete_net;
@@ -1957,8 +1941,10 @@ static int lxc_spawn(struct lxc_handler *handler)
19571941
goto out_delete_net;
19581942

19591943
/* Verify that we can actually make use of pidfds. */
1960-
if (!lxc_can_use_pidfd(handler->pidfd))
1944+
if (!lxc_can_use_pidfd(handler->pidfd)) {
19611945
close_prot_errno_disarm(handler->pidfd);
1946+
goto out_delete_net;
1947+
}
19621948

19631949
ret = strnprintf(pidstr, 20, "%d", handler->pid);
19641950
if (ret < 0)

0 commit comments

Comments
 (0)