2
0
mirror of git://github.com/lxc/lxc synced 2025-08-31 01:29:33 +00:00
Commit Graph

10509 Commits

Author SHA1 Message Date
Christian Brauner
0a9531960a execute: ensure parent is notified about child exec and close all unneeded fds
lxc_container_init() creates the container payload process as it's child
so lxc_container_init() itself never really exits and thus the parent
isn't notified about the child exec'ing since the sync file descriptor
is never closed. Make sure it's closed to notify the parent about the
child's exec.

In addition we're currently leaking all file descriptors associated with
the handler into the stub init. Make sure that all file descriptors
other than stderr are closed.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-01 17:13:46 +02:00
Christian Brauner
0089d71762 network: log network devices while sending
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-01 17:13:45 +02:00
Christian Brauner
91ee6c8bfe initutils: use vfork() in lxc_container_init()
We can let the child finish calling exec before continuing in the
parent.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-07-01 17:13:43 +02:00
Tycho Andersen
a429519676 execute: don't exec init, call it
Instead of having a statically linked init that we put on the host fs
somewhere via packaging, have to either bind mount in or detect fexecve()
functionality, let's just call it as a library function. This way we don't
have to do any of that.

This also fixes up a bunch of conditions from:

if (quiet)
    fprintf(stderr, "log message");

to

if (!quiet)
    fprintf(stderr, "log message");

:)

and it drops all the code for fexecve() detection and bind mounting our
init in, since we no longer need any of that.

A couple other thoughts:

* I left the lxc-init binary in since we ship it, so someone could be using
  it outside of the internal uses.
* There are lots of unused arguments to lxc-init (including presumably
  --quiet, since nobody noticed the above); those may be part of the API
  though and so we don't want to drop them.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
2021-07-01 17:13:40 +02:00
Tomasz Blaszczak
7cb9565c7f When an item is added to an array, then the array is realloc()ed (to size+1),
and the item is copied (strdup()) to the array.
Thus, when an item is removed from an array, memory allocated for that item
should be freed, successive items should be left-shifted and the array
realloc()ed again (size-1).

Additional changes:
- If strdup() fails in add_to_array(), then an array should be
  realloc()ed again to original size.
- Initialize an array in list_all_containers().

Signed-off-by: Tomasz Blaszczak <tomasz.blaszczak@consult.red>
2021-06-29 09:39:01 +02:00
Christian Brauner
13facae3d7 cgroups: verify that hierarchies are non-empty
Fixes: #3881
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 09:38:59 +02:00
Stéphane Graber
3efa0cf345 lxc-download: Switch GPG server
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2021-06-29 09:38:58 +02:00
Tomasz Blaszczak
7c2e8e16be Resize array in remove_from_array() and fix a crash
When an item is added to an array, then the array is realloc()ed (to size+1),
and the item is copied (strdup()) to the array.
Thus, when an item is removed from an array, allocated memory pointed by
the item (not the item itself) should be freed, successive items should
be left-shifted and the array realloc()ed again (size-1).

Additional changes:
- Initialize an array in list_all_containers().

Signed-off-by: Tomasz Blaszczak <tomasz.blaszczak@consult.red>
2021-06-29 09:38:57 +02:00
Tomasz Blaszczak
dfdf49268e When an item is added to an array, then the array is realloc()ed (to size+1),
and the item is copied (strdup()) to the array.
Thus, when an item is removed from an array, memory allocated for that item
should be freed, successive items should be left-shifted and the array
realloc()ed again (size-1).

Additional changes:
- If strdup() fails in add_to_array(), then an array should be
  realloc()ed again to original size.
- Initialize an array in list_all_containers().

Signed-off-by: Tomasz Blaszczak <tomasz.blaszczak@consult.red>
2021-06-29 09:38:56 +02:00
Christian Brauner
b88eabf0bc cgroups: use stable ordering for co-mounted v1 controllers
Fixes: #3703
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 09:38:52 +02:00
Christian Brauner
b9bf2e27fe tree-wide: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 09:38:51 +02:00
Christian Brauner
111277a543 tree-wide: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 09:38:50 +02:00
Christian Brauner
53dfebff46 tree-wide: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 09:38:49 +02:00
Christian Brauner
b519ca6e78 tree-wide: remove problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 09:38:48 +02:00
Christian Brauner
4d376816e3 seccomp: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 09:38:48 +02:00
Christian Brauner
fd8222a011 common.conf: replace problematic terminology
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-29 09:38:45 +02:00
Ruben Jenster
ae3fb5405b Add support for LISTEN_FDS environment variable.
The LISTEN_FDS environment variable defines the number of
file descriptors that should be inherited by the container,
in addition to stdio.
The LISTEN_FDS environment variable is defined in the OCI spec
and used to support socket activation.

Refs #3845

Signed-off-by: Ruben Jenster <r.jenster@drachenfels.de>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 14:23:16 +02:00
LiFeng
176a249d21 string utils: Make sure don't return uninitialized memory.
The function lxc_string_split_quoted and lxc_string_split_and_trim use
realloc to reduce the memory. But the result may be NULL, the the
returned memory will be uninitialized

Signed-off-by: LiFeng <lifeng68@huawei.com>
2021-06-14 14:23:12 +02:00
Christian Brauner
19b18b6970 confile: backport lxc.init.groups config key
This is needed for lxcri.

Fixes: #3862
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 12:10:46 +02:00
Christian Brauner
b781fb3a31 api_extensions: introduce idmapped_mounts_v2 api extension
This indicates that LXC supports idmapping the rootfs and
idmapped lxc.mount.entry entries.

Link: https://github.com/lxc/lxd/issues/8870
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 12:02:28 +02:00
Christian Brauner
8c89dd0cfd tools/lxc_autostart: fix failed count
Don't include skipped containers in the failed count.

Fixes: #3857
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-14 12:02:22 +02:00
Christian Brauner
ef68581ce4 lsm/apparmor: actually report an error when we fail to wire AppArmor profile
Link: https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/1931064
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-08 14:49:08 +02:00
Christian Brauner
88a5ffc936 lxc: add lpthread to lxc.pc
Fixes: #3853
Suggested-by: Tycho Andersen <tycho@tycho.pizza>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-06-08 14:49:05 +02:00
Pablo Correa Gómez
71def1ad00 Update lxc-net to support nftables
Closes #3093
Closes #3602

Add support for nftables firewall rules if `nft` command line
interface is available in the system

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
2021-06-08 14:49:01 +02:00
Christian Brauner
d41b0293f5 network: please broken compilers
Some users report that compilation fails because of reports that this
variable can be used uninitialized. Initialize it to silence the
compiler.

Fixes: https://github.com/lxc/lxc/issues/3850
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:39 +02:00
Stéphane Graber
7cf81ec6f1 README: Update IRC
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2021-05-28 12:48:38 +02:00
Christian Brauner
93be53b39d start: simplify startup synchronization
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:37 +02:00
Christian Brauner
5b5c4e0c9c start: reorder START_SYNC_POST_CONFIGURE
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:36 +02:00
Christian Brauner
837f9fe51e start: use barrier instead of wake/wait pair
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:35 +02:00
Christian Brauner
87dcc8d414 conf: use explicit signage in bit field
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:34 +02:00
Christian Brauner
2765b5c442 conf: move file descriptor synchronization with parent into single function
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:33 +02:00
Christian Brauner
e8e538a54d conf: move file descriptor synchronization with child into single function
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:32 +02:00
Christian Brauner
1c662b823f cgroups: rework check whether legacy hierarchy is writable
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:31 +02:00
Christian Brauner
d4034c931f conf: fix mount option parsing
Fixes: Coverity 1484906
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:30 +02:00
Christian Brauner
08eab8c005 confile: free mount data
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:28 +02:00
Christian Brauner
ceb0675657 conf: add sequence when setting up idmapped mounts
Make sure we catch any weird behavior.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:27 +02:00
Christian Brauner
bf310548a0 conf: support idmapped lxc.mount.entry entries
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:25 +02:00
Wei Mingzhi
80cb4de65e Skip rootfs pinning for read-only file system.
Signed-off-by: Wei Mingzhi <weimingzhi@baidu.com>
2021-05-28 12:48:22 +02:00
Christian Brauner
835721f9e5 conf: rename struct mount_opt flag member s/flag/legacy_flag/
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:20 +02:00
Christian Brauner
407dcc8a15 tree-wide: s/parse_mntopts/parse_mntopts_legacy/
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-28 12:48:16 +02:00
Christian Brauner
d64c225f26 start: move idmapped mount setup later
At the prior location we we're placed between sending and receiving
networking information over the data socket causing the startup to fail.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-17 11:05:40 +02:00
Christian Brauner
e9aab3d42d conf: tweak rootfs handling
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-12 16:17:17 +02:00
Christian Brauner
a96aa89b08 conf: don't unmount procfs and sysfs
Fixes: #3838
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-12 16:17:16 +02:00
Christian Brauner
3628ccc5f2 conf: allow xdev when setting up /dev
Fixes: #3838
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-12 16:17:15 +02:00
Christian Brauner
f002379124 cgroups: clean up cgroup_ops on initialization error
Fixes: #3836
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-12 16:17:12 +02:00
Christian Brauner
96c3018762 oss-fuzz: add basic cgroup_init()/cgroup_exit() fuzzing
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-11 09:07:10 +02:00
Stéphane Graber
f8764e8a67 Merge pull request #3835 from brauner/2021-05-10.fixes.apparmor.stable-4.0
confile: convert AppArmor and SELinux confile parsing from errors to …
2021-05-10 12:12:33 -04:00
Christian Brauner
05cd29daad confile: convert AppArmor and SELinux confile parsing from errors to warnings
Fixes: https://github.com/lxc/lxc/issues/3765#issuecomment-836792820
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-10 17:40:39 +02:00
Christian Brauner
aedfce1fc1 tests: fix lxc-test-arch-parse for make dist
Fixes: https://jenkins.linuxcontainers.org/job/lxc-build-tarballs/2762/console
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-10 17:28:29 +02:00
Christian Brauner
7d24ac5a58 tests: add tests for supported architectures
Ensure that we detect all supported architectures and don't regress
recognizing them.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-05-10 13:02:43 +02:00