]> git.proxmox.com Git - mirror_lxc.git/log
mirror_lxc.git
13 months agoRelease LXC 5.0.3 stable-5.0
Stéphane Graber [Tue, 25 Jul 2023 22:00:11 +0000 (18:00 -0400)]
Release LXC 5.0.3

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
13 months agogithub: Update for main branch
Stéphane Graber [Mon, 24 Jul 2023 15:37:53 +0000 (11:37 -0400)]
github: Update for main branch

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
13 months agoCONTRIBUTING: add a note on AI generated code
Serge Hallyn [Mon, 17 Jul 2023 12:57:17 +0000 (07:57 -0500)]
CONTRIBUTING: add a note on AI generated code

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
13 months agoget_hierarchy: dont WARN about no usable controller
Serge Hallyn [Thu, 6 Jul 2023 23:34:59 +0000 (18:34 -0500)]
get_hierarchy: dont WARN about no usable controller

If I start a container with loglevel WARN, and (on a pretty
stock ubuntu) do lxc-info -n $c, I get

lxc-start media 20230706233337.765 WARN     cgfsng - cgroups/cgfsng.c:get_hierarchy:142 - There is no useable cpuacct controller
lxc-start media 20230706233337.765 WARN     cgfsng - cgroups/cgfsng.c:get_hierarchy:142 - There is no useable blkio controller

I don't think that's worth WARNing about, so change it to
INFO.

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
13 months agogithub: Add DCO/target tests
Stéphane Graber [Thu, 22 Jun 2023 01:45:21 +0000 (21:45 -0400)]
github: Add DCO/target tests

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
13 months agoexplicitly convert *mainloop_handler to __u64
Anatolii Gryzlov [Wed, 24 May 2023 23:26:14 +0000 (02:26 +0300)]
explicitly convert *mainloop_handler to __u64

GCC treats such conversion as warning, while Clang-15 aborts compilation

Signed-off-by: Anatolii Gryzlov <agryzlov.mosbrew@gmail.com>
13 months agotests: fix parse_config_file seccomp test
Magali Lemes [Mon, 15 May 2023 23:31:37 +0000 (20:31 -0300)]
tests: fix parse_config_file seccomp test

Link: https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/1980218
Check if seccomp is enabled before throwing error.

Signed-off-by: Magali Lemes <magali.lemes@canonical.com>
13 months agosrc/tests: Fix container creation errors
Stéphane Graber [Thu, 4 May 2023 14:58:40 +0000 (16:58 +0200)]
src/tests: Fix container creation errors

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
13 months agorename functions which clash with libsystemd's
Serge Hallyn [Sat, 22 Apr 2023 00:10:14 +0000 (19:10 -0500)]
rename functions which clash with libsystemd's

If statically linking against both liblxc and libsystemd, some
function names conflict:

mkdir_p fd_cloexec path_simplify is_dir is_fs_type

Rename those to lxc_\0, as:

for sym in mkdir_p fd_cloexec path_simplify is_dir is_fs_type; do
git grep "$sym" | awk -F: '{ print $1 }' | sort | uniq | xargs sed -i "s/$sym/lxc_$sym/g"
done

(the above loop wrongly replaces is_dir in meson.build, but
c'est la vie)

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
13 months agomainloop: io_uring: disable IORING_POLL_ADD_MULTI
Alexander Mikhalitsyn [Fri, 21 Apr 2023 17:23:06 +0000 (19:23 +0200)]
mainloop: io_uring: disable IORING_POLL_ADD_MULTI

Let's disable IORING_POLL_ADD_MULTI to workaround an issue
with false-positive POLLIN events in CQ.

In my local setup I managed to fix an issue without this
by making terminal FDs non-blocking, but during full
testsuite execution in Jenkins it was found that issue
still persists. So, let's add this ugly workaround too.

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
13 months agoterminal: make a terminal FDs non-blocking
Alexander Mikhalitsyn [Fri, 21 Apr 2023 16:38:53 +0000 (18:38 +0200)]
terminal: make a terminal FDs non-blocking

Let's prevent freezes on read(2) by making a terminal FDs non-blocking.

It was discovered that there is an issue with io_uring mainloop when
multishot poll (IORING_POLL_ADD_MULTI) mode is enabled. Sometimes
false-positive poll events are put into a CQ. It makes further read(2)
stuck forever and blocks all mainloop processing for an infinite time.

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
13 months agofile_utils: add fd_make_nonblocking helper
Alexander Mikhalitsyn [Fri, 21 Apr 2023 16:11:46 +0000 (18:11 +0200)]
file_utils: add fd_make_nonblocking helper

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
13 months agofile_utils: rename fd_make_nonblocking to fd_make_blocking
Alexander Mikhalitsyn [Fri, 21 Apr 2023 16:08:27 +0000 (18:08 +0200)]
file_utils: rename fd_make_nonblocking to fd_make_blocking

Currently, fd_make_nonblocking does exactly the opposite thing,
it clears O_NONBLOCK flag and makes fd blocking.

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
13 months agosetproctitle(): Handle potential NULL return from strrchr()
Solar Designer [Tue, 11 Apr 2023 13:29:46 +0000 (15:29 +0200)]
setproctitle(): Handle potential NULL return from strrchr()

Signed-off-by: Solar Designer <solar@openwall.com>
13 months agomake setproctitle()'s /proc/pid/stat parsing safe
Tycho Andersen [Mon, 10 Apr 2023 23:12:24 +0000 (17:12 -0600)]
make setproctitle()'s /proc/pid/stat parsing safe

it turns out that our parsing of /proc/pid/stat was not safe in general
(though probably safe for lxc, since our executable names do not contain
spaces).

Let's fix this by looking backwards through the file for ), and then
continuing on from there.

This was reported to me by Solar Designer, who pointed me to this thread:
https://twitter.com/solardiz/status/1634204168545001473

Indeed, this is a lot of tap dancing to work around the kernel's 16
character executable limit. Perhaps I'll send a kernel patch to raise that
limit next.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
13 months agoconsole-log test: make sure container is stopped before restarting
Serge Hallyn [Sun, 19 Mar 2023 20:31:18 +0000 (15:31 -0500)]
console-log test: make sure container is stopped before restarting

Closes #4237

Signed-off-by: Serge Hallyn <serge@hallyn.com>
13 months agotree-wide: convert fcntl(FD_CLOEXEC) to SOCK_CLOEXEC
Alexander Mikhalitsyn [Fri, 17 Mar 2023 12:43:34 +0000 (13:43 +0100)]
tree-wide: convert fcntl(FD_CLOEXEC) to SOCK_CLOEXEC

- replace accept() + fcntl(FD_CLOEXEC) with accept4(..., SOCK_CLOEXEC)
- remove fcntl(FD_CLOEXEC) in lxc_server_init() as we already set
SOCK_CLOEXEC in lxc_abstract_unix_open().

See also: ad9429e52 ("tree-wide: make socket SOCK_CLOEXEC")
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
13 months agoAllow fuse mounts in apparmor start-container.
Scott Moser [Fri, 24 Feb 2023 21:48:10 +0000 (16:48 -0500)]
Allow fuse mounts in apparmor start-container.

Unprivledged user should be able to do fuse mounts during start-container.
Specifically this solves the problem for un-priv fuse mounting via
pre-hook.

Signed-off-by: Scott Moser <smoser@brickies.net>
13 months agoAdd support for squashfs images in oci via atomfs
Scott Moser [Tue, 21 Feb 2023 18:31:06 +0000 (13:31 -0500)]
Add support for squashfs images in oci via atomfs

This adds support to the oci template for squashfs images.
It uses 'atomfs' from [1] to accomplish this.

Squashfs images (media type
application/vnd.stacker.image.layer.squashfs+zstd+verity) have several
benefits compared to tar+gz:

 * immediately mountable
 * read-only filesystem
 * verity data present in oci manifest.

I presented this at Fosdem 2023 at [2].

The 'atomfs' program can be replaced by passing '--mount-helper'
argument to the oci template.

    mount-helper mount oci:<oci_dir>:<oci_name> <mountpoint>
    mount-helper umount <mountpoint>

[1] https://github.com/project-machine/atomfs
[2] https://fosdem.org/2023/schedule/event/container_secure_storage/

Signed-off-by: Scott Moser <smoser@brickies.net>
13 months agoapparmor: don't try to mmap empty files
Wolfgang Bumiller [Mon, 27 Feb 2023 10:02:43 +0000 (11:02 +0100)]
apparmor: don't try to mmap empty files

In case empty profile files linger somehow (eg. powerloss or
oom killer etc. between creating and writing the file) we
tried to use mmap() with a length of 0 which is invalid.
Let's treat this as if it did not exist.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
13 months agoinitutils: use PRIu64 for uint64_t in setproctitle
Alexander Mikhalitsyn [Thu, 16 Feb 2023 12:29:56 +0000 (13:29 +0100)]
initutils: use PRIu64 for uint64_t in setproctitle

Kernel UAPI provides as with the following declaration:
/*
 * This structure provides new memory descriptor
 * map which mostly modifies /proc/pid/stat[m]
 * output for a task. This mostly done in a
 * sake of checkpoint/restore functionality.
 */
struct prctl_mm_map {
__u64 start_code; /* code section bounds */
__u64 end_code;
__u64 start_data; /* data section bounds */
__u64 end_data;
__u64 start_brk; /* heap for brk() syscall */
__u64 brk;
__u64 start_stack; /* stack starts at */
__u64 arg_start; /* command line arguments bounds */
__u64 arg_end;
__u64 env_start; /* environment variables bounds */
__u64 env_end;
__u64 *auxv; /* auxiliary vector */
__u32 auxv_size; /* vector size */
__u32 exe_fd; /* /proc/$pid/exe link file */
};

Let's use appropriate types/format specifiers everywhere.

Issue #4268

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
13 months agolxc-net.in: fix nftables syntax for IPv6 NAT
Quentin Lyons [Sun, 12 Feb 2023 02:03:42 +0000 (02:03 +0000)]
lxc-net.in: fix nftables syntax for IPv6 NAT

The nftables masquarade rule for IPv6 was using the IPv4 syntax. This
resulted in the following error when starting the lxc-net.service with
LXC_IPV6_NAT="true" and nftables:

    Feb 11 18:54:54 pc lxc-net[4936]: Error: conflicting protocols specified: ip6 vs. ip
    Feb 11 18:54:54 pc lxc-net[4936]:                              ^^^^^^^^
    Feb 11 18:54:54 pc lxc-net[4917]: Failed to setup lxc-net.
    Feb 11 18:54:54 pc systemd[1]: lxc-net.service: Main process exited, code=exited, status=1/FAILURE
    Feb 11 18:54:54 pc systemd[1]: lxc-net.service: Failed with result 'exit-code'.
    Feb 11 18:54:54 pc systemd[1]: Failed to start LXC network bridge setup.

Signed-off-by: Quentin Lyons <36303164+n0p90@users.noreply.github.com>
13 months agoFix strlcat's return value checks
Ariel Miculas [Tue, 7 Feb 2023 11:10:50 +0000 (13:10 +0200)]
Fix strlcat's return value checks

Alternatively we could have used safe_strlcat, but it's not used
anywhere and there's also no safe_strlcpy

Signed-off-by: Ariel Miculas <amiculas@cisco.com>
13 months agoFix typo: bev_type -> bdev_type
Ariel Miculas [Mon, 30 Jan 2023 16:20:31 +0000 (18:20 +0200)]
Fix typo: bev_type -> bdev_type

Signed-off-by: Ariel Miculas <amiculas@cisco.com>
19 months agodrop broken lxc-test-fuzzers
Serge Hallyn [Fri, 20 Jan 2023 21:18:00 +0000 (15:18 -0600)]
drop broken lxc-test-fuzzers

Closes #4261

Signed-off-by: Serge Hallyn <serge@hallyn.com>
20 months agoRelease LXC 5.0.2 lxc-5.0.2
Stéphane Graber [Mon, 16 Jan 2023 21:08:50 +0000 (16:08 -0500)]
Release LXC 5.0.2

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
20 months agoFix build error on sparc64 caused by using the gold linker
Mathias Gibbens [Tue, 10 Jan 2023 23:20:14 +0000 (23:20 +0000)]
Fix build error on sparc64 caused by using the gold linker

Signed-off-by: Mathias Gibbens <gibmat@debian.org>
20 months agolxc-default-cgns apparmor profile: allow overlay mounts
Serge Hallyn [Mon, 9 Jan 2023 19:36:45 +0000 (13:36 -0600)]
lxc-default-cgns apparmor profile: allow overlay mounts

Signed-off-by: Serge Hallyn <serge@hallyn.com>
20 months agolxc_user_nic: fix get_mtu() error handling
Alexander Mikhalitsyn [Fri, 6 Jan 2023 15:20:02 +0000 (16:20 +0100)]
lxc_user_nic: fix get_mtu() error handling

get_mtu() returns int, but "mtu" variable has unsigned int type.
It leads to logical error in error handling, which can end up
with strange -EINVAL error in lxc_veth_create(), cause (mtu > 0)
condition is met, but negative "mtu" value is too large when set
as mtu for network device.

Issue #4232

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
20 months agoPatching an incoming CVE (CVE-2022-47952)
Maher Azzouzi [Sun, 25 Dec 2022 12:50:25 +0000 (13:50 +0100)]
Patching an incoming CVE (CVE-2022-47952)

lxc-user-nic in lxc through 5.0.1 is installed setuid root, and may
allow local users to infer whether any file exists, even within a
protected directory tree, because "Failed to open" often indicates
that a file does not exist, whereas "does not refer to a network
namespace path" often indicates that a file exists. NOTE: this is
different from CVE-2018-6556 because the CVE-2018-6556 fix design was
based on the premise that "we will report back to the user that the
open() failed but the user has no way of knowing why it failed";
however, in many realistic cases, there are no plausible reasons for
failing except that the file does not exist.

PoC:
> % ls /l
> ls: cannot open directory '/l': Permission denied
> % /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic delete lol lol /l/h/tt h h
> cmd/lxc_user_nic.c: 1096: main: Failed to open "/l/h/tt" <----- file does not exist.
> % /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic delete lol lol /l/h/t h h
> cmd/lxc_user_nic.c: 1101: main: Path "/l/h/t" does not refer to a network namespace path <---- file exist!

Signed-off-by: MaherAzzouzi <maherazz04@gmail.com>
Acked-by: Serge Hallyn <serge@hallyn.com>
20 months agobuild: force linking against liblxc
Christian Brauner [Wed, 4 Jan 2023 15:45:03 +0000 (16:45 +0100)]
build: force linking against liblxc

We really need to split up our code into better chunks so we avoid all of this
duplicated compilation.

Fixes: https://github.com/lxc/lxc/issues/4249
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
20 months agocheckconfig: Fix filesystem capability check
Stéphane Graber [Tue, 3 Jan 2023 23:02:44 +0000 (18:02 -0500)]
checkconfig: Fix filesystem capability check

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
20 months agocheckconfig: Tweak cgroup handling
Stéphane Graber [Tue, 3 Jan 2023 23:02:08 +0000 (18:02 -0500)]
checkconfig: Tweak cgroup handling

Only run the Cgroup V1 checks if we're not on a fully functional CGroup
V2 system.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
20 months agocheckconfig: Tweak layout
Stéphane Graber [Tue, 3 Jan 2023 22:43:01 +0000 (17:43 -0500)]
checkconfig: Tweak layout

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
20 months agocheckconfig: Hide version if no lxc-start
Stéphane Graber [Tue, 3 Jan 2023 22:42:47 +0000 (17:42 -0500)]
checkconfig: Hide version if no lxc-start

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
20 months agocheckconfig: Fix mixed tabs/spaces
Stéphane Graber [Tue, 3 Jan 2023 22:39:44 +0000 (17:39 -0500)]
checkconfig: Fix mixed tabs/spaces

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
20 months agosrc/lxc/meson.build: fix build without apparmor
Fabrice Fontaine [Thu, 29 Dec 2022 13:42:45 +0000 (14:42 +0100)]
src/lxc/meson.build: fix build without apparmor

Don't build lsm/apparmor.c if apparmor is explicitly disabled by the
user to avoid the following build failure with gcc 4.8:

/home/buildroot/autobuild/run/instance-3/output-1/host/arm-buildroot-linux-gnueabi/sysroot/usr/include/bits/fcntl2.h: In function '__apparmor_process_label_open.isra.0':
/home/buildroot/autobuild/run/instance-3/output-1/host/arm-buildroot-linux-gnueabi/sysroot/usr/include/bits/fcntl2.h:50:24: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
    __open_missing_mode ();
                        ^

Fixes:
 - http://autobuild.buildroot.org/results/c9f05ad264543adf429badb99310905427092772

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
21 months agobuild: use cc.get_define to detect FS_CONFIG_* symbols
Aleksa Sarai [Fri, 28 Oct 2022 01:50:41 +0000 (12:50 +1100)]
build: use cc.get_define to detect FS_CONFIG_* symbols

For some reason, openSUSE has a very strange layout in sys/mount.h where
the definition of all of the FS_CONFIG_* idents are present but are
ifdef'd out in such a way that they will never be defined in an actual
build:

  #define FSOPEN_CLOEXEC          0x00000001
  /* ... */
  #ifndef FSOPEN_CLOEXEC
  enum fsconfig_command
  {
    FSCONFIG_SET_FLAG       = 0,    /* Set parameter, supplying no value */
  # define FSCONFIG_SET_FLAG FSCONFIG_SET_FLAG
  /* ... */
  };
  #endif

Unfortunately, while cc.has_header_symbol is faster, it cannot handle
this which results in compilation errors on openSUSE because the
FS_CONFIG_* symbols are actually not defined when compiling even though
the ident is present in the header. Switching to cc.get_define fixes
this issue.

Fixes: cbabe8abf11e ("build: check for FS_CONFIG_* header symbol in sys/mount.h")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
21 months agocgroups: fix cgroup layout detection in __initialize_cgroups
Alexander Mikhalitsyn [Mon, 12 Dec 2022 11:28:31 +0000 (12:28 +0100)]
cgroups: fix cgroup layout detection in __initialize_cgroups

It looks like we made a mistake while detecting cgroup layout,
we are always set CGFSNG_LAYOUT_UNIFIED bit.

Reported-by: coverity (CID #1497115)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
21 months agostate: additional check in lxc_wait to prevent OOB
Alexander Mikhalitsyn [Mon, 12 Dec 2022 10:26:21 +0000 (11:26 +0100)]
state: additional check in lxc_wait to prevent OOB

I can't see a real problem here, but let's just add a check
just in case.

Reported-by: coverity (CID #1517314)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
21 months agocgroups: check snprintf retval in unpriv_systemd_create_scope
Alexander Mikhalitsyn [Fri, 9 Dec 2022 18:34:54 +0000 (19:34 +0100)]
cgroups: check snprintf retval in unpriv_systemd_create_scope

Reported-by: coverity (CID #1517315)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
21 months agocgroups: fix buffer out-of-bounds access in enable_controllers_delegation
Alexander Mikhalitsyn [Fri, 9 Dec 2022 18:22:56 +0000 (19:22 +0100)]
cgroups: fix buffer out-of-bounds access in enable_controllers_delegation

Reported-by: coverity (CID #1517317)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
21 months agonetwork: always initialize struct nl_handler
Alexander Mikhalitsyn [Fri, 9 Dec 2022 17:33:04 +0000 (18:33 +0100)]
network: always initialize struct nl_handler

Despite the fact that struct nl_handler is filled zeros
in netlink_open() there are two cases where we have possible
exit paths from the function before netlink_open() is called.

At the same time we have cleaner registered:
call_cleaner(netlink_close)

Two cases:
- netdev_get_flag
- lxc_ipvlan_create

If we are exiting from these functions before netlink_open()
is called we will close random file descriptor by reading
it from (struct nl_handler)->fd.

Let's just properly initialize this structure in all cases
to prevent this bug in the future.

Reported-by: coverity (CID #1517319 and #1517316)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
21 months agoapparmor: properly check lxc_strmmap ret value
Alexander Mikhalitsyn [Fri, 9 Dec 2022 17:31:04 +0000 (18:31 +0100)]
apparmor: properly check lxc_strmmap ret value

Reported-by: coverity (CID #1517320)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
21 months agogithub: fix coverity (add libpam-dev)
Alexander Mikhalitsyn [Thu, 8 Dec 2022 15:12:14 +0000 (16:12 +0100)]
github: fix coverity (add libpam-dev)

Should fix
meson.build:494:0: ERROR: C header 'security/pam_modules.h' not found

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
21 months agogithub: fix coverity build
Alexander Mikhalitsyn [Wed, 7 Dec 2022 11:08:55 +0000 (12:08 +0100)]
github: fix coverity build

1. install meson (ninja is dependency)
2. run meson setup before ninja build

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
21 months agoconf: ensure mount tunnel is a dependent mount
Christian Brauner [Tue, 29 Nov 2022 20:36:43 +0000 (21:36 +0100)]
conf: ensure mount tunnel is a dependent mount

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agoapparmor: allow shared mounts in start-container.in
Christian Brauner [Tue, 29 Nov 2022 19:58:14 +0000 (20:58 +0100)]
apparmor: allow shared mounts in start-container.in

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agoconf: create separate peer group for container's root
Christian Brauner [Thu, 24 Nov 2022 08:30:19 +0000 (09:30 +0100)]
conf: create separate peer group for container's root

Finally, we turn the rootfs into a shared mount. Note, that this
doesn't reestablish mount propagation with the hosts mount
namespace. Instead we'll create a new peer group.

We're doing this because most workloads do rely on the rootfs being
a shared mount. For example, systemd daemon like sytemd-udevd run in
their own mount namespace. Their mount namespace has been made a
dependent mount (MS_SLAVE) with the host rootfs as it's dominating
mount. This means new mounts on the host propagate into the
respective services.

This is broken if we leave the container's rootfs a dependent mount.
In which case both the container's rootfs and the service's rootfs
will be dependent mounts with the host's rootfs as their dominating
mount. So if you were to mount over the rootfs from the host it
would not just propagate into the container's mount namespace it
would also propagate into the service. That's nonsense semantics for
nearly all relevant use-cases. Instead, establish the container's
rootfs as a separate peer group mirroring the behavior on the host.

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agocgroups: only allocate user namespace if we have to
Christian Brauner [Thu, 24 Nov 2022 11:44:15 +0000 (12:44 +0100)]
cgroups: only allocate user namespace if we have to

If the monitor runs as root we can assume it's able to remove the cgroups it
created when the container started.

Fixes: https://github.com/lxc/lxd/issues/11108
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agocgroups: use userns_exec_full() during cgroup removal
Christian Brauner [Thu, 24 Nov 2022 11:41:04 +0000 (12:41 +0100)]
cgroups: use userns_exec_full() during cgroup removal

When removing cgroups we can't always use the minimal idmap if the user has
specified a specific map for the container instead of just a simple one.
Execute cgroup removal under the full map.

Fixes: https://github.com/lxc/lxd/issues/11108
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agoREADME: remove lgtm
Christian Brauner [Thu, 24 Nov 2022 08:46:24 +0000 (09:46 +0100)]
README: remove lgtm

It's more or less dead. If we care about a service like this we should use
something else.

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agotests: lxc-test-reboot: Fix build on ia64
Mathias Gibbens [Sat, 19 Nov 2022 15:14:47 +0000 (15:14 +0000)]
tests: lxc-test-reboot: Fix build on ia64

Add the prototype for __clone2(...) that is used on ia64, and adjust the
code to use it via macro tests.

Verified that the code compiles properly on Debian's ia64 porterbox
(yttrium), but was unable to actually run as lxc-test-reboot requires
root privileges.

Signed-off-by: Mathias Gibbens <gibmat@debian.org>
21 months agoUnroll IN_SET since the max usage is 2 elements check
HisShadow [Tue, 25 Oct 2022 17:43:21 +0000 (20:43 +0300)]
Unroll IN_SET since the max usage is 2 elements check

Signed-off-by: HisShadow <shadowpilot34@gmail.com>
21 months agotests: lxc-test-checkpoint-restore: use trap to do cleanup
Po-Hsu Lin [Wed, 19 Oct 2022 06:17:29 +0000 (14:17 +0800)]
tests: lxc-test-checkpoint-restore: use trap to do cleanup

This test will fail on Jammy 5.15, and because of the "set -e" it
will never go through the lxc-stop and lxc-destroy code in the end
of this script. Thus the lxc-test-criu container will not be removed.

Compose a cleanup() and use TRAP to solve this problem.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
21 months agotools: lxc-destroy: update help message for --force
Po-Hsu Lin [Wed, 19 Oct 2022 03:59:34 +0000 (11:59 +0800)]
tools: lxc-destroy: update help message for --force

Looks like the --force is a flag to stop a running container before
destroying it.

Update the help message accordingly.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
21 months agolxc/attach: Detect EACCES from execvp and convert to 126 exit status
Thomas Parrott [Thu, 13 Oct 2022 14:33:30 +0000 (15:33 +0100)]
lxc/attach: Detect EACCES from execvp and convert to 126 exit status

Before:

  sudo lxc-attach -n test /etc/passwd ; echo $?
  lxc-attach: test: ../src/lxc/attach.c: lxc_attach_run_command: 1841 Permission denied - Failed to exec "/etc/passwd"
  255

After:

  sudo lxc-attach -n test /etc/passwd ; echo $?
  lxc-attach: test: ../src/lxc/attach.c: lxc_attach_run_command: 1841 Permission denied - Failed to exec "/etc/passwd"
  126

Which better aligns with bash:

  /etc/passwd; echo $?
  bash: /etc/passwd: Permission denied
  126

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
21 months agolxc-attach: Fix lost return codes of spawned processes that are killed
Mohammed Ajmal Siddiqui [Wed, 5 Oct 2022 06:50:58 +0000 (12:20 +0530)]
lxc-attach: Fix lost return codes of spawned processes that are killed

lxc-attach swallows the return codes of processes that are terminated
via a signal, and by default exits with a return code of 0 (i.e.
indicating success) even if the command it tried to execute was
terminated.

This patch fixes it by explicitly checking if the process was terminated
via a signal, and returning an appropriate exit code.

Note that we add 128 to the signal value to generate the exit code
because by convention the exit code is 128 + signal number. e.g. if a
process is killed via signal 9, then the error code is 9 + 128 = 137.

Signed-off-by: Mohammed Ajmal Siddiqui <ajmalsiddiqui21@gmail.com>
21 months agoUpdate README.md
DarkGuySM [Sun, 2 Oct 2022 10:06:50 +0000 (15:36 +0530)]
Update README.md

Corrected grammar in readme.

Signed-off-by: DarkGuySM <78262720+DarkGuySM@users.noreply.github.com>
21 months agoconf: allow cross-device links
Christian Brauner [Wed, 14 Sep 2022 14:21:20 +0000 (16:21 +0200)]
conf: allow cross-device links

Fixes: https://github.com/lxc/lxd/issues/10914
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agobuild(deps): bump actions/checkout from 2 to 3
dependabot[bot] [Mon, 12 Sep 2022 13:31:52 +0000 (13:31 +0000)]
build(deps): bump actions/checkout from 2 to 3

Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
21 months agoUpdate cifuzz.yml
Alex [Thu, 1 Sep 2022 14:52:05 +0000 (15:52 +0100)]
Update cifuzz.yml

Signed-off-by: sashashura <93376818+sashashura@users.noreply.github.com>
Signed-off-by: Alex <93376818+sashashura@users.noreply.github.com>
21 months agofix error message when use tools with -? option
Neil.wrz [Thu, 1 Sep 2022 09:13:03 +0000 (02:13 -0700)]
fix error message when use tools with -? option

Signed-off-by: Neil.wrz <wangrunze13@huawei.com>
21 months agouse sd_bus_call_method_async to replace the asyncv one
Chen Qi [Thu, 25 Aug 2022 12:45:53 +0000 (05:45 -0700)]
use sd_bus_call_method_async to replace the asyncv one

The sd_bus_call_method_asyncv's 10th parameter is of type
va_list and supplying NULL when invoking it causes compilation
error. Just replace it with the async one.

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
21 months agotree-wide: split open helpers into open_utils.h
Christian Brauner [Wed, 17 Aug 2022 07:58:34 +0000 (09:58 +0200)]
tree-wide: split open helpers into open_utils.h

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agobuild: prevent the inclusion of linux/mount.h with a hack
Christian Brauner [Wed, 17 Aug 2022 07:48:32 +0000 (09:48 +0200)]
build: prevent the inclusion of linux/mount.h with a hack

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agomount_utils: remove conf.h include
Christian Brauner [Wed, 17 Aug 2022 07:46:14 +0000 (09:46 +0200)]
mount_utils: remove conf.h include

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agomount: move mount utilities from syscall_wrappers.h into mount_utils.h
Christian Brauner [Wed, 17 Aug 2022 07:44:34 +0000 (09:44 +0200)]
mount: move mount utilities from syscall_wrappers.h into mount_utils.h

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agotree-wide: minimize liburing.h inclusion
Christian Brauner [Wed, 17 Aug 2022 07:39:25 +0000 (09:39 +0200)]
tree-wide: minimize liburing.h inclusion

because it brings in linux/fs.h and defines struct open_how.

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agomeson: fix docbook2x detection
Cameron Nemo [Wed, 17 Aug 2022 03:30:39 +0000 (20:30 -0700)]
meson: fix docbook2x detection

docbook2man can sometimes be docbook2x and other times be docbook-utils.
Rather than compare paths, use version constraints to detect version.

Signed-off-by: Cameron Nemo <cam@nohom.org>
21 months agotree-wide: use struct open_how directly
Christian Brauner [Wed, 10 Aug 2022 10:18:49 +0000 (12:18 +0200)]
tree-wide: use struct open_how directly

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agotree-wide: use struct clone_args directly
Christian Brauner [Wed, 10 Aug 2022 10:03:54 +0000 (12:03 +0200)]
tree-wide: use struct clone_args directly

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agotree-wide: wipe direct or indirect linux/mount.h inclusion
Christian Brauner [Wed, 10 Aug 2022 09:42:52 +0000 (11:42 +0200)]
tree-wide: wipe direct or indirect linux/mount.h inclusion

It is incompatible with sys/mount.h and causes massive headaches.

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agobuild: check for FS_CONFIG_* header symbol in sys/mount.h
Christian Brauner [Tue, 9 Aug 2022 15:19:40 +0000 (17:19 +0200)]
build: check for FS_CONFIG_* header symbol in sys/mount.h

Fixes: #4176
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
21 months agogitignore: Simplify
Stéphane Graber [Mon, 1 Aug 2022 21:45:52 +0000 (17:45 -0400)]
gitignore: Simplify

The move to meson has made it so that all rendered/built files are now
nicely self-contained. This lets us greatly simplify our gitignore,
effectively just ignoring release tarballs and the few usual temporary
files we may deal with during development.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
21 months agoMerge pull request #4227 from rchincha/stable-5.0
Christian Brauner [Wed, 23 Nov 2022 23:26:06 +0000 (00:26 +0100)]
Merge pull request #4227 from rchincha/stable-5.0

meson.build: strip newline for variable assignments

21 months agomeson.build: strip newline for variable assignments
Ramkumar Chinchani [Wed, 23 Nov 2022 19:49:30 +0000 (19:49 +0000)]
meson.build: strip newline for variable assignments

Unfortunately, builds using alpine:edge still break!
Apparently, run_command(...).stdout() must be strip()'ed for variable
assignments

Addendum to d5600cf76a4d932a03ea75aea6dd6c997a4e2f35
Fixes issue #4223

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
21 months agoMerge pull request #4224 from rchincha/stable-5.0
Christian Brauner [Wed, 23 Nov 2022 08:14:14 +0000 (09:14 +0100)]
Merge pull request #4224 from rchincha/stable-5.0

meson.build: strip newlines from git output

21 months agomeson.build: strip newlines from git output
Ramkumar Chinchani [Tue, 22 Nov 2022 18:08:03 +0000 (18:08 +0000)]
meson.build: strip newlines from git output

Fixes issue #4223

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
21 months agoMerge pull request #4225 from smoser/stable-5.0/cherry-pick-static-lib
Christian Brauner [Tue, 22 Nov 2022 14:23:14 +0000 (15:23 +0100)]
Merge pull request #4225 from smoser/stable-5.0/cherry-pick-static-lib

src/lxc/meson.build: fix the static library path

21 months agosrc/lxc/meson.build: fix the static library path
Serge Hallyn [Sat, 12 Nov 2022 00:20:37 +0000 (18:20 -0600)]
src/lxc/meson.build: fix the static library path

Since switching to meson, liblxc.a is being shipped as liblxc_static.a.
Change it back to liblxc.a.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
(cherry picked from commit 64eb31d02d4933ad414239130df3dff45a0f6f91)

21 months agoMerge pull request #4215 from cyphar/lxc5.x-opensuse-build
Christian Brauner [Tue, 22 Nov 2022 07:10:46 +0000 (08:10 +0100)]
Merge pull request #4215 from cyphar/lxc5.x-opensuse-build

[lxc-5.0.z] build: fix build issues on openSUSE

22 months agobuild: drop build-time systemd dependency
Aleksa Sarai [Fri, 28 Oct 2022 01:58:10 +0000 (12:58 +1100)]
build: drop build-time systemd dependency

On openSUSE, our packages are build in the Open Build Service which does
not have a proper systemd installation that you can query to get the
systemdunitdir.

The simplest solution is to re-add the ability to explicitly set the
systemdunitdir (as was previously possible with the autotools build
system in pre-5.0 LXC).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
22 months agobuild: only build init.lxc.static if libcap is statically linkable
Aleksa Sarai [Fri, 28 Oct 2022 01:44:39 +0000 (12:44 +1100)]
build: only build init.lxc.static if libcap is statically linkable

Without setting this, the default build will fail if you don't have the
static libcap library installed (on openSUSE this is packaged separately
to libcap-devel).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
22 months agobuild: fix handling of dependancies to fix build on openSUSE
Aleksa Sarai [Fri, 28 Oct 2022 01:38:20 +0000 (12:38 +1100)]
build: fix handling of dependancies to fix build on openSUSE

Among other things, openSUSE places seccomp.h inside a non-default
include directory (/usr/include/seccomp/seccomp.h) which revealed
several issues with how dependencies were being handled previously.

The most notable issue is that the include cflags of our build
dependencies were not being provided to the recipes for static
executables (yet they still expected access to the dependency headers).

This also involved a minor cleanup of how these dependencies are
collected, and added liburing to the set of private pkg-config libs
(which I assume was an oversight?).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
22 months agocgroups: fix -Waddress warning
Aleksa Sarai [Fri, 28 Oct 2022 01:27:57 +0000 (12:27 +1100)]
cgroups: fix -Waddress warning

While in principle the pointer could overflow, GCC 12 considers this to
not be possible and issues the following warning:

  ../src/lxc/cgroups/cgfsng.c: In function ‘__cgfsng_delegate_controllers’:
  ../src/lxc/cgroups/cgfsng.c:3306:21: warning: the comparison will always evaluate as ‘true’ for the pointer operand in ‘it + 8’ must not be NULL [-Waddress]
   3306 |                 if ((it + 1) && *(it + 1))
        |                     ^

This removes the only build warning triggered when building on openSUSE.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
22 months agobuild: detect sys/pidfd.h availability
Christian Brauner [Tue, 9 Aug 2022 14:27:40 +0000 (16:27 +0200)]
build: detect sys/pidfd.h availability

Fixes: #4176
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
22 months agobuild: detect where struct mount_attr is declared
Christian Brauner [Tue, 9 Aug 2022 14:14:25 +0000 (16:14 +0200)]
build: detect where struct mount_attr is declared

Fixes: #4176
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
22 months agomeson.build: allow explicit distrosysconfdir
Đoàn Trần Công Danh [Tue, 9 Aug 2022 15:24:09 +0000 (22:24 +0700)]
meson.build: allow explicit distrosysconfdir

Allows either:

- Build inside minimal-and-clean chroot with neither
  /etc/sysconfig nor /etc/default available.
- Cross Compile lxc from foreign distro,
  let's say host distro uses /etc/sysconfig and build distro
  uses /etc/default and vice versus.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
2 years agoRelease LXC 5.0.1
Stéphane Graber [Thu, 28 Jul 2022 04:20:41 +0000 (00:20 -0400)]
Release LXC 5.0.1

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2 years agoREADME: update security mails
Christian Brauner [Tue, 19 Jul 2022 08:29:41 +0000 (10:29 +0200)]
README: update security mails

Reported-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
2 years agomeson.build: fix build without stack-protector
Fabrice Fontaine [Thu, 14 Jul 2022 15:49:54 +0000 (17:49 +0200)]
meson.build: fix build without stack-protector

Move -fstack-protector-strong from possible_cc_flags to
possible_link_flags to avoid a build failure on toolchains without ssp

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2 years agomeson.build: fix build with -Dcapabilities=false
Fabrice Fontaine [Thu, 14 Jul 2022 15:03:40 +0000 (17:03 +0200)]
meson.build: fix build with -Dcapabilities=false

Define libcap_static to an empty array to avoid the following build
failure with -Dcapabilities=false:

output/build/lxc-5.0.0/src/lxc/cmd/meson.build:64:4: ERROR: Unknown variable "libcap_static".

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2 years agosrc/lxc/log.h: fix STRERROR_R_CHAR_P
Fabrice Fontaine [Thu, 14 Jul 2022 10:31:21 +0000 (12:31 +0200)]
src/lxc/log.h: fix STRERROR_R_CHAR_P

STRERROR_R_CHAR_P is always defined to 0 or 1 depending on the value of
have_func_strerror_r_char_p in meson.build so replace #ifdef by #if to
avoid a redefinition build failure if char *strerror_r is not defined

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2 years agomeson: add remaining still-in-use config checks
Wolfgang Bumiller [Mon, 4 Jul 2022 09:27:14 +0000 (11:27 +0200)]
meson: add remaining still-in-use config checks

These are all still in use in the code but have not been
added to meson.build when switching over from autoconf.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2 years agoStore mount options in correct variable
srd424 [Sun, 3 Jul 2022 17:18:23 +0000 (18:18 +0100)]
Store mount options in correct variable

This was exposed by the fix in the previous commit.

Signed-off-by: srd424 <srd424@users.noreply.github.com>
2 years agoFix off-by-one error constructing mount options
srd424 [Sun, 3 Jul 2022 09:21:30 +0000 (10:21 +0100)]
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 <srd424@users.noreply.github.com>
2 years agoadd check for statvfs
Wolfgang Bumiller [Fri, 1 Jul 2022 09:09:15 +0000 (11:09 +0200)]
add check for statvfs

we use HAVE_STATVFS in the code but with meson the check got
lost causing mount_entry to fail to remount some things such
as a bind mount of /dev/fuse via

    lxc.mount.entry = /dev/fuse dev/fuse none bind,create=file 0 0

which would cause the following log messages:

    DEBUG    conf - ../src/lxc/conf.c:mount_entry:2416 - Remounting "/dev/fuse" on "/usr/lib/x86_64-linux-gnu/lxc/rootfs/dev/fuse" to respect bind or remount options
    ERROR    conf - ../src/lxc/conf.c:mount_entry:2459 - Operation not permitted - Failed to mount "/dev/fuse" on "/usr/lib/x86_64-linux-gnu/lxc/rootfs/dev/fuse"

note that the `Flags for ... were ...` line is not showing
up there, which depends on HAVE_STATVFS

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2 years agostart: fix namespace sharing
Christian Brauner [Fri, 1 Jul 2022 08:12:45 +0000 (10:12 +0200)]
start: fix namespace sharing

Fixes: #4134
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
2 years agoconf: fix append_ttyname()
Christian Brauner [Thu, 30 Jun 2022 10:48:01 +0000 (12:48 +0200)]
conf: fix append_ttyname()

We appended container_tty= and then used setenv(container_tty, ...)
resulting int container_tty=container_tty=.

Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>