Commit Graph

11729 Commits

Author SHA1 Message Date
Christian Brauner
a8e1070c61
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>
2023-01-04 16:45:03 +01:00
Christian Brauner
6564e6ccb2
Merge pull request #4248 from stgraber/master
Tweak checkconfig output
2023-01-04 00:08:24 +01:00
Stéphane Graber
c27ea96f7f
checkconfig: Fix filesystem capability check
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-01-03 18:02:55 -05:00
Stéphane Graber
3f361da618
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>
2023-01-03 18:02:54 -05:00
Stéphane Graber
3ab04999d8
checkconfig: Tweak layout
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-01-03 18:02:54 -05:00
Stéphane Graber
e027ca7119
checkconfig: Hide version if no lxc-start
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-01-03 18:02:53 -05:00
Stéphane Graber
914fec51b0
checkconfig: Fix mixed tabs/spaces
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-01-03 18:02:52 -05:00
Fabrice Fontaine
70b176b0d1 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>
2022-12-29 14:47:50 +01:00
Stéphane Graber
0b83d71c2c
Merge pull request #4242 from mihalicyn/fixes_after_coverity
Fixes after coverity scan
2022-12-12 11:39:17 -05:00
Alexander Mikhalitsyn
42b22da6d1 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>
2022-12-12 12:28:31 +01:00
Alexander Mikhalitsyn
0072919ddc 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>
2022-12-12 11:26:21 +01:00
Alexander Mikhalitsyn
62b94d3ec3 cgroups: check snprintf retval in unpriv_systemd_create_scope
Reported-by: coverity (CID #1517315)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2022-12-12 10:35:21 +01:00
Alexander Mikhalitsyn
93d545e378 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>
2022-12-12 10:35:02 +01:00
Alexander Mikhalitsyn
f8aa61f97f 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>
2022-12-12 10:34:18 +01:00
Alexander Mikhalitsyn
6ea4a6c06b apparmor: properly check lxc_strmmap ret value
Reported-by: coverity (CID #1517320)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2022-12-12 10:33:12 +01:00
Christian Brauner
667292ad89
Merge pull request #4239 from mihalicyn/github_coverity_fix
github: fix coverity (add libpam-dev)
2022-12-08 22:01:48 +01:00
Alexander Mikhalitsyn
b37cce95b6 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>
2022-12-08 16:12:14 +01:00
Stéphane Graber
e85c649c25
Merge pull request #4236 from mihalicyn/github_check_fixes
github: fix coverity build
2022-12-08 08:32:15 -05:00
Serge Hallyn
6ab3551615
Merge pull request #4209 from DuratarskeyK/master
Simplify IN_SET macro considerably
2022-12-07 08:17:55 -06:00
Alexander Mikhalitsyn
a8dcf88d05 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>
2022-12-07 12:09:33 +01:00
Stéphane Graber
b16e4ea85b
Merge pull request #4229 from brauner/rootfs.propagate.shared
conf: create separate peer group for container's root
2022-11-29 17:11:29 -05:00
Christian Brauner
7e73934130
conf: ensure mount tunnel is a dependent mount
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
2022-11-29 21:36:43 +01:00
Christian Brauner
01ae6d4713
apparmor: allow shared mounts in start-container.in
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
2022-11-29 20:58:14 +01:00
Christian Brauner
81d94a4eec
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>
2022-11-24 17:26:27 +01:00
Stéphane Graber
d493695e30
Merge pull request #4230 from brauner/kill.lgtm
README: remove lgtm
2022-11-24 10:16:29 -05:00
Christian Brauner
07670dacdd
Merge pull request #4231 from brauner/cgroup.removal
cgroups: fix cgroup removal
2022-11-24 14:00:40 +01:00
Christian Brauner
68020412c2
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>
2022-11-24 12:45:52 +01:00
Christian Brauner
27f69d45bf
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>
2022-11-24 12:45:32 +01:00
Christian Brauner
1029c2a06e
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>
2022-11-24 09:46:24 +01:00
Christian Brauner
fa56702e6c
Merge pull request #4228 from rchincha/issue-4223
meson.build: strip newline for variable assignments
2022-11-24 00:26:34 +01:00
Ramkumar Chinchani
dcf85308cb
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 60e292c64a
Fixes issue #4223

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
2022-11-23 19:57:21 +00:00
Christian Brauner
60e292c64a
Merge pull request #4226 from rchincha/issue-4223
meson.build: strip newlines from git output
2022-11-23 09:14:50 +01:00
Ramkumar Chinchani
8aac588663
meson.build: strip newlines from git output
Fixes issue #4223

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
2022-11-22 18:20:19 +00:00
Christian Brauner
cafced2a3f
Merge pull request #4214 from cyphar/opensuse-build
build: fix build issues on openSUSE
2022-11-22 16:07:41 +01:00
Christian Brauner
cf9474fab6
Merge pull request #4222 from gibmat/fix-ia64-build
tests: lxc-test-reboot: Fix build on ia64
2022-11-22 12:32:49 +01:00
Mathias Gibbens
16c6ff2269
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>
2022-11-19 15:14:47 +00:00
Stéphane Graber
8a49476094
Merge pull request #4221 from hallyn/2022-11-11/staticlib
src/lxc/meson.build: fix the static library path
2022-11-12 12:14:30 -05:00
Serge Hallyn
64eb31d02d 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>
2022-11-11 18:20:37 -06:00
Aleksa Sarai
c6c705bfa3
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>
2022-10-31 00:07:56 +11:00
Aleksa Sarai
f321cd610a
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: cbabe8abf1 ("build: check for FS_CONFIG_* header symbol in sys/mount.h")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2022-10-31 00:07:55 +11:00
Aleksa Sarai
5aff4ea371
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>
2022-10-31 00:07:55 +11:00
Aleksa Sarai
c1f87c8113
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>
2022-10-31 00:07:54 +11:00
Aleksa Sarai
bc318926d7
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>
2022-10-31 00:07:53 +11:00
HisShadow
4deaa28c04 Unroll IN_SET since the max usage is 2 elements check
Signed-off-by: HisShadow <shadowpilot34@gmail.com>
2022-10-25 20:44:16 +03:00
Christian Brauner
fbed9bb759
Merge pull request #4204 from ajmalsiddiqui/master
lxc-attach: Fix lost return codes of spawned processes that are killed
2022-10-19 13:01:05 +02:00
Christian Brauner
bff4223cd8
Merge pull request #4210 from Cypresslin/lxc-destroy-help-force
tools: lxc-destroy: update help message for --force
2022-10-19 12:59:51 +02:00
Christian Brauner
a5d2343996
Merge pull request #4211 from Cypresslin/lxc-test-checkpoint-restore-cleanup
tests: lxc-test-checkpoint-restore: use trap to do cleanup
2022-10-19 12:59:20 +02:00
Po-Hsu Lin
73fd9bf558 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>
2022-10-19 14:20:39 +08:00
Po-Hsu Lin
8480c56a45 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>
2022-10-19 12:57:29 +08:00
Stéphane Graber
37b5f00454
Merge pull request #4208 from brauner/2022-10-13.oss-fuzz.fixes
build: add libsystemd to oss fuzz dependencies
2022-10-13 13:25:20 -04:00